[CMake] libs only target

Sylvain Benner benner at virtools.com
Thu Jun 1 04:06:37 EDT 2006


>
> Hi,
> is there a way to compile/link only the "libs" (ADD_LIBRARY)
> but skip linking the executables (ADD_EXECUTABLE)
> using a global option/switch on cmake level?
>
> I want to save compilation time when I need only the libraries for linking 
> my client project.
> But we have about 200 examples in subdirectories and linking them takes a 
> lot of time...
>
>
> Jan

A solution may be to add a top-level configuration file which regroups the
CMakeLists.txt you want to process. It is like a user file.
To achieve this, you create a master CMakeLists.txt which include a user
file that is an entry in the cache (the idea comes from Brad, thanks to
him).

Something like this :

In the master CMakeLists.txt
SET(USER_CONFIG_FILE "Choose a user configuration file (.anyextension)"
CACHE FILEPATH "User Configuration File")
IF(${USER_CONFIG_FILE} MATCHES ".*[.](anyextension)$")
    INCLUDE(${USER_CONFIG_FILE})
ELSE(${USER_CONFIG_FILE} MATCHES ".*[.](anyextension)$")
    MESSAGE("Please choose a user configuration file.")
ENDIF(${USER_CONFIG_FILE} MATCHES ".*[.](anyextension)$")

In the user file :
SUBDIRS("pathtotarget1")
SUBDIRS("pathtotarget2")
....
SUBDIRS("pathtotargetn")

It works best with a wizard that generate the user file, if you have a lot
of targets and you must create the file from scratch, it's a bit annoying.
So another way is to declare a boolean in the cache, it's simplier but not
as flexible.
See the help for the SET command and you will find what you need.

I hope that we'll help you a bit for what you want to do.

Sylvain






More information about the CMake mailing list