[CMake] How to have a static/shared option in a Find script ?

Barth barthelemy.von.haller at cern.ch
Thu Feb 16 09:14:21 EST 2012


Hi again,

I have understood what you meant :)

For records here is what I did :

# (1) Use FIND_LIBRARY() to look for the shared and the static library
#     and define DIM_SHARED_LIBRARY and DIM_STATIC_LIBRARY in the cache. 
find_library(DIM_STATIC_LIBRARY NAMES libdim.a PATHS $ENV{DIMDIR}
PATH_SUFFIXES linux)
find_library(DIM_SHARED_LIBRARY NAMES dim PATHS $ENV{DIMDIR} PATH_SUFFIXES
linux)

# (2) Inspect DIM_FIND_COMPONENTS to see which flavor has been requested,
#     defaulting to "shared" if no components have been requested at all. 
LIST(FIND DIM_FIND_COMPONENTS static ASK_STATIC_COMP) 
LIST(FIND DIM_FIND_COMPONENTS shared ASK_SHARED_COMP) 

# (3) Warn or bail out if "shared" and "static" have both been requested
if ( ${ASK_STATIC_COMP} GREATER -1 AND ${ASK_SHARED_COMP} GREATER -1)
    message(WARNING "Two incompatible components specified : static and
shared. We are going to ignore the static component.")
endif ( ${ASK_STATIC_COMP} GREATER -1 AND ${ASK_SHARED_COMP} GREATER -1)

# (4) DIM_USE_STATIC decides if DIM_LIBRARIES receives DIM_STATIC_LIBRARY
#     or DIM_SHARED_LIBRARY
option(DIM_FORCE_STATIC "Turn on to force the use of the static library"
OFF)
if( ${DIM_FORCE_STATIC} OR ${ASK_STATIC_COMP} GREATER -1) 
    set(DIM_LIBRARIES ${DIM_STATIC_LIBRARY} )
else ( ${DIM_FORCE_STATIC} OR ${ASK_STATIC_COMP} GREATER -1) 
    set(DIM_LIBRARIES ${DIM_SHARED_LIBRARY} )
endif( ${DIM_FORCE_STATIC} OR ${ASK_STATIC_COMP} GREATER -1) 


Thank you again for your supprot,
Best regards,
Barth

--
View this message in context: http://cmake.3232098.n2.nabble.com/How-to-have-a-static-shared-option-in-a-Find-script-tp7287655p7291064.html
Sent from the CMake mailing list archive at Nabble.com.


More information about the CMake mailing list