I have an add_custom_target
that triggers a make for a project (that project does not use cmake!) and generates an object file. I would like to add this object file to an executable target in my project's cmake. Is there a way to do this?
相关问题
- Avoid cmake to add the flags -search_paths_first a
- CMakeList file to generate LLVM bitcode file from
- How to fix NDK build error for HelloCardboard samp
- Linking against GLEW with CMake
- Linking libavcodec in Cmake, find_library won'
相关文章
- Target requires the language dialect “CXX17” (with
- How do I tell cmake not to create a console window
- Do something for all targets
- CMake: Replace compile flags of an INTERFACE targe
- Generate Web Assembly from CMake Project with a Sp
- Integrate ITK (Insight Toolkit) into own project
- Is there a way to disallow “experimental” C++17 in
- CMake properties and expanding generator expressio
You can list object files along sources in
add_executable()
andaddlibrary()
:The only thing is that you need to use
add_custom_command
to produce object files, so CMake would know where to get them. This would also make sure your object files are built beforemyProgram
is linked.That worked for me. Apparently one must set these two properties, EXTERNAL_OBJECT and GENERATED.
I've done this in my projects with
target_link_libraries()
:Any full path given to
target_link_libraries()
is assumed a file to be forwarded to the linker.For CMake version >= 3.9 there are the
add_library(... OBJECT IMPORTED ..)
targets you can use.See Cmake: Use imported object
And - see also the answer from @arrowd - there is the undocumented way of adding them directly to your target's source file list (actually meant to support object file outputs for
add_custom_command()
build steps like in your case).