-
Notifications
You must be signed in to change notification settings - Fork 0
/
AddCompileTimeTest.cmake
35 lines (31 loc) · 1.47 KB
/
AddCompileTimeTest.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
macro(add_compile_time_test name path base ext)
set(compiler ${CMAKE_Fortran_COMPILER_ID})
if (CMAKE_VERSION VERSION_GREATER 3.2.3)
# Detect Fortran compiler version directly
set(compiler_version "${CMAKE_Fortran_COMPILER_VERSION}")
else()
# Use the C compiler version as a proxy for the Fortran compiler version (won't work with NAG)
set(compiler_version "${CMAKE_C_COMPILER_VERSION}")
endif()
set(executable base)
# Copy the source to the binary tree
configure_file(
${CMAKE_SOURCE_DIR}/${path}/${base}.${ext}
${CMAKE_BINARY_DIR}/${path}/${base}.${ext}
COPYONLY
)
# Write a script to compile the code at test time instead of at build time so
# CMake doesn't bail during the build process because of the compilation failure
set(bug_harness "${CMAKE_BINARY_DIR}/staging/test-${base}.sh")
install(
FILES "${bug_harness}"
PERMISSIONS WORLD_EXECUTE WORLD_READ WORLD_WRITE OWNER_EXECUTE OWNER_READ OWNER_WRITE GROUP_EXECUTE GROUP_READ GROUP_WRITE
DESTINATION ${CMAKE_BINARY_DIR}/${path}
)
file(WRITE "${bug_harness}" "#!/bin/bash\n")
file(APPEND "${bug_harness}" "cd ${CMAKE_BINARY_DIR}/${path}\n")
file(APPEND "${bug_harness}"
"$ENV{FC} ${base}.${ext} -o ${base} &> ${CMAKE_SOURCE_DIR}/${path}/${compiler}-${compiler_version}.out\n")
add_test(NAME ${name} COMMAND "${path}/test-${base}.sh")
set_property(TEST ${name} PROPERTY PASS_REGULAR_EXPRESSION "Test passed.")
endmacro(add_compile_time_test)