Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Tests / Complex / Executable / CMakeLists.txt
blob6f47838c73603b0536c9cf5a249f965dea3a5e6b
1 CMAKE_MINIMUM_REQUIRED(VERSION 1.3)
3 # Create exe. 
5 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTEST_CXX_FLAGS")
6 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DTEST_C_FLAGS")
7 SET(CMAKE_C_FLAGS "${CMAKE_ANSI_CFLAGS} ${CMAKE_C_FLAGS}")
9 IF(COMPLEX_TEST_CMAKELIB)
10   # Link to CMake lib
11   LINK_DIRECTORIES(${Complex_BINARY_DIR}/../../Source)
12   LINK_DIRECTORIES(${Complex_BINARY_DIR}/../../Source/kwsys)
13   LINK_DIRECTORIES(${Complex_BINARY_DIR}/../../Utilities/cmexpat)
14   LINK_DIRECTORIES(${Complex_BINARY_DIR}/../../Utilities/cmzlib)
15   # prefer the new curl if it is around
16   IF(EXISTS ${Complex_BINARY_DIR}/../../Utilities/cmcurl-7.19.0)
17     LINK_DIRECTORIES(${Complex_BINARY_DIR}/../../Utilities/cmcurl-7.19.0/lib)
18   ENDIF(EXISTS ${Complex_BINARY_DIR}/../../Utilities/cmcurl-7.19.0)
19   IF(EXISTS ${Complex_BINARY_DIR}/../../Utilities/cmcurl)
20     LINK_DIRECTORIES(${Complex_BINARY_DIR}/../../Utilities/cmcurl)
21   ENDIF(EXISTS ${Complex_BINARY_DIR}/../../Utilities/cmcurl)
22   LINK_DIRECTORIES(${Complex_BINARY_DIR}/../../Utilities/cmtar)
23 ENDIF(COMPLEX_TEST_CMAKELIB)
25 # Create an imported target for if(TARGET) test below.
26 ADD_LIBRARY(ExeImportedTarget UNKNOWN IMPORTED)
28 # Test if(TARGET) command.
29 IF(NOT TARGET CMakeTestLibrary)
30   MESSAGE(FATAL_ERROR "IF(NOT TARGET CMakeTestLibrary) returned true!")
31 ENDIF(NOT TARGET CMakeTestLibrary)
32 IF(NOT TARGET ExeImportedTarget)
33   MESSAGE(FATAL_ERROR "IF(NOT TARGET ExeImportedTarget) returned true!")
34 ENDIF(NOT TARGET ExeImportedTarget)
35 IF(TARGET LibImportedTarget)
36   MESSAGE(FATAL_ERROR "IF(TARGET LibImportedTarget) returned true!")
37 ENDIF(TARGET LibImportedTarget)
38 IF(TARGET NotATarget)
39   MESSAGE(FATAL_ERROR "IF(TARGET NotATarget) returned true!")
40 ENDIF(TARGET NotATarget)
42   # Use LINK_LIBRARIES instead of TARGET_LINK_LIBRARIES to 
43 SET(COMPLEX_LIBS CMakeTestLibrary;CMakeTestLibraryShared;CMakeTestCLibraryShared)
44 LINK_LIBRARIES(${COMPLEX_LIBS})
46 # Test forcing a .cxx file to not build.
47 SET_SOURCE_FILES_PROPERTIES(complex_nobuild.cxx PROPERTIES
48   HEADER_FILE_ONLY 1)
50 ADD_EXECUTABLE(A A.cxx A.hh A.h A.txt)
51 ADD_EXECUTABLE(complex complex testcflags.c )
52 #  Sub1/NameConflictTest.c Sub2/NameConflictTest.c)
53 ADD_EXECUTABLE(complex.file complex.file.cxx complex_nobuild.cxx)
54 IF(COMPLEX_TEST_CMAKELIB)
55   TARGET_LINK_LIBRARIES(complex CMakeLib cmsys cmexpat cmzlib cmtar cmcurl)
56 ENDIF(COMPLEX_TEST_CMAKELIB)
58 IF (UNIX)
59   TARGET_LINK_LIBRARIES(complex ${CMAKE_DL_LIBS})
60 ELSE(UNIX)
61   IF (NOT BORLAND)
62     IF(NOT MINGW)
63       TARGET_LINK_LIBRARIES(complex rpcrt4.lib)
64     ENDIF(NOT MINGW)
65   ENDIF(NOT BORLAND)
66 ENDIF (UNIX)
68 # Test linking to static lib when a shared lib has the same name.
69 IF(CMAKE_EXE_LINK_STATIC_CXX_FLAGS)
70   ADD_DEFINITIONS(-DCOMPLEX_TEST_LINK_STATIC)
71   TARGET_LINK_LIBRARIES(complex CMakeTestLinkStatic)
72 ENDIF(CMAKE_EXE_LINK_STATIC_CXX_FLAGS)
74 # can we get the path to a source file
75 GET_SOURCE_FILE_PROPERTY(A_LOCATION A.cxx LOCATION)
76 IF ("${A_LOCATION}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}/A.cxx")
77   ADD_DEFINITIONS(-DCMAKE_FOUND_ACXX)
78 ENDIF ("${A_LOCATION}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}/A.cxx")
80 # get the directory parent
81 GET_DIRECTORY_PROPERTY(P_VALUE PARENT_DIRECTORY)
82 IF ("${P_VALUE}" STREQUAL "${CMAKE_SOURCE_DIR}")
83   ADD_DEFINITIONS(-DCMAKE_FOUND_PARENT)
84 ENDIF ("${P_VALUE}" STREQUAL "${CMAKE_SOURCE_DIR}")
86 # get the stack of listfiles
87 INCLUDE(Included.cmake)
88 IF ("${LF_VALUE}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt;${CMAKE_CURRENT_SOURCE_DIR}/Included.cmake")
89   ADD_DEFINITIONS(-DCMAKE_FOUND_LISTFILE_STACK)
90 ENDIF ("${LF_VALUE}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt;${CMAKE_CURRENT_SOURCE_DIR}/Included.cmake")
92 # Test add/remove definitions.
93 ADD_DEFINITIONS(
94   -DCOMPLEX_DEFINED_PRE
95   -DCOMPLEX_DEFINED
96   -DCOMPLEX_DEFINED_POST
97   -DCOMPLEX_DEFINED
98   )
99 REMOVE_DEFINITIONS(-DCOMPLEX_DEFINED)
101 # Test pre-build/pre-link/post-build rules for an executable.
102 ADD_CUSTOM_COMMAND(TARGET complex PRE_BUILD
103                    COMMAND ${CREATE_FILE_EXE}
104                    ARGS "${Complex_BINARY_DIR}/Executable/prebuild.txt")
105 ADD_CUSTOM_COMMAND(TARGET complex PRE_BUILD
106                    COMMAND ${CREATE_FILE_EXE}
107                    ARGS "${Complex_BINARY_DIR}/Executable/prelink.txt")
108 ADD_CUSTOM_COMMAND(TARGET complex POST_BUILD
109                    COMMAND ${CREATE_FILE_EXE}
110                    ARGS "${Complex_BINARY_DIR}/Executable/postbuild.txt")
111 ADD_CUSTOM_COMMAND(TARGET complex POST_BUILD
112                    COMMAND ${CMAKE_COMMAND}
113                    ARGS -E copy
114                         "${Complex_BINARY_DIR}/Executable/postbuild.txt"
115                         "${Complex_BINARY_DIR}/Executable/postbuild2.txt")
117 SET_SOURCE_FILES_PROPERTIES(complex
118   COMPILE_FLAGS
119   "-DFILE_HAS_EXTRA_COMPILE_FLAGS"
120   #" -DFILE_DEFINE_STRING=\\\"hello\\\""
121   OBJECT_DEPENDS ${Complex_BINARY_DIR}/cmTestGeneratedHeader.h
123 SET_TARGET_PROPERTIES(complex PROPERTIES COMPILE_FLAGS "-DCOMPLEX_TARGET_FLAG")
124 ADD_CUSTOM_COMMAND(
125   TARGET complex
126   SOURCE ${Complex_SOURCE_DIR}/cmTestGeneratedHeader.h.in
127   COMMAND ${CMAKE_COMMAND}
128   ARGS -E copy ${Complex_SOURCE_DIR}/cmTestGeneratedHeader.h.in
129                ${Complex_BINARY_DIR}/cmTestGeneratedHeader.h
130   OUTPUTS ${Complex_BINARY_DIR}/cmTestGeneratedHeader.h
131   DEPENDS ${CMAKE_COMMAND}
134 # Test creating an executable that is not built by default.
135 ADD_EXECUTABLE(notInAllExe EXCLUDE_FROM_ALL notInAllExe.cxx)
136 TARGET_LINK_LIBRARIES(notInAllExe notInAllLib)
138 # Test user-value flag mapping for the VS IDE.
139 IF(MSVC)
140   SET_TARGET_PROPERTIES(notInAllExe PROPERTIES
141     LINK_FLAGS "/NODEFAULTLIB:LIBC;LIBCMT;MSVCRT")
142 ENDIF(MSVC)
144 # Test creating a custom target that builds not-in-all targets.
145 ADD_CUSTOM_TARGET(notInAllCustom)
146 ADD_DEPENDENCIES(notInAllCustom notInAllExe)
149 # Output the files required by 'complex' to a file.
151 # This test has been moved to the 'required' subdir so that it
152 # has no side-effects on the current Makefile (duplicated source file
153 # due to source list expansion done twice).
155 ADD_SUBDIRECTORY(Temp)
157 IF(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_INCLUDE_SYSTEM_FLAG_CXX)
158   ADD_EXECUTABLE(testSystemDir testSystemDir.cxx)
159   SET_TARGET_PROPERTIES(testSystemDir PROPERTIES COMPILE_FLAGS "-Werror")
160 ENDIF(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_INCLUDE_SYSTEM_FLAG_CXX)
163 # Extra coverage.Not used.
165 INSTALL_TARGETS(/tmp complex)
166 INSTALL_PROGRAMS(/tmp complex)
168 CONFIGURE_FILE(
169   ${Complex_SOURCE_DIR}/Executable/cmVersion.h.in
170   ${Complex_BINARY_DIR}/cmVersion.h)
172 SOURCE_GROUP(A_GROUP ".cxx")
173 SOURCE_GROUP(B_GROUP REGULAR_EXPRESSION "cxx")
174 SOURCE_GROUP(C_GROUP FILES complex.cxx)
176 FILE(WRITE ${Complex_BINARY_DIR}/A/libA.a "test")
177 FILE(WRITE ${Complex_BINARY_DIR}/A/libC.a "test")
178 FILE(WRITE ${Complex_BINARY_DIR}/B/libB.a "test")
179 FILE(WRITE ${Complex_BINARY_DIR}/B/libA.a "test")
180 FILE(WRITE ${Complex_BINARY_DIR}/C/libC.a "test")
181 FILE(WRITE ${Complex_BINARY_DIR}/C/libB.a "test")