Skip to content
This repository has been archived by the owner on Jan 26, 2024. It is now read-only.

Commit

Permalink
cmake: Use LIB_INSTALL_DIR instead of hardcoding lib destination (#78)
Browse files Browse the repository at this point in the history
The comon practice in cmake to allow to specify the libdir is
using the LIB_INSTALL_DIR variable. The main use case of that
variable is setting /usr/lib64 as the destination dir for
libraries which is a common pattern in many Linux distributions.
  • Loading branch information
vadorovsky authored and rnburn committed May 2, 2018
1 parent 900f9d9 commit d2e12fe
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
15 changes: 11 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ if (NOT BUILD_SHARED_LIBS AND NOT BUILD_STATIC_LIBS)
message(FATAL_ERROR "One or both of BUILD_SHARED_LIBS or BUILD_STATIC_LIBS must be set to ON to build")
endif()

# ==============================================================================
# Set up libdir

if (NOT DEFINED LIB_INSTALL_DIR)
set(LIB_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/lib)
endif()

# ==============================================================================
# Set up generated header files config.h and version.h

Expand Down Expand Up @@ -127,8 +134,8 @@ if (BUILD_SHARED_LIBS)
set_target_properties(opentracing PROPERTIES VERSION ${OPENTRACING_VERSION_STRING}
SOVERSION ${OPENTRACING_VERSION_MAJOR})
install(TARGETS opentracing EXPORT OpenTracingTargets
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
LIBRARY DESTINATION ${LIB_INSTALL_DIR}
ARCHIVE DESTINATION ${LIB_INSTALL_DIR})
if (CLANG_TIDY_EXE)
set_target_properties(opentracing PROPERTIES
CXX_CLANG_TIDY "${DO_CLANG_TIDY}")
Expand All @@ -141,7 +148,7 @@ if (BUILD_STATIC_LIBS)
set_target_properties(opentracing-static PROPERTIES OUTPUT_NAME opentracing)
target_include_directories(opentracing-static INTERFACE "$<INSTALL_INTERFACE:include/>")
install(TARGETS opentracing-static EXPORT OpenTracingTargets
ARCHIVE DESTINATION lib)
ARCHIVE DESTINATION ${LIB_INSTALL_DIR})
endif()


Expand Down Expand Up @@ -172,7 +179,7 @@ export(EXPORT OpenTracingTargets
configure_file(cmake/OpenTracingConfig.cmake
"${CMAKE_CURRENT_BINARY_DIR}/OpenTracingConfig.cmake"
COPYONLY)
set(ConfigPackageLocation lib/cmake/OpenTracing)
set(ConfigPackageLocation ${LIB_INSTALL_DIR}/cmake/OpenTracing)
install(EXPORT OpenTracingTargets
FILE OpenTracingTargets.cmake
NAMESPACE OpenTracing::
Expand Down
6 changes: 3 additions & 3 deletions mocktracer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ if (BUILD_SHARED_LIBS)
SOVERSION ${OPENTRACING_VERSION_MAJOR})
target_link_libraries(opentracing_mocktracer opentracing)
install(TARGETS opentracing_mocktracer EXPORT OpenTracingTargets
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
LIBRARY DESTINATION ${LIB_INSTALL_DIR}
ARCHIVE DESTINATION ${LIB_INSTALL_DIR})
endif()

if (BUILD_STATIC_LIBS)
Expand All @@ -27,7 +27,7 @@ if (BUILD_STATIC_LIBS)
target_include_directories(opentracing_mocktracer-static INTERFACE "$<INSTALL_INTERFACE:include/>")
target_link_libraries(opentracing_mocktracer-static opentracing-static)
install(TARGETS opentracing_mocktracer-static EXPORT OpenTracingTargets
ARCHIVE DESTINATION lib)
ARCHIVE DESTINATION ${LIB_INSTALL_DIR})
endif()

install(DIRECTORY include/opentracing DESTINATION include
Expand Down

0 comments on commit d2e12fe

Please sign in to comment.