简体   繁体   中英

CMAKE - Glob files in post build

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?

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.

Copies all shaders/* files into a directory in the build output called "shaders"

file(GLOB out shaders/*)
foreach (o ${out})
    message("${o} was copied to shaders")
    file(COPY ${o} DESTINATION shaders)
endforeach ()

This only works sometimes , like when I reload the CMake project, eg:

/opt/clion-2021.2.3/bin/cmake/linux/bin/cmake \
  -DCMAKE_BUILD_TYPE=Debug -DCMAKE_DEPENDS_USE_COMPILER=FALSE \
  -G "CodeBlocks - Unix Makefiles" \
  /home/hack/glad

Also, It doesn't execute "POST_BUILD", so take it with a grain of salt.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM