ENH: Added test for generation of files listed explicitly as sources but not used during the build of a target.

This commit is contained in:
Brad King 2006-06-01 13:01:31 -04:00
parent 4189370497
commit 09f2be12b8
3 changed files with 32 additions and 10 deletions

View File

@ -131,22 +131,31 @@ ADD_CUSTOM_COMMAND(OUTPUT ${PROJECT_BINARY_DIR}/foo.c
${PROJECT_BINARY_DIR}/foo.c ${PROJECT_BINARY_DIR}/foo.c
) )
# These object dependencies can be removed to test the # Add custom command to generate not_included.h, which is a header
# auto-object-depends feature of the Makefile generator. Currently # file that is not included by any source in this project. This will
# the feature does not seem to work in Visual Studio generators so # test whether all custom command outputs explicitly listed as sources
# these dependencies are needed. # get generated even if they are not needed by an object file.
#SET_SOURCE_FILES_PROPERTIES(${PROJECT_BINARY_DIR}/foo.c ADD_CUSTOM_COMMAND(OUTPUT ${PROJECT_BINARY_DIR}/not_included.h
#PROPERTIES DEPENDS ${PROJECT_SOURCE_DIR}/foo.h.in
# OBJECT_DEPENDS "${PROJECT_BINARY_DIR}/doc1.h;${PROJECT_BINARY_DIR}/foo.h" COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/foo.h.in
#) ${PROJECT_BINARY_DIR}/not_included.h
)
# add the library # 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
ADD_EXECUTABLE(CustomCommand ADD_EXECUTABLE(CustomCommand
${PROJECT_BINARY_DIR}/foo.h ${PROJECT_BINARY_DIR}/foo.h
${PROJECT_BINARY_DIR}/foo.c ${PROJECT_BINARY_DIR}/foo.c
${PROJECT_BINARY_DIR}/wrapped.c ${PROJECT_BINARY_DIR}/wrapped.c
${PROJECT_BINARY_DIR}/wrapped_help.c ${PROJECT_BINARY_DIR}/wrapped_help.c
${PROJECT_BINARY_DIR}/generated.c ${PROJECT_BINARY_DIR}/generated.c
${PROJECT_BINARY_DIR}/not_included.h
) )
TARGET_LINK_LIBRARIES(CustomCommand GeneratedHeader) TARGET_LINK_LIBRARIES(CustomCommand GeneratedHeader)

View File

@ -0,0 +1 @@
#define PROJECT_BINARY_DIR "@PROJECT_BINARY_DIR@"

View File

@ -1,5 +1,8 @@
#include "doc1.h" #include "doc1.h"
#include "foo.h" #include "foo.h"
#include "config.h"
#include <stdio.h>
int generated(); int generated();
int wrapped(); int wrapped();
@ -8,7 +11,16 @@ int main ()
{ {
if (generated()*wrapped()*doc() == 3*5*7) if (generated()*wrapped()*doc() == 3*5*7)
{ {
return 0; FILE* fin = fopen(PROJECT_BINARY_DIR "/not_included.h", "r");
if(fin)
{
fclose(fin);
return 0;
}
else
{
return -2;
}
} }
return -1; return -1;