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.
This commit is contained in:
parent
126c93cdda
commit
555fcbd2e2
|
@ -1485,6 +1485,15 @@ ${CMake_BINARY_DIR}/bin/cmake -DVERSION=CVS -P ${CMake_SOURCE_DIR}/Utilities/Rel
|
||||||
--build-two-config
|
--build-two-config
|
||||||
--test-command testf)
|
--test-command testf)
|
||||||
LIST(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Fortran")
|
LIST(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Fortran")
|
||||||
|
|
||||||
|
# FortranCInterface tests.
|
||||||
|
IF(UNIX)
|
||||||
|
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/FortranC/Flags.cmake.in
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/FortranC/Flags.cmake @ONLY)
|
||||||
|
ADD_TEST(FortranC.Flags ${CMAKE_CMAKE_COMMAND} -P
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/FortranC/Flags.cmake)
|
||||||
|
LIST(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/FortranC/Flags")
|
||||||
|
ENDIF()
|
||||||
ENDIF()
|
ENDIF()
|
||||||
ENDIF()
|
ENDIF()
|
||||||
|
|
||||||
|
|
|
@ -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()
|
|
@ -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()
|
|
@ -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"
|
Loading…
Reference in New Issue