[cmake] add RDTK_FORCE_STATIC_BUILD

since rdtk is only used by shadow server add an option to directly link
it with -DRDTK_FORCE_STATIC_BUILD=ON without installing any header or
library
This commit is contained in:
Armin Novak 2023-12-21 10:34:29 +01:00 committed by akallabeth
parent 9a62d05943
commit e8f5f90603
4 changed files with 50 additions and 36 deletions

View File

@ -81,6 +81,11 @@ include(GNUInstallDirsWrapper)
include(CMakePackageConfigHelpers) include(CMakePackageConfigHelpers)
include (SetFreeRDPCMakeInstallDir) include (SetFreeRDPCMakeInstallDir)
option(RDTK_FORCE_STATIC_BUILD "Force RDTK to be build as static libary" OFF)
if (RDTK_FORCE_STATIC_BUILD)
set(BUILD_SHARED_LIBS OFF)
endif()
add_definitions(-DRDTK_EXPORTS) add_definitions(-DRDTK_EXPORTS)
if (NOT IOS) if (NOT IOS)
@ -109,7 +114,9 @@ add_subdirectory(librdtk)
add_subdirectory(templates) add_subdirectory(templates)
add_subdirectory(include) add_subdirectory(include)
install(EXPORT rdtk DESTINATION ${RDTK_CMAKE_INSTALL_DIR}) if (NOT RDTK_FORCE_STATIC_BUILD)
install(EXPORT rdtk DESTINATION ${RDTK_CMAKE_INSTALL_DIR})
endif()
if(WITH_SAMPLE) if(WITH_SAMPLE)
if(WITH_X11) if(WITH_X11)

View File

@ -1,8 +1,10 @@
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/
DESTINATION ${RDTK_INCLUDE_DIR}
FILES_MATCHING PATTERN "*.h")
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/ if (NOT RDTK_FORCE_STATIC_BUILD)
DESTINATION ${RDTK_INCLUDE_DIR} install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/
FILES_MATCHING PATTERN "*.h") DESTINATION ${RDTK_INCLUDE_DIR}
FILES_MATCHING PATTERN "*.h")
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/
DESTINATION ${RDTK_INCLUDE_DIR}
FILES_MATCHING PATTERN "*.h")
endif()

View File

@ -71,12 +71,14 @@ if(BUILD_TESTING)
add_subdirectory(test) add_subdirectory(test)
endif() endif()
install(TARGETS ${MODULE_NAME} COMPONENT libraries EXPORT rdtk if (NOT RDTK_FORCE_STATIC_BUILD)
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} install(TARGETS ${MODULE_NAME} COMPONENT libraries EXPORT rdtk
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
if (WITH_DEBUG_SYMBOLS AND MSVC AND BUILD_SHARED_LIBS) if (WITH_DEBUG_SYMBOLS AND MSVC AND BUILD_SHARED_LIBS)
get_target_property(OUTPUT_FILENAME ${MODULE_NAME} OUTPUT_NAME) get_target_property(OUTPUT_FILENAME ${MODULE_NAME} OUTPUT_NAME)
install(FILES ${CMAKE_PDB_BINARY_DIR}/${OUTPUT_FILENAME}.pdb DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT symbols) install(FILES ${CMAKE_PDB_BINARY_DIR}/${OUTPUT_FILENAME}.pdb DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT symbols)
endif()
endif() endif()

View File

@ -1,19 +1,21 @@
include (SetFreeRDPCMakeInstallDir) if (NOT RDTK_FORCE_STATIC_BUILD)
include (SetFreeRDPCMakeInstallDir)
# cmake package # cmake package
export(PACKAGE rdtk) export(PACKAGE rdtk)
configure_package_config_file( configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/rdtkConfig.cmake.in ${CMAKE_CURRENT_SOURCE_DIR}/rdtkConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/rdtkConfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/rdtkConfig.cmake
INSTALL_DESTINATION ${RDTK_CMAKE_INSTALL_DIR} INSTALL_DESTINATION ${RDTK_CMAKE_INSTALL_DIR}
PATH_VARS RDTK_INCLUDE_DIR) PATH_VARS RDTK_INCLUDE_DIR)
write_basic_package_version_file( write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/rdtkConfigVersion.cmake ${CMAKE_CURRENT_BINARY_DIR}/rdtkConfigVersion.cmake
VERSION ${RDTK_VERSION} VERSION ${RDTK_VERSION}
COMPATIBILITY SameMajorVersion) COMPATIBILITY SameMajorVersion)
endif()
set(RDTK_BUILD_CONFIG_LIST "") set(RDTK_BUILD_CONFIG_LIST "")
GET_CMAKE_PROPERTY(res VARIABLES) GET_CMAKE_PROPERTY(res VARIABLES)
@ -30,16 +32,17 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/version.h.in ${CMAKE_CURRENT_BINARY_D
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/buildflags.h.in ${CMAKE_CURRENT_BINARY_DIR}/../include/rdtk/buildflags.h) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/buildflags.h.in ${CMAKE_CURRENT_BINARY_DIR}/../include/rdtk/buildflags.h)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/build-config.h.in ${CMAKE_CURRENT_BINARY_DIR}/../include/rdtk/build-config.h) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/build-config.h.in ${CMAKE_CURRENT_BINARY_DIR}/../include/rdtk/build-config.h)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/../include/rdtk/config.h) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/../include/rdtk/config.h)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/rdtk.pc.in ${CMAKE_CURRENT_BINARY_DIR}/rdtk${RDTK_VERSION_MAJOR}.pc @ONLY)
set(RDTK_INSTALL_INCLUDE_DIR ${RDTK_INCLUDE_DIR}/rdtk) if (NOT RDTK_FORCE_STATIC_BUILD)
install(FILES configure_file(${CMAKE_CURRENT_SOURCE_DIR}/rdtk.pc.in ${CMAKE_CURRENT_BINARY_DIR}/rdtk${RDTK_VERSION_MAJOR}.pc @ONLY)
${CMAKE_CURRENT_BINARY_DIR}/rdtk${RDTK_VERSION_MAJOR}.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/rdtkConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/rdtkConfigVersion.cmake
DESTINATION ${RDTK_CMAKE_INSTALL_DIR})
set(RDTK_INSTALL_INCLUDE_DIR ${RDTK_INCLUDE_DIR}/rdtk)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/rdtk${RDTK_VERSION_MAJOR}.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/rdtkConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/rdtkConfigVersion.cmake
DESTINATION ${RDTK_CMAKE_INSTALL_DIR})
endif()