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