cmake: Allow overriding flags in compiler/linker flag checks#282
Conversation
|
Reading https://cmake.org/cmake/help/latest/variable/CMAKE_TRY_COMPILE_PLATFORM_VARIABLES.html, one of the first things it says is:
So I think this needs some documentation, or an explanation of what it's doing. |
All CMake checks are implemented using the Setting the non-cache |
Note that this also isn't just append flags. |
Testing this branch it seems like they are also still being ignored? The test case from #279 is still broken. |
It is possible to override only using |
This change allows overriding flags in compiler/linker flag checks.
The `APPEND_{CPP,C,CXX,LD}FLAGS` flags are now considered when checking
compiler/linker flags.
|
An explaining comment has been added per @fanquake's offline request. |
|
I've been playing with this all day and it's.. a mess. From my tests I don't see a better way to get the flags appended, so utACK that I guess :( For @fanquake's complaint, it seems this is our problem: https://gitlab.kitware.com/cmake/cmake/-/issues/19512 I'm able to get build_type flags into the try_compiles by moving the default build type selection up and setting CMAKE_TRY_COMPILE_CONFIGURATION: diff --git a/CMakeLists.txt b/CMakeLists.txt
index fe6eab74f01..27e96e5b278 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -73,6 +73,10 @@ set(CMAKE_CXX_EXTENSIONS OFF)
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/module)
+include(ProcessConfigurations)
+set_default_config(RelWithDebInfo)
+set (CMAKE_TRY_COMPILE_CONFIGURATION ${CMAKE_BUILD_TYPE})
+
#=============================
# Configurable options
#=============================
@@ -457,9 +461,6 @@ else()
)
endif()
-include(ProcessConfigurations)
-set_default_config(RelWithDebInfo)
-
# Redefine/adjust per-configuration flags.
target_compile_definitions(core_interface_debug INTERFACE
DEBUG@hebasto Mind having a look at that? Maybe it'd make sense to set that flag as part of set_default_config instead? Either way, it seems it's necessary to move the default selection up towards the beginning of the file. |
The
APPEND_{CPP,C,CXX,LD}FLAGSflags are now considered when checking compiler/linker flags.Fixes #279.