Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Tests / BuildDepends / CMakeLists.txt
blobd8f83605a02073015e432dac5703dab2566099b6
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)
8 project(BuildDepends)
10 # This entire test takes place during the initial
11 # configure step.  It should not run again when the
12 # project is built.
13 set(CMAKE_SUPPRESS_REGENERATION 1)
15 # Xcode needs some help with the fancy dependencies in this test.
16 if("${CMAKE_GENERATOR}" MATCHES "Xcode")
17   set(HELP_XCODE 1)
18 endif("${CMAKE_GENERATOR}" MATCHES "Xcode")
19 function(help_xcode_depends)
20   if(HELP_XCODE)
21     file(GLOB_RECURSE MACRO_OBJS
22       ${BuildDepends_BINARY_DIR}/Project/zot_macro_*.o*
23       )
24     if(MACRO_OBJS)
25       message("Helping Xcode by removing objects [${MACRO_OBJS}]")
26       file(REMOVE ${MACRO_OBJS})
27     endif(MACRO_OBJS)
28   endif(HELP_XCODE)
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")
45 help_xcode_depends()
47 message("Building project first time")
48 try_compile(RESULT 
49   ${BuildDepends_BINARY_DIR}/Project
50   ${BuildDepends_SOURCE_DIR}/Project
51   testRebuild
52   OUTPUT_VARIABLE OUTPUT)
53 if(HELP_XCODE)
54   try_compile(RESULT 
55     ${BuildDepends_BINARY_DIR}/Project
56     ${BuildDepends_SOURCE_DIR}/Project
57     testRebuild
58     OUTPUT_VARIABLE OUTPUT)
59   try_compile(RESULT 
60     ${BuildDepends_BINARY_DIR}/Project
61     ${BuildDepends_SOURCE_DIR}/Project
62     testRebuild
63     OUTPUT_VARIABLE OUTPUT)
64 endif(HELP_XCODE)
66 if(NOT RESULT)
67   message(SEND_ERROR "Could not build test project: ${OUTPUT}")
68 endif(NOT RESULT)
70 set(bar ${BuildDepends_BINARY_DIR}/Project/bar${CMAKE_EXECUTABLE_SUFFIX})
71 if(EXISTS 
72     "${BuildDepends_BINARY_DIR}/Project/Debug/bar${CMAKE_EXECUTABLE_SUFFIX}" )
73   message("found debug")
74   set(bar 
75     "${BuildDepends_BINARY_DIR}/Project/Debug/bar${CMAKE_EXECUTABLE_SUFFIX}")
76 endif(EXISTS 
77   "${BuildDepends_BINARY_DIR}/Project/Debug/bar${CMAKE_EXECUTABLE_SUFFIX}")
78 set(zot ${BuildDepends_BINARY_DIR}/Project/zot${CMAKE_EXECUTABLE_SUFFIX})
79 if(EXISTS 
80     "${BuildDepends_BINARY_DIR}/Project/Debug/zot${CMAKE_EXECUTABLE_SUFFIX}" )
81   message("found debug")
82   set(zot 
83     "${BuildDepends_BINARY_DIR}/Project/Debug/zot${CMAKE_EXECUTABLE_SUFFIX}")
84 endif(EXISTS 
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 ")
93   message("Worked!")
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}")
105   message("Worked!")
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")
126 help_xcode_depends()
128 message("Building project second time")
129 try_compile(RESULT 
130   ${BuildDepends_BINARY_DIR}/Project
131   ${BuildDepends_SOURCE_DIR}/Project
132   testRebuild
133   OUTPUT_VARIABLE OUTPUT)
135 # Xcode is in serious need of help here
136 if(HELP_XCODE)
137   try_compile(RESULT 
138     ${BuildDepends_BINARY_DIR}/Project
139     ${BuildDepends_SOURCE_DIR}/Project
140     testRebuild
141     OUTPUT_VARIABLE OUTPUT)
142   try_compile(RESULT 
143     ${BuildDepends_BINARY_DIR}/Project
144     ${BuildDepends_SOURCE_DIR}/Project
145     testRebuild
146     OUTPUT_VARIABLE OUTPUT)
147 endif(HELP_XCODE)
149 if(NOT RESULT)
150   message(SEND_ERROR "Could not build test project: ${OUTPUT}")
151 endif(NOT RESULT)
152 if(EXISTS 
153     "${BuildDepends_BINARY_DIR}/Project/Debug/bar${CMAKE_EXECUTABLE_SUFFIX}" )
154   message("found debug")
155 endif(EXISTS 
156   "${BuildDepends_BINARY_DIR}/Project/Debug/bar${CMAKE_EXECUTABLE_SUFFIX}")
157 if(EXISTS 
158     "${BuildDepends_BINARY_DIR}/Project/Debug/zot${CMAKE_EXECUTABLE_SUFFIX}" )
159   message("found debug")
160 endif(EXISTS 
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 ")
169   message("Worked!")
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}\"")
179 set(VALUE_CHANGED
180   "[zot changed] [zot_custom changed] [zot_macro_dir changed] [zot_macro_tgt changed] "
181   )
182 if("${out}" STREQUAL "${VALUE_CHANGED}")
183   message("Worked!")
184 else("${out}" STREQUAL "${VALUE_CHANGED}")
185   message(SEND_ERROR "Project did not rebuild properly!")
186 endif("${out}" STREQUAL "${VALUE_CHANGED}")