CMake/Tests/CustomCommand/CMakeLists.txt

157 lines
5.3 KiB
CMake
Raw Normal View History

2003-06-03 18:34:15 +04:00
#
# Wrapping
#
PROJECT (CustomCommand)
ADD_SUBDIRECTORY(GeneratedHeader)
2003-06-03 18:34:15 +04:00
#
# Lib and exe path
#
SET (LIBRARY_OUTPUT_PATH
${PROJECT_BINARY_DIR}/bin/ CACHE INTERNAL
2003-06-30 18:12:24 +04:00
"Single output directory for building all libraries.")
2003-06-03 18:34:15 +04:00
SET (EXECUTABLE_OUTPUT_PATH
${PROJECT_BINARY_DIR}/bin/ CACHE INTERNAL
2003-06-30 18:12:24 +04:00
"Single output directory for building all executables.")
2003-06-03 18:34:15 +04:00
################################################################
#
# First test using a compiled generator to create a .c file
#
################################################################
# add the executable that will generate the file
2003-06-04 17:02:50 +04:00
ADD_EXECUTABLE(generator generator.cxx)
2003-06-03 18:34:15 +04:00
GET_TARGET_PROPERTY(generator_PATH generator LOCATION)
MESSAGE("Location ${generator_PATH}")
2003-06-03 18:34:15 +04:00
# the folowing assumes that a cmSourceFile
# is instantiated for the output, with GENERATED 1
# at the end of the day this becomes a what in VS ?
ADD_CUSTOM_COMMAND(OUTPUT ${PROJECT_BINARY_DIR}/generated.c
2003-06-30 18:12:24 +04:00
DEPENDS generator
COMMAND ${generator_PATH}
2003-06-30 18:12:24 +04:00
ARGS ${PROJECT_BINARY_DIR}/generated.c
)
2003-06-03 18:34:15 +04:00
################################################################
#
# Test using a wrapper to wrap a header file
#
################################################################
# add the executable that will generate the file
2003-06-04 17:02:50 +04:00
ADD_EXECUTABLE(wrapper wrapper.cxx)
2003-06-03 18:34:15 +04:00
# the following assumes that a cmSourceFile
# is instantiated for the output, with GENERATED 1
# at the end of the day this becomes a what in VS ?
ADD_CUSTOM_COMMAND(
2003-06-30 18:12:24 +04:00
OUTPUT ${PROJECT_BINARY_DIR}/wrapped.c
DEPENDS wrapper
MAIN_DEPENDENCY ${PROJECT_SOURCE_DIR}/wrapped.h
COMMAND ${EXECUTABLE_OUTPUT_PATH}/${CMAKE_CFG_INTDIR}/wrapper
ARGS ${PROJECT_BINARY_DIR}/wrapped.c ${PROJECT_SOURCE_DIR}/wrapped.h
)
2003-06-03 18:34:15 +04:00
################################################################
#
# Test creating files from a custom target
#
################################################################
ADD_CUSTOM_COMMAND(OUTPUT ${PROJECT_BINARY_DIR}/doc1.dvi
2003-06-30 18:12:24 +04:00
DEPENDS ${PROJECT_SOURCE_DIR}/doc1.tex
COMMAND ${CMAKE_COMMAND}
ARGS -E copy ${PROJECT_SOURCE_DIR}/doc1.tex
${PROJECT_BINARY_DIR}/doc1.dvi
)
2003-06-03 18:34:15 +04:00
ADD_CUSTOM_COMMAND(OUTPUT ${PROJECT_BINARY_DIR}/doc1.h
DEPENDS ${PROJECT_BINARY_DIR}/doc1.dvi
COMMAND ${CMAKE_COMMAND} -E echo " Copying doc1.dvi to doc1temp.h."
COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_BINARY_DIR}/doc1.dvi
${PROJECT_BINARY_DIR}/doc1temp.h
COMMAND ${CMAKE_COMMAND} -E echo " Copying doc1temp.h to doc1.h."
COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_BINARY_DIR}/doc1temp.h
${PROJECT_BINARY_DIR}/doc1.h
COMMAND ${CMAKE_COMMAND} -E echo " Removing doc1temp.h."
COMMAND ${CMAKE_COMMAND} -E remove -f ${PROJECT_BINARY_DIR}/doc1temp.h
2003-06-30 18:12:24 +04:00
)
2003-06-03 18:34:15 +04:00
# Add custom command to generate foo.h.
ADD_CUSTOM_COMMAND(OUTPUT ${PROJECT_BINARY_DIR}/foo.h
DEPENDS ${PROJECT_SOURCE_DIR}/foo.h.in
COMMAND ${CMAKE_COMMAND} -E echo " Copying foo.h.in to foo.h."
COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/foo.h.in
${PROJECT_BINARY_DIR}/foo.h
)
# Add the location of foo.h to the include path.
INCLUDE_DIRECTORIES(${PROJECT_BINARY_DIR})
# Add a custom target to drive generation of doc1.h.
ADD_CUSTOM_TARGET(TDocument ALL
COMMAND ${CMAKE_COMMAND} -E echo " Copying doc1.h to doc2.h."
COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_BINARY_DIR}/doc1.h
${PROJECT_BINARY_DIR}/doc2.h
2003-06-30 18:12:24 +04:00
DEPENDS ${PROJECT_BINARY_DIR}/doc1.h
)
2003-06-03 18:34:15 +04:00
# Setup a pre- and post-build pair that will fail if not run in the
# proper order.
ADD_CUSTOM_COMMAND(
TARGET TDocument PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E echo " Writing doc1pre.txt."
COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/doc1.tex ${PROJECT_BINARY_DIR}/doc1pre.txt
)
ADD_CUSTOM_COMMAND(
TARGET TDocument POST_BUILD
COMMAND ${CMAKE_COMMAND} -E echo " Copying doc1pre.txt to doc2post.txt."
COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_BINARY_DIR}/doc1pre.txt
${PROJECT_BINARY_DIR}/doc2post.txt
)
2003-06-03 18:34:15 +04:00
################################################################
#
# Test using a multistep generated file
#
################################################################
ADD_CUSTOM_COMMAND(OUTPUT ${PROJECT_BINARY_DIR}/foo.pre
2003-06-30 18:12:24 +04:00
DEPENDS ${PROJECT_SOURCE_DIR}/foo.in
COMMAND ${CMAKE_COMMAND}
ARGS -E copy ${PROJECT_SOURCE_DIR}/foo.in
${PROJECT_BINARY_DIR}/foo.pre
)
2003-06-03 18:34:15 +04:00
ADD_CUSTOM_COMMAND(OUTPUT ${PROJECT_BINARY_DIR}/foo.c
DEPENDS ${PROJECT_BINARY_DIR}/foo.pre
2003-06-30 18:12:24 +04:00
COMMAND ${CMAKE_COMMAND}
ARGS -E copy ${PROJECT_BINARY_DIR}/foo.pre
${PROJECT_BINARY_DIR}/foo.c
)
2003-06-03 18:34:15 +04:00
# These object dependencies can be removed to test the
# auto-object-depends feature of the Makefile generator. Currently
# the feature does not seem to work in Visual Studio generators so
# these dependencies are needed.
#SET_SOURCE_FILES_PROPERTIES(${PROJECT_BINARY_DIR}/foo.c
#PROPERTIES
# OBJECT_DEPENDS "${PROJECT_BINARY_DIR}/doc1.h;${PROJECT_BINARY_DIR}/foo.h"
#)
2003-06-03 18:34:15 +04:00
# add the library
ADD_EXECUTABLE(CustomCommand
2006-03-24 20:20:46 +03:00
${PROJECT_BINARY_DIR}/foo.h
2003-06-03 18:34:15 +04:00
${PROJECT_BINARY_DIR}/foo.c
${PROJECT_BINARY_DIR}/wrapped.c
${PROJECT_BINARY_DIR}/generated.c
)
TARGET_LINK_LIBRARIES(CustomCommand GeneratedHeader)
2003-06-03 18:34:15 +04:00
# must add a dependency on TDocument otherwise it might never build and
# the CustomCommand executable really needs doc1.h
2003-06-30 18:12:24 +04:00
ADD_DEPENDENCIES(CustomCommand TDocument)