diff options
author | Brad King <brad.king@kitware.com> | 2023-10-17 14:18:47 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2023-10-17 14:18:56 (GMT) |
commit | c672e51bd375b3fca4a22eef00ad6bcb8d4b1a10 (patch) | |
tree | 45b3ac6c9bdd8ff409867c390046652348de3c29 /Tests | |
parent | bb9a91c500c6c8ce57e57cef5b4c0fdac9b03e43 (diff) | |
parent | 0f37000304fc2cbf3945a2a2be9f969be3eef62d (diff) | |
download | CMake-c672e51bd375b3fca4a22eef00ad6bcb8d4b1a10.zip CMake-c672e51bd375b3fca4a22eef00ad6bcb8d4b1a10.tar.gz CMake-c672e51bd375b3fca4a22eef00ad6bcb8d4b1a10.tar.bz2 |
Merge topic 'try_compile-linker-language'
0f37000304 try_{compile,run}: add LINKER_LANGUAGE option
dc0dbffb0f Tests: Remove redundant policy setting from RunCMake.try_{compile,run} cases
Acked-by: Kitware Robot <kwrobot@kitware.com>
Tested-by: buildbot <buildbot@kitware.com>
Merge-request: !8871
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/RunCMake/CMakeLists.txt | 4 | ||||
-rw-r--r-- | Tests/RunCMake/try_compile/LinkOptions.cmake | 3 | ||||
-rw-r--r-- | Tests/RunCMake/try_run/LinkOptions.cmake | 3 | ||||
-rw-r--r-- | Tests/RunCMake/try_run/LinkerLanguage.cmake | 29 | ||||
-rw-r--r-- | Tests/RunCMake/try_run/RunCMakeTest.cmake | 10 | ||||
-rw-r--r-- | Tests/RunCMake/try_run/lib.cxx | 4 | ||||
-rw-r--r-- | Tests/RunCMake/try_run/main.f90 | 12 |
7 files changed, 58 insertions, 7 deletions
diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index 4f80015..5a23b8b 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -583,7 +583,9 @@ endfunction() add_RunCMake_test_try_compile() add_RunCMake_test(try_run -DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME} - -DCMAKE_C_COMPILER_ID=${CMAKE_C_COMPILER_ID}) + -DCMAKE_C_COMPILER_ID=${CMAKE_C_COMPILER_ID} + -DCMAKE_CXX_COMPILER_ID=${CMAKE_CXX_COMPILER_ID} + -DCMAKE_Fortran_COMPILER_ID=${CMAKE_Fortran_COMPILER_ID}) add_RunCMake_test(set) add_RunCMake_test(variable_watch) add_RunCMake_test(while) diff --git a/Tests/RunCMake/try_compile/LinkOptions.cmake b/Tests/RunCMake/try_compile/LinkOptions.cmake index 7fae35c..45cbedf 100644 --- a/Tests/RunCMake/try_compile/LinkOptions.cmake +++ b/Tests/RunCMake/try_compile/LinkOptions.cmake @@ -1,8 +1,5 @@ - enable_language(C) -cmake_policy(SET CMP0054 NEW) - set (lib_name "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}lib${CMAKE_STATIC_LIBRARY_SUFFIX}") if (CMAKE_SYSTEM_NAME STREQUAL "Windows") if (RunCMake_C_COMPILER_ID STREQUAL "MSVC" diff --git a/Tests/RunCMake/try_run/LinkOptions.cmake b/Tests/RunCMake/try_run/LinkOptions.cmake index b9a87f3..b19141c 100644 --- a/Tests/RunCMake/try_run/LinkOptions.cmake +++ b/Tests/RunCMake/try_run/LinkOptions.cmake @@ -1,8 +1,5 @@ - enable_language(C) -cmake_policy(SET CMP0054 NEW) - set (lib_name "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}lib${CMAKE_STATIC_LIBRARY_SUFFIX}") if (CMAKE_SYSTEM_NAME STREQUAL "Windows") if (RunCMake_C_COMPILER_ID STREQUAL "MSVC" diff --git a/Tests/RunCMake/try_run/LinkerLanguage.cmake b/Tests/RunCMake/try_run/LinkerLanguage.cmake new file mode 100644 index 0000000..137e198 --- /dev/null +++ b/Tests/RunCMake/try_run/LinkerLanguage.cmake @@ -0,0 +1,29 @@ +enable_language(CXX) +enable_language(Fortran) + +set (lib_name "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}lib${CMAKE_STATIC_LIBRARY_SUFFIX}") +if (CMAKE_SYSTEM_NAME STREQUAL "Windows") + if (CMAKE_SIZEOF_VOID_P EQUAL 4) + set (undef_flag -u _func) + else() + set (undef_flag -u func) + endif() +elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin") + set (undef_flag -u _func) +else() + set (undef_flag -u func) +endif() + +set(CMAKE_TRY_COMPILE_TARGET_TYPE EXECUTABLE) +try_run(run_result compile_result + SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/lib.cxx ${CMAKE_CURRENT_SOURCE_DIR}/main.f90 + COMPILE_OUTPUT_VARIABLE compile_out + RUN_OUTPUT_VARIABLE run_out + LINKER_LANGUAGE Fortran) + +if(NOT compile_result) + message(FATAL_ERROR "try_run(... LINKER_LANGUAGE Fortran) compilation failed:\n${compile_out}") +endif() +if(run_result STREQUAL "FAILED_TO_RUN") + message(FATAL_ERROR "try_run(... LINKER_LANGUAGE Fortran) execution failed:\n${run_out}") +endif() diff --git a/Tests/RunCMake/try_run/RunCMakeTest.cmake b/Tests/RunCMake/try_run/RunCMakeTest.cmake index 62e3caf..bd7cd9b 100644 --- a/Tests/RunCMake/try_run/RunCMakeTest.cmake +++ b/Tests/RunCMake/try_run/RunCMakeTest.cmake @@ -19,3 +19,13 @@ if (CMAKE_SYSTEM_NAME MATCHES "^(Linux|Darwin|Windows)$" AND run_cmake(LinkOptions) unset (RunCMake_TEST_OPTIONS) endif() + +if (CMAKE_SYSTEM_NAME MATCHES "^(Linux|Darwin|Windows)$" AND + CMAKE_CXX_COMPILER_ID MATCHES "^(GNU|Clang|AppleClang)$" AND + CMAKE_Fortran_COMPILER_ID MATCHES "^(GNU)$") + set (RunCMake_TEST_OPTIONS + -DRunCMake_CXX_COMPILER_ID=${CMAKE_CXX_COMPILER_ID} + -DRunCMake_Fortran_COMPILER_ID=${CMAKE_Fortran_COMPILER_ID}) + run_cmake(LinkerLanguage) + unset (RunCMake_TEST_OPTIONS) +endif() diff --git a/Tests/RunCMake/try_run/lib.cxx b/Tests/RunCMake/try_run/lib.cxx new file mode 100644 index 0000000..b01a075 --- /dev/null +++ b/Tests/RunCMake/try_run/lib.cxx @@ -0,0 +1,4 @@ + +extern "C" void func() +{ +} diff --git a/Tests/RunCMake/try_run/main.f90 b/Tests/RunCMake/try_run/main.f90 new file mode 100644 index 0000000..29b933e --- /dev/null +++ b/Tests/RunCMake/try_run/main.f90 @@ -0,0 +1,12 @@ +program main + +implicit none + +interface +subroutine func() bind(C) +end subroutine +end interface + +call func() + +end program |