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 file(MAKE_DIRECTORY ${BuildDepends_BINARY_DIR}/Project)
16 message("Creating Project/foo.cxx")
17 write_file(${BuildDepends_BINARY_DIR}/Project/foo.cxx
18 "const char* foo() { return \"foo\";}" )
20 file(WRITE ${BuildDepends_BINARY_DIR}/Project/zot.hxx.in
21 "static const char* zot = \"zot\";\n")
22 file(WRITE ${BuildDepends_BINARY_DIR}/Project/zot_custom.hxx.in
23 "static const char* zot_custom = \"zot_custom\";\n")
25 message("Building project first time")
27 ${BuildDepends_BINARY_DIR}/Project
28 ${BuildDepends_SOURCE_DIR}/Project
30 OUTPUT_VARIABLE OUTPUT)
31 if("${CMAKE_GENERATOR}" MATCHES "Xcode")
33 ${BuildDepends_BINARY_DIR}/Project
34 ${BuildDepends_SOURCE_DIR}/Project
36 OUTPUT_VARIABLE OUTPUT)
38 ${BuildDepends_BINARY_DIR}/Project
39 ${BuildDepends_SOURCE_DIR}/Project
41 OUTPUT_VARIABLE OUTPUT)
42 endif("${CMAKE_GENERATOR}" MATCHES "Xcode")
45 message(SEND_ERROR "Could not build test project: ${OUTPUT}")
48 set(bar ${BuildDepends_BINARY_DIR}/Project/bar${CMAKE_EXECUTABLE_SUFFIX})
50 "${BuildDepends_BINARY_DIR}/Project/Debug/bar${CMAKE_EXECUTABLE_SUFFIX}" )
51 message("found debug")
53 "${BuildDepends_BINARY_DIR}/Project/Debug/bar${CMAKE_EXECUTABLE_SUFFIX}")
55 "${BuildDepends_BINARY_DIR}/Project/Debug/bar${CMAKE_EXECUTABLE_SUFFIX}")
56 set(zot ${BuildDepends_BINARY_DIR}/Project/zot${CMAKE_EXECUTABLE_SUFFIX})
58 "${BuildDepends_BINARY_DIR}/Project/Debug/zot${CMAKE_EXECUTABLE_SUFFIX}" )
59 message("found debug")
61 "${BuildDepends_BINARY_DIR}/Project/Debug/zot${CMAKE_EXECUTABLE_SUFFIX}")
63 "${BuildDepends_BINARY_DIR}/Project/Debug/zot${CMAKE_EXECUTABLE_SUFFIX}")
65 message("Running ${bar} ")
66 execute_process(COMMAND ${bar} OUTPUT_VARIABLE out RESULT_VARIABLE runResult)
67 string(REGEX REPLACE "[\r\n]" " " out "${out}")
68 message("Run result: ${runResult} Output: \"${out}\"")
70 if("${out}" STREQUAL "foo ")
72 else("${out}" STREQUAL "foo ")
73 message(SEND_ERROR "Project did not initially build properly: ${out}")
74 endif("${out}" STREQUAL "foo ")
76 message("Running ${zot} ")
77 execute_process(COMMAND ${zot} OUTPUT_VARIABLE out RESULT_VARIABLE runResult)
78 string(REGEX REPLACE "[\r\n]" " " out "${out}")
79 message("Run result: ${runResult} Output: \"${out}\"")
81 if("${out}" STREQUAL "[zot] [zot_custom] ")
83 else("${out}" STREQUAL "[zot] [zot_custom] ")
84 message(SEND_ERROR "Project did not initially build properly: ${out}")
85 endif("${out}" STREQUAL "[zot] [zot_custom] ")
87 message("Waiting 3 seconds...")
88 # any additional argument will cause ${bar} to wait forever
89 execute_process(COMMAND ${bar} -infinite TIMEOUT 3 OUTPUT_VARIABLE out)
91 message("Modifying Project/foo.cxx")
92 write_file(${BuildDepends_BINARY_DIR}/Project/foo.cxx
93 "const char* foo() { return \"foo changed\";}" )
94 file(WRITE ${BuildDepends_BINARY_DIR}/Project/zot.hxx.in
95 "static const char* zot = \"zot changed\";\n")
96 file(WRITE ${BuildDepends_BINARY_DIR}/Project/zot_custom.hxx.in
97 "static const char* zot_custom = \"zot_custom changed\";\n")
99 message("Building project second time")
101 ${BuildDepends_BINARY_DIR}/Project
102 ${BuildDepends_SOURCE_DIR}/Project
104 OUTPUT_VARIABLE OUTPUT)
106 # Xcode is in serious need of help here
107 if("${CMAKE_GENERATOR}" MATCHES "Xcode")
109 ${BuildDepends_BINARY_DIR}/Project
110 ${BuildDepends_SOURCE_DIR}/Project
112 OUTPUT_VARIABLE OUTPUT)
114 ${BuildDepends_BINARY_DIR}/Project
115 ${BuildDepends_SOURCE_DIR}/Project
117 OUTPUT_VARIABLE OUTPUT)
118 endif("${CMAKE_GENERATOR}" MATCHES "Xcode")
121 message(SEND_ERROR "Could not build test project: ${OUTPUT}")
124 "${BuildDepends_BINARY_DIR}/Project/Debug/bar${CMAKE_EXECUTABLE_SUFFIX}" )
125 message("found debug")
127 "${BuildDepends_BINARY_DIR}/Project/Debug/bar${CMAKE_EXECUTABLE_SUFFIX}")
129 "${BuildDepends_BINARY_DIR}/Project/Debug/zot${CMAKE_EXECUTABLE_SUFFIX}" )
130 message("found debug")
132 "${BuildDepends_BINARY_DIR}/Project/Debug/zot${CMAKE_EXECUTABLE_SUFFIX}")
134 message("Running ${bar} ")
135 execute_process(COMMAND ${bar} OUTPUT_VARIABLE out RESULT_VARIABLE runResult)
136 string(REGEX REPLACE "[\r\n]" " " out "${out}")
137 message("Run result: ${runResult} Output: \"${out}\"")
139 if("${out}" STREQUAL "foo changed ")
141 else("${out}" STREQUAL "foo changed ")
142 message(SEND_ERROR "Project did not rebuild properly!")
143 endif("${out}" STREQUAL "foo changed ")
145 message("Running ${zot} ")
146 execute_process(COMMAND ${zot} OUTPUT_VARIABLE out RESULT_VARIABLE runResult)
147 string(REGEX REPLACE "[\r\n]" " " out "${out}")
148 message("Run result: ${runResult} Output: \"${out}\"")
150 if("${out}" STREQUAL "[zot changed] [zot_custom changed] ")
152 else("${out}" STREQUAL "[zot changed] [zot_custom changed] ")
153 message(SEND_ERROR "Project did not rebuild properly!")
154 endif("${out}" STREQUAL "[zot changed] [zot_custom changed] ")