CMake all_object_files target

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

CMake all_object_files target

Raphael Grimm

I want to create a CMake target to build all object files. To do this, I
first modified all targets to build an object file lib and link against it:

     add_library(exe_object_files OBJECT ${sources})
     set(ARMARX_EXE_OBJECT_FILES $<TARGET_OBJECTS:exe_object_files>)
     add_executable(exe $<TARGET_OBJECTS:exe_object_files>)

Since I have multiple executables, I added a target for all object files
and added the targets for each executable as dependency:

     add_dependencies(all_exe_object_files exe_object_files)

This adds a all_exe_object_files target I can make, but making the
target does nothing.
Then I tried adding the object files as sources:

all_exe_object_files SOURCES)
     if(NOT all_exe_object_files_sources)
     list(APPEND all_exe_object_files_sources
     set_target_properties(all_exe_object_files PROPERTIES SOURCES

This did not help.

I guess the reason is that add_library(... OBJECT ...) behaves similar
to add_custom_command and the files are only build if a target uses them
(and my custom target probably does not count as using the generated files).

What am I doing wrong and how can I create a target to build all object

Thanks for all hints.


Powered by

Please keep messages on-topic and check the CMake FAQ at:

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support:
CMake Consulting:
CMake Training Courses:

Visit other Kitware open-source projects at

Follow this link to subscribe/unsubscribe:

smime.p7s (6K) Download Attachment