diff --git a/MyxCMakeConfig.cmake b/MyxCMakeConfig.cmake index ca3eaca..80537c6 100644 --- a/MyxCMakeConfig.cmake +++ b/MyxCMakeConfig.cmake @@ -1,6 +1,7 @@ cmake_policy(PUSH) cmake_policy(SET CMP0057 NEW) # IN_LIST operator +# Каталог для модулей, выполняющих поиск библиотек list(INSERT CMAKE_MODULE_PATH 0 "${PROJECT_SOURCE_DIR}/cmake/find") get_filename_component(MYX_CMAKE_SOURCE_DIR "${CMAKE_CURRENT_LIST_FILE}" DIRECTORY) diff --git a/MyxCMakeConfigVersion.cmake b/MyxCMakeConfigVersion.cmake index 384dba1..f60fb7d 100644 --- a/MyxCMakeConfigVersion.cmake +++ b/MyxCMakeConfigVersion.cmake @@ -1,4 +1,4 @@ -set(MYX_CMAKE_PACKAGE_VERSION "1.99.33") +set(MYX_CMAKE_PACKAGE_VERSION "1.99.40") 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 8550109..8c94f6c 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ ```cmake if(MYX_CMAKE_USE_SYSTEM) - find_package(MyxCMake 1.99.33 REQUIRED) + find_package(MyxCMake 1.99.40 REQUIRED) else() include(${PROJECT_SOURCE_DIR}/cmake/myx/MyxCMakeConfig.cmake) endif() diff --git a/VERSION.txt b/VERSION.txt index c11ca64..869d9fd 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -1.99.33 +1.99.40 diff --git a/lib/AddLibrary.cmake b/lib/AddLibrary.cmake index c01aae9..11b286f 100644 --- a/lib/AddLibrary.cmake +++ b/lib/AddLibrary.cmake @@ -4,7 +4,8 @@ myx_add_library Вспомогательная функция для создания библиотеки:: - myx_add_library(NAME TYPE) + myx_add_library(NAME TYPE + [ OUTPUT_NAME output_name ]) Обязательные параметры: `NAME` - имя библиотеки и `TYPE` - тип цели. Все остальные параметры передаются стандартной функции `add_library()` @@ -22,11 +23,15 @@ include(GenerateExportHeader) function(myx_add_library NAME TYPE) set(options) - set(oneValueArgs) + set(oneValueArgs OUTPUT_NAME EXPORT_FILE_NAME EXPORT_BASE_NAME) set(multiValueArgs) cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + if(NOT ARG_OUTPUT_NAME) + set(ARG_OUTPUT_NAME ${NAME}) + endif() + # Вызов стандартной функции `add_library()` add_library(${NAME} ${TYPE} ${ARG_UNPARSED_ARGUMENTS}) @@ -60,15 +65,22 @@ function(myx_add_library NAME TYPE) # для создания динамической библиотеки set_target_properties(${NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON) - string(TOUPPER ${NAME} suffix) + if(NOT EXPORT_BASE_NAME) + string(TOUPPER ${NAME} ARG_EXPORT_BASE_NAME) + endif() + + if(NOT ARG_EXPORT_FILE_NAME) + set(ARG_EXPORT_FILE_NAME "${PROJECT_SOURCE_DIR}/include/${NAME}/${NAME}_export.hpp") + endif() + 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/${NAME}/${NAME}_export.hpp" + BASE_NAME ${ARG_EXPORT_BASE_NAME} + EXPORT_MACRO_NAME "EXPORT_${ARG_EXPORT_BASE_NAME}" + DEPRECATED_MACRO_NAME "DEPRECATED_${ARG_EXPORT_BASE_NAME}" + NO_DEPRECATED_MACRO_NAME "NO_DEPRECATED_${ARG_EXPORT_BASE_NAME}" + NO_EXPORT_MACRO_NAME "NO_EXPORT_${ARG_EXPORT_BASE_NAME}" + STATIC_DEFINE "STATIC_DEFINE_${ARG_EXPORT_BASE_NAME}" + EXPORT_FILE_NAME ${ARG_EXPORT_FILE_NAME} DEFINE_NO_DEPRECATED ) @@ -86,7 +98,7 @@ function(myx_add_library NAME TYPE) VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR} LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR} - OUTPUT_NAME ${NAME}) + OUTPUT_NAME ${ARG_OUTPUT_NAME}) endif() # Цель для создания статической библиотеки из объектных файлов @@ -99,7 +111,7 @@ function(myx_add_library NAME TYPE) set_target_properties(${NAME}_static PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR} - OUTPUT_NAME ${NAME}) + OUTPUT_NAME ${ARG_OUTPUT_NAME}) endif() endif() @@ -152,6 +164,7 @@ function(myx_add_library NAME TYPE) "prefix=${CMAKE_INSTALL_PREFIX}\n" "exec_prefix=${CMAKE_INSTALL_PREFIX}\n" "includedir=${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}\n") + if(NOT TYPE STREQUAL "INTERFACE") file(APPEND "${CMAKE_BINARY_DIR}/${NAME}.pc" "libdir=${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}\n") @@ -165,6 +178,7 @@ function(myx_add_library NAME TYPE) "\n" "Requires:\n" "Cflags: -I${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}\n") + if(NOT TYPE STREQUAL "INTERFACE") file(APPEND "${CMAKE_BINARY_DIR}/${NAME}.pc" "Libs: -L${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR} -l${NAME}\n") diff --git a/lib/Qt5TargetSetup.cmake b/lib/Qt5TargetSetup.cmake index 6bfa4a2..8d307f7 100644 --- a/lib/Qt5TargetSetup.cmake +++ b/lib/Qt5TargetSetup.cmake @@ -3,12 +3,16 @@ include_guard(GLOBAL) function(myx_qt5_target_setup NAME) set(options) set(oneValueArgs) - set(multiValueArgs COMPONENTS PRIVATE SOURCES MOC UI QRC LANGS) + set(multiValueArgs COMPONENTS PRIVATE CPP HPP MOC UI QRC LANGS SOURCES) cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) get_target_property(type ${NAME} TYPE) + if(ARG_SOURCES) + myx_message_deprecation("MyxCMake: Use CPP and HPP arguments instead of SOURCES") + endif() + if(ARG_COMPONENTS) find_package(Qt5 COMPONENTS ${ARG_COMPONENTS} REQUIRED) foreach(iter ${ARG_COMPONENTS}) @@ -29,9 +33,23 @@ function(myx_qt5_target_setup NAME) target_compile_options(${NAME} PRIVATE ${Qt5Core_EXECUTABLE_COMPILE_FLAGS}) endif() - qt5_wrap_cpp(moc_cpp ${ARG_MOC}) - qt5_add_resources(qrc_cpp ${ARG_QRC}) - if("Widgets" IN_LIST ARG_COMPONENTS) + if(ARG_CPP) + set_target_properties(${NAME} PROPERTIES CPP_FILES ${ARG_CPP}) + endif() + + if(ARG_HPP) + set_target_properties(${NAME} PROPERTIES HPP_FILES ${ARG_HPP}) + endif() + + if(ARG_MOC) + qt5_wrap_cpp(moc_cpp ${ARG_MOC}) + endif() + + if(ARG_QRC) + qt5_add_resources(qrc_cpp ${ARG_QRC}) + endif() + + if(ARG_UI AND "Widgets" IN_LIST ARG_COMPONENTS) qt5_wrap_ui(ui_h ${ARG_UI}) endif() @@ -46,6 +64,6 @@ function(myx_qt5_target_setup NAME) unset(qm) endif() - target_sources(${NAME} PRIVATE ${ARG_SOURCES} ${ARG_MOC} ${moc_cpp} ${ui_h} ${qrc_cpp}) + target_sources(${NAME} PRIVATE ${ARG_HPP} ${ARG_CPP} ${ARG_SOURCES} ${ARG_MOC} ${moc_cpp} ${ui_h} ${qrc_cpp}) endfunction() diff --git a/lib/TargetSetup.cmake b/lib/TargetSetup.cmake index 5d9cb5e..cde515e 100644 --- a/lib/TargetSetup.cmake +++ b/lib/TargetSetup.cmake @@ -3,7 +3,7 @@ include_guard(GLOBAL) function(myx_target_setup NAME) set(options) set(oneValueArgs PCH) - set(multiValueArgs COMPILE_DEFINITIONS FIND_PACKAGES LINK_LIBRARIES SOURCES) + set(multiValueArgs COMPILE_DEFINITIONS FIND_PACKAGES LINK_LIBRARIES CPP HPP SOURCES) cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) @@ -14,21 +14,36 @@ function(myx_target_setup NAME) get_target_property(type ${NAME} TYPE) foreach(iter ${ARG_FIND_PACKAGES}) - find_package(${iter} REQUIRED) - target_include_directories(${NAME} PRIVATE ${${iter}_INCLUDE_DIRS}) - target_compile_definitions(${NAME} PRIVATE ${${iter}_COMPILE_DEFINITIONS}) + find_package(${iter} REQUIRED) + target_include_directories(${NAME} PRIVATE ${${iter}_INCLUDE_DIRS}) + target_compile_definitions(${NAME} PRIVATE ${${iter}_COMPILE_DEFINITIONS}) endforeach() target_compile_definitions(${NAME} PRIVATE ${ARG_COMPILE_DEFINITIONS}) + if(ARG_SOURCES) + myx_message_deprecation("MyxCMake: Use CPP and HPP arguments instead of SOURCES") + endif() + + if(ARG_CPP) + set_target_properties(${NAME} PROPERTIES CPP_FILES ${ARG_CPP}) + endif() + + if(ARG_HPP) + set_target_properties(${NAME} PROPERTIES HPP_FILES ${ARG_HPP}) + endif() + if(ARG_PCH) if(${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.16) - target_precompile_headers(${NAME} PRIVATE "${PROJECT_SOURCE_DIR}/${ARG_PCH}") + target_precompile_headers(${NAME} PRIVATE ${ARG_PCH}) else() - target_compile_options(${NAME} PRIVATE -include "${PROJECT_SOURCE_DIR}/${ARG_PCH}") + target_compile_options(${NAME} PRIVATE -include ${ARG_PCH}) endif() - target_sources(${NAME} PRIVATE "${PROJECT_SOURCE_DIR}/${ARG_PCH}") + target_sources(${NAME} PRIVATE ${ARG_PCH}) endif() + target_include_directories(${PROJECT_NAME} PRIVATE + $) + if(IS_DIRECTORY "${PROJECT_SOURCE_DIR}/src") target_include_directories(${PROJECT_NAME} PRIVATE $) @@ -50,7 +65,7 @@ function(myx_target_setup NAME) install(TARGETS ${NAME} COMPONENT main RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() - target_sources(${NAME} PRIVATE ${ARG_SOURCES}) + target_sources(${NAME} PRIVATE ${ARG_CPP} ${ARG_HPP} ${ARG_SOURCES}) target_link_libraries(${NAME} PRIVATE ${ARG_LINK_LIBRARIES}) target_compile_definitions(${NAME} PRIVATE ${ARG_COMPILE_DEFINITIONS}) endfunction()