Reputation: 33
I want to copy intermediate object files from build folder into another folder.
I have used : file(GLOB OUTPUT_COMPILED_FILES_POST CONFIGURE_DEPENDS "IntCode/*/*" "ApplicationComps/*/src/Common/*.*)"
to collect the names of the files as they are plenty.
and then I used file(COPY ${OUTPUT_COMPILED_FILES_POST} DESTINATION ${OBJECTS_FOLDER})
to copy the files but It doesn't do anything as when the glob command is working the files are not yet generated.
I have multiple sub directories the 4th one has add_executable which generates object files and exe file the fifth and sixth sub directories need some object files.
So. My question:
Is there any other way to do this?
Upvotes: 2
Views: 976
Reputation: 10847
If you can refactor your glob and instead only copy the files under a certain directory, you can use this command
add_custom_command(TARGET bar
# Run after all other rules within the target have been executed
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory source destination
COMMENT "This command will be executed after building bar"
)
Upvotes: 1
Reputation: 19826
I have multiple sub directories the 4th one has add_executable which generates object files and exe file the fifth and sixth sub directories need some object files.
You can achieve this with object libraries in CMake. See below for a sketch and the documentation here:
Suppose you have a higher-level CMakeLists.txt file with:
...
add_subdirectory(subdir1)
add_subdirectory(subdir2)
add_subdirectory(subdir3)
add_subdirectory(subdir4)
add_subdirectory(subdir5)
add_subdirectory(subdir6)
...
Then in subdir4's CMakeLists.txt you would write:
add_library(target4objs OBJECT src1.cpp src2.cpp ...)
add_executable(target4 extra_src_not_shared.cpp ...)
target_link_libraries(target4 PRIVATE target4objs)
And in subdir5/6 you would write:
add_executable(target5 src1.cpp ...)
target_link_libraries(target5 PRIVATE target4objs)
General advice: manually copying files from the build tree to either elsewhere in the build tree or especially to the source tree is practically never needed and a bad idea.
Upvotes: 0