RunCMakeTest.cmake 1.8 KB

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