Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Tests / Complex / Library / CMakeLists.txt
blob4f2e5a4aec9a6f47f81b9ee98892ecfd163c360e
1 REMOVE_DEFINITIONS(-DCMAKE_IS_REALLY_FUN)
4 # Small utility used to create file
5 # UTILITY_SOURCE is used for coverage and for getting the exact name
6 # of the executable.
8 UTILITY_SOURCE(CREATE_FILE_EXE create_file "." create_file.cxx)
9 ADD_EXECUTABLE(create_file create_file.cxx)
10 SET_TARGET_PROPERTIES(create_file PROPERTIES RUNTIME_OUTPUT_DIRECTORY ".")
13 # Create static library
14 # SOURCE_FILES_REMOVE is used for Coverage. empty.h is included for coverage
16 AUX_SOURCE_DIRECTORY(ExtraSources LibrarySources)
17 SET(LibrarySources ${LibrarySources}
18   file2 
19   empty 
20   create_file.cxx 
21   GENERATED 
22   nonexisting_file)
23 REMOVE(LibrarySources create_file.cxx GENERATED nonexisting_file) 
24 ADD_LIBRARY(CMakeTestLibrary ${LibrarySources})
26 IF(WIN32)
27   IF(NOT CYGWIN)
28     IF(NOT BORLAND)
29       IF(NOT MINGW)
30         TARGET_LINK_LIBRARIES(CMakeTestLibrary
31           debug 
32           user32.lib)
33         TARGET_LINK_LIBRARIES(CMakeTestLibrary
34           optimized 
35           kernel32.lib)
36       ENDIF(NOT MINGW)
37     ENDIF(NOT BORLAND)
38   ENDIF(NOT CYGWIN)
39 ENDIF(WIN32)
42 # Create shared library
44 SET(SharedLibrarySources sharedFile)
45 ADD_LIBRARY(CMakeTestLibraryShared SHARED ${SharedLibrarySources})
46 ADD_LIBRARY(CMakeTestModule MODULE moduleFile.c)
47 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DTEST_C_FLAGS")
48 ADD_LIBRARY(CMakeTestCLibraryShared SHARED testConly.c)
49 DEFINE_PROPERTY(
50   TARGET PROPERTY FOO
51   BRIEF_DOCS "a test property"
52   FULL_DOCS "A simple etst proerty that means nothign and is used for nothing"
53   )
54 SET_TARGET_PROPERTIES(CMakeTestCLibraryShared PROPERTIES FOO BAR)
55 IF(NOT BEOS)  # No libm on BeOS.
56   SET_TARGET_PROPERTIES(CMakeTestCLibraryShared PROPERTIES LINK_FLAGS "-lm")
57 ENDIF(NOT BEOS)
58 GET_TARGET_PROPERTY(FOO_BAR_VAR CMakeTestCLibraryShared FOO)
59 IF(${FOO_BAR_VAR} MATCHES "BAR")
60 ELSE(${FOO_BAR_VAR} MATCHES "BAR")
61   MESSAGE(SEND_ERROR "SET_TARGET_PROPERTIES or GET_TARGET_PROPERTY failed, FOO_BAR_VAR should be BAR, but is ${FOO_BAR_VAR}")
62 ENDIF(${FOO_BAR_VAR} MATCHES "BAR")
64 # Create static and shared lib of same name.
65 IF(CMAKE_EXE_LINK_STATIC_CXX_FLAGS)
66   ADD_LIBRARY(CMakeTestLinkStatic STATIC TestLink.c)
67   ADD_LIBRARY(CMakeTestLinkShared SHARED TestLink.c)
68   SET_TARGET_PROPERTIES(CMakeTestLinkStatic CMakeTestLinkShared
69     PROPERTIES OUTPUT_NAME CMakeTestLink CLEAN_DIRECT_OUTPUT 1)
70 ENDIF(CMAKE_EXE_LINK_STATIC_CXX_FLAGS)
73 # Attach pre-build/pre-link/post-build custom-commands to the lib.
74 # Each runs ${CREATE_FILE_EXE} which will create a file.
75 # The 'complex' executable will then test if this file exists and remove it.
77 ADD_DEPENDENCIES(CMakeTestLibraryShared create_file)
78 MESSAGE("complex bin dir is ${Complex_BINARY_DIR}")
79 ADD_CUSTOM_COMMAND(TARGET CMakeTestLibraryShared PRE_BUILD
80                    COMMAND ${CREATE_FILE_EXE}
81                    ARGS "${Complex_BINARY_DIR}/Library/prebuild.txt")
82 ADD_CUSTOM_COMMAND(TARGET CMakeTestLibraryShared PRE_BUILD
83                    COMMAND ${CREATE_FILE_EXE}
84                    ARGS "${Complex_BINARY_DIR}/Library/prelink.txt")
85 ADD_CUSTOM_COMMAND(TARGET CMakeTestLibraryShared POST_BUILD
86                    COMMAND ${CREATE_FILE_EXE}
87                    ARGS "${Complex_BINARY_DIR}/Library/postbuild.txt")
88 ADD_CUSTOM_COMMAND(TARGET CMakeTestLibraryShared POST_BUILD
89                    COMMAND ${CMAKE_COMMAND}
90                    ARGS -E copy
91                         "${Complex_BINARY_DIR}/Library/postbuild.txt"
92                         "${Complex_BINARY_DIR}/Library/postbuild2.txt")
95 # Add a custom target.
96 # It runs ${CREATE_FILE_EXE} which will create a file.
97 # The 'complex' executable will then test if this file exists and remove it.
99 ADD_CUSTOM_TARGET(custom_target1
100                   ALL
101                   ${CREATE_FILE_EXE} 
102                   "${Complex_BINARY_DIR}/Library/custom_target1.txt")
104 ADD_DEPENDENCIES(custom_target1 create_file)
107 # Extra coverage
109 SET_SOURCE_FILES_PROPERTIES(file2 PROPERTIES ABSTRACT 1)
111 INSTALL_FILES(/tmp .h ${Complex_BINARY_DIR}/cmTestConfigure.h)
112 INSTALL_FILES(/tmp .cxx ${Complex_BINARY_DIR}/cmTestConfigure.h)
114 # Test creating a library that is not built by default.
115 ADD_LIBRARY(notInAllLib EXCLUDE_FROM_ALL notInAllLib.cxx)
117 # Create an imported target for if(TARGET) test in Executable dir.
118 # That test should not see this target.
119 ADD_LIBRARY(LibImportedTarget UNKNOWN IMPORTED)
121 # Test generation of preprocessed sources.
122 IF("${CMAKE_GENERATOR}" MATCHES "Makefile" AND CMAKE_MAKE_PROGRAM)
123   IF(CMAKE_CXX_CREATE_PREPROCESSED_SOURCE)
124     # Skip running this part of the test on certain platforms
125     # until they are fixed.
126     SET(MAYBE_ALL ALL)
127     LIST(LENGTH CMAKE_OSX_ARCHITECTURES ARCH_COUNT)
128     IF(ARCH_COUNT GREATER 1)
129       # OSX does not support preprocessing more than one architecture.
130       SET(MAYBE_ALL)
131     ENDIF(ARCH_COUNT GREATER 1)
133     # Custom target to try preprocessing invocation.
134     ADD_CUSTOM_TARGET(test_preprocess ${MAYBE_ALL}
135       COMMAND ${CMAKE_COMMAND} -E remove CMakeFiles/create_file.dir/create_file.i
136       COMMAND ${CMAKE_MAKE_PROGRAM} create_file.i
137       COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/test_preprocess.cmake
138       WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
139       )
140   ENDIF(CMAKE_CXX_CREATE_PREPROCESSED_SOURCE)
141 ENDIF("${CMAKE_GENERATOR}" MATCHES "Makefile" AND CMAKE_MAKE_PROGRAM)