As an example suppose four folders(app1, app2, app3 and main) such as below
main
|__ CMakeLists.txt
\__ module1
|______ CMakeLists.txt
|______ sub1.cpp
|______ sub1.h
\__ library5
|______ CMakeLists.txt
|______ sub5.cpp
|______ sub5.h
\__app1
\__app2
\__app3
Which output of module1 is module1.dll and output of library5 is lib5.dll. Folder of app1 must contain module1.dll and lib5.dll, app2 needs lib5.dll and finally app3 needs module1.dll(number of apps, modules and libs are more than this example and as I explain below we don't want to change modules/libraries's CMakeLists.txt
, just main's CMakeLists.txt
is ours).
PS:
I have a cmake
project which has several libraries and modules. They included in my project using add_subdirectory
command (note that my project just made up from multiple modules and it has not any add_library
or add_target
).
I need to copy outputs of libraries/modules without changing their CMakeLists.txt
(add_custom_command
with POST_BUILD
option actually is not a good choice because at this point I need to change CMakeLists.txt
of libraries/modules which they are not just belong to my project). On the other hand it must done in outer(major) CMakeLists.txt
which has others(libraries/modules).
I tried some other commands such as file (COPY )
and configure_file()
but I think they operate in generating cmake-cache
phase and just can copy resource files which are exist in pre-build phase.
Moreover, In another approach I write a bash script file to copy the files and call it in major CMakeLists.txt
via bellow command.
add_custom_target (copy_all
COMMAND ${CMAKE_SOURCE_DIR}/copy.sh ${files}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
The files
has the list of files. But the copy not performed! I manually test the script which works as desired. But I don't have any idea why it can not operate at call in CMakeLists.txt.
What can I do to copy sub-projects outputs to some locations from major CMakeLists.txt
?