cmake: Set build type before package find

Packages may use the build type to decide whether to look for
release or debug binaries. It is therefore cruicial to set the
build type before searching any package.
This commit is contained in:
Lars Amsel 2025-01-27 11:57:40 +01:00 committed by Jörg Hofrichter
parent fcf6f4c5f4
commit 308126a479

View File

@ -5,15 +5,31 @@
# SPDX-License-Identifier: GPL-3.0-or-later
#
########################################################################
# Project setup
########################################################################
# NOTE! If you change the version in the following line, also change
# UHD_CMAKE_MIN_VERSION in UHDMinDepVersions. (This won't take a variable).
cmake_minimum_required(VERSION 3.12)
if(POLICY CMP0048)
cmake_policy(SET CMP0048 NEW) # Suppress Version warnings
endif(POLICY CMP0048)
########################################################################
# Select cmake build type
# Use release build type by default to get optimization flags
# Do this before project setup to ensure dependend libraries use
# the correct build type for library search.
########################################################################
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
message(STATUS "Build type not specified: defaulting to release.")
endif(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}" CACHE STRING "")
#force UHD_RELEASE_MODE to be a string for cmake-gui
set(UHD_RELEASE_MODE "${UHD_RELEASE_MODE}" CACHE STRING "UHD Release Mode")
########################################################################
# Project setup
########################################################################
project(UHD CXX C)
enable_testing()
@ -220,16 +236,6 @@ macro(UHD_ADD_OPTIONAL_CXX_COMPILER_FLAG flag have)
endif(${have})
endmacro(UHD_ADD_OPTIONAL_CXX_COMPILER_FLAG)
#select the release build type by default to get optimization flags
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
message(STATUS "Build type not specified: defaulting to release.")
endif(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}" CACHE STRING "")
#force UHD_RELEASE_MODE to be a string for cmake-gui
set(UHD_RELEASE_MODE "${UHD_RELEASE_MODE}" CACHE STRING "UHD Release Mode")
if(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU" OR
${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
if(STRIP_BINARIES)