Reputation: 295
My program generates c++ code which needs to be compiled into a dynamic library. The code is generated in some directory, the name of it is unknown before generating a Makefile (the directories are created in runtime), but the names of the files the library depend on are predefined (src1.cpp, src2.cpp ..). Is there any way to generate a Makefile using cmake so that it could be copied into a directory with sources of the library that need to be compiled. I've tried to add_library which is dependent on src1.cpp src2.cpp .. , but cmake doesn't want to generate a Makefile without having the sources available.
Upvotes: 1
Views: 472
Reputation: 78478
I'm not sure I fully understand your use-case, but I think you could probably set the GENERATED
property to TRUE
for each non-existent file to fix this. e.g. say your list of files is MyFiles
, you can use set_source_files_properties
:
set_source_files_properties(${MyFiles} PROPERTIES GENERATED TRUE)
You might also have to create dependencies to ensure these files actually exist before make tries to build the library (e.g. if they're generated by a script, have the script invoked as a pre-build command of the library using add_custom_command(TARGET MyLib PRE_BUILD ...)
).
Upvotes: 4