Skip to content

Commit

Permalink
Add option to install only BUILD_SHARED_LIBS-matching files
Browse files Browse the repository at this point in the history
TD_ENABLE_FILTERED_INSTALL allows limiting installed libraries & supporting files to only those matching
BUILD_SHARED_LIBS.
  • Loading branch information
OPNA2608 authored and levlam committed Oct 21, 2024
1 parent 89b22ed commit 1e380de
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 43 deletions.
10 changes: 9 additions & 1 deletion CMake/GeneratePkgConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,13 @@ CFlags: -I\"${PKGCONFIG_INCLUDEDIR}\"
Libs: -L\"${PKGCONFIG_LIBDIR}\" -l${TARGET}
${REQUIRES}${LIBRARIES}")

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/${TARGET}.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
get_target_property(LIBRARY_TYPE "${TARGET}" TYPE)
if (NOT (LIBRARY_TYPE STREQUAL STATIC_LIBRARY OR LIBRARY_TYPE STREQUAL SHARED_LIBRARY))
message(FATAL_ERROR "Don't know how to handle ${TARGET} of type ${LIBRARY_TYPE}")
endif()
if (NOT TD_ENABLE_FILTERED_INSTALL
OR (LIBRARY_TYPE STREQUAL SHARED_LIBRARY AND BUILD_SHARED_LIBS)
OR (LIBRARY_TYPE STREQUAL STATIC_LIBRARY AND NOT BUILD_SHARED_LIBS))
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/${TARGET}.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
endif()
endfunction()
52 changes: 31 additions & 21 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ endif()
include(PreventInSourceBuild)
prevent_in_source_build()

option(TD_ENABLE_FILTERED_INSTALL "Use \"ON\" to limit installation to files (libraries, dev files) relevant for the chosen \"BUILD_SHARED_LIBS\" value." OFF)
option(TD_ENABLE_JNI "Use \"ON\" to enable JNI-compatible TDLib API.")
option(TD_ENABLE_DOTNET "Use \"ON\" to enable generation of C++/CLI or C++/CX TDLib API bindings.")
if (NOT CMAKE_CROSSCOMPILING)
Expand Down Expand Up @@ -1310,18 +1311,22 @@ add_library(Td::TdJsonStatic ALIAS TdJsonStatic)
set(INSTALL_TARGETS tdjson TdJson)
set(INSTALL_STATIC_TARGETS tdjson_static TdJsonStatic tdjson_private "${TD_CORE_PART_TARGETS}" tdcore tdmtproto tdclient TdStatic tdapi)

install(TARGETS ${INSTALL_TARGETS} EXPORT TdTargets
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)
if (NOT TD_ENABLE_FILTERED_INSTALL OR BUILD_SHARED_LIBS)
install(TARGETS ${INSTALL_TARGETS} EXPORT TdTargets
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)
endif()

install(TARGETS ${INSTALL_STATIC_TARGETS} EXPORT TdStaticTargets
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)
if (NOT TD_ENABLE_FILTERED_INSTALL OR NOT BUILD_SHARED_LIBS)
install(TARGETS ${INSTALL_STATIC_TARGETS} EXPORT TdStaticTargets
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)
endif()

# generate pkg-config files
include(GeneratePkgConfig)
Expand All @@ -1346,16 +1351,21 @@ generate_pkgconfig(tdjson_private "Telegram Library - JSON interface (private)")
generate_pkgconfig(tdjson "Telegram Library - JSON interface (shared)")
generate_pkgconfig(tdjson_static "Telegram Library - JSON interface (static)")

install(EXPORT TdTargets
FILE TdTargets.cmake
NAMESPACE Td::
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Td"
)
install(EXPORT TdStaticTargets
FILE TdStaticTargets.cmake
NAMESPACE Td::
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Td"
)
if (NOT TD_ENABLE_FILTERED_INSTALL OR BUILD_SHARED_LIBS)
install(EXPORT TdTargets
FILE TdTargets.cmake
NAMESPACE Td::
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Td"
)
endif()

if (NOT TD_ENABLE_FILTERED_INSTALL OR NOT BUILD_SHARED_LIBS)
install(EXPORT TdStaticTargets
FILE TdStaticTargets.cmake
NAMESPACE Td::
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Td"
)
endif()

# Install tdjson/tdjson_static:
install(FILES ${TD_JSON_HEADERS} "${CMAKE_CURRENT_BINARY_DIR}/td/telegram/tdjson_export.h" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/td/telegram")
Expand Down
4 changes: 3 additions & 1 deletion TdConfig.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
include(CMakeFindDependencyMacro)
#TODO: write all external dependencies
include("${CMAKE_CURRENT_LIST_DIR}/TdTargets.cmake")
if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/TdTargets.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/TdTargets.cmake")
endif()
if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/TdStaticTargets.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/TdStaticTargets.cmake")
endif()
10 changes: 6 additions & 4 deletions sqlite/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ elseif (MSVC)
target_compile_options(tdsqlite PRIVATE /wd4996)
endif()

install(TARGETS tdsqlite EXPORT TdStaticTargets
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
)
if (NOT TD_ENABLE_FILTERED_INSTALL OR NOT BUILD_SHARED_LIBS)
install(TARGETS tdsqlite EXPORT TdStaticTargets
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
)
endif()
10 changes: 6 additions & 4 deletions tdactor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ if (NOT CMAKE_CROSSCOMPILING)
target_link_libraries(example PRIVATE tdactor)
endif()

install(TARGETS tdactor EXPORT TdStaticTargets
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
)
if (NOT TD_ENABLE_FILTERED_INSTALL OR NOT BUILD_SHARED_LIBS)
install(TARGETS tdactor EXPORT TdStaticTargets
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
)
endif()
10 changes: 6 additions & 4 deletions tddb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ if (NOT CMAKE_CROSSCOMPILING)
target_link_libraries(binlog_dump PRIVATE tddb)
endif()

install(TARGETS tddb EXPORT TdStaticTargets
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
)
if (NOT TD_ENABLE_FILTERED_INSTALL OR NOT BUILD_SHARED_LIBS)
install(TARGETS tddb EXPORT TdStaticTargets
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
)
endif()
10 changes: 6 additions & 4 deletions tdnet/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ if (APPLE_WATCH)
target_link_libraries(tdnet PRIVATE ${FOUNDATION_LIBRARY})
endif()

install(TARGETS tdnet EXPORT TdStaticTargets
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
)
if (NOT TD_ENABLE_FILTERED_INSTALL OR NOT BUILD_SHARED_LIBS)
install(TARGETS tdnet EXPORT TdStaticTargets
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
)
endif()
10 changes: 6 additions & 4 deletions tdutils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -409,10 +409,12 @@ if (ATOMICS_LIBRARIES)
target_link_libraries(tdutils PUBLIC "${ATOMICS_LIBRARIES}")
endif()

install(TARGETS tdutils EXPORT TdStaticTargets
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
)
if (NOT TD_ENABLE_FILTERED_INSTALL OR NOT BUILD_SHARED_LIBS)
install(TARGETS tdutils EXPORT TdStaticTargets
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
)
endif()

if (TD_TEST_FOLLY AND ABSL_FOUND AND TDUTILS_USE_EXTERNAL_DEPENDENCIES)
find_package(benchmark QUIET)
Expand Down

0 comments on commit 1e380de

Please sign in to comment.