RunCMakeTest.cmake 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. include(RunCMake)
  2. function(find_compiler lang)
  3. # Detect the compiler in use in the current environment.
  4. run_cmake(Find${lang}Compiler)
  5. # Use the detected compiler
  6. include(${RunCMake_BINARY_DIR}/Find${lang}Compiler-build/${lang}_comp.cmake)
  7. if(NOT temp_CMAKE_${lang}_COMPILER)
  8. message(FATAL_ERROR "FindCompiler provided no compiler!")
  9. endif()
  10. # Create a toolchain file
  11. set(__test_compiler_var CMAKE_${lang}_COMPILER)
  12. set(__test_compiler "${temp_CMAKE_${lang}_COMPILER}")
  13. configure_file(${RunCMake_SOURCE_DIR}/toolchain.cmake.in
  14. ${RunCMake_BINARY_DIR}/Find${lang}Compiler-build/toolchain_${lang}_comp.cmake @ONLY)
  15. endfunction()
  16. function(run_compiler_env lang)
  17. # Use the correct compiler
  18. include(${RunCMake_BINARY_DIR}/Find${lang}Compiler-build/${lang}_comp.cmake)
  19. # Use a single build tree for tests without cleaning.
  20. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${lang}-env-build)
  21. set(RunCMake_TEST_NO_CLEAN 1)
  22. file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  23. file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
  24. # Set the compiler
  25. if(lang STREQUAL "C")
  26. set(ENV{CC} "'${temp_CMAKE_${lang}_COMPILER}' -DFOO1 -DFOO2")
  27. else()
  28. set(ENV{${lang}} "'${temp_CMAKE_${lang}_COMPILER}' -DFOO1 -DFOO2")
  29. endif()
  30. run_cmake(${lang})
  31. run_cmake_command(${lang}-Build ${CMAKE_COMMAND} --build . ${verbose_args})
  32. endfunction()
  33. function(run_compiler_tc lang)
  34. # Use a single build tree for tests without cleaning.
  35. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${lang}-tc-build)
  36. set(RunCMake_TEST_NO_CLEAN 1)
  37. file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  38. file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
  39. set(RunCMake_TEST_OPTIONS
  40. -DCMAKE_TOOLCHAIN_FILE=${RunCMake_BINARY_DIR}/Find${lang}Compiler-build/toolchain_${lang}_comp.cmake)
  41. run_cmake(${lang})
  42. run_cmake_command(${lang}-Build ${CMAKE_COMMAND} --build . ${verbose_args})
  43. endfunction()
  44. set(langs C CXX)
  45. foreach(lang ${langs})
  46. find_compiler(${lang})
  47. run_compiler_env(${lang})
  48. run_compiler_tc(${lang})
  49. endforeach()