This commit is contained in:
Andrei Astafev 2022-09-29 14:19:40 +03:00
parent ed56c18888
commit 47c10bfbae
6 changed files with 76 additions and 3 deletions

View File

@ -22,6 +22,7 @@ include(${MYX_CMAKE_LIB_DIR}/SemanticProjectVersion.cmake)
include(${MYX_CMAKE_LIB_DIR}/NinjaGeneratorWrapper.cmake)
include(${MYX_CMAKE_LIB_DIR}/AddLibrary.cmake)
include(${MYX_CMAKE_LIB_DIR}/InstallLibrary.cmake)
include(${MYX_CMAKE_LIB_DIR}/Qt5TargetSetup.cmake)
unset(MYX_CMAKE_SOURCE_DIR)

View File

@ -1,4 +1,4 @@
set(MYX_CMAKE_PACKAGE_VERSION "1.99.3")
set(MYX_CMAKE_PACKAGE_VERSION "1.99.4")
if(MYX_CMAKE_PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION)
set(PACKAGE_VERSION_COMPATIBLE FALSE)
else()

View File

@ -11,6 +11,6 @@
`project` добавить строку:
```cmake
find_package(MyxCMake 1.99.3 PATHS cmake/myx NO_DEFAULT_PATH QUIET REQUIRED)
find_package(MyxCMake 1.99.4 PATHS cmake/myx NO_DEFAULT_PATH QUIET REQUIRED)
```

View File

@ -1,7 +1,6 @@
include_guard(GLOBAL)
include(GenerateExportHeader)
include(GNUInstallDirs)
function(myx_add_library)
set(options)
@ -42,6 +41,32 @@ function(myx_add_library)
EXPORT_FILE_NAME "${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME}/export.hpp"
DEFINE_NO_DEPRECATED
)
# Цель для создания разделяемой библиотеки из объектных файлов
if(${PROJECT_NAME_UPPER}_BUILD_SHARED)
# Для создания разделяемой библиотеки используются объектные файлы цели ${PROJECT_NAME}
add_library(${PROJECT_NAME}_shared SHARED $<TARGET_OBJECTS:${PROJECT_NAME}>)
# Установка дополнительных свойств для цели ${PROJECT_NAME}_shared
# OUTPUT_NAME: базовое имя выходного файла (без учёта расширения)
# VERSION: версия библиотеки
# SOVERSION: мажорная версия библиотеки
set_target_properties(${PROJECT_NAME}_shared
PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
OUTPUT_NAME ${PROJECT_NAME})
endif()
# Цель для создания статической библиотеки из объектных файлов
if(${PROJECT_NAME_UPPER}_BUILD_STATIC)
# Для создания статической библиотеки используются объектные файлы цели ${PROJECT_NAME}
add_library(${PROJECT_NAME}_static STATIC $<TARGET_OBJECTS:${PROJECT_NAME}>)
# Установка дополнительных свойств для цели ${PROJECT_NAME}_static
# OUTPUT_NAME: базовое имя выходного файла (без учёта расширения)
set_target_properties(${PROJECT_NAME}_static
PROPERTIES
OUTPUT_NAME ${PROJECT_NAME})
endif()
endif()
if(arg_PCH)
@ -52,5 +77,6 @@ function(myx_add_library)
endif()
endif()
target_sources(${PROJECT_NAME} PRIVATE ${arg_SOURCES})
target_compile_definitions(${PROJECT_NAME} PRIVATE ${arg_COMPILE_DEFINITIONS})
endfunction()

41
lib/InstallLibrary.cmake Normal file
View File

@ -0,0 +1,41 @@
include(CMakePackageConfigHelpers)
function(myx_install_library)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
configure_package_config_file(
${CMAKE_CURRENT_LIST_DIR}/InstallLibraryConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
NO_SET_AND_CHECK_MACRO
NO_CHECK_REQUIRED_COMPONENTS_MACRO
)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
COMPONENT dev
)
install(TARGETS ${PROJECT_NAME}
EXPORT "${PROJECT_NAME}Targets"
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
COMPONENT dev
)
install(EXPORT "${PROJECT_NAME}Targets"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
COMPONENT dev
)
install(
FILES
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
COMPONENT dev
)
endfunction()

View File

@ -0,0 +1,5 @@
@PACKAGE_INIT@
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")
check_required_components("@PROJECT_NAME@")