]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Use try_compile in macro_check_compiler_setup.cmake 14771/head
authorDaniel Arndt <arndtd@ornl.gov>
Wed, 8 Feb 2023 21:49:11 +0000 (16:49 -0500)
committerDaniel Arndt <arndtd@ornl.gov>
Tue, 14 Feb 2023 03:36:17 +0000 (22:36 -0500)
cmake/macros/check_compiler_setup/CMakeLists.txt [new file with mode: 0644]
cmake/macros/check_compiler_setup/dummy.cpp [new file with mode: 0644]
cmake/macros/macro_check_compiler_setup.cmake

diff --git a/cmake/macros/check_compiler_setup/CMakeLists.txt b/cmake/macros/check_compiler_setup/CMakeLists.txt
new file mode 100644 (file)
index 0000000..53c61e6
--- /dev/null
@@ -0,0 +1,8 @@
+project(CheckCompilerSetup)
+cmake_minimum_required(VERSION 3.13.4)
+add_executable(CheckCompilerSetupExec dummy.cpp)
+
+target_compile_options(CheckCompilerSetupExec PRIVATE ${TEST_COMPILE_FLAGS})
+set_property(TARGET CheckCompilerSetupExec PROPERTY LINK_FLAGS "${TEST_LINK_OPTIONS}")
+target_link_libraries(CheckCompilerSetupExec ${TEST_LINK_LIBRARIES})
+
diff --git a/cmake/macros/check_compiler_setup/dummy.cpp b/cmake/macros/check_compiler_setup/dummy.cpp
new file mode 100644 (file)
index 0000000..1075f35
--- /dev/null
@@ -0,0 +1 @@
+int main(){ return 0; }
index 287366585320b06fac5c4594f82436bd90ddee28..c86045624fee4c43cb2c4685d95e8bde76744199 100644 (file)
@@ -32,6 +32,8 @@ macro(check_compiler_setup _compiler_flags_unstr _linker_flags_unstr _var)
   string(STRIP "${_compiler_flags_unstr}" _compiler_flags)
   string(STRIP "${_linker_flags_unstr}" _linker_flags)
 
+  separate_arguments(_compiler_flags)
+
   #
   # Rerun this test if flags have changed:
   #
@@ -49,13 +51,23 @@ macro(check_compiler_setup _compiler_flags_unstr _linker_flags_unstr _var)
     )
   set(CACHED_${_var}_ARGN "${ARGN}" CACHE INTERNAL "" FORCE)
 
-  set(CMAKE_REQUIRED_FLAGS "${_compiler_flags} ${_linker_flags}")
-  set(CMAKE_REQUIRED_LIBRARIES ${ARGN})
+  message(STATUS "Testing ${_var}")
 
-  CHECK_CXX_SOURCE_COMPILES("int main(){ return 0; }" ${_var})
-  reset_cmake_required()
+  try_compile(
+    ${_var}
+    ${CMAKE_CURRENT_BINARY_DIR}/check_compiler_setup/CheckCompilerSetup${_var}
+    ${CMAKE_CURRENT_SOURCE_DIR}/cmake/macros/check_compiler_setup
+    CheckCompilerSetup${_var}
+    CMAKE_FLAGS "-DTEST_COMPILE_FLAGS=${_compiler_flags}"
+                "-DTEST_LINK_OPTIONS=${_linker_flags}"
+                "-DTEST_LINK_LIBRARIES=${ARGN}"
+                "-DCMAKE_VERBOSE_MAKEFILE=ON"
+    OUTPUT_VARIABLE _output)
 
   if(${_var})
     set(${_var} TRUE CACHE INTERNAL "")
+    file(REMOVE_RECURSE ${CMAKE_CURRENT_BINARY_DIR}/check_compiler_setup/CheckCompilerSetup${var})
+  else()
+    message(STATUS "Compiler setup check for ${_var} failed with:\n${_output}")
   endif()
 endmacro()

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.