2003-06-03 18:34:15 +04:00
|
|
|
#
|
|
|
|
# Wrapping
|
|
|
|
#
|
|
|
|
PROJECT (CustomCommand)
|
|
|
|
|
2006-01-09 22:40:31 +03:00
|
|
|
ADD_SUBDIRECTORY(GeneratedHeader)
|
|
|
|
|
2003-06-03 18:34:15 +04:00
|
|
|
#
|
|
|
|
# Lib and exe path
|
|
|
|
#
|
|
|
|
SET (LIBRARY_OUTPUT_PATH
|
2006-01-02 23:01:43 +03:00
|
|
|
${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
|
2006-01-02 23:01:43 +03:00
|
|
|
${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
|
|
|
|
2004-04-27 20:03:17 +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
|
2004-04-27 20:03:17 +04:00
|
|
|
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(
|
2006-04-11 19:06:19 +04:00
|
|
|
OUTPUT ${PROJECT_BINARY_DIR}/wrapped.c ${PROJECT_BINARY_DIR}/wrapped_help.c
|
2003-06-30 18:12:24 +04:00
|
|
|
DEPENDS wrapper
|
|
|
|
MAIN_DEPENDENCY ${PROJECT_SOURCE_DIR}/wrapped.h
|
|
|
|
COMMAND ${EXECUTABLE_OUTPUT_PATH}/${CMAKE_CFG_INTDIR}/wrapper
|
2006-04-11 19:06:19 +04:00
|
|
|
${PROJECT_BINARY_DIR}/wrapped.c ${PROJECT_BINARY_DIR}/wrapped_help.c
|
2003-06-30 18:12:24 +04:00
|
|
|
)
|
|
|
|
|
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
|
2005-04-26 19:55:20 +04:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E echo " Copying doc1.dvi to doc1temp.h."
|
2005-02-22 20:04:02 +03:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_BINARY_DIR}/doc1.dvi
|
|
|
|
${PROJECT_BINARY_DIR}/doc1temp.h
|
2006-10-04 23:24:26 +04:00
|
|
|
)
|
|
|
|
ADD_CUSTOM_COMMAND(OUTPUT ${PROJECT_BINARY_DIR}/doc1.h APPEND
|
|
|
|
DEPENDS ${PROJECT_BINARY_DIR}/doc1.dvi
|
2005-04-26 19:55:20 +04:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E echo " Copying doc1temp.h to doc1.h."
|
2005-02-22 20:04:02 +03:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_BINARY_DIR}/doc1temp.h
|
|
|
|
${PROJECT_BINARY_DIR}/doc1.h
|
2005-04-26 19:55:20 +04:00
|
|
|
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
|
|
|
|
2005-08-17 19:48:05 +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})
|
|
|
|
|
2005-04-26 19:55:20 +04:00
|
|
|
# Add a custom target to drive generation of doc1.h.
|
2005-02-22 20:04:02 +03:00
|
|
|
ADD_CUSTOM_TARGET(TDocument ALL
|
2005-04-26 19:55:20 +04:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E echo " Copying doc1.h to doc2.h."
|
2005-02-22 20:04:02 +03:00
|
|
|
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
|
2006-10-05 02:10:30 +04:00
|
|
|
COMMENT "Running top-level TDocument commands"
|
2005-02-22 20:04:02 +03:00
|
|
|
)
|
2003-06-03 18:34:15 +04:00
|
|
|
|
2005-04-26 19:55:20 +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."
|
2005-04-27 17:12:41 +04:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/doc1.tex ${PROJECT_BINARY_DIR}/doc1pre.txt
|
2005-04-26 19:55:20 +04:00
|
|
|
)
|
|
|
|
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
|
2005-02-22 20:04:02 +03:00
|
|
|
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
|
|
|
|
2006-06-01 21:01:31 +04:00
|
|
|
# Add custom command to generate not_included.h, which is a header
|
|
|
|
# file that is not included by any source in this project. This will
|
|
|
|
# test whether all custom command outputs explicitly listed as sources
|
|
|
|
# get generated even if they are not needed by an object file.
|
|
|
|
ADD_CUSTOM_COMMAND(OUTPUT ${PROJECT_BINARY_DIR}/not_included.h
|
|
|
|
DEPENDS ${PROJECT_SOURCE_DIR}/foo.h.in
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/foo.h.in
|
|
|
|
${PROJECT_BINARY_DIR}/not_included.h
|
|
|
|
)
|
|
|
|
|
|
|
|
# Tell the executable where to find not_included.h.
|
|
|
|
CONFIGURE_FILE(
|
|
|
|
${PROJECT_SOURCE_DIR}/config.h.in
|
|
|
|
${PROJECT_BINARY_DIR}/config.h
|
|
|
|
@ONLY IMMEDIATE
|
|
|
|
)
|
|
|
|
|
|
|
|
# add the executable
|
2003-06-03 18:34:15 +04:00
|
|
|
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
|
2006-04-11 19:06:19 +04:00
|
|
|
${PROJECT_BINARY_DIR}/wrapped_help.c
|
2003-06-03 18:34:15 +04:00
|
|
|
${PROJECT_BINARY_DIR}/generated.c
|
2006-06-01 21:01:31 +04:00
|
|
|
${PROJECT_BINARY_DIR}/not_included.h
|
2003-06-03 18:34:15 +04:00
|
|
|
)
|
|
|
|
|
2006-01-09 22:40:31 +03:00
|
|
|
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)
|
2006-01-09 22:40:31 +03:00
|
|
|
|
2007-05-09 16:25:45 +04:00
|
|
|
##############################################################################
|
|
|
|
# Test for using just the target name as executable in the COMMAND
|
|
|
|
# section. Has to be recognized and replaced by CMake with the output
|
|
|
|
# actual location of the executable.
|
|
|
|
# Additionally the generator is created in an extra subdir after the
|
|
|
|
# ADD_CUSTOM_COMMAND() is used.
|
|
|
|
#
|
|
|
|
# Test the same for ADD_CUSTOM_TARGET()
|
|
|
|
|
|
|
|
ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/generated_extern.cxx
|
|
|
|
COMMAND generator_extern ${CMAKE_CURRENT_BINARY_DIR}/generated_extern.cxx
|
|
|
|
)
|
|
|
|
|
|
|
|
ADD_EXECUTABLE(CustomCommandUsingTargetTest main.cxx ${CMAKE_CURRENT_BINARY_DIR}/generated_extern.cxx )
|
|
|
|
|
|
|
|
ADD_CUSTOM_TARGET(RunTarget
|
|
|
|
COMMAND generator_extern ${CMAKE_CURRENT_BINARY_DIR}/run_target.cxx
|
|
|
|
)
|
|
|
|
|
|
|
|
ADD_CUSTOM_COMMAND(TARGET CustomCommandUsingTargetTest POST_BUILD
|
|
|
|
COMMAND dummy_generator ${CMAKE_CURRENT_BINARY_DIR}/generated_dummy.cxx)
|
|
|
|
|
|
|
|
ADD_SUBDIRECTORY(GeneratorInExtraDir)
|
|
|
|
|
|
|
|
|
2006-09-22 00:11:25 +04:00
|
|
|
##############################################################################
|
|
|
|
# Test non-trivial command line arguments in custom commands.
|
|
|
|
SET(EXPECTED_ARGUMENTS)
|
|
|
|
SET(CHECK_ARGS
|
|
|
|
c:/posix/path
|
|
|
|
c:\\windows\\path
|
|
|
|
'single-quotes'
|
|
|
|
single'quote
|
|
|
|
\"double-quotes\"
|
|
|
|
double\"quote
|
|
|
|
"\\;semi-colons\\;"
|
|
|
|
"semi\\;colon"
|
2006-09-28 19:30:49 +04:00
|
|
|
`back-ticks`
|
|
|
|
back`tick
|
|
|
|
"(parens)"
|
|
|
|
"(lparen"
|
|
|
|
"rparen)"
|
|
|
|
$dollar-signs$
|
|
|
|
dollar$sign
|
|
|
|
&ersands&
|
|
|
|
amper&sand
|
2006-10-04 22:37:42 +04:00
|
|
|
@two-ats@
|
2006-09-28 19:30:49 +04:00
|
|
|
one@at
|
2006-10-25 19:23:23 +04:00
|
|
|
"#two-pounds#"
|
|
|
|
"one#pound"
|
2006-09-22 00:11:25 +04:00
|
|
|
"c:/posix/path/with space"
|
|
|
|
"c:\\windows\\path\\with space"
|
|
|
|
"'single quotes with space'"
|
|
|
|
"single'quote with space"
|
|
|
|
"\"double-quotes with space\""
|
|
|
|
"double\"quote with space"
|
|
|
|
"\\;semi-colons with space\\;"
|
|
|
|
"semi\\;colon with space"
|
2006-09-28 19:30:49 +04:00
|
|
|
"`back-ticks` with space"
|
|
|
|
"back`tick with space"
|
|
|
|
"(parens) with space"
|
|
|
|
"(lparen with space"
|
|
|
|
"rparen) with space"
|
|
|
|
"$dollar-signs$ with space"
|
|
|
|
"dollar$sign with space"
|
|
|
|
"&ersands& with space"
|
|
|
|
"amper&sand with space"
|
2006-10-04 22:37:42 +04:00
|
|
|
"@two-ats@ with space"
|
2006-09-28 19:30:49 +04:00
|
|
|
"one@at with space"
|
2006-10-25 19:23:23 +04:00
|
|
|
"#two-pounds# with space"
|
|
|
|
"one#pound with space"
|
2006-09-22 00:11:25 +04:00
|
|
|
)
|
|
|
|
FOREACH(arg ${CHECK_ARGS})
|
|
|
|
SET(ARG "${arg}")
|
|
|
|
STRING(REGEX REPLACE "\\\\" "\\\\\\\\" ARG "${ARG}")
|
|
|
|
STRING(REGEX REPLACE "\"" "\\\\\"" ARG "${ARG}")
|
|
|
|
SET(EXPECTED_ARGUMENTS
|
|
|
|
"${EXPECTED_ARGUMENTS} \"${ARG}\",
|
|
|
|
")
|
|
|
|
ENDFOREACH(arg)
|
2006-09-22 16:42:45 +04:00
|
|
|
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_ANSI_CFLAGS}")
|
2006-09-22 00:11:25 +04:00
|
|
|
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/check_command_line.c.in
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/check_command_line.c
|
|
|
|
@ONLY IMMEDIATE)
|
|
|
|
ADD_EXECUTABLE(check_command_line
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/check_command_line.c)
|
2006-09-28 19:30:49 +04:00
|
|
|
ADD_CUSTOM_COMMAND(
|
|
|
|
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/command_line_check
|
2007-05-01 22:12:56 +04:00
|
|
|
COMMAND ${CMAKE_COMMAND} -DMARK_FILE=${CMAKE_CURRENT_BINARY_DIR}/check_mark.txt
|
|
|
|
-P ${CMAKE_CURRENT_SOURCE_DIR}/check_mark.cmake
|
2006-09-28 19:30:49 +04:00
|
|
|
COMMAND ${EXECUTABLE_OUTPUT_PATH}/${CMAKE_CFG_INTDIR}/check_command_line
|
|
|
|
${CHECK_ARGS}
|
|
|
|
VERBATIM
|
2006-10-05 02:57:59 +04:00
|
|
|
COMMENT "Checking custom command line escapes (single'quote)"
|
2006-09-28 19:30:49 +04:00
|
|
|
)
|
2006-10-02 18:17:22 +04:00
|
|
|
SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_BINARY_DIR}/command_line_check
|
|
|
|
PROPERTIES SYMBOLIC 1)
|
2006-09-28 19:30:49 +04:00
|
|
|
ADD_CUSTOM_TARGET(do_check_command_line ALL
|
|
|
|
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/command_line_check
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E echo "Checking custom target command escapes"
|
2006-09-22 00:11:25 +04:00
|
|
|
COMMAND ${EXECUTABLE_OUTPUT_PATH}/${CMAKE_CFG_INTDIR}/check_command_line
|
|
|
|
${CHECK_ARGS}
|
2006-09-28 19:30:49 +04:00
|
|
|
VERBATIM
|
2006-10-05 02:57:59 +04:00
|
|
|
COMMENT "Checking custom target command line escapes ($dollar-signs$)"
|
2006-09-22 00:11:25 +04:00
|
|
|
)
|
|
|
|
ADD_DEPENDENCIES(do_check_command_line check_command_line)
|
2007-05-01 22:12:56 +04:00
|
|
|
|
|
|
|
ADD_CUSTOM_TARGET(pre_check_command_line
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E remove ${CMAKE_CURRENT_BINARY_DIR}/check_mark.txt
|
|
|
|
)
|
|
|
|
ADD_DEPENDENCIES(do_check_command_line pre_check_command_line)
|