2003-02-11 00:20:10 +03:00
|
|
|
PROJECT(TryCompile)
|
2003-02-10 21:19:34 +03:00
|
|
|
|
|
|
|
# try to compile a file that should compile
|
2007-05-24 20:06:59 +04:00
|
|
|
# also check that COPY_FILE works
|
2003-02-10 21:19:34 +03:00
|
|
|
TRY_COMPILE(SHOULD_PASS
|
2006-06-14 20:28:32 +04:00
|
|
|
${TryCompile_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp
|
2003-02-11 00:20:10 +03:00
|
|
|
${TryCompile_SOURCE_DIR}/pass.c
|
2007-05-24 20:06:59 +04:00
|
|
|
OUTPUT_VARIABLE TRY_OUT
|
|
|
|
COPY_FILE ${TryCompile_BINARY_DIR}/CopyOfPass
|
|
|
|
)
|
|
|
|
|
2003-02-10 21:19:34 +03:00
|
|
|
IF(NOT SHOULD_PASS)
|
2007-01-31 22:00:44 +03:00
|
|
|
MESSAGE(SEND_ERROR "should pass failed ${TRY_OUT}")
|
2003-02-10 21:19:34 +03:00
|
|
|
ENDIF(NOT SHOULD_PASS)
|
2007-05-24 20:06:59 +04:00
|
|
|
IF(NOT EXISTS "${TryCompile_BINARY_DIR}/CopyOfPass")
|
|
|
|
MESSAGE(SEND_ERROR "COPY_FILE to \"${TryCompile_BINARY_DIR}/CopyOfPass\" failed")
|
|
|
|
ELSE(NOT EXISTS "${TryCompile_BINARY_DIR}/CopyOfPass")
|
|
|
|
FILE(REMOVE "${TryCompile_BINARY_DIR}/CopyOfPass")
|
|
|
|
ENDIF(NOT EXISTS "${TryCompile_BINARY_DIR}/CopyOfPass")
|
2003-02-10 21:19:34 +03:00
|
|
|
|
|
|
|
# try to compile a file that should not compile
|
|
|
|
TRY_COMPILE(SHOULD_FAIL
|
2006-06-14 20:28:32 +04:00
|
|
|
${TryCompile_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp
|
2003-02-11 00:20:10 +03:00
|
|
|
${TryCompile_SOURCE_DIR}/fail.c
|
2003-02-10 21:19:34 +03:00
|
|
|
OUTPUT_VARIABLE TRY_OUT)
|
|
|
|
IF(SHOULD_FAIL)
|
2007-01-31 22:00:44 +03:00
|
|
|
MESSAGE(SEND_ERROR "Should fail passed ${TRY_OUT}")
|
2003-02-10 21:19:34 +03:00
|
|
|
ENDIF(SHOULD_FAIL)
|
|
|
|
|
|
|
|
# try to compile a file that should compile
|
|
|
|
TRY_COMPILE(SHOULD_PASS
|
2006-06-14 20:28:32 +04:00
|
|
|
${TryCompile_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp
|
2003-02-11 00:20:10 +03:00
|
|
|
${TryCompile_SOURCE_DIR}/pass.c
|
2003-02-10 21:19:34 +03:00
|
|
|
OUTPUT_VARIABLE TRY_OUT)
|
|
|
|
IF(NOT SHOULD_PASS)
|
2007-01-31 22:00:44 +03:00
|
|
|
MESSAGE(SEND_ERROR "should pass failed ${TRY_OUT}")
|
2003-02-10 21:19:34 +03:00
|
|
|
ENDIF(NOT SHOULD_PASS)
|
|
|
|
|
|
|
|
# try to compile a file that should not compile
|
|
|
|
TRY_COMPILE(SHOULD_FAIL
|
2006-06-14 20:28:32 +04:00
|
|
|
${TryCompile_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp
|
2003-02-11 00:20:10 +03:00
|
|
|
${TryCompile_SOURCE_DIR}/fail.c
|
2003-02-10 21:19:34 +03:00
|
|
|
OUTPUT_VARIABLE TRY_OUT)
|
|
|
|
IF(SHOULD_FAIL)
|
2007-01-31 22:00:44 +03:00
|
|
|
MESSAGE(SEND_ERROR "Should fail passed ${TRY_OUT}")
|
2003-02-10 21:19:34 +03:00
|
|
|
ENDIF(SHOULD_FAIL)
|
|
|
|
|
|
|
|
IF(NOT SHOULD_FAIL)
|
|
|
|
IF(SHOULD_PASS)
|
|
|
|
MESSAGE("All Tests passed, ignore all previous output.")
|
|
|
|
ELSE(SHOULD_PASS)
|
|
|
|
MESSAGE("Test failed")
|
|
|
|
ENDIF(SHOULD_PASS)
|
|
|
|
ELSE(NOT SHOULD_FAIL)
|
|
|
|
MESSAGE("Test failed")
|
|
|
|
ENDIF(NOT SHOULD_FAIL)
|
2006-01-12 21:49:32 +03:00
|
|
|
TRY_COMPILE(CMAKE_ANSI_FOR_SCOPE
|
2006-06-14 20:28:32 +04:00
|
|
|
${TryCompile_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp
|
2003-02-11 06:00:40 +03:00
|
|
|
${CMAKE_ROOT}/Modules/TestForAnsiForScope.cxx OUTPUT_VARIABLE OUT)
|
|
|
|
IF (CMAKE_ANSI_FOR_SCOPE)
|
|
|
|
MESSAGE("Compiler supports ansi for")
|
|
|
|
ELSE(CMAKE_ANSI_FOR_SCOPE)
|
|
|
|
MESSAGE("Compiler does not support ansi for scope")
|
|
|
|
ENDIF(CMAKE_ANSI_FOR_SCOPE)
|
|
|
|
|
2006-01-12 21:49:32 +03:00
|
|
|
TRY_COMPILE(CMAKE_ANSI_FOR_SCOPE
|
2006-06-14 20:28:32 +04:00
|
|
|
${TryCompile_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp
|
2003-02-11 06:00:40 +03:00
|
|
|
${CMAKE_ROOT}/Modules/TestForAnsiForScope.cxx OUTPUT_VARIABLE OUT)
|
|
|
|
IF (CMAKE_ANSI_FOR_SCOPE)
|
|
|
|
MESSAGE("Compiler supports ansi for")
|
|
|
|
ELSE(CMAKE_ANSI_FOR_SCOPE)
|
|
|
|
MESSAGE("Compiler does not support ansi for scope")
|
2007-05-24 19:27:51 +04:00
|
|
|
ENDIF(CMAKE_ANSI_FOR_SCOPE)
|
2003-02-11 06:00:40 +03:00
|
|
|
|
|
|
|
MESSAGE("use the module now")
|
|
|
|
INCLUDE(${CMAKE_ROOT}/Modules/TestForANSIForScope.cmake)
|
|
|
|
IF (CMAKE_ANSI_FOR_SCOPE)
|
|
|
|
MESSAGE("Compiler supports ansi for")
|
|
|
|
ELSE(CMAKE_ANSI_FOR_SCOPE)
|
|
|
|
MESSAGE("Compiler does not support ansi for scope")
|
|
|
|
ENDIF(CMAKE_ANSI_FOR_SCOPE)
|
2003-02-10 21:19:34 +03:00
|
|
|
|
2003-02-11 00:20:10 +03:00
|
|
|
ADD_EXECUTABLE(TryCompile pass.c)
|
2007-05-24 19:27:51 +04:00
|
|
|
|
|
|
|
######################################
|
|
|
|
|
|
|
|
# now two tests for TRY_RUN
|
|
|
|
|
|
|
|
# try to run a file that should compile and run without error
|
|
|
|
TRY_RUN(SHOULD_RUN SHOULD_COMPILE
|
|
|
|
${TryCompile_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp
|
|
|
|
${TryCompile_SOURCE_DIR}/exit_success.c
|
|
|
|
OUTPUT_VARIABLE TRY_OUT)
|
|
|
|
IF(NOT SHOULD_COMPILE)
|
|
|
|
MESSAGE(SEND_ERROR "exit_success failed compiling: ${TRY_OUT}")
|
|
|
|
ENDIF(NOT SHOULD_COMPILE)
|
|
|
|
IF(NOT "${SHOULD_RUN}" STREQUAL "0")
|
|
|
|
MESSAGE(SEND_ERROR "exit_success failed running with exit code ${SHOULD_RUN}")
|
|
|
|
ENDIF(NOT "${SHOULD_RUN}" STREQUAL "0")
|
|
|
|
|
|
|
|
# try to run a file that should compile and run, but return an error
|
|
|
|
TRY_RUN(SHOULD_EXIT_WITH_ERROR SHOULD_COMPILE
|
|
|
|
${TryCompile_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp
|
|
|
|
${TryCompile_SOURCE_DIR}/exit_with_error.c
|
|
|
|
OUTPUT_VARIABLE TRY_OUT)
|
|
|
|
IF(NOT SHOULD_COMPILE)
|
|
|
|
MESSAGE(STATUS " exit_with_error failed compiling: ${TRY_OUT}")
|
|
|
|
ENDIF(NOT SHOULD_COMPILE)
|
|
|
|
IF("${SHOULD_EXIT_WITH_ERROR}" STREQUAL "0")
|
|
|
|
MESSAGE(SEND_ERROR " exit_with_error passed with exit code ${SHOULD_EXIT_WITH_ERROR}")
|
|
|
|
ENDIF("${SHOULD_EXIT_WITH_ERROR}" STREQUAL "0")
|
|
|
|
|