diff options
author | Brad King <brad.king@kitware.com> | 2009-11-20 13:37:56 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2009-11-20 13:37:56 (GMT) |
commit | 1136b97647ddd5b3eb77122494ee47fa3026a97e (patch) | |
tree | d9ff5d9dd774478031778a1db72a04837d150640 | |
parent | 2d80c9e31a3aab40589795d769602821afcb4030 (diff) | |
download | CMake-1136b97647ddd5b3eb77122494ee47fa3026a97e.zip CMake-1136b97647ddd5b3eb77122494ee47fa3026a97e.tar.gz CMake-1136b97647ddd5b3eb77122494ee47fa3026a97e.tar.bz2 |
Create KWSYS_PLATFORM_INFO_TEST macro
This macro helps KWSys perform try-compile tests that extract 'INFO'
strings out of compiled binaries. It works for CMake 2.6 and above.
On CMake 2.4 it always returns an empty list of information values,
so this should be used only as an optimization until 2.6 is required.
-rw-r--r-- | Source/kwsys/kwsysPlatformTests.cmake | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/Source/kwsys/kwsysPlatformTests.cmake b/Source/kwsys/kwsysPlatformTests.cmake index efff762..994b7e7 100644 --- a/Source/kwsys/kwsysPlatformTests.cmake +++ b/Source/kwsys/kwsysPlatformTests.cmake @@ -162,3 +162,55 @@ MACRO(KWSYS_PLATFORM_CXX_TEST_RUN var description invert) SET(KWSYS_PLATFORM_TEST_DEFINES) SET(KWSYS_PLATFORM_TEST_EXTRA_FLAGS) ENDMACRO(KWSYS_PLATFORM_CXX_TEST_RUN) + +#----------------------------------------------------------------------------- +# KWSYS_PLATFORM_INFO_TEST(lang var description) +# +# Compile test named by ${var} and store INFO strings extracted from binary. +MACRO(KWSYS_PLATFORM_INFO_TEST lang var description) + # We can implement this macro on CMake 2.6 and above. + IF("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" LESS 2.6) + SET(${var} "") + ELSE() + # Choose a location for the result binary. + SET(KWSYS_PLATFORM_INFO_FILE + ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/${var}.bin) + + # Compile the test binary. + IF(NOT DEFINED ${var}_COMPILED) + MESSAGE(STATUS "${description}") + TRY_COMPILE(${var}_COMPILED + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/${KWSYS_PLATFORM_TEST_FILE_${lang}} + COMPILE_DEFINITIONS -DTEST_${var} + ${KWSYS_PLATFORM_${lang}_TEST_DEFINES} + ${KWSYS_PLATFORM_${lang}_TEST_EXTRA_FLAGS} + OUTPUT_VARIABLE OUTPUT + COPY_FILE ${KWSYS_PLATFORM_INFO_FILE} + ) + IF(${var}_COMPILED) + FILE(APPEND + ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log + "${description} compiled with the following output:\n${OUTPUT}\n\n") + ELSE() + FILE(APPEND + ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log + "${description} failed to compile with the following output:\n${OUTPUT}\n\n") + ENDIF() + IF(${var}_COMPILED) + MESSAGE(STATUS "${description} - compiled") + ELSE() + MESSAGE(STATUS "${description} - failed") + ENDIF() + ENDIF() + + # Parse info strings out of the compiled binary. + IF(${var}_COMPILED) + FILE(STRINGS ${KWSYS_PLATFORM_INFO_FILE} ${var} REGEX "INFO:[A-Za-z0-9]+\\[[^]]*\\]") + ELSE() + SET(${var} "") + ENDIF() + + SET(KWSYS_PLATFORM_INFO_FILE) + ENDIF() +ENDMACRO() |