1 # this test creates a static library and an executable
2 # the source to the library is then changed
3 # and the build is done on the executable and if things
4 # are working the executable should relink with the new
5 # value. The subdir Project contains the CMakelists.txt
6 # and source files for the test project.
7 cmake_minimum_required (VERSION 2.6)
10 # This entire test takes place during the initial
11 # configure step. It should not run again when the
13 set(CMAKE_SUPPRESS_REGENERATION 1)
15 # Xcode needs some help with the fancy dependencies in this test.
16 if("${CMAKE_GENERATOR}" MATCHES "Xcode")
18 endif("${CMAKE_GENERATOR}" MATCHES "Xcode")
19 function(help_xcode_depends)
21 file(GLOB_RECURSE MACRO_OBJS
22 ${BuildDepends_BINARY_DIR}/Project/zot_macro_*.o*
25 message("Helping Xcode by removing objects [${MACRO_OBJS}]")
26 file(REMOVE ${MACRO_OBJS})
29 endfunction(help_xcode_depends)
31 file(MAKE_DIRECTORY ${BuildDepends_BINARY_DIR}/Project)
32 message("Creating Project/foo.cxx")
33 write_file(${BuildDepends_BINARY_DIR}/Project/foo.cxx
34 "const char* foo() { return \"foo\";}" )
36 file(WRITE ${BuildDepends_BINARY_DIR}/Project/zot.hxx.in
37 "static const char* zot = \"zot\";\n")
38 file(WRITE ${BuildDepends_BINARY_DIR}/Project/zot_custom.hxx.in
39 "static const char* zot_custom = \"zot_custom\";\n")
40 file(WRITE ${BuildDepends_BINARY_DIR}/Project/zot_macro_dir.hxx
41 "static const char* zot_macro_dir = \"zot_macro_dir\";\n")
42 file(WRITE ${BuildDepends_BINARY_DIR}/Project/zot_macro_tgt.hxx
43 "static const char* zot_macro_tgt = \"zot_macro_tgt\";\n")
47 message("Building project first time")
49 ${BuildDepends_BINARY_DIR}/Project
50 ${BuildDepends_SOURCE_DIR}/Project
52 OUTPUT_VARIABLE OUTPUT)
55 ${BuildDepends_BINARY_DIR}/Project
56 ${BuildDepends_SOURCE_DIR}/Project
58 OUTPUT_VARIABLE OUTPUT)
60 ${BuildDepends_BINARY_DIR}/Project
61 ${BuildDepends_SOURCE_DIR}/Project
63 OUTPUT_VARIABLE OUTPUT)
67 message(SEND_ERROR "Could not build test project: ${OUTPUT}")
70 set(bar ${BuildDepends_BINARY_DIR}/Project/bar${CMAKE_EXECUTABLE_SUFFIX})
72 "${BuildDepends_BINARY_DIR}/Project/Debug/bar${CMAKE_EXECUTABLE_SUFFIX}" )
73 message("found debug")
75 "${BuildDepends_BINARY_DIR}/Project/Debug/bar${CMAKE_EXECUTABLE_SUFFIX}")
77 "${BuildDepends_BINARY_DIR}/Project/Debug/bar${CMAKE_EXECUTABLE_SUFFIX}")
78 set(zot ${BuildDepends_BINARY_DIR}/Project/zot${CMAKE_EXECUTABLE_SUFFIX})
80 "${BuildDepends_BINARY_DIR}/Project/Debug/zot${CMAKE_EXECUTABLE_SUFFIX}" )
81 message("found debug")
83 "${BuildDepends_BINARY_DIR}/Project/Debug/zot${CMAKE_EXECUTABLE_SUFFIX}")
85 "${BuildDepends_BINARY_DIR}/Project/Debug/zot${CMAKE_EXECUTABLE_SUFFIX}")
87 message("Running ${bar} ")
88 execute_process(COMMAND ${bar} OUTPUT_VARIABLE out RESULT_VARIABLE runResult)
89 string(REGEX REPLACE "[\r\n]" " " out "${out}")
90 message("Run result: ${runResult} Output: \"${out}\"")
92 if("${out}" STREQUAL "foo ")
94 else("${out}" STREQUAL "foo ")
95 message(SEND_ERROR "Project did not initially build properly: ${out}")
96 endif("${out}" STREQUAL "foo ")
98 message("Running ${zot} ")
99 execute_process(COMMAND ${zot} OUTPUT_VARIABLE out RESULT_VARIABLE runResult)
100 string(REGEX REPLACE "[\r\n]" " " out "${out}")
101 message("Run result: ${runResult} Output: \"${out}\"")
103 set(VALUE_UNCHANGED "[zot] [zot_custom] [zot_macro_dir] [zot_macro_tgt] ")
104 if("${out}" STREQUAL "${VALUE_UNCHANGED}")
106 else("${out}" STREQUAL "${VALUE_UNCHANGED}")
107 message(SEND_ERROR "Project did not initially build properly: ${out}")
108 endif("${out}" STREQUAL "${VALUE_UNCHANGED}")
110 message("Waiting 3 seconds...")
111 # any additional argument will cause ${bar} to wait forever
112 execute_process(COMMAND ${bar} -infinite TIMEOUT 3 OUTPUT_VARIABLE out)
114 message("Modifying Project/foo.cxx")
115 write_file(${BuildDepends_BINARY_DIR}/Project/foo.cxx
116 "const char* foo() { return \"foo changed\";}" )
117 file(WRITE ${BuildDepends_BINARY_DIR}/Project/zot.hxx.in
118 "static const char* zot = \"zot changed\";\n")
119 file(WRITE ${BuildDepends_BINARY_DIR}/Project/zot_custom.hxx.in
120 "static const char* zot_custom = \"zot_custom changed\";\n")
121 file(WRITE ${BuildDepends_BINARY_DIR}/Project/zot_macro_dir.hxx
122 "static const char* zot_macro_dir = \"zot_macro_dir changed\";\n")
123 file(WRITE ${BuildDepends_BINARY_DIR}/Project/zot_macro_tgt.hxx
124 "static const char* zot_macro_tgt = \"zot_macro_tgt changed\";\n")
128 message("Building project second time")
130 ${BuildDepends_BINARY_DIR}/Project
131 ${BuildDepends_SOURCE_DIR}/Project
133 OUTPUT_VARIABLE OUTPUT)
135 # Xcode is in serious need of help here
138 ${BuildDepends_BINARY_DIR}/Project
139 ${BuildDepends_SOURCE_DIR}/Project
141 OUTPUT_VARIABLE OUTPUT)
143 ${BuildDepends_BINARY_DIR}/Project
144 ${BuildDepends_SOURCE_DIR}/Project
146 OUTPUT_VARIABLE OUTPUT)
150 message(SEND_ERROR "Could not build test project: ${OUTPUT}")
153 "${BuildDepends_BINARY_DIR}/Project/Debug/bar${CMAKE_EXECUTABLE_SUFFIX}" )
154 message("found debug")
156 "${BuildDepends_BINARY_DIR}/Project/Debug/bar${CMAKE_EXECUTABLE_SUFFIX}")
158 "${BuildDepends_BINARY_DIR}/Project/Debug/zot${CMAKE_EXECUTABLE_SUFFIX}" )
159 message("found debug")
161 "${BuildDepends_BINARY_DIR}/Project/Debug/zot${CMAKE_EXECUTABLE_SUFFIX}")
163 message("Running ${bar} ")
164 execute_process(COMMAND ${bar} OUTPUT_VARIABLE out RESULT_VARIABLE runResult)
165 string(REGEX REPLACE "[\r\n]" " " out "${out}")
166 message("Run result: ${runResult} Output: \"${out}\"")
168 if("${out}" STREQUAL "foo changed ")
170 else("${out}" STREQUAL "foo changed ")
171 message(SEND_ERROR "Project did not rebuild properly!")
172 endif("${out}" STREQUAL "foo changed ")
174 message("Running ${zot} ")
175 execute_process(COMMAND ${zot} OUTPUT_VARIABLE out RESULT_VARIABLE runResult)
176 string(REGEX REPLACE "[\r\n]" " " out "${out}")
177 message("Run result: ${runResult} Output: \"${out}\"")
180 "[zot changed] [zot_custom changed] [zot_macro_dir changed] [zot_macro_tgt changed] "
182 if("${out}" STREQUAL "${VALUE_CHANGED}")
184 else("${out}" STREQUAL "${VALUE_CHANGED}")
185 message(SEND_ERROR "Project did not rebuild properly!")
186 endif("${out}" STREQUAL "${VALUE_CHANGED}")