Hello,
short description: I want to have a configuration header file per unit test. For this purpose I wrote the following function, which creates a header file in ${CURRENT_BINARY_DIR} and copy all test files into the binary directory. Howewer, I got it to work when I use add_custom_target as pre_build target, but this doesnt work on *nix systems. So here is the current function: function(CopyUnitTestFiles projectName) set(UnitTestConfigName "${projectName}UnitTestConfig") set(UNITTESTCONFIGNAME "${projectName}UnitTestConfig") set(PROJECT_NAME ${projectName}) set(OUTPUT_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/${UnitTestConfigName}.cmake") set(HEADER_INPUT_FILENAME "${CMAKE_SOURCE_DIR}/cmake/UnitTestConfig.h.in") set(HEADER_OUTPUT_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/${UnitTestConfigName}.h") set(CURRENT_FILENAME "${OUTPUT_FILENAME}") set(RELATIVE_FILEPATH "testfiles/${projectName}") set(INCLUDE_GUARD "${projectName}_UNITTESTCONFIG_H") string(TOUPPER ${INCLUDE_GUARD} INCLUDE_GUARD) set(TARGET_FILE_DIR $<TARGET_FILE_DIR:${projectName}>) set(CopyUnitTestFilesProjectName CopyUnitTestFiles_${projectName}) configure_file(${CMAKE_SOURCE_DIR}/cmake/UnitTestConfig.cmake.in ${OUTPUT_FILENAME} @ONLY) add_custom_target(${CopyUnitTestFilesProjectName} COMMAND ${CMAKE_COMMAND} -DABSFILEPATH=${TARGET_FILE_DIR} -P ${OUTPUT_FILENAME} COMMAND ${CMAKE_COMMAND} -E remove_directory ${TARGET_FILE_DIR}/testfiles/${projectName} COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/data/testfiles ${TARGET_FILE_DIR}/testfiles/${projectName} ) set_property(TARGET ${CopyUnitTestFilesProjectName} PROPERTY FOLDER "Custom Targets/CopyUnitTestFiles") add_dependencies(${projectName} ${CopyUnitTestFilesProjectName}) endfunction(CopyUnitTestFiles) The function should be called like: project(UnitTest1) add_executable(${PROJECT_NAME} ${HEADERS} ${SOURCES}) target_link_libraries(${PROJECT_NAME} gtest gtest_main) CopyUnitTestFiles(${PROJECT_NAME}) The error message which I get: -- Configuring done CMake Error: The inter-target dependency graph contains the following strongly connected component (cycle): "CopyUnitTestFiles_UnitTest1" of type UTILITY depends on "UnitTest1" (strong) "UnitTest1" of type EXECUTABLE depends on "CopyUnitTestFiles_UnitTest1" (strong) At least one of these targets is not a STATIC_LIBRARY. Cyclic dependencies are allowed only among static libraries. UnitTestConfig.cmake.in: set(ProjectName "@PROJECT_NAME@") set(UnitTestConfigName "@UNITTESTCONFIGNAME@") set(NAMESPACE "${UnitTestConfigName}") set(UNITTESTNAME "${ProjectName}") set(RELATIVE_FILEPATH "testfiles/${ProjectName}") set(ABSOLUTE_FILEPATH "${ABSFILEPATH}/testfiles/${ProjectName}") set(INCLUDE_GUARD "${ProjectName}_UNITTESTCONFIG_H") string(TOUPPER ${INCLUDE_GUARD} INCLUDE_GUARD) configure_file("@HEADER_INPUT_FILENAME@" "@HEADER_OUTPUT_FILENAME@") UnitTestConfig.h.in: #ifndef @INCLUDE_GUARD@ #define @INCLUDE_GUARD@ namespace @NAMESPACE@ { const char *const UnitTestName = "@UNITTESTNAME@"; const char *const RelativeTestFilesPath = "@RELATIVE_FILEPATH@"; const char *const AbsoluteTestFilesPath = "@ABSOLUTE_FILEPATH@"; const wchar_t *const UnitTestNameW= L"@UNITTESTNAME@"; const wchar_t *const RelativeTestFilesPathW = L"@RELATIVE_FILEPATH@"; const wchar_t *const AbsoluteTestFilesPathW = L"@ABSOLUTE_FILEPATH@"; } #endif // @INCLUDE_GUARD@ It would be great if generator expressions can be used with configure_file to avoid such overhead. Does anyone have an idea on how to solve that? Best Regards Roman
-- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake-developers