summaryrefslogtreecommitdiffstats
path: root/Tests/FortranC
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2009-12-14 17:36:25 (GMT)
committerBrad King <brad.king@kitware.com>2009-12-14 17:36:25 (GMT)
commit555fcbd2e2e5cafbb7cbf55b88093cc8f73a8009 (patch)
tree2ab8a9c2032c7ce1a9c27b31570e02cfd8b69af2 /Tests/FortranC
parent126c93cddae95f46060f6d88af9c92dc6297f88d (diff)
downloadCMake-555fcbd2e2e5cafbb7cbf55b88093cc8f73a8009.zip
CMake-555fcbd2e2e5cafbb7cbf55b88093cc8f73a8009.tar.gz
CMake-555fcbd2e2e5cafbb7cbf55b88093cc8f73a8009.tar.bz2
Test FortranCInterface flag propagation
We create test FortranC.Flags to try passing per-language flags from a project into its FortranCInterface detect/verify checks. We wrap the compilers with scripts that enforce presence of expected flags.
Diffstat (limited to 'Tests/FortranC')
-rw-r--r--Tests/FortranC/CMakeLists.txt25
-rw-r--r--Tests/FortranC/Flags.cmake.in29
-rwxr-xr-xTests/FortranC/test_opt.sh.in18
3 files changed, 72 insertions, 0 deletions
diff --git a/Tests/FortranC/CMakeLists.txt b/Tests/FortranC/CMakeLists.txt
new file mode 100644
index 0000000..e4e8ca1
--- /dev/null
+++ b/Tests/FortranC/CMakeLists.txt
@@ -0,0 +1,25 @@
+cmake_minimum_required(VERSION 2.8)
+project(FortranC C Fortran)
+
+# Skip this test for compilers not known to be compatible.
+if(NOT ("${CMAKE_C_COMPILER_ID}" STREQUAL "${CMAKE_Fortran_COMPILER_ID}" OR
+ "${CMAKE_C_COMPILER_ID}-${CMAKE_Fortran_COMPILER_ID}" MATCHES "^(MSVC-Intel)$"))
+ message(STATUS "${CMAKE_C_COMPILER_ID} C and ${CMAKE_Fortran_COMPILER_ID} Fortran not known to be compatible!")
+ return()
+endif()
+
+# Wipe out all FortranCInterface information to ensure it re-runs.
+file(REMOVE_RECURSE ${CMAKE_BINARY_DIR}/CMakeFiles/FortranCInterface)
+
+if(FortranC_TEST_FLAGS)
+ # Test whether FortranCInterface checks see C flags.
+ set(ENV{TEST_OPT_CC} "--test-opt-cc")
+ set(CMAKE_C_FLAGS "$ENV{TEST_OPT_CC}")
+
+ # Test whether FortranCInterface checks see Fortran flags.
+ set(ENV{TEST_OPT_FC} "--test-opt-fc")
+ set(CMAKE_Fortran_FLAGS "$ENV{TEST_OPT_FC}")
+endif()
+
+include(FortranCInterface)
+FortranCInterface_VERIFY()
diff --git a/Tests/FortranC/Flags.cmake.in b/Tests/FortranC/Flags.cmake.in
new file mode 100644
index 0000000..8bf0c5c
--- /dev/null
+++ b/Tests/FortranC/Flags.cmake.in
@@ -0,0 +1,29 @@
+set(src "@CMAKE_CURRENT_SOURCE_DIR@/FortranC")
+set(bld "@CMAKE_CURRENT_BINARY_DIR@/FortranC/Flags")
+
+# Create wrapper scripts for the compilers that check for expected
+# flags, remove them, and invoke the real compiler.
+set(ID "CC")
+set(COMMAND "@CMAKE_C_COMPILER@")
+configure_file("${src}/test_opt.sh.in" "${bld}/cc.sh" @ONLY)
+set(ID "FC")
+set(COMMAND "@CMAKE_Fortran_COMPILER@")
+configure_file("${src}/test_opt.sh.in" "${bld}/fc.sh" @ONLY)
+set(ID)
+set(COMMAND)
+
+set(ENV{CFLAGS})
+set(ENV{FFLAGS})
+
+execute_process(
+ WORKING_DIRECTORY "${bld}"
+ COMMAND ${CMAKE_COMMAND} "${src}" -G "@CMAKE_TEST_GENERATOR@"
+ "-DFortranC_TEST_FLAGS=1"
+ "-DCMAKE_C_COMPILER=${bld}/cc.sh"
+ "-DCMAKE_Fortran_COMPILER=${bld}/fc.sh"
+ RESULT_VARIABLE result
+ )
+
+if(NOT "${result}" STREQUAL "0")
+ message(FATAL_ERROR "Configuration failed: ${result}")
+endif()
diff --git a/Tests/FortranC/test_opt.sh.in b/Tests/FortranC/test_opt.sh.in
new file mode 100755
index 0000000..f3d93dc
--- /dev/null
+++ b/Tests/FortranC/test_opt.sh.in
@@ -0,0 +1,18 @@
+#!/bin/sh
+
+TEST_OPT_@ID@_FOUND=0
+ARGS=""
+for a in "$@"; do
+ if [ "x${TEST_OPT_@ID@}" != "x" -a "x${TEST_OPT_@ID@}" = "x$a" ]; then
+ TEST_OPT_@ID@_FOUND=1
+ else
+ ARGS="$ARGS \"$a\""
+ fi
+done
+
+if [ "x${TEST_OPT_@ID@}" != "x" -a "x${TEST_OPT_@ID@_FOUND}" != "x1" ]; then
+ echo "Not given option '${TEST_OPT_@ID@}' as expected!"
+ exit 1
+fi
+
+eval "\"@COMMAND@\"" "$ARGS"