[CMake] installing source (or object) files

Kris Thielemans kris.f.thielemans at gmail.com
Thu Jan 19 02:49:14 EST 2017


Hi

 

I haven't had any replies to my message below, hopefully because it was sent
at the wrong time of year. So I'm reposting, but with some  clarifications.

 

I wrote the message about include_flags only. I've currently solved this by
adding a variable 

 

               Set(STIR_INCLUDE_DIRS blabla)

 

in my STIRConfig.cmake.in (which is at
<https://github.com/UCL/UCL-STIR/blob/master/src/cmake/STIRConfig.cmake.in>
https://github.com/UCL/UCL-STIR/blob/master/src/cmake/STIRConfig.cmake.in)

 

and tell the user of the library that they have to do

 

include_directories(${STIR_INCLUDE_DIRS})

 

This works but only for include directories, not for other compiler flags.
I've currently solved that by putting all (most?) of these in a
STIRConfig.h.in.

 

I don't particularly like the include_directories solution however. I
believe CMake's eport facility is trying to get away from this. Indeed, for
the library, its include path (and other compilation flags) get
automatically exported, so the user doesn't have to do anything else than
target_link_libraries to inherit all necessary flags.

 

Also, my current solution relies on exporting the .cxx. It seems safer to
export the object file as that is guaranteed to have been compiled with the
correct flags, but I don't know how to do that.

 

I hope my message below makes more sense now.

 

Thanks

 

Kris

From: Kris Thielemans
Sent: 27 December 2016 16:12
To: cmake at cmake.org
Subject: installing source (or object) files

 

Hi all

 

I have a non-standard set-up where I have a library that needs to be linked
together with some extra source files that contain "registries"). So in my
CMakeLists.txt I use

 

Add_executable(wonderful_program wonderful_program.cxx registry.cxx)

target_link_libraries(wonderful_program mylib)

 

registry.cxx needs to be compiled with some of my include files.

 

For that, I added

 

include_directories("${PROJECT_SOURCE_DIR}/src/include")

 

I guess I could just as well have added

 

SET_PROPERTY(SOURCE registry.cxx PROPERTY COMPILE_FLAG
"-I${STIR_INCLUDE_DIR}")

 

 

This works fine, but now I want to export my library (relocatable). I have
created a config file etc, added mylib as an install target, installed the
include files etc. All of that works great for the library. However, I have
no idea how to install registry.cxx. I could just 

 

INSTALL(FILES registry.cxx .)

 

However, that doesn't copy the properties of the source files anywhere. In
particular, it means that a "client" doesn't know what compilation flags to
use.

 

Any ideas?

 

Best wishes for 2017!

 

Kris

 

PS: The reason that I need registry.cxx is that it contains some variables
that have a funky constructor that initialises some registries somewhere.

PS: Full source code is at https://github.com/UCL/STIR

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20170119/fae6e9ef/attachment.html>


More information about the CMake mailing list