Skip to content

Commit

Permalink
Configure CMakeLists not to install libs
Browse files Browse the repository at this point in the history
If the built libs are static and not needed by other packages,
there's no need to install them or make them shared.
BUILD_SHARED_LIBS and INSTALL_LIBS options are provided to control
this behavior.

This patch comes from the Debian distribution with some modifications.
  • Loading branch information
rakhimov committed Dec 12, 2016
1 parent 8d13627 commit cfa57e2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 23 deletions.
8 changes: 6 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ set(SCRAM_VERSION_MICRO 4) # Bug fixes.

####################### Begin Options ###################

set(BUILD_SHARED_LIBS TRUE) # Change this for static building.
option(BUILD_SHARED_LIBS OFF)

option(INSTALL_LIBS "Install the generated libraries" ON)

# Linking of external libraries, such as BOOST.
option(WITH_STATIC_LIBS "Try to link against static libraries" OFF)
Expand Down Expand Up @@ -118,7 +120,9 @@ set(CMAKE_SKIP_BUILD_RPATH FALSE)
# (but later on when installing).
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)

set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
if(INSTALL_LIBS)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
endif()

# Add the automatically determined parts of the RPATH,
# which point to directories outside the build tree
Expand Down
1 change: 1 addition & 0 deletions install.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def generate_make_files(args):
sys.exit("CMake could not be found, "
"please install CMake before developing SCRAM.")
cmake_cmd = ["cmake", os.path.abspath(root_dir)]
cmake_cmd += ["-DBUILD_SHARED_LIBS=ON"]
if args.prefix:
cmake_cmd += ["-DCMAKE_INSTALL_PREFIX=" + absexpanduser(args.prefix)]

Expand Down
43 changes: 22 additions & 21 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,30 +59,31 @@ set(SCRAM_CORE_SRC
)
add_library(scramcore ${SCRAM_CORE_SRC})

set_target_properties(scramcore
PROPERTIES
INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib"
INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib"
LINK_FLAGS "${LIB_LINK_FLAGS}"
)

target_link_libraries(scramcore ${LIBS})

if(WIN32)
install(
TARGETS scramcore
RUNTIME DESTINATION bin COMPONENT scram
LIBRARY DESTINATION lib COMPONENT scram
ARCHIVE DESTINATION lib COMPONENT scram
)
else()
install(
TARGETS scramcore
DESTINATION lib
COMPONENT scram
if(INSTALL_LIBS)
set_target_properties(scramcore
PROPERTIES
INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib"
INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib"
LINK_FLAGS "${LIB_LINK_FLAGS}"
)
if(WIN32)
install(
TARGETS scramcore
RUNTIME DESTINATION bin COMPONENT scram
LIBRARY DESTINATION lib COMPONENT scram
ARCHIVE DESTINATION lib COMPONENT scram
)
else()
install(
TARGETS scramcore
DESTINATION lib
COMPONENT scram
)
endif()
endif()

target_link_libraries(scramcore ${LIBS})

add_executable(scram scram.cc)
target_link_libraries(scram scramcore ${Boost_LIBRARIES})

Expand Down

0 comments on commit cfa57e2

Please sign in to comment.