Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Tests / BuildDepends / CMakeLists.txt
blob0d143ca170376a16bcba72984faea826324c02f8
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 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")
26 try_compile(RESULT 
27   ${BuildDepends_BINARY_DIR}/Project
28   ${BuildDepends_SOURCE_DIR}/Project
29   testRebuild
30   OUTPUT_VARIABLE OUTPUT)
31 if("${CMAKE_GENERATOR}" MATCHES "Xcode")
32   try_compile(RESULT 
33     ${BuildDepends_BINARY_DIR}/Project
34     ${BuildDepends_SOURCE_DIR}/Project
35     testRebuild
36     OUTPUT_VARIABLE OUTPUT)
37   try_compile(RESULT 
38     ${BuildDepends_BINARY_DIR}/Project
39     ${BuildDepends_SOURCE_DIR}/Project
40     testRebuild
41     OUTPUT_VARIABLE OUTPUT)
42 endif("${CMAKE_GENERATOR}" MATCHES "Xcode")
44 if(NOT RESULT)
45   message(SEND_ERROR "Could not build test project: ${OUTPUT}")
46 endif(NOT RESULT)
48 set(bar ${BuildDepends_BINARY_DIR}/Project/bar${CMAKE_EXECUTABLE_SUFFIX})
49 if(EXISTS 
50     "${BuildDepends_BINARY_DIR}/Project/Debug/bar${CMAKE_EXECUTABLE_SUFFIX}" )
51   message("found debug")
52   set(bar 
53     "${BuildDepends_BINARY_DIR}/Project/Debug/bar${CMAKE_EXECUTABLE_SUFFIX}")
54 endif(EXISTS 
55   "${BuildDepends_BINARY_DIR}/Project/Debug/bar${CMAKE_EXECUTABLE_SUFFIX}")
56 set(zot ${BuildDepends_BINARY_DIR}/Project/zot${CMAKE_EXECUTABLE_SUFFIX})
57 if(EXISTS 
58     "${BuildDepends_BINARY_DIR}/Project/Debug/zot${CMAKE_EXECUTABLE_SUFFIX}" )
59   message("found debug")
60   set(zot 
61     "${BuildDepends_BINARY_DIR}/Project/Debug/zot${CMAKE_EXECUTABLE_SUFFIX}")
62 endif(EXISTS 
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 ")
71   message("Worked!")
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] ")
82   message("Worked!")
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")
100 try_compile(RESULT 
101   ${BuildDepends_BINARY_DIR}/Project
102   ${BuildDepends_SOURCE_DIR}/Project
103   testRebuild
104   OUTPUT_VARIABLE OUTPUT)
106 # Xcode is in serious need of help here
107 if("${CMAKE_GENERATOR}" MATCHES "Xcode")
108   try_compile(RESULT 
109     ${BuildDepends_BINARY_DIR}/Project
110     ${BuildDepends_SOURCE_DIR}/Project
111     testRebuild
112     OUTPUT_VARIABLE OUTPUT)
113   try_compile(RESULT 
114     ${BuildDepends_BINARY_DIR}/Project
115     ${BuildDepends_SOURCE_DIR}/Project
116     testRebuild
117     OUTPUT_VARIABLE OUTPUT)
118 endif("${CMAKE_GENERATOR}" MATCHES "Xcode")
120 if(NOT RESULT)
121   message(SEND_ERROR "Could not build test project: ${OUTPUT}")
122 endif(NOT RESULT)
123 if(EXISTS 
124     "${BuildDepends_BINARY_DIR}/Project/Debug/bar${CMAKE_EXECUTABLE_SUFFIX}" )
125   message("found debug")
126 endif(EXISTS 
127   "${BuildDepends_BINARY_DIR}/Project/Debug/bar${CMAKE_EXECUTABLE_SUFFIX}")
128 if(EXISTS 
129     "${BuildDepends_BINARY_DIR}/Project/Debug/zot${CMAKE_EXECUTABLE_SUFFIX}" )
130   message("found debug")
131 endif(EXISTS 
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 ")
140   message("Worked!")
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] ")
151   message("Worked!")
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] ")