This commit is contained in:
Andrei Astafev 2022-10-04 06:08:31 +03:00
parent 3b750e439f
commit 3157540238
10 changed files with 68 additions and 35 deletions

View File

@ -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)

View File

@ -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()

View File

@ -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()

View File

@ -1 +1 @@
1.99.65
1.99.70

View File

@ -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")

View File

@ -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)

View File

@ -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 "</qresource></RCC>\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)

View File

@ -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()

View File

@ -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)

View File

@ -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)