| 1 |
include(RunCMake) |
| 2 |
|
| 3 |
# Detect the compiler in use in the current environment. |
| 4 |
run_cmake(FindCompiler) |
| 5 |
include(${RunCMake_BINARY_DIR}/FindCompiler-build/cc.cmake) |
| 6 |
if(NOT CMAKE_C_COMPILER) |
| 7 |
message(FATAL_ERROR "FindCompiler provided no compiler!") |
| 8 |
endif() |
| 9 |
if(NOT IS_ABSOLUTE "${CMAKE_C_COMPILER}") |
| 10 |
message(FATAL_ERROR "FindCompiler provided non-absolute path \"${CMAKE_C_COMPILER}\"!") |
| 11 |
endif() |
| 12 |
if(NOT EXISTS "${CMAKE_C_COMPILER}") |
| 13 |
message(FATAL_ERROR "FindCompiler provided non-existing path \"${CMAKE_C_COMPILER}\"!") |
| 14 |
endif() |
| 15 |
|
| 16 |
# Now that we have the full compiler path, hide CC. |
| 17 |
unset(ENV{CC}) |
| 18 |
|
| 19 |
# Wrap around the real compiler so we can change the compiler |
| 20 |
# path without changing the underlying compiler. |
| 21 |
set(ccIn ${RunCMake_SOURCE_DIR}/cc.sh.in) |
| 22 |
set(cc1 ${RunCMake_BINARY_DIR}/cc1.sh) |
| 23 |
set(cc2 ${RunCMake_BINARY_DIR}/cc2.sh) |
| 24 |
set(cc3 CMAKE_C_COMPILER-NOTFOUND) |
| 25 |
configure_file(${ccIn} ${cc1} @ONLY) |
| 26 |
configure_file(${ccIn} ${cc2} @ONLY) |
| 27 |
|
| 28 |
block() |
| 29 |
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/ChangeCompiler-build) |
| 30 |
set(ENV{RunCMake_TEST} "FirstCompiler") |
| 31 |
run_cmake_with_options(FirstCompiler -DCMAKE_C_COMPILER=${cc1}) |
| 32 |
set(RunCMake_TEST_NO_CLEAN 1) |
| 33 |
set(ENV{RunCMake_TEST} "SecondCompiler") |
| 34 |
run_cmake_with_options(SecondCompiler -DCMAKE_C_COMPILER=${cc2}) |
| 35 |
set(ENV{RunCMake_TEST} "EmptyCompiler") |
| 36 |
run_cmake_with_options(EmptyCompiler -DCMAKE_C_COMPILER=) |
| 37 |
endblock() |
| 38 |
|
| 39 |
block() |
| 40 |
set(cc1_dot ${RunCMake_BINARY_DIR}/./cc1.sh) |
| 41 |
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/CompilerPath-build) |
| 42 |
set(RunCMake_TEST_VARIANT_DESCRIPTION "-step1") |
| 43 |
run_cmake_with_options(CompilerPath "-DCMAKE_C_COMPILER=${cc1_dot}" -DCACHE_ENTRY=cached) |
| 44 |
set(RunCMake_TEST_NO_CLEAN 1) |
| 45 |
set(RunCMake_TEST_VARIANT_DESCRIPTION "-step2") |
| 46 |
run_cmake_with_options(CompilerPath "-DCMAKE_C_COMPILER=${cc1_dot}") |
| 47 |
endblock() |