Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmake: fix static library build (vcpkg) #1096

Merged
merged 3 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ if(CMAKE_C_COMPILER_ID MATCHES "Clang")
endif()

set(re_DIR ${CMAKE_CURRENT_LIST_DIR}/cmake)
find_package(re CONFIG REQUIRED)
include("${CMAKE_CURRENT_LIST_DIR}/cmake/re-config.cmake")

list(APPEND RE_DEFINITIONS
-DRE_VERSION="${PROJECT_VERSION_FULL}"
Expand Down Expand Up @@ -649,7 +649,7 @@ endif()
if(LIBRE_BUILD_STATIC)
list(APPEND RE_INSTALL_TARGETS re)
add_library(re STATIC $<TARGET_OBJECTS:re-objs>)
target_link_libraries(re PUBLIC ${RE_LIBS})
target_link_libraries(re PRIVATE ${RE_LIBS})
target_include_directories(re PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)
Expand Down Expand Up @@ -705,6 +705,9 @@ configure_file(packaging/libre.pc.in libre.pc @ONLY)

install(TARGETS ${RE_INSTALL_TARGETS}
EXPORT libre
RUNTIME
DESTINATION ${CMAKE_INSTALL_BINDIR}
COMPONENT Libraries
LIBRARY
DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT Libraries
Expand All @@ -723,7 +726,9 @@ install(FILES ${HEADERS}

install(EXPORT libre
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libre
FILE libre-targets.cmake
NAMESPACE libre::
COMPONENT Development
)

if(LIBRE_BUILD_SHARED)
Expand All @@ -740,7 +745,9 @@ install(FILES cmake/re-config.cmake
COMPONENT Development
)

install(FILES cmake/libre-config.cmake
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/libre-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/cmake/libre-config.cmake" @ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/cmake/libre-config.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libre
COMPONENT Development
)
Expand Down
24 changes: 23 additions & 1 deletion cmake/libre-config.cmake
Original file line number Diff line number Diff line change
@@ -1 +1,23 @@
include("${CMAKE_CURRENT_LIST_DIR}/libre.cmake")
if("@LIBRE_BUILD_STATIC@")
include(CMakeFindDependencyMacro)
find_dependency(Threads)
if("@USE_OPENSSL@")
find_dependency(OpenSSL)
endif()
if("@ZLIB_FOUND@")
find_dependency(ZLIB)
endif()
endif()

include("${CMAKE_CURRENT_LIST_DIR}/libre-targets.cmake")

# convenience target libre::libre for uniform usage
if(NOT TARGET libre::libre)
if(TARGET libre::re_shared AND (BUILD_SHARED_LIBS OR NOT TARGET libre::re))
add_library(libre::libre INTERFACE IMPORTED)
set_target_properties(libre::libre PROPERTIES INTERFACE_LINK_LIBRARIES libre::re_shared)
elseif(TARGET libre::re AND (NOT BUILD_SHARED_LIBS OR NOT TARGET libre::re_shared))
add_library(libre::libre INTERFACE IMPORTED)
set_target_properties(libre::libre PROPERTIES INTERFACE_LINK_LIBRARIES libre::re)
endif()
endif()
Loading