From 315754023872cbc4c567ebe88dfb13589ef8b06b Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Tue, 4 Oct 2022 06:08:31 +0300 Subject: [PATCH] 1.99.70 --- MyxCMakeConfig.cmake | 1 + MyxCMakeConfigVersion.cmake | 2 +- README.md | 4 ++-- VERSION | 2 +- lib/AddLibrary.cmake | 10 ++++----- lib/FetchContentAdd.cmake | 4 +++- lib/Qt5TargetSetup.cmake | 29 ++++++++++--------------- lib/TargetSetup.cmake | 5 ++--- lib/generators/GitInfoHeader.cmake | 11 +++++----- lib/macro/FindPackages.cmake | 35 ++++++++++++++++++++++++++++++ 10 files changed, 68 insertions(+), 35 deletions(-) create mode 100644 lib/macro/FindPackages.cmake diff --git a/MyxCMakeConfig.cmake b/MyxCMakeConfig.cmake index a9a0800..b3378fe 100644 --- a/MyxCMakeConfig.cmake +++ b/MyxCMakeConfig.cmake @@ -9,6 +9,7 @@ get_filename_component(MYX_CMAKE_SOURCE_DIR "${CMAKE_CURRENT_LIST_FILE}" DIRECTO set(MYX_CMAKE_BACKPORTS_DIR "${MYX_CMAKE_SOURCE_DIR}/backports") set(MYX_CMAKE_LIB_DIR "${MYX_CMAKE_SOURCE_DIR}/lib") +include(${MYX_CMAKE_LIB_DIR}/macro/FindPackages.cmake) include(${MYX_CMAKE_LIB_DIR}/macro/InstallRelative.cmake) include(${MYX_CMAKE_BACKPORTS_DIR}/IncludeGuard.cmake) diff --git a/MyxCMakeConfigVersion.cmake b/MyxCMakeConfigVersion.cmake index 8ba3de6..1293352 100644 --- a/MyxCMakeConfigVersion.cmake +++ b/MyxCMakeConfigVersion.cmake @@ -1,4 +1,4 @@ -set(MYX_CMAKE_PACKAGE_VERSION "1.99.65") +set(MYX_CMAKE_PACKAGE_VERSION "1.99.70") 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 aff5c68..19862ba 100644 --- a/README.md +++ b/README.md @@ -36,10 +36,10 @@ if(MYX_CMAKE_DIR) set(ENV{MYX_CMAKE_DIR} ${MYX_CMAKE_DIR}) endif() if(DEFINED ENV{MYX_CMAKE_DIR}) - find_package(MyxCMake 1.99.65 REQUIRED) + find_package(MyxCMake 1.99.70 REQUIRED) else() if(MYX_CMAKE_USE_SYSTEM) - find_package(MyxCMake 1.99.65 REQUIRED) + find_package(MyxCMake 1.99.70 REQUIRED) else() include(${PROJECT_SOURCE_DIR}/cmake/myx/MyxCMakeConfig.cmake) endif() diff --git a/VERSION b/VERSION index 338050c..e13d10b 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.99.65 +1.99.70 diff --git a/lib/AddLibrary.cmake b/lib/AddLibrary.cmake index 1596676..a7c6357 100644 --- a/lib/AddLibrary.cmake +++ b/lib/AddLibrary.cmake @@ -161,17 +161,17 @@ function(myx_add_library NAME TYPE) ) # Формирование файла для pkg-config - file(WRITE "${CMAKE_BINARY_DIR}/${NAME}.pc" + file(WRITE "${PROJECT_BINARY_DIR}/${NAME}.pc" "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" + file(APPEND "${PROJECT_BINARY_DIR}/${NAME}.pc" "libdir=${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}\n") endif() - file(APPEND "${CMAKE_BINARY_DIR}/${NAME}.pc" + file(APPEND "${PROJECT_BINARY_DIR}/${NAME}.pc" "\n" "Name: ${NAME}\n" "Description: ${NAME} library\n" @@ -181,13 +181,13 @@ function(myx_add_library NAME TYPE) "Cflags: -I${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}\n") if(NOT TYPE STREQUAL "INTERFACE") - file(APPEND "${CMAKE_BINARY_DIR}/${NAME}.pc" + file(APPEND "${PROJECT_BINARY_DIR}/${NAME}.pc" "Libs: -L${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR} -l${NAME}\n") endif() # Установка файла для pkg-config install( - FILES "${CMAKE_BINARY_DIR}/${NAME}.pc" + FILES "${PROJECT_BINARY_DIR}/${NAME}.pc" COMPONENT dev DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") diff --git a/lib/FetchContentAdd.cmake b/lib/FetchContentAdd.cmake index 6da7051..e94de22 100644 --- a/lib/FetchContentAdd.cmake +++ b/lib/FetchContentAdd.cmake @@ -1,5 +1,8 @@ include_guard(GLOBAL) +# Обязательно в глобальной области +find_package(Git) + function(FetchContent_Add NAME) set(options "") set(oneValueArgs GIT_REPOSITORY GIT_REMOTE GIT_PATH) @@ -7,7 +10,6 @@ function(FetchContent_Add NAME) cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) - find_package(Git) if(GIT_FOUND AND ARG_GIT_REMOTE AND ARG_GIT_PATH) execute_process(COMMAND ${GIT_EXECUTABLE} config --get remote.${ARG_GIT_REMOTE}.url OUTPUT_VARIABLE REMOTE_URL ERROR_QUIET) if(REMOTE_URL) diff --git a/lib/Qt5TargetSetup.cmake b/lib/Qt5TargetSetup.cmake index 68342f3..15617d5 100644 --- a/lib/Qt5TargetSetup.cmake +++ b/lib/Qt5TargetSetup.cmake @@ -9,22 +9,16 @@ function(myx_qt5_target_setup NAME) get_target_property(type ${NAME} TYPE) - if(ARG_COMPONENTS) - find_package(Qt5 COMPONENTS ${ARG_COMPONENTS} REQUIRED) - foreach(iter ${ARG_COMPONENTS}) - target_include_directories(${NAME} PRIVATE ${Qt5${iter}_INCLUDE_DIRS}) - if(type STREQUAL "EXECUTABLE" AND NOT iter STREQUAL "LinguistTools") - target_link_libraries(${NAME} PRIVATE "Qt5::${iter}") - endif() - endforeach() - endif() + foreach(iter ${ARG_COMPONENTS}) + target_include_directories(${NAME} PRIVATE ${Qt5${iter}_INCLUDE_DIRS}) + if(type STREQUAL "EXECUTABLE" AND NOT iter STREQUAL "LinguistTools") + target_link_libraries(${NAME} PRIVATE "Qt5::${iter}") + endif() + endforeach() - if(ARG_PRIVATE) - foreach(iter ${ARG_PRIVATE}) - find_package("Qt5${iter}" COMPONENTS Private REQUIRED) - target_include_directories(${NAME} PRIVATE ${Qt5${iter}_PRIVATE_INCLUDE_DIRS}) - endforeach() - endif() + foreach(iter ${ARG_PRIVATE}) + target_include_directories(${NAME} PRIVATE ${Qt5${iter}_PRIVATE_INCLUDE_DIRS}) + endforeach() if(type STREQUAL "EXECUTABLE") target_compile_options(${NAME} PRIVATE ${Qt5Core_EXECUTABLE_COMPILE_FLAGS}) @@ -75,9 +69,10 @@ function(myx_qt5_target_setup NAME) # Окончение файла ресурсов file(APPEND ${PROJECT_BINARY_DIR}/${NAME}_l10n.qrc "\n") # Комплияция файла ресурсов с переводами - qt5_add_resources(qrc_l10n ${CMAKE_BINARY_DIR}/${NAME}_l10n.qrc) + qt5_add_resources(qrc_l10n ${PROJECT_BINARY_DIR}/${NAME}_l10n.qrc) + target_sources(${NAME} PRIVATE ${qrc_l10n}) endif() - target_sources(${NAME} PRIVATE ${ARG_PUBLIC_MOC} ${ARG_PRIVATE_MOC} ${moc_cpp} ${ui_h} ${qrc_cpp} ${qrc_l10n}) + target_sources(${NAME} PRIVATE ${ARG_PUBLIC_MOC} ${ARG_PRIVATE_MOC} ${moc_cpp} ${ui_h} ${qrc_cpp}) # Установка публичных заголовочных файлов if(PROJECT_IS_TOP_LEVEL) diff --git a/lib/TargetSetup.cmake b/lib/TargetSetup.cmake index bcf2f22..af38db6 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 + set(multiValueArgs COMPILE_DEFINITIONS PACKAGES LINK_LIBRARIES CPP PUBLIC_HEADERS PRIVATE_HEADERS) cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) @@ -14,8 +14,7 @@ function(myx_target_setup NAME) get_target_property(type ${NAME} TYPE) - foreach(iter ${ARG_FIND_PACKAGES}) - find_package(${iter} REQUIRED) + foreach(iter ${ARG_PACKAGES}) target_include_directories(${NAME} PRIVATE ${${iter}_INCLUDE_DIRS}) target_compile_definitions(${NAME} PRIVATE ${${iter}_COMPILE_DEFINITIONS}) endforeach() diff --git a/lib/generators/GitInfoHeader.cmake b/lib/generators/GitInfoHeader.cmake index 53f81d1..52263c4 100644 --- a/lib/generators/GitInfoHeader.cmake +++ b/lib/generators/GitInfoHeader.cmake @@ -67,16 +67,17 @@ set(GIT_DIFF \"\") set(GIT_TAG \"N/A\") set(GIT_BRANCH \"N/A\") -find_program(GIT_EXECUTABLE git) +find_package(Git) + if(GIT_EXECUTABLE) - execute_process(COMMAND git log --pretty=format:'%h' -n 1 OUTPUT_VARIABLE GIT_REV ERROR_QUIET) + execute_process(COMMAND ${GIT_EXECUTABLE} log --pretty=format:'%h' -n 1 OUTPUT_VARIABLE GIT_REV ERROR_QUIET) # Check whether we got any revision (which isn't always the case, # e.g. when someone downloaded a zip file from Github instead of a checkout) if(NOT \"\${GIT_REV}\" STREQUAL \"\") - execute_process(COMMAND bash -c \"git diff --quiet --exit-code || echo +\" OUTPUT_VARIABLE GIT_DIFF) - execute_process(COMMAND git describe --exact-match --tags OUTPUT_VARIABLE GIT_TAG ERROR_QUIET) - execute_process(COMMAND git rev-parse --abbrev-ref HEAD OUTPUT_VARIABLE GIT_BRANCH) + execute_process(COMMAND bash -c \"${GIT_EXECUTABLE} diff --quiet --exit-code || echo +\" OUTPUT_VARIABLE GIT_DIFF) + execute_process(COMMAND ${GIT_EXECUTABLE} describe --exact-match --tags OUTPUT_VARIABLE GIT_TAG ERROR_QUIET) + execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD OUTPUT_VARIABLE GIT_BRANCH) string(STRIP \"\${GIT_REV}\" GIT_REV) string(SUBSTRING \"\${GIT_REV}\" 1 7 GIT_REV) diff --git a/lib/macro/FindPackages.cmake b/lib/macro/FindPackages.cmake new file mode 100644 index 0000000..9727195 --- /dev/null +++ b/lib/macro/FindPackages.cmake @@ -0,0 +1,35 @@ +include_guard(GLOBAL) + +macro(myx_find_packages) + set(options) + set(oneValueArgs) + set(multiValueArgs PACKAGES Boost Qt5 Qt5Private) + + cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + foreach(iter ${ARG_PACKAGES}) + find_package(${iter} REQUIRED) + endforeach() + + if(ARG_Boost) + find_package(Boost COMPONENTS ${ARG_Boost} REQUIRED) + endif() + + if(ARG_Qt5) + find_package(Qt5 COMPONENTS ${ARG_Qt5} REQUIRED) + endif() + + if(ARG_Qt5Private) + foreach(iter ${ARG_Qt5Private}) + find_package("Qt5${iter}" COMPONENTS Private REQUIRED) + endforeach() + endif() + + foreach(iter IN LISTS oneValueArgs multiValueArgs) + unset(ARG_${iter}) + endforeach() + unset(ARG_UNPARSED_ARGUMENTS) + unset(multiValueArgs) + unset(oneValueArgs) + unset(options) +endmacro(myx_find_packages)