CMakeLists.txt 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. PROJECT(TryCompile)
  2. # try to compile a file that should compile
  3. TRY_COMPILE(SHOULD_PASS
  4. ${TryCompile_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/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}${CMAKE_FILES_DIRECTORY}/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}${CMAKE_FILES_DIRECTORY}/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}${CMAKE_FILES_DIRECTORY}/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
  44. ${TryCompile_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp
  45. ${CMAKE_ROOT}/Modules/TestForAnsiForScope.cxx OUTPUT_VARIABLE OUT)
  46. IF (CMAKE_ANSI_FOR_SCOPE)
  47. MESSAGE("Compiler supports ansi for")
  48. ELSE(CMAKE_ANSI_FOR_SCOPE)
  49. MESSAGE("Compiler does not support ansi for scope")
  50. ENDIF(CMAKE_ANSI_FOR_SCOPE)
  51. TRY_COMPILE(CMAKE_ANSI_FOR_SCOPE
  52. ${TryCompile_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp
  53. ${CMAKE_ROOT}/Modules/TestForAnsiForScope.cxx OUTPUT_VARIABLE OUT)
  54. IF (CMAKE_ANSI_FOR_SCOPE)
  55. MESSAGE("Compiler supports ansi for")
  56. ELSE(CMAKE_ANSI_FOR_SCOPE)
  57. MESSAGE("Compiler does not support ansi for scope")
  58. ENDIF(CMAKE_ANSI_FOR_SCOPE)
  59. MESSAGE("use the module now")
  60. INCLUDE(${CMAKE_ROOT}/Modules/TestForANSIForScope.cmake)
  61. IF (CMAKE_ANSI_FOR_SCOPE)
  62. MESSAGE("Compiler supports ansi for")
  63. ELSE(CMAKE_ANSI_FOR_SCOPE)
  64. MESSAGE("Compiler does not support ansi for scope")
  65. ENDIF(CMAKE_ANSI_FOR_SCOPE)
  66. ADD_EXECUTABLE(TryCompile pass.c)