summaryrefslogtreecommitdiffstats
path: root/Tests/RunCMake/try_run
diff options
context:
space:
mode:
authorscivision <scivision@users.noreply.github.com>2023-10-12 17:49:15 (GMT)
committerBrad King <brad.king@kitware.com>2023-10-16 15:30:17 (GMT)
commit0f37000304fc2cbf3945a2a2be9f969be3eef62d (patch)
tree2e7f5b54ef0bbf1037f071b471cab7064c0d1615 /Tests/RunCMake/try_run
parentdc0dbffb0ffbfa7713b2b96994c453a90a99e209 (diff)
downloadCMake-0f37000304fc2cbf3945a2a2be9f969be3eef62d.zip
CMake-0f37000304fc2cbf3945a2a2be9f969be3eef62d.tar.gz
CMake-0f37000304fc2cbf3945a2a2be9f969be3eef62d.tar.bz2
try_{compile,run}: add LINKER_LANGUAGE option
Fixes: #25326
Diffstat (limited to 'Tests/RunCMake/try_run')
-rw-r--r--Tests/RunCMake/try_run/LinkerLanguage.cmake29
-rw-r--r--Tests/RunCMake/try_run/RunCMakeTest.cmake10
-rw-r--r--Tests/RunCMake/try_run/lib.cxx4
-rw-r--r--Tests/RunCMake/try_run/main.f9012
4 files changed, 55 insertions, 0 deletions
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