[CMake] linkage order of static libraries and object files (ENABLE_EXPORTS)

Ivan Sergio Borgonovo mail at webthatworks.it
Sat Nov 2 20:56:29 EDT 2013


On Sat, 2 Nov 2013 15:09:25 +0100
Petr Kmoch <petr.kmoch at gmail.com> wrote:

> Hi Ivan.

> The correct use of OBJECT libraries is not to link against them, but
> to list them as sources (using a special syntax), like this:

> add_executable(project main.c $<TARGET_OBJECTS:serial>)

> (Assuming 'serial' is the name of the object library). This is
> outlined in the documentation for OBJECT libraries.

Thanks, it was not really clear even after your explanation. I had to
try a couple of times to get it right.

To sum it up for posterity:

# main CMakeLists.txt
project(projectname C ASM)
include_directories(...)
add_subdirectories(/somedir/MODULEA)
add_subdirectories(/somedir/MODULEB)
...
add_executable(projectname main.c
  $<TARGET_OBJECTS:modulea>
  $<TARGET_OBJECTS:moduleb>
)
set_target_proprieties(projectname PROPRIETIES ENABLE_EXPORTS ON)

# CMakeLists.txt for each module directory
add_library(modulea OBJECT modulea.c)

Thanks again

I need to cleanup a bit my python code, then I should have a working
program to convert projects from Eclipse/AVR32 Studio to CMake.

BTW compiling time went from 16sec to 4sec (I think mainly because
there is something impeding to successfully launch parallel build, but
even running a serial build with cmake/make shaves a bit more than a
couple of seconds)

-- 
Ivan Sergio Borgonovo
http://www.webthatworks.it



More information about the CMake mailing list