Skip to content

Commit

Permalink
Merge pull request #16 from ManManson/fix_default_cmake_build_install…
Browse files Browse the repository at this point in the history
…_import_sequence

cmake: Don't install `plum-static` and configure `plum` target to be dependent on `BUILD_SHARED_LIBS` option
  • Loading branch information
paullouisageneau committed Jun 15, 2024
2 parents bdb9bc5 + 95f3cb8 commit c111e0a
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set(PROJECT_DESCRIPTION "Multi-protocol Port Mapping client library")

option(NO_EXAMPLE "Disable example build" OFF)
option(WARNINGS_AS_ERRORS "Treat warnings as errors" OFF)
option(BUILD_SHARED_LIBS "Build using shared libraries" ON)

set(CMAKE_C_STANDARD 11)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
Expand Down Expand Up @@ -50,7 +51,7 @@ set(EXAMPLE_SOURCES
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)

add_library(plum SHARED ${LIBPLUM_SOURCES})
add_library(plum ${LIBPLUM_SOURCES})
set_target_properties(plum PROPERTIES VERSION ${PROJECT_VERSION})
target_include_directories(plum PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
Expand Down Expand Up @@ -83,8 +84,6 @@ endif()

set_target_properties(plum PROPERTIES EXPORT_NAME LibPlum)
add_library(LibPlum::LibPlum ALIAS plum)

set_target_properties(plum-static PROPERTIES EXPORT_NAME LibPlumStatic)
add_library(LibPlum::LibPlumStatic ALIAS plum-static)

install(TARGETS plum EXPORT LibPlumTargets
Expand All @@ -93,12 +92,9 @@ install(TARGETS plum EXPORT LibPlumTargets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)

install(TARGETS plum-static EXPORT LibPlumTargets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
OPTIONAL
)
# Don't install `plum-static` target, since it may not always be
# available in the build tree (i.e. marked with `EXCLUDE_FROM_ALL`).
# CMake doesn't support installing targets with `EXCLUDE_FROM_ALL` set.

install(FILES ${LIBPLUM_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/plum)

Expand Down Expand Up @@ -132,6 +128,9 @@ install(FILES

set_target_properties(plum PROPERTIES C_VISIBILITY_PRESET hidden)
target_compile_definitions(plum PRIVATE PLUM_EXPORTS)
if (NOT BUILD_SHARED_LIBS)
target_compile_definitions(plum PUBLIC PLUM_STATIC)
endif()
target_compile_definitions(plum-static PRIVATE PLUM_EXPORTS PUBLIC PLUM_STATIC)

if(NOT MSVC)
Expand Down

0 comments on commit c111e0a

Please sign in to comment.