[CMake] How to add a lib in a target/tool independent way?
Claus Klein
claus.klein at arcormail.de
Tue Jul 20 17:24:04 EDT 2010
I have a cpp project with some lib targets and executables, which
depends on the libs and the header files.
I want to link the libs from my build/src tree and not the installed
versions.
With this snip below from my CMakeFile.txt it works on my MacBook and
cygwin after a make clean,
but with MVS2005, it will always try to link the desD.lib and not the
desD.dll?
Note: When I first build static libs and than change the option to
shared libs without make clean,
it find the static libs and use them what is not intended by me!
Q: is there a whay to control which libs are found (e.g.) only static
or shared one?
AGENTPP_LIBRARY agent++
AGENTXPP_LIBRARY agentx++
BUILD_SHARED_LIBS ON
CMAKE_BUILD_TYPE
CMAKE_INSTALL_PREFIX /usr/local
CMAKE_OSX_ARCHITECTURES
CMAKE_OSX_DEPLOYMENT_TARGET 10.5
CMAKE_OSX_SYSROOT /Developer/SDKs/MacOSX10.5.sdk
CMAKE_USE_RELATIVE_PATHS OFF
DES_LIBRARY des
SNMP_PP_LIBRARY snmp++
USE_DOXYGEN OFF
USE_LIBDES ON
USE_PROXY_FORWARDER ON
#----------------------
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
option(USE_LIBDES "Use the provided libdes implementation" ON)
set( CMAKE_DEBUG_POSTFIX "D" CACHE STRING "Postfix added to the debug
version of libraries and executables" )
# add the libdes library?
if (USE_LIBDES)
add_subdirectory (libdes)
find_library(DES_LIBRARY des HINTS ${PROJECT_SOURCE_DIR}/libdes
NO_DEFAULT_PATH)
if ("${DES_LIBRARY}" STREQUAL "DES_LIBRARY-NOTFOUND")
set (DES_LIBRARY "des" CACHE FILEPATH "path to the local des lib"
FORCE)
endif()
include_directories ("${PROJECT_SOURCE_DIR}/libdes")
link_directories (${PROJECT_SOURCE_DIR}/libdes)
set (EXTRA_LIBS ${EXTRA_LIBS} ${DES_LIBRARY})
else (USE_LIBDES)
find_library(CRYPTO_LIBRARY crypto)
set (EXTRA_LIBS ${EXTRA_LIBS} ${CRYPTO_LIBRARY})
add_definitions(-D_USE_OPENSSL)
endif (USE_LIBDES)
add_subdirectory (snmp++/src)
if (USE_LIBDES)
add_dependencies(snmp++ des)
endif (USE_LIBDES)
#--------------------------
Why is Win32 (MS) always a Problem?
//Regards
Claus
More information about the CMake
mailing list