2007-05-09 23:10:12 +04:00
|
|
|
# this test creates a static library and an executable
|
|
|
|
# the source to the library is then changed
|
|
|
|
# and the build is done on the executable and if things
|
|
|
|
# are working the executable should relink with the new
|
|
|
|
# value. The subdir Project contains the CMakelists.txt
|
|
|
|
# and source files for the test project.
|
2008-03-25 18:27:18 +03:00
|
|
|
cmake_minimum_required (VERSION 2.6)
|
2007-05-09 23:10:12 +04:00
|
|
|
project(BuildDepends)
|
2007-06-14 00:26:50 +04:00
|
|
|
|
2007-12-22 04:19:23 +03:00
|
|
|
# This entire test takes place during the initial
|
|
|
|
# configure step. It should not run again when the
|
|
|
|
# project is built.
|
|
|
|
set(CMAKE_SUPPRESS_REGENERATION 1)
|
|
|
|
|
2008-05-14 19:55:12 +04:00
|
|
|
# Xcode needs some help with the fancy dependencies in this test.
|
|
|
|
if("${CMAKE_GENERATOR}" MATCHES "Xcode")
|
|
|
|
set(HELP_XCODE 1)
|
|
|
|
endif("${CMAKE_GENERATOR}" MATCHES "Xcode")
|
|
|
|
function(help_xcode_depends)
|
|
|
|
if(HELP_XCODE)
|
|
|
|
file(GLOB_RECURSE MACRO_OBJS
|
|
|
|
${BuildDepends_BINARY_DIR}/Project/zot_macro_*.o*
|
|
|
|
)
|
|
|
|
if(MACRO_OBJS)
|
|
|
|
message("Helping Xcode by removing objects [${MACRO_OBJS}]")
|
|
|
|
file(REMOVE ${MACRO_OBJS})
|
|
|
|
endif(MACRO_OBJS)
|
|
|
|
endif(HELP_XCODE)
|
|
|
|
endfunction(help_xcode_depends)
|
|
|
|
|
2009-10-27 18:31:40 +03:00
|
|
|
# The Intel compiler causes the MSVC linker to crash during
|
|
|
|
# incremental linking, so avoid the /INCREMENTAL:YES flag.
|
|
|
|
if(WIN32 AND "${CMAKE_CXX_COMPILER_ID}" MATCHES "Intel")
|
|
|
|
set(_cmake_options "-DCMAKE_EXE_LINKER_FLAGS=")
|
|
|
|
endif()
|
|
|
|
|
2007-06-14 00:26:50 +04:00
|
|
|
file(MAKE_DIRECTORY ${BuildDepends_BINARY_DIR}/Project)
|
|
|
|
message("Creating Project/foo.cxx")
|
2007-05-16 15:55:00 +04:00
|
|
|
write_file(${BuildDepends_BINARY_DIR}/Project/foo.cxx
|
2007-05-09 23:10:12 +04:00
|
|
|
"const char* foo() { return \"foo\";}" )
|
2007-06-14 00:26:50 +04:00
|
|
|
|
2007-09-17 18:51:05 +04:00
|
|
|
file(WRITE ${BuildDepends_BINARY_DIR}/Project/zot.hxx.in
|
|
|
|
"static const char* zot = \"zot\";\n")
|
2007-12-21 20:22:12 +03:00
|
|
|
file(WRITE ${BuildDepends_BINARY_DIR}/Project/zot_custom.hxx.in
|
|
|
|
"static const char* zot_custom = \"zot_custom\";\n")
|
2008-05-14 19:55:12 +04:00
|
|
|
file(WRITE ${BuildDepends_BINARY_DIR}/Project/zot_macro_dir.hxx
|
|
|
|
"static const char* zot_macro_dir = \"zot_macro_dir\";\n")
|
|
|
|
file(WRITE ${BuildDepends_BINARY_DIR}/Project/zot_macro_tgt.hxx
|
|
|
|
"static const char* zot_macro_tgt = \"zot_macro_tgt\";\n")
|
|
|
|
|
|
|
|
help_xcode_depends()
|
2007-09-17 18:51:05 +04:00
|
|
|
|
2007-06-14 00:26:50 +04:00
|
|
|
message("Building project first time")
|
2007-05-09 23:10:12 +04:00
|
|
|
try_compile(RESULT
|
|
|
|
${BuildDepends_BINARY_DIR}/Project
|
|
|
|
${BuildDepends_SOURCE_DIR}/Project
|
|
|
|
testRebuild
|
2009-10-27 18:31:40 +03:00
|
|
|
CMAKE_FLAGS ${_cmake_options}
|
2007-05-09 23:10:12 +04:00
|
|
|
OUTPUT_VARIABLE OUTPUT)
|
2008-05-14 19:55:12 +04:00
|
|
|
if(HELP_XCODE)
|
2007-05-24 01:58:14 +04:00
|
|
|
try_compile(RESULT
|
|
|
|
${BuildDepends_BINARY_DIR}/Project
|
|
|
|
${BuildDepends_SOURCE_DIR}/Project
|
|
|
|
testRebuild
|
|
|
|
OUTPUT_VARIABLE OUTPUT)
|
|
|
|
try_compile(RESULT
|
|
|
|
${BuildDepends_BINARY_DIR}/Project
|
|
|
|
${BuildDepends_SOURCE_DIR}/Project
|
|
|
|
testRebuild
|
|
|
|
OUTPUT_VARIABLE OUTPUT)
|
2008-05-14 19:55:12 +04:00
|
|
|
endif(HELP_XCODE)
|
2007-05-24 01:58:14 +04:00
|
|
|
|
2009-10-22 17:35:58 +04:00
|
|
|
message("Output from first build:\n${OUTPUT}")
|
2007-05-16 15:55:00 +04:00
|
|
|
if(NOT RESULT)
|
2009-10-22 17:35:58 +04:00
|
|
|
message(SEND_ERROR "Could not build test project (1)!")
|
2007-05-16 15:55:00 +04:00
|
|
|
endif(NOT RESULT)
|
|
|
|
|
2007-05-10 18:05:52 +04:00
|
|
|
set(bar ${BuildDepends_BINARY_DIR}/Project/bar${CMAKE_EXECUTABLE_SUFFIX})
|
|
|
|
if(EXISTS
|
|
|
|
"${BuildDepends_BINARY_DIR}/Project/Debug/bar${CMAKE_EXECUTABLE_SUFFIX}" )
|
|
|
|
message("found debug")
|
|
|
|
set(bar
|
|
|
|
"${BuildDepends_BINARY_DIR}/Project/Debug/bar${CMAKE_EXECUTABLE_SUFFIX}")
|
|
|
|
endif(EXISTS
|
|
|
|
"${BuildDepends_BINARY_DIR}/Project/Debug/bar${CMAKE_EXECUTABLE_SUFFIX}")
|
2007-09-17 18:51:05 +04:00
|
|
|
set(zot ${BuildDepends_BINARY_DIR}/Project/zot${CMAKE_EXECUTABLE_SUFFIX})
|
|
|
|
if(EXISTS
|
|
|
|
"${BuildDepends_BINARY_DIR}/Project/Debug/zot${CMAKE_EXECUTABLE_SUFFIX}" )
|
|
|
|
message("found debug")
|
|
|
|
set(zot
|
|
|
|
"${BuildDepends_BINARY_DIR}/Project/Debug/zot${CMAKE_EXECUTABLE_SUFFIX}")
|
|
|
|
endif(EXISTS
|
|
|
|
"${BuildDepends_BINARY_DIR}/Project/Debug/zot${CMAKE_EXECUTABLE_SUFFIX}")
|
2007-06-14 00:26:50 +04:00
|
|
|
|
|
|
|
message("Running ${bar} ")
|
|
|
|
execute_process(COMMAND ${bar} OUTPUT_VARIABLE out RESULT_VARIABLE runResult)
|
2007-05-10 18:05:52 +04:00
|
|
|
string(REGEX REPLACE "[\r\n]" " " out "${out}")
|
2007-06-14 00:26:50 +04:00
|
|
|
message("Run result: ${runResult} Output: \"${out}\"")
|
|
|
|
|
2007-05-10 18:05:52 +04:00
|
|
|
if("${out}" STREQUAL "foo ")
|
2007-05-09 23:10:12 +04:00
|
|
|
message("Worked!")
|
2007-05-10 18:05:52 +04:00
|
|
|
else("${out}" STREQUAL "foo ")
|
2007-05-24 01:58:14 +04:00
|
|
|
message(SEND_ERROR "Project did not initially build properly: ${out}")
|
2007-05-10 18:05:52 +04:00
|
|
|
endif("${out}" STREQUAL "foo ")
|
2007-05-09 23:10:12 +04:00
|
|
|
|
2007-09-17 18:51:05 +04:00
|
|
|
message("Running ${zot} ")
|
|
|
|
execute_process(COMMAND ${zot} OUTPUT_VARIABLE out RESULT_VARIABLE runResult)
|
|
|
|
string(REGEX REPLACE "[\r\n]" " " out "${out}")
|
|
|
|
message("Run result: ${runResult} Output: \"${out}\"")
|
|
|
|
|
2008-05-14 19:55:12 +04:00
|
|
|
set(VALUE_UNCHANGED "[zot] [zot_custom] [zot_macro_dir] [zot_macro_tgt] ")
|
|
|
|
if("${out}" STREQUAL "${VALUE_UNCHANGED}")
|
2007-09-17 18:51:05 +04:00
|
|
|
message("Worked!")
|
2008-05-14 19:55:12 +04:00
|
|
|
else("${out}" STREQUAL "${VALUE_UNCHANGED}")
|
2007-09-17 18:51:05 +04:00
|
|
|
message(SEND_ERROR "Project did not initially build properly: ${out}")
|
2008-05-14 19:55:12 +04:00
|
|
|
endif("${out}" STREQUAL "${VALUE_UNCHANGED}")
|
2007-09-17 18:51:05 +04:00
|
|
|
|
2007-06-14 00:26:50 +04:00
|
|
|
message("Waiting 3 seconds...")
|
|
|
|
# any additional argument will cause ${bar} to wait forever
|
|
|
|
execute_process(COMMAND ${bar} -infinite TIMEOUT 3 OUTPUT_VARIABLE out)
|
|
|
|
|
|
|
|
message("Modifying Project/foo.cxx")
|
2007-05-16 15:55:00 +04:00
|
|
|
write_file(${BuildDepends_BINARY_DIR}/Project/foo.cxx
|
2007-05-09 23:10:12 +04:00
|
|
|
"const char* foo() { return \"foo changed\";}" )
|
2007-09-17 18:51:05 +04:00
|
|
|
file(WRITE ${BuildDepends_BINARY_DIR}/Project/zot.hxx.in
|
|
|
|
"static const char* zot = \"zot changed\";\n")
|
2007-12-21 20:22:12 +03:00
|
|
|
file(WRITE ${BuildDepends_BINARY_DIR}/Project/zot_custom.hxx.in
|
|
|
|
"static const char* zot_custom = \"zot_custom changed\";\n")
|
2008-05-14 19:55:12 +04:00
|
|
|
file(WRITE ${BuildDepends_BINARY_DIR}/Project/zot_macro_dir.hxx
|
|
|
|
"static const char* zot_macro_dir = \"zot_macro_dir changed\";\n")
|
|
|
|
file(WRITE ${BuildDepends_BINARY_DIR}/Project/zot_macro_tgt.hxx
|
|
|
|
"static const char* zot_macro_tgt = \"zot_macro_tgt changed\";\n")
|
|
|
|
|
|
|
|
help_xcode_depends()
|
2007-06-14 00:26:50 +04:00
|
|
|
|
|
|
|
message("Building project second time")
|
2007-05-09 23:10:12 +04:00
|
|
|
try_compile(RESULT
|
|
|
|
${BuildDepends_BINARY_DIR}/Project
|
|
|
|
${BuildDepends_SOURCE_DIR}/Project
|
|
|
|
testRebuild
|
2009-10-27 18:31:40 +03:00
|
|
|
CMAKE_FLAGS ${_cmake_options}
|
2007-05-09 23:10:12 +04:00
|
|
|
OUTPUT_VARIABLE OUTPUT)
|
|
|
|
|
2007-05-24 01:58:14 +04:00
|
|
|
# Xcode is in serious need of help here
|
2008-05-14 19:55:12 +04:00
|
|
|
if(HELP_XCODE)
|
2007-05-24 01:58:14 +04:00
|
|
|
try_compile(RESULT
|
|
|
|
${BuildDepends_BINARY_DIR}/Project
|
|
|
|
${BuildDepends_SOURCE_DIR}/Project
|
|
|
|
testRebuild
|
|
|
|
OUTPUT_VARIABLE OUTPUT)
|
|
|
|
try_compile(RESULT
|
|
|
|
${BuildDepends_BINARY_DIR}/Project
|
|
|
|
${BuildDepends_SOURCE_DIR}/Project
|
|
|
|
testRebuild
|
|
|
|
OUTPUT_VARIABLE OUTPUT)
|
2008-05-14 19:55:12 +04:00
|
|
|
endif(HELP_XCODE)
|
2007-05-24 01:58:14 +04:00
|
|
|
|
2009-10-22 17:35:58 +04:00
|
|
|
message("Output from second build:\n${OUTPUT}")
|
2007-05-16 15:55:00 +04:00
|
|
|
if(NOT RESULT)
|
2009-10-22 17:35:58 +04:00
|
|
|
message(SEND_ERROR "Could not build test project (2)!")
|
2007-05-16 15:55:00 +04:00
|
|
|
endif(NOT RESULT)
|
2007-05-10 18:05:52 +04:00
|
|
|
if(EXISTS
|
|
|
|
"${BuildDepends_BINARY_DIR}/Project/Debug/bar${CMAKE_EXECUTABLE_SUFFIX}" )
|
|
|
|
message("found debug")
|
|
|
|
endif(EXISTS
|
|
|
|
"${BuildDepends_BINARY_DIR}/Project/Debug/bar${CMAKE_EXECUTABLE_SUFFIX}")
|
2007-09-17 18:51:05 +04:00
|
|
|
if(EXISTS
|
|
|
|
"${BuildDepends_BINARY_DIR}/Project/Debug/zot${CMAKE_EXECUTABLE_SUFFIX}" )
|
|
|
|
message("found debug")
|
|
|
|
endif(EXISTS
|
|
|
|
"${BuildDepends_BINARY_DIR}/Project/Debug/zot${CMAKE_EXECUTABLE_SUFFIX}")
|
2007-05-10 18:05:52 +04:00
|
|
|
|
2007-06-14 00:26:50 +04:00
|
|
|
message("Running ${bar} ")
|
|
|
|
execute_process(COMMAND ${bar} OUTPUT_VARIABLE out RESULT_VARIABLE runResult)
|
2007-05-10 18:05:52 +04:00
|
|
|
string(REGEX REPLACE "[\r\n]" " " out "${out}")
|
2007-06-14 00:26:50 +04:00
|
|
|
message("Run result: ${runResult} Output: \"${out}\"")
|
2007-05-09 23:10:12 +04:00
|
|
|
|
2007-05-10 18:05:52 +04:00
|
|
|
if("${out}" STREQUAL "foo changed ")
|
2007-05-09 23:10:12 +04:00
|
|
|
message("Worked!")
|
2007-05-10 18:05:52 +04:00
|
|
|
else("${out}" STREQUAL "foo changed ")
|
2007-05-23 21:27:00 +04:00
|
|
|
message(SEND_ERROR "Project did not rebuild properly!")
|
2007-05-10 18:05:52 +04:00
|
|
|
endif("${out}" STREQUAL "foo changed ")
|
2007-09-17 18:51:05 +04:00
|
|
|
|
|
|
|
message("Running ${zot} ")
|
|
|
|
execute_process(COMMAND ${zot} OUTPUT_VARIABLE out RESULT_VARIABLE runResult)
|
|
|
|
string(REGEX REPLACE "[\r\n]" " " out "${out}")
|
|
|
|
message("Run result: ${runResult} Output: \"${out}\"")
|
|
|
|
|
2008-05-14 19:55:12 +04:00
|
|
|
set(VALUE_CHANGED
|
|
|
|
"[zot changed] [zot_custom changed] [zot_macro_dir changed] [zot_macro_tgt changed] "
|
|
|
|
)
|
|
|
|
if("${out}" STREQUAL "${VALUE_CHANGED}")
|
2007-09-17 18:51:05 +04:00
|
|
|
message("Worked!")
|
2008-05-14 19:55:12 +04:00
|
|
|
else("${out}" STREQUAL "${VALUE_CHANGED}")
|
2007-09-17 18:51:05 +04:00
|
|
|
message(SEND_ERROR "Project did not rebuild properly!")
|
2008-05-14 19:55:12 +04:00
|
|
|
endif("${out}" STREQUAL "${VALUE_CHANGED}")
|