CMakeLists.txt 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. PROJECT(TryCompile)
  2. # try to compile a file that should compile
  3. TRY_COMPILE(SHOULD_PASS
  4. ${TryCompile_BINARY_DIR}/CMakeTmp
  5. ${TryCompile_SOURCE_DIR}/pass.c
  6. OUTPUT_VARIABLE TRY_OUT)
  7. IF(NOT SHOULD_PASS)
  8. MESSAGE(SEND_ERROR "should pass failed ")
  9. ENDIF(NOT SHOULD_PASS)
  10. MESSAGE( "output from TRY_COMPILE ${TRY_OUT} ")
  11. # try to compile a file that should not compile
  12. TRY_COMPILE(SHOULD_FAIL
  13. ${TryCompile_BINARY_DIR}/CMakeTmp
  14. ${TryCompile_SOURCE_DIR}/fail.c
  15. OUTPUT_VARIABLE TRY_OUT)
  16. IF(SHOULD_FAIL)
  17. MESSAGE(SEND_ERROR "Should fail passed")
  18. ENDIF(SHOULD_FAIL)
  19. MESSAGE("output from TRY_COMPILE ${TRY_OUT} ")
  20. # try to compile a file that should compile
  21. TRY_COMPILE(SHOULD_PASS
  22. ${TryCompile_BINARY_DIR}/CMakeTmp
  23. ${TryCompile_SOURCE_DIR}/pass.c
  24. OUTPUT_VARIABLE TRY_OUT)
  25. IF(NOT SHOULD_PASS)
  26. MESSAGE(SEND_ERROR "should pass failed ")
  27. ENDIF(NOT SHOULD_PASS)
  28. MESSAGE("output from TRY_COMPILE ${TRY_OUT} ")
  29. # try to compile a file that should not compile
  30. TRY_COMPILE(SHOULD_FAIL
  31. ${TryCompile_BINARY_DIR}/CMakeTmp
  32. ${TryCompile_SOURCE_DIR}/fail.c
  33. OUTPUT_VARIABLE TRY_OUT)
  34. IF(SHOULD_FAIL)
  35. MESSAGE(SEND_ERROR "Should fail passed")
  36. ENDIF(SHOULD_FAIL)
  37. MESSAGE("output from TRY_COMPILE ${TRY_OUT} ")
  38. IF(NOT SHOULD_FAIL)
  39. IF(SHOULD_PASS)
  40. MESSAGE("All Tests passed, ignore all previous output.")
  41. ELSE(SHOULD_PASS)
  42. MESSAGE("Test failed")
  43. ENDIF(SHOULD_PASS)
  44. ELSE(NOT SHOULD_FAIL)
  45. MESSAGE("Test failed")
  46. ENDIF(NOT SHOULD_FAIL)
  47. TRY_COMPILE(CMAKE_ANSI_FOR_SCOPE ${TryCompile_BINARY_DIR}/CMakeTmp
  48. ${CMAKE_ROOT}/Modules/TestForAnsiForScope.cxx OUTPUT_VARIABLE OUT)
  49. IF (CMAKE_ANSI_FOR_SCOPE)
  50. MESSAGE("Compiler supports ansi for")
  51. ELSE(CMAKE_ANSI_FOR_SCOPE)
  52. MESSAGE("Compiler does not support ansi for scope")
  53. ENDIF(CMAKE_ANSI_FOR_SCOPE)
  54. MESSAGE("output from TRY_COMPILE ${OUT} ")
  55. TRY_COMPILE(CMAKE_ANSI_FOR_SCOPE ${TryCompile_BINARY_DIR}/CMakeTmp
  56. ${CMAKE_ROOT}/Modules/TestForAnsiForScope.cxx OUTPUT_VARIABLE OUT)
  57. IF (CMAKE_ANSI_FOR_SCOPE)
  58. MESSAGE("Compiler supports ansi for")
  59. ELSE(CMAKE_ANSI_FOR_SCOPE)
  60. MESSAGE("Compiler does not support ansi for scope")
  61. ENDIF(CMAKE_ANSI_FOR_SCOPE)
  62. MESSAGE("output from TRY_COMPILE ${OUT} ")
  63. MESSAGE("use the module now")
  64. INCLUDE(${CMAKE_ROOT}/Modules/TestForANSIForScope.cmake)
  65. IF (CMAKE_ANSI_FOR_SCOPE)
  66. MESSAGE("Compiler supports ansi for")
  67. ELSE(CMAKE_ANSI_FOR_SCOPE)
  68. MESSAGE("Compiler does not support ansi for scope")
  69. ENDIF(CMAKE_ANSI_FOR_SCOPE)
  70. ADD_EXECUTABLE(TryCompile pass.c)