diff --git a/MyxCMakeConfigVersion.cmake b/MyxCMakeConfigVersion.cmake index 3e1f32b..03775d6 100644 --- a/MyxCMakeConfigVersion.cmake +++ b/MyxCMakeConfigVersion.cmake @@ -1,4 +1,4 @@ -set(MYX_CMAKE_PACKAGE_VERSION "1.99.7") +set(MYX_CMAKE_PACKAGE_VERSION "1.99.8") if(MYX_CMAKE_PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION) set(PACKAGE_VERSION_COMPATIBLE FALSE) else() diff --git a/README.md b/README.md index bbfb609..00bdf93 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,6 @@ `project` добавить строку: ```cmake -find_package(MyxCMake 1.99.7 PATHS cmake/myx NO_DEFAULT_PATH QUIET REQUIRED) +find_package(MyxCMake 1.99.8 PATHS cmake/myx NO_DEFAULT_PATH QUIET REQUIRED) ``` diff --git a/lib/AddLibrary.cmake b/lib/AddLibrary.cmake index edcdc05..41e2381 100644 --- a/lib/AddLibrary.cmake +++ b/lib/AddLibrary.cmake @@ -2,87 +2,88 @@ include_guard(GLOBAL) include(GenerateExportHeader) -function(myx_add_library) +function(myx_add_library NAME) set(options) set(oneValueArgs PCH TYPE) - set(multiValueArgs SOURCES COMPILE_DEFINITIONS) + set(multiValueArgs SOURCES LINK_LIBRARIES COMPILE_DEFINITIONS) cmake_parse_arguments(arg "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) if(NOT arg_TYPE) set(arg_TYPE "OBJECT") endif() - add_library(${PROJECT_NAME} ${arg_TYPE}) + add_library(${NAME} ${arg_TYPE}) if(arg_TYPE STREQUAL INTERFACE) - target_include_directories(${PROJECT_NAME} + target_include_directories(${NAME} INTERFACE $ $ ) else() - string(TOUPPER ${PROJECT_NAME} PROJECT_NAME_UPPER) + string(TOUPPER ${NAME} PROJECT_NAME_UPPER) # Опция для разрешения сборки разделяемой библиотеки option(${PROJECT_NAME_UPPER}_BUILD_SHARED "Build shared library" ON) # Опция для разрешения сборки статической библиотеки option(${PROJECT_NAME_UPPER}_BUILD_STATIC "Build static library" ON) - target_include_directories(${PROJECT_NAME} + target_include_directories(${NAME} PUBLIC $ PRIVATE $ ) - set_target_properties(${PROJECT_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON) + set_target_properties(${NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON) - string(TOUPPER ${PROJECT_NAME} suffix) - generate_export_header(${PROJECT_NAME} + string(TOUPPER ${NAME} suffix) + generate_export_header(${NAME} BASE_NAME "${suffix}" EXPORT_MACRO_NAME "EXPORT_${suffix}" DEPRECATED_MACRO_NAME "DEPRECATED_${suffix}" NO_DEPRECATED_MACRO_NAME "NO_DEPRECATED_${suffix}" NO_EXPORT_MACRO_NAME "NO_EXPORT_${suffix}" STATIC_DEFINE "STATIC_DEFINE_${suffix}" - EXPORT_FILE_NAME "${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME}/export_autogen.hpp" + EXPORT_FILE_NAME "${PROJECT_SOURCE_DIR}/include/${NAME}/export_autogen.hpp" DEFINE_NO_DEPRECATED ) # Цель для создания разделяемой библиотеки из объектных файлов if(${PROJECT_NAME_UPPER}_BUILD_SHARED) - # Для создания разделяемой библиотеки используются объектные файлы цели ${PROJECT_NAME} - add_library(${PROJECT_NAME}_shared SHARED $) - # Установка дополнительных свойств для цели ${PROJECT_NAME}_shared + # Для создания разделяемой библиотеки используются объектные файлы цели ${NAME} + add_library(${NAME}_shared SHARED $) + # Установка дополнительных свойств для цели ${NAME}_shared # OUTPUT_NAME: базовое имя выходного файла (без учёта расширения) # VERSION: версия библиотеки # SOVERSION: мажорная версия библиотеки - set_target_properties(${PROJECT_NAME}_shared + set_target_properties(${NAME}_shared PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR} - OUTPUT_NAME ${PROJECT_NAME}) + OUTPUT_NAME ${NAME}) endif() # Цель для создания статической библиотеки из объектных файлов if(${PROJECT_NAME_UPPER}_BUILD_STATIC) - # Для создания статической библиотеки используются объектные файлы цели ${PROJECT_NAME} - add_library(${PROJECT_NAME}_static STATIC $) - # Установка дополнительных свойств для цели ${PROJECT_NAME}_static + # Для создания статической библиотеки используются объектные файлы цели ${NAME} + add_library(${NAME}_static STATIC $) + # Установка дополнительных свойств для цели ${NAME}_static # OUTPUT_NAME: базовое имя выходного файла (без учёта расширения) - set_target_properties(${PROJECT_NAME}_static + set_target_properties(${NAME}_static PROPERTIES - OUTPUT_NAME ${PROJECT_NAME}) + OUTPUT_NAME ${NAME}) endif() endif() if(arg_PCH) if(${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.16) - target_precompile_headers(${PROJECT_NAME} PRIVATE ${PROJECT_SOURCE_DIR}/${arg_PCH}) + target_precompile_headers(${NAME} PRIVATE ${PROJECT_SOURCE_DIR}/${arg_PCH}) else() - target_compile_options(${PROJECT_NAME} PRIVATE -include ${PROJECT_SOURCE_DIR}/${arg_PCH}) + target_compile_options(${NAME} PRIVATE -include ${PROJECT_SOURCE_DIR}/${arg_PCH}) endif() endif() - target_sources(${PROJECT_NAME} PRIVATE ${arg_SOURCES}) - target_compile_definitions(${PROJECT_NAME} PRIVATE ${arg_COMPILE_DEFINITIONS}) + target_sources(${NAME} PRIVATE ${arg_SOURCES} ${PROJECT_SOURCE_DIR}/${arg_PCH}) + target_compile_definitions(${NAME} PRIVATE ${arg_COMPILE_DEFINITIONS}) + target_link_libraries(${NAME} PRIVATE ${arg_LINK_LIBRARIES}) endfunction() diff --git a/lib/InstallLibrary.cmake b/lib/InstallLibrary.cmake index a1f4af2..f2a18d4 100644 --- a/lib/InstallLibrary.cmake +++ b/lib/InstallLibrary.cmake @@ -1,22 +1,26 @@ include_guard(GLOBAL) if(${CMAKE_VERSION} VERSION_LESS "3.17.0") - set(CMAKE_CURRENT_FUNCTION_LIST_DIR "${CMAKE_CURRENT_LIST_DIR}") + set(CMAKE_CURRENT_FUNCTION_LIST_DIR ${CMAKE_CURRENT_LIST_DIR}) endif() include(CMakePackageConfigHelpers) -function(myx_install_library) +function(myx_install_library NAME) + if(NOT PROJECT_IS_TOP_LEVEL) + return() + endif() + write_basic_package_version_file( - ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake + ${CMAKE_CURRENT_BINARY_DIR}/${NAME}ConfigVersion.cmake VERSION ${PROJECT_VERSION} COMPATIBILITY AnyNewerVersion ) configure_package_config_file( ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/InstallLibraryConfig.cmake.in - ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake - INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} + ${CMAKE_CURRENT_BINARY_DIR}/${NAME}Config.cmake + INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${NAME} NO_SET_AND_CHECK_MACRO NO_CHECK_REQUIRED_COMPONENTS_MACRO ) @@ -26,42 +30,36 @@ function(myx_install_library) 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} + install(EXPORT ${NAME}Targets + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${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} + ${PROJECT_BINARY_DIR}/${NAME}ConfigVersion.cmake + ${PROJECT_BINARY_DIR}/${NAME}Config.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${NAME} COMPONENT dev ) - if(TARGET ${PROJECT_NAME}_shared) + if(TARGET ${NAME}_shared) install( - TARGETS ${PROJECT_NAME}_shared - EXPORT ${PROJECT_NAME}Target + TARGETS ${NAME}_shared + EXPORT ${NAME}Targets LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT lib ) endif() - if(TARGET ${PROJECT_NAME}_static) + if(TARGET ${NAME}_static) install( - TARGETS ${PROJECT_NAME}_static - EXPORT ${PROJECT_NAME}Target - ARCHIVE - DESTINATION ${CMAKE_INSTALL_LIBDIR} - COMPONENT lib + TARGETS ${NAME}_static + EXPORT ${NAME}Targets + ARCHIVE + DESTINATION ${CMAKE_INSTALL_LIBDIR} + COMPONENT lib ) endif() endfunction() diff --git a/lib/Qt5TargetSetup.cmake b/lib/Qt5TargetSetup.cmake index e88c079..f225130 100644 --- a/lib/Qt5TargetSetup.cmake +++ b/lib/Qt5TargetSetup.cmake @@ -1,6 +1,6 @@ include_guard(GLOBAL) -function(myx_qt5_target_setup) +function(myx_qt5_target_setup NAME) set(options) set(oneValueArgs) set(multiValueArgs COMPONENTS PRIVATE SOURCES MOC UI QRC LANGS) @@ -9,7 +9,7 @@ function(myx_qt5_target_setup) if(arg_COMPONENTS) find_package(Qt5 COMPONENTS ${arg_COMPONENTS} REQUIRED) foreach(iter ${arg_COMPONENTS}) - target_include_directories(${PROJECT_NAME} PRIVATE ${Qt5${iter}_INCLUDE_DIRS}) + target_include_directories(${NAME} PRIVATE ${Qt5${iter}_INCLUDE_DIRS}) endforeach() endif() @@ -26,7 +26,7 @@ function(myx_qt5_target_setup) if("LinguistTools" IN_LIST arg_COMPONENTS) set(ts) foreach(iter ${arg_LANGS}) - list(APPEND ts ${PROJECT_SOURCE_DIR}/l10n/${PROJECT_NAME}_${iter}.ts) + list(APPEND ts ${PROJECT_SOURCE_DIR}/l10n/${NAME}_${iter}.ts) endforeach() qt5_create_translation(qm @@ -36,7 +36,7 @@ function(myx_qt5_target_setup) ) endif() - target_sources(${PROJECT_NAME} + target_sources(${NAME} PRIVATE ${arg_SOURCES} ${moc_cpp} ${ui_h} ${qrc_cpp} ${qm}) endfunction()