| 1 |
remove_definitions(-DCMAKE_IS_REALLY_FUN) |
| 2 |
|
| 3 |
set(CREATE_FILE_EXE create_file CACHE INTERNAL "") # make globally visible |
| 4 |
add_executable(create_file create_file.cxx) |
| 5 |
set_target_properties(create_file PROPERTIES RUNTIME_OUTPUT_DIRECTORY ".") |
| 6 |
|
| 7 |
# |
| 8 |
# Create static library |
| 9 |
# SOURCE_FILES_REMOVE is used for Coverage. empty.h is included for coverage |
| 10 |
# |
| 11 |
aux_source_directory(ExtraSources LibrarySources) |
| 12 |
set(LibrarySources ${LibrarySources} |
| 13 |
file2 |
| 14 |
empty |
| 15 |
create_file.cxx |
| 16 |
GENERATED |
| 17 |
nonexisting_file) |
| 18 |
remove(LibrarySources create_file.cxx GENERATED nonexisting_file) |
| 19 |
add_library(CMakeTestLibrary ${LibrarySources}) |
| 20 |
|
| 21 |
if(WIN32 AND NOT CYGWIN AND NOT BORLAND AND NOT MINGW AND NOT CMAKE_C_COMPILER_ID STREQUAL "OrangeC") |
| 22 |
target_link_libraries(CMakeTestLibrary debug user32.lib) |
| 23 |
target_link_libraries(CMakeTestLibrary optimized kernel32.lib) |
| 24 |
endif() |
| 25 |
|
| 26 |
# |
| 27 |
# Create shared library |
| 28 |
# |
| 29 |
set(SharedLibrarySources sharedFile) |
| 30 |
add_library(CMakeTestLibraryShared SHARED ${SharedLibrarySources}) |
| 31 |
string(APPEND CMAKE_C_FLAGS " -DTEST_C_FLAGS") |
| 32 |
add_library(CMakeTestCLibraryShared SHARED testConly.c) |
| 33 |
define_property( |
| 34 |
TARGET PROPERTY FOO |
| 35 |
BRIEF_DOCS "a test property" |
| 36 |
FULL_DOCS "A simple test property that means nothing and is used for nothing" |
| 37 |
) |
| 38 |
set_target_properties(CMakeTestCLibraryShared PROPERTIES FOO BAR) |
| 39 |
if(NOT BEOS AND NOT WIN32 AND NOT HAIKU) # No libm on BeOS. |
| 40 |
set_target_properties(CMakeTestCLibraryShared PROPERTIES LINK_FLAGS "-lm") |
| 41 |
endif() |
| 42 |
get_target_property(FOO_BAR_VAR CMakeTestCLibraryShared FOO) |
| 43 |
if(${FOO_BAR_VAR} MATCHES "BAR") |
| 44 |
else() |
| 45 |
message(SEND_ERROR "SET_TARGET_PROPERTIES or GET_TARGET_PROPERTY failed, FOO_BAR_VAR should be BAR, but is ${FOO_BAR_VAR}") |
| 46 |
endif() |
| 47 |
|
| 48 |
# Create static and shared lib of same name. |
| 49 |
if(CMAKE_EXE_LINK_STATIC_CXX_FLAGS) |
| 50 |
add_library(CMakeTestLinkStatic STATIC TestLink.c) |
| 51 |
add_library(CMakeTestLinkShared SHARED TestLink.c) |
| 52 |
set_target_properties(CMakeTestLinkStatic CMakeTestLinkShared |
| 53 |
PROPERTIES OUTPUT_NAME CMakeTestLink) |
| 54 |
endif() |
| 55 |
|
| 56 |
# |
| 57 |
# Attach pre-build/pre-link/post-build custom-commands to the lib. |
| 58 |
# Each runs ${CREATE_FILE_EXE} which will create a file. |
| 59 |
# The 'complex' executable will then test if this file exists and remove it. |
| 60 |
# |
| 61 |
add_dependencies(CMakeTestLibraryShared create_file) |
| 62 |
message("complex bin dir is ${Complex_BINARY_DIR}") |
| 63 |
add_custom_command(TARGET CMakeTestLibraryShared PRE_BUILD |
| 64 |
COMMAND ${CREATE_FILE_EXE} |
| 65 |
ARGS "${Complex_BINARY_DIR}/Library/prebuild.txt") |
| 66 |
add_custom_command(TARGET CMakeTestLibraryShared PRE_BUILD |
| 67 |
COMMAND ${CREATE_FILE_EXE} |
| 68 |
ARGS "${Complex_BINARY_DIR}/Library/prelink.txt") |
| 69 |
add_custom_command(TARGET CMakeTestLibraryShared POST_BUILD |
| 70 |
COMMAND ${CREATE_FILE_EXE} |
| 71 |
ARGS "${Complex_BINARY_DIR}/Library/postbuild.txt") |
| 72 |
add_custom_command(TARGET CMakeTestLibraryShared POST_BUILD |
| 73 |
COMMAND ${CMAKE_COMMAND} |
| 74 |
ARGS -E copy |
| 75 |
"${Complex_BINARY_DIR}/Library/postbuild.txt" |
| 76 |
"${Complex_BINARY_DIR}/Library/postbuild2.txt") |
| 77 |
|
| 78 |
# |
| 79 |
# Add a custom target. |
| 80 |
# It runs ${CREATE_FILE_EXE} which will create a file. |
| 81 |
# The 'complex' executable will then test if this file exists and remove it. |
| 82 |
# |
| 83 |
add_custom_target(custom_target1 |
| 84 |
ALL |
| 85 |
${CREATE_FILE_EXE} |
| 86 |
"${Complex_BINARY_DIR}/Library/custom_target1.txt") |
| 87 |
|
| 88 |
add_dependencies(custom_target1 create_file) |
| 89 |
|
| 90 |
# |
| 91 |
# Extra coverage |
| 92 |
# |
| 93 |
set_source_files_properties(file2 PROPERTIES ABSTRACT 1) |
| 94 |
|
| 95 |
install_files(/tmp .h ${Complex_BINARY_DIR}/cmTestConfigure.h) |
| 96 |
install_files(/tmp .cxx ${Complex_BINARY_DIR}/cmTestConfigure.h) |
| 97 |
|
| 98 |
# Test creating a library that is not built by default. |
| 99 |
add_library(notInAllLib EXCLUDE_FROM_ALL notInAllLib.cxx) |
| 100 |
|
| 101 |
# Create an imported target for if(TARGET) test in Executable dir. |
| 102 |
# That test should not see this target. |
| 103 |
add_library(LibImportedTarget UNKNOWN IMPORTED) |
| 104 |
|
| 105 |
# Test generation of preprocessed sources. |
| 106 |
if("${CMAKE_GENERATOR}" MATCHES "Makefile" AND CMAKE_MAKE_PROGRAM) |
| 107 |
if(CMAKE_CXX_CREATE_PREPROCESSED_SOURCE) |
| 108 |
# Skip running this part of the test on certain platforms |
| 109 |
# until they are fixed. |
| 110 |
set(MAYBE_ALL ALL) |
| 111 |
list(LENGTH CMAKE_OSX_ARCHITECTURES ARCH_COUNT) |
| 112 |
if(ARCH_COUNT GREATER 1) |
| 113 |
# OSX does not support preprocessing more than one architecture. |
| 114 |
set(MAYBE_ALL) |
| 115 |
endif() |
| 116 |
|
| 117 |
# Custom target to try preprocessing invocation. |
| 118 |
add_custom_target(test_preprocess ${MAYBE_ALL} |
| 119 |
COMMAND ${CMAKE_COMMAND} -E rm -f CMakeFiles/create_file.dir/create_file.cxx.i |
| 120 |
COMMAND ${CMAKE_MAKE_PROGRAM} create_file.i |
| 121 |
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/test_preprocess.cmake |
| 122 |
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 123 |
) |
| 124 |
endif() |
| 125 |
endif() |