CMakeLists.txt 2.2 KB

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