2008-05-14 19:55:12 +04:00
|
|
|
cmake_minimum_required(VERSION 2.6)
|
2007-05-09 23:10:12 +04:00
|
|
|
project(testRebuild)
|
2009-02-19 23:24:44 +03:00
|
|
|
if(APPLE)
|
|
|
|
# only use multi-arch if the sysroot exists on this machine
|
|
|
|
if(EXISTS "${CMAKE_OSX_SYSROOT}")
|
|
|
|
set(CMAKE_OSX_ARCHITECTURES "ppc;i386")
|
|
|
|
endif(EXISTS "${CMAKE_OSX_SYSROOT}")
|
|
|
|
endif(APPLE)
|
|
|
|
|
2007-05-16 15:56:56 +04:00
|
|
|
add_library(foo STATIC ${testRebuild_BINARY_DIR}/foo.cxx)
|
2009-02-19 19:51:24 +03:00
|
|
|
set_target_properties(foo PROPERTIES OUTPUT_NAME "foolib")
|
2007-05-23 21:27:00 +04:00
|
|
|
# Add a generated header that regenerates when the generator is
|
|
|
|
# rebuilt.
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/regen.h
|
|
|
|
COMMAND generator ${CMAKE_CURRENT_BINARY_DIR}/regen.h regen
|
|
|
|
DEPENDS generator # adds file-level dependency to re-run rule
|
|
|
|
)
|
|
|
|
|
|
|
|
# Add a generated header that does NOT regenerate when the generator
|
|
|
|
# is rebuilt.
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/noregen.h
|
|
|
|
COMMAND generator ${CMAKE_CURRENT_BINARY_DIR}/noregen.h noregen
|
|
|
|
)
|
|
|
|
|
|
|
|
# Test that the generator rebuilds when the static library source file
|
|
|
|
# changes. This should cause regen.h to be recreated also.
|
|
|
|
add_executable(generator generator.cxx)
|
|
|
|
target_link_libraries(generator foo)
|
2009-02-19 19:51:24 +03:00
|
|
|
set_target_properties(generator PROPERTIES OUTPUT_NAME "gen")
|
2007-05-23 21:27:00 +04:00
|
|
|
|
|
|
|
# Build an executable to drive the build and rebuild.
|
|
|
|
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
|
|
|
add_executable(bar bar.cxx
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/regen.h
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/noregen.h
|
|
|
|
)
|
2007-09-17 18:51:05 +04:00
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
IF("${CMAKE_GENERATOR}" MATCHES "Make")
|
|
|
|
# Test the IMPLICIT_DEPENDS feature.
|
|
|
|
SET(ZOT_DEPENDS IMPLICIT_DEPENDS CXX ${CMAKE_CURRENT_SOURCE_DIR}/dep.cxx)
|
2007-12-21 20:22:12 +03:00
|
|
|
SET(ZOT_CUSTOM_DEP
|
|
|
|
IMPLICIT_DEPENDS CXX ${CMAKE_CURRENT_SOURCE_DIR}/dep_custom.cxx)
|
2007-09-17 18:51:05 +04:00
|
|
|
ELSE("${CMAKE_GENERATOR}" MATCHES "Make")
|
|
|
|
# No IMPLICIT_DEPENDS...just depend directly.
|
|
|
|
SET(ZOT_DEPENDS DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/zot.hxx.in)
|
2007-12-21 20:22:12 +03:00
|
|
|
SET(ZOT_CUSTOM_DEP DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/zot_custom.hxx.in)
|
2007-09-17 18:51:05 +04:00
|
|
|
ENDIF("${CMAKE_GENERATOR}" MATCHES "Make")
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/zot.hxx
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/zot.hxx.in
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/zot.hxx
|
|
|
|
${ZOT_DEPENDS}
|
|
|
|
)
|
|
|
|
|
2007-12-21 20:22:12 +03:00
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/zot_custom.hxx
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/zot_custom.hxx.in
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/zot_custom.hxx
|
|
|
|
${ZOT_CUSTOM_DEP}
|
|
|
|
)
|
|
|
|
add_custom_target(zot_custom ALL DEPENDS
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/zot_custom.hxx)
|
|
|
|
|
2008-05-14 19:55:12 +04:00
|
|
|
add_executable(zot zot.cxx ${CMAKE_CURRENT_BINARY_DIR}/zot.hxx
|
|
|
|
zot_macro_dir.cxx zot_macro_tgt.cxx)
|
2007-12-21 20:22:12 +03:00
|
|
|
add_dependencies(zot zot_custom)
|
2008-05-14 19:55:12 +04:00
|
|
|
|
|
|
|
# Test the #include line macro transformation rule support.
|
|
|
|
set_property(
|
|
|
|
TARGET zot
|
|
|
|
PROPERTY IMPLICIT_DEPENDS_INCLUDE_TRANSFORM "ZOT_TGT(%)=<zot_%_tgt.hxx>"
|
|
|
|
)
|
|
|
|
|
|
|
|
set_property(
|
|
|
|
DIRECTORY
|
|
|
|
PROPERTY IMPLICIT_DEPENDS_INCLUDE_TRANSFORM "ZOT_DIR(%)=<zot_%_dir.hxx>"
|
|
|
|
)
|