update
This commit is contained in:
parent
74652c90f1
commit
41e7d2192b
@ -1,34 +1,44 @@
|
|||||||
# Минимальная версия CMake
|
# Минимальная версия CMake, требуемая для сборки проекта
|
||||||
cmake_minimum_required(VERSION 3.3)
|
cmake_minimum_required(VERSION 3.6 FATAL_ERROR)
|
||||||
|
|
||||||
# Предпочтительно следовать стандартам принятым в указанном диапазоне версий
|
# Предпочтительно следовать стандартам принятым в указанном диапазоне версий
|
||||||
cmake_policy(VERSION 3.0.2..3.7)
|
cmake_policy(VERSION 3.6..3.7)
|
||||||
|
|
||||||
# Название и версия проекта и используемые языки программирования
|
# Название и версия проекта и используемые языки программирования
|
||||||
project(myx-cmake-example-features VERSION 0.2.0 LANGUAGES CXX)
|
project(myx-example-features VERSION 0.3.0 LANGUAGES CXX)
|
||||||
|
|
||||||
###
|
# Рекомендуемый способ подключения MyxCMake
|
||||||
# Обязательные переменные для MyxCMake
|
include(cmake/myx_setup.cmake)
|
||||||
###
|
|
||||||
# Название организации
|
|
||||||
set(MYX_CMAKE_ORGANIZATION_NAME "Org." CACHE STRING "")
|
|
||||||
|
|
||||||
# Имя автора
|
# Поиск пакетов
|
||||||
set(MYX_CMAKE_AUTHOR_NAME "John Doe" CACHE STRING "")
|
myx_find_packages(
|
||||||
|
Qt5 Core
|
||||||
|
Qt5Private Core)
|
||||||
|
|
||||||
# Почта автора
|
# Цель для создания исполняемого файла
|
||||||
set(MYX_CMAKE_AUTHOR_EMAIL "mail@johndoe.com" CACHE STRING "")
|
add_executable(${PROJECT_NAME})
|
||||||
|
|
||||||
# Краткое описание проекта
|
# Настройка свойств цели
|
||||||
set(MYX_CMAKE_DESCRIPTION "Пример проекта: разные возможности" CACHE STRING "")
|
myx_target_setup(${PROJECT_NAME}
|
||||||
|
CPP
|
||||||
|
${PROJECT_SOURCE_DIR}/src/${PROJECT_NAME}/main.cpp
|
||||||
|
)
|
||||||
|
|
||||||
find_package(MyxCMake 0.4.1 REQUIRED)
|
# Настройка Qt для цели
|
||||||
|
myx_qt5_target_setup(${PROJECT_NAME}
|
||||||
|
COMPONENTS Core
|
||||||
|
PRIVATE Core
|
||||||
|
PRIVATE_MOC
|
||||||
|
${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME}/processor.hpp
|
||||||
|
)
|
||||||
|
|
||||||
# Qt5
|
# Автоматически генерируемый файл с информацией о репозитории
|
||||||
find_package(Qt5 COMPONENTS Core REQUIRED)
|
myx_generate_git_info_header(${PROJECT_NAME} "git_info_p.hpp")
|
||||||
|
|
||||||
# Приложение
|
# Автоматически генерируемый приватный заголовочный файл
|
||||||
add_subdirectory(src/myx-cmake-example-features)
|
myx_generate_private_config_header(${PROJECT_NAME} "config_p.hpp")
|
||||||
|
|
||||||
# Документирование
|
# Форматирование исходных текстов с помощью uncrustify
|
||||||
myx_cmake_doc_doxygen(LATEX YES HTML YES)
|
myx_uncrustify(${PROJECT_NAME})
|
||||||
|
|
||||||
|
myx_doc_doxygen(${PROJECT_NAME} HTML YES XML NO)
|
||||||
|
54
cmake/myx/MyxCMakeConfig.cmake
Normal file
54
cmake/myx/MyxCMakeConfig.cmake
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
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)
|
||||||
|
|
||||||
|
#set(MYX_CMAKE_BACKPORTS_DIR "${MYX_CMAKE_SOURCE_DIR}/backports" CACHE PATH "")
|
||||||
|
#set(MYX_CMAKE_LIB_DIR "${MYX_CMAKE_SOURCE_DIR}/lib" CACHE PATH "")
|
||||||
|
|
||||||
|
set(MYX_CMAKE_BACKPORTS_DIR "${MYX_CMAKE_SOURCE_DIR}/backports")
|
||||||
|
set(MYX_CMAKE_LIB_DIR "${MYX_CMAKE_SOURCE_DIR}/lib")
|
||||||
|
|
||||||
|
include(${MYX_CMAKE_BACKPORTS_DIR}/IncludeGuard.cmake)
|
||||||
|
include(${MYX_CMAKE_BACKPORTS_DIR}/TopLevelProject.cmake)
|
||||||
|
if(${CMAKE_VERSION} VERSION_LESS "3.11.0")
|
||||||
|
include(${MYX_CMAKE_BACKPORTS_DIR}/FetchContent.cmake)
|
||||||
|
else()
|
||||||
|
include(FetchContent)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
include(GNUInstallDirs)
|
||||||
|
include(CMakeDependentOption)
|
||||||
|
|
||||||
|
include(${MYX_CMAKE_LIB_DIR}/macro/CreateSymlink.cmake)
|
||||||
|
include(${MYX_CMAKE_LIB_DIR}/macro/FindPackages.cmake)
|
||||||
|
include(${MYX_CMAKE_LIB_DIR}/macro/InstallRelative.cmake)
|
||||||
|
|
||||||
|
include(${MYX_CMAKE_LIB_DIR}/PopulateCMakeBinaryDir.cmake)
|
||||||
|
include(${MYX_CMAKE_LIB_DIR}/CurrentDate.cmake)
|
||||||
|
include(${MYX_CMAKE_LIB_DIR}/ColoredMessages.cmake)
|
||||||
|
include(${MYX_CMAKE_LIB_DIR}/NinjaGeneratorWarning.cmake)
|
||||||
|
include(${MYX_CMAKE_LIB_DIR}/DirectoriesGuards.cmake)
|
||||||
|
include(${MYX_CMAKE_LIB_DIR}/SemanticProjectVersion.cmake)
|
||||||
|
include(${MYX_CMAKE_LIB_DIR}/NinjaGeneratorWrapper.cmake)
|
||||||
|
include(${MYX_CMAKE_LIB_DIR}/FetchContentAdd.cmake)
|
||||||
|
|
||||||
|
include(${MYX_CMAKE_LIB_DIR}/AddExecutable.cmake)
|
||||||
|
include(${MYX_CMAKE_LIB_DIR}/AddLibrary.cmake)
|
||||||
|
include(${MYX_CMAKE_LIB_DIR}/TargetSetup.cmake)
|
||||||
|
include(${MYX_CMAKE_LIB_DIR}/Qt5TargetSetup.cmake)
|
||||||
|
|
||||||
|
include(${MYX_CMAKE_LIB_DIR}/uncrustify/Uncrustify.cmake)
|
||||||
|
include(${MYX_CMAKE_LIB_DIR}/doc/Doxygen.cmake)
|
||||||
|
|
||||||
|
include(${MYX_CMAKE_LIB_DIR}/generators/PrivateConfigHeader.cmake)
|
||||||
|
include(${MYX_CMAKE_LIB_DIR}/generators/GitInfoHeader.cmake)
|
||||||
|
|
||||||
|
unset(MYX_CMAKE_SOURCE_DIR)
|
||||||
|
unset(MYX_CMAKE_BACKPORTS_DIR)
|
||||||
|
unset(MYX_CMAKE_LIB_DIR)
|
||||||
|
|
||||||
|
cmake_policy(POP)
|
9
cmake/myx/MyxCMakeConfigVersion.cmake
Normal file
9
cmake/myx/MyxCMakeConfigVersion.cmake
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
set(MYX_CMAKE_PACKAGE_VERSION "1.99.99")
|
||||||
|
if(MYX_CMAKE_PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION)
|
||||||
|
set(PACKAGE_VERSION_COMPATIBLE FALSE)
|
||||||
|
else()
|
||||||
|
set(PACKAGE_VERSION_COMPATIBLE TRUE)
|
||||||
|
if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION)
|
||||||
|
set(PACKAGE_VERSION_EXACT TRUE)
|
||||||
|
endif()
|
||||||
|
endif()
|
464
cmake/myx/backports/FetchContent.cmake
Normal file
464
cmake/myx/backports/FetchContent.cmake
Normal file
@ -0,0 +1,464 @@
|
|||||||
|
include_guard(GLOBAL)
|
||||||
|
|
||||||
|
set(__FetchContent_privateDir "${CMAKE_CURRENT_LIST_DIR}/FetchContent")
|
||||||
|
|
||||||
|
#=======================================================================
|
||||||
|
# Recording and retrieving content details for later population
|
||||||
|
#=======================================================================
|
||||||
|
|
||||||
|
# Internal use, projects must not call this directly. It is
|
||||||
|
# intended for use by FetchContent_Declare() only.
|
||||||
|
#
|
||||||
|
# Sets a content-specific global property (not meant for use
|
||||||
|
# outside of functions defined here in this file) which can later
|
||||||
|
# be retrieved using __FetchContent_getSavedDetails() with just the
|
||||||
|
# same content name. If there is already a value stored in the
|
||||||
|
# property, it is left unchanged and this call has no effect.
|
||||||
|
# This allows parent projects to define the content details,
|
||||||
|
# overriding anything a child project may try to set (properties
|
||||||
|
# are not cached between runs, so the first thing to set it in a
|
||||||
|
# build will be in control).
|
||||||
|
function(__FetchContent_declareDetails contentName)
|
||||||
|
|
||||||
|
string(TOLOWER ${contentName} contentNameLower)
|
||||||
|
set(propertyName "_FetchContent_${contentNameLower}_savedDetails")
|
||||||
|
get_property(alreadyDefined GLOBAL PROPERTY ${propertyName} DEFINED)
|
||||||
|
if(NOT alreadyDefined)
|
||||||
|
define_property(GLOBAL PROPERTY ${propertyName}
|
||||||
|
BRIEF_DOCS "Internal implementation detail of FetchContent_Populate()"
|
||||||
|
FULL_DOCS "Details used by FetchContent_Populate() for ${contentName}"
|
||||||
|
)
|
||||||
|
set_property(GLOBAL PROPERTY ${propertyName} ${ARGN})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
|
||||||
|
# Internal use, projects must not call this directly. It is
|
||||||
|
# intended for use by the FetchContent_Declare() function.
|
||||||
|
#
|
||||||
|
# Retrieves details saved for the specified content in an
|
||||||
|
# earlier call to __FetchContent_declareDetails().
|
||||||
|
function(__FetchContent_getSavedDetails contentName outVar)
|
||||||
|
|
||||||
|
string(TOLOWER ${contentName} contentNameLower)
|
||||||
|
set(propertyName "_FetchContent_${contentNameLower}_savedDetails")
|
||||||
|
get_property(alreadyDefined GLOBAL PROPERTY ${propertyName} DEFINED)
|
||||||
|
if(NOT alreadyDefined)
|
||||||
|
message(FATAL_ERROR "No content details recorded for ${contentName}")
|
||||||
|
endif()
|
||||||
|
get_property(propertyValue GLOBAL PROPERTY ${propertyName})
|
||||||
|
set(${outVar} "${propertyValue}" PARENT_SCOPE)
|
||||||
|
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
|
||||||
|
# Saves population details of the content, sets defaults for the
|
||||||
|
# SOURCE_DIR and BUILD_DIR.
|
||||||
|
function(FetchContent_Declare contentName)
|
||||||
|
|
||||||
|
set(options "")
|
||||||
|
set(oneValueArgs SVN_REPOSITORY)
|
||||||
|
set(multiValueArgs "")
|
||||||
|
|
||||||
|
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
||||||
|
|
||||||
|
unset(srcDirSuffix)
|
||||||
|
unset(svnRepoArgs)
|
||||||
|
if(ARG_SVN_REPOSITORY)
|
||||||
|
# Add a hash of the svn repository URL to the source dir. This works
|
||||||
|
# around the problem where if the URL changes, the download would
|
||||||
|
# fail because it tries to checkout/update rather than switch the
|
||||||
|
# old URL to the new one. We limit the hash to the first 7 characters
|
||||||
|
# so that the source path doesn't get overly long (which can be a
|
||||||
|
# problem on windows due to path length limits).
|
||||||
|
string(SHA1 urlSHA ${ARG_SVN_REPOSITORY})
|
||||||
|
string(SUBSTRING ${urlSHA} 0 7 urlSHA)
|
||||||
|
set(srcDirSuffix "-${urlSHA}")
|
||||||
|
set(svnRepoArgs SVN_REPOSITORY ${ARG_SVN_REPOSITORY})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
string(TOLOWER ${contentName} contentNameLower)
|
||||||
|
__FetchContent_declareDetails(
|
||||||
|
${contentNameLower}
|
||||||
|
SOURCE_DIR "${FETCHCONTENT_BASE_DIR}/${contentNameLower}-src${srcDirSuffix}"
|
||||||
|
BINARY_DIR "${FETCHCONTENT_BASE_DIR}/${contentNameLower}-build"
|
||||||
|
${svnRepoArgs}
|
||||||
|
# List these last so they can override things we set above
|
||||||
|
${ARG_UNPARSED_ARGUMENTS}
|
||||||
|
)
|
||||||
|
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
|
||||||
|
#=======================================================================
|
||||||
|
# Set/get whether the specified content has been populated yet.
|
||||||
|
# The setter also records the source and binary dirs used.
|
||||||
|
#=======================================================================
|
||||||
|
|
||||||
|
# Internal use, projects must not call this directly. It is
|
||||||
|
# intended for use by the FetchContent_Populate() function to
|
||||||
|
# record when FetchContent_Populate() is called for a particular
|
||||||
|
# content name.
|
||||||
|
function(__FetchContent_setPopulated contentName sourceDir binaryDir)
|
||||||
|
|
||||||
|
string(TOLOWER ${contentName} contentNameLower)
|
||||||
|
set(prefix "_FetchContent_${contentNameLower}")
|
||||||
|
|
||||||
|
set(propertyName "${prefix}_sourceDir")
|
||||||
|
define_property(GLOBAL PROPERTY ${propertyName}
|
||||||
|
BRIEF_DOCS "Internal implementation detail of FetchContent_Populate()"
|
||||||
|
FULL_DOCS "Details used by FetchContent_Populate() for ${contentName}"
|
||||||
|
)
|
||||||
|
set_property(GLOBAL PROPERTY ${propertyName} ${sourceDir})
|
||||||
|
|
||||||
|
set(propertyName "${prefix}_binaryDir")
|
||||||
|
define_property(GLOBAL PROPERTY ${propertyName}
|
||||||
|
BRIEF_DOCS "Internal implementation detail of FetchContent_Populate()"
|
||||||
|
FULL_DOCS "Details used by FetchContent_Populate() for ${contentName}"
|
||||||
|
)
|
||||||
|
set_property(GLOBAL PROPERTY ${propertyName} ${binaryDir})
|
||||||
|
|
||||||
|
set(propertyName "${prefix}_populated")
|
||||||
|
define_property(GLOBAL PROPERTY ${propertyName}
|
||||||
|
BRIEF_DOCS "Internal implementation detail of FetchContent_Populate()"
|
||||||
|
FULL_DOCS "Details used by FetchContent_Populate() for ${contentName}"
|
||||||
|
)
|
||||||
|
set_property(GLOBAL PROPERTY ${propertyName} True)
|
||||||
|
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
|
||||||
|
# Set variables in the calling scope for any of the retrievable
|
||||||
|
# properties. If no specific properties are requested, variables
|
||||||
|
# will be set for all retrievable properties.
|
||||||
|
#
|
||||||
|
# This function is intended to also be used by projects as the canonical
|
||||||
|
# way to detect whether they should call FetchContent_Populate()
|
||||||
|
# and pull the populated source into the build with add_subdirectory(),
|
||||||
|
# if they are using the populated content in that way.
|
||||||
|
function(FetchContent_GetProperties contentName)
|
||||||
|
|
||||||
|
string(TOLOWER ${contentName} contentNameLower)
|
||||||
|
|
||||||
|
set(options "")
|
||||||
|
set(oneValueArgs SOURCE_DIR BINARY_DIR POPULATED)
|
||||||
|
set(multiValueArgs "")
|
||||||
|
|
||||||
|
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
||||||
|
|
||||||
|
if(NOT ARG_SOURCE_DIR AND
|
||||||
|
NOT ARG_BINARY_DIR AND
|
||||||
|
NOT ARG_POPULATED)
|
||||||
|
# No specific properties requested, provide them all
|
||||||
|
set(ARG_SOURCE_DIR ${contentNameLower}_SOURCE_DIR)
|
||||||
|
set(ARG_BINARY_DIR ${contentNameLower}_BINARY_DIR)
|
||||||
|
set(ARG_POPULATED ${contentNameLower}_POPULATED)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(prefix "_FetchContent_${contentNameLower}")
|
||||||
|
|
||||||
|
if(ARG_SOURCE_DIR)
|
||||||
|
set(propertyName "${prefix}_sourceDir")
|
||||||
|
get_property(value GLOBAL PROPERTY ${propertyName})
|
||||||
|
if(value)
|
||||||
|
set(${ARG_SOURCE_DIR} ${value} PARENT_SCOPE)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(ARG_BINARY_DIR)
|
||||||
|
set(propertyName "${prefix}_binaryDir")
|
||||||
|
get_property(value GLOBAL PROPERTY ${propertyName})
|
||||||
|
if(value)
|
||||||
|
set(${ARG_BINARY_DIR} ${value} PARENT_SCOPE)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(ARG_POPULATED)
|
||||||
|
set(propertyName "${prefix}_populated")
|
||||||
|
get_property(value GLOBAL PROPERTY ${propertyName} DEFINED)
|
||||||
|
set(${ARG_POPULATED} ${value} PARENT_SCOPE)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
|
||||||
|
#=======================================================================
|
||||||
|
# Performing the population
|
||||||
|
#=======================================================================
|
||||||
|
|
||||||
|
# The value of contentName will always have been lowercased by the caller.
|
||||||
|
# All other arguments are assumed to be options that are understood by
|
||||||
|
# ExternalProject_Add(), except for QUIET and SUBBUILD_DIR.
|
||||||
|
function(__FetchContent_directPopulate contentName)
|
||||||
|
|
||||||
|
set(options
|
||||||
|
QUIET
|
||||||
|
)
|
||||||
|
set(oneValueArgs
|
||||||
|
SUBBUILD_DIR
|
||||||
|
SOURCE_DIR
|
||||||
|
BINARY_DIR
|
||||||
|
# Prevent the following from being passed through
|
||||||
|
CONFIGURE_COMMAND
|
||||||
|
BUILD_COMMAND
|
||||||
|
INSTALL_COMMAND
|
||||||
|
TEST_COMMAND
|
||||||
|
# We force both of these to be ON since we are always executing serially
|
||||||
|
# and we want all steps to have access to the terminal in case they
|
||||||
|
# need input from the command line (e.g. ask for a private key password)
|
||||||
|
# or they want to provide timely progress. We silently absorb and
|
||||||
|
# discard these if they are set by the caller.
|
||||||
|
USES_TERMINAL_DOWNLOAD
|
||||||
|
USES_TERMINAL_UPDATE
|
||||||
|
)
|
||||||
|
set(multiValueArgs "")
|
||||||
|
|
||||||
|
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
||||||
|
|
||||||
|
if(NOT ARG_SUBBUILD_DIR)
|
||||||
|
message(FATAL_ERROR "Internal error: SUBBUILD_DIR not set")
|
||||||
|
elseif(NOT IS_ABSOLUTE "${ARG_SUBBUILD_DIR}")
|
||||||
|
set(ARG_SUBBUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/${ARG_SUBBUILD_DIR}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT ARG_SOURCE_DIR)
|
||||||
|
message(FATAL_ERROR "Internal error: SOURCE_DIR not set")
|
||||||
|
elseif(NOT IS_ABSOLUTE "${ARG_SOURCE_DIR}")
|
||||||
|
set(ARG_SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/${ARG_SOURCE_DIR}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT ARG_BINARY_DIR)
|
||||||
|
message(FATAL_ERROR "Internal error: BINARY_DIR not set")
|
||||||
|
elseif(NOT IS_ABSOLUTE "${ARG_BINARY_DIR}")
|
||||||
|
set(ARG_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/${ARG_BINARY_DIR}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Ensure the caller can know where to find the source and build directories
|
||||||
|
# with some convenient variables. Doing this here ensures the caller sees
|
||||||
|
# the correct result in the case where the default values are overridden by
|
||||||
|
# the content details set by the project.
|
||||||
|
set(${contentName}_SOURCE_DIR "${ARG_SOURCE_DIR}" PARENT_SCOPE)
|
||||||
|
set(${contentName}_BINARY_DIR "${ARG_BINARY_DIR}" PARENT_SCOPE)
|
||||||
|
|
||||||
|
# The unparsed arguments may contain spaces, so build up ARG_EXTRA
|
||||||
|
# in such a way that it correctly substitutes into the generated
|
||||||
|
# CMakeLists.txt file with each argument quoted.
|
||||||
|
unset(ARG_EXTRA)
|
||||||
|
foreach(arg IN LISTS ARG_UNPARSED_ARGUMENTS)
|
||||||
|
set(ARG_EXTRA "${ARG_EXTRA} \"${arg}\"")
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
# Hide output if requested, but save it to a variable in case there's an
|
||||||
|
# error so we can show the output upon failure. When not quiet, don't
|
||||||
|
# capture the output to a variable because the user may want to see the
|
||||||
|
# output as it happens (e.g. progress during long downloads). Combine both
|
||||||
|
# stdout and stderr in the one capture variable so the output stays in order.
|
||||||
|
if (ARG_QUIET)
|
||||||
|
set(outputOptions
|
||||||
|
OUTPUT_VARIABLE capturedOutput
|
||||||
|
ERROR_VARIABLE capturedOutput
|
||||||
|
)
|
||||||
|
else()
|
||||||
|
set(capturedOutput)
|
||||||
|
set(outputOptions)
|
||||||
|
message(STATUS "Populating ${contentName}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(CMAKE_GENERATOR)
|
||||||
|
set(generatorOpts "-G${CMAKE_GENERATOR}")
|
||||||
|
if(CMAKE_GENERATOR_PLATFORM)
|
||||||
|
list(APPEND generatorOpts "-A${CMAKE_GENERATOR_PLATFORM}")
|
||||||
|
endif()
|
||||||
|
if(CMAKE_GENERATOR_TOOLSET)
|
||||||
|
list(APPEND generatorOpts "-T${CMAKE_GENERATOR_TOOLSET}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(CMAKE_MAKE_PROGRAM)
|
||||||
|
list(APPEND generatorOpts "-DCMAKE_MAKE_PROGRAM:FILEPATH=${CMAKE_MAKE_PROGRAM}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
else()
|
||||||
|
# Likely we've been invoked via CMake's script mode where no
|
||||||
|
# generator is set (and hence CMAKE_MAKE_PROGRAM could not be
|
||||||
|
# trusted even if provided). We will have to rely on being
|
||||||
|
# able to find the default generator and build tool.
|
||||||
|
unset(generatorOpts)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Create and build a separate CMake project to carry out the population.
|
||||||
|
# If we've already previously done these steps, they will not cause
|
||||||
|
# anything to be updated, so extra rebuilds of the project won't occur.
|
||||||
|
# Make sure to pass through CMAKE_MAKE_PROGRAM in case the main project
|
||||||
|
# has this set to something not findable on the PATH.
|
||||||
|
configure_file("${__FetchContent_privateDir}/CMakeLists.cmake.in"
|
||||||
|
"${ARG_SUBBUILD_DIR}/CMakeLists.txt")
|
||||||
|
execute_process(
|
||||||
|
COMMAND ${CMAKE_COMMAND} ${generatorOpts} .
|
||||||
|
RESULT_VARIABLE result
|
||||||
|
${outputOptions}
|
||||||
|
WORKING_DIRECTORY "${ARG_SUBBUILD_DIR}"
|
||||||
|
)
|
||||||
|
if(result)
|
||||||
|
if(capturedOutput)
|
||||||
|
message("${capturedOutput}")
|
||||||
|
endif()
|
||||||
|
message(FATAL_ERROR "CMake step for ${contentName} failed: ${result}")
|
||||||
|
endif()
|
||||||
|
execute_process(
|
||||||
|
COMMAND ${CMAKE_COMMAND} --build .
|
||||||
|
RESULT_VARIABLE result
|
||||||
|
${outputOptions}
|
||||||
|
WORKING_DIRECTORY "${ARG_SUBBUILD_DIR}"
|
||||||
|
)
|
||||||
|
if(result)
|
||||||
|
if(capturedOutput)
|
||||||
|
message("${capturedOutput}")
|
||||||
|
endif()
|
||||||
|
message(FATAL_ERROR "Build step for ${contentName} failed: ${result}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
|
||||||
|
option(FETCHCONTENT_FULLY_DISCONNECTED "Disables all attempts to download or update content and assumes source dirs already exist")
|
||||||
|
option(FETCHCONTENT_UPDATES_DISCONNECTED "Enables UPDATE_DISCONNECTED behavior for all content population")
|
||||||
|
option(FETCHCONTENT_QUIET "Enables QUIET option for all content population" ON)
|
||||||
|
set(FETCHCONTENT_BASE_DIR "${CMAKE_BINARY_DIR}/_deps" CACHE PATH "Directory under which to collect all populated content")
|
||||||
|
|
||||||
|
# Populate the specified content using details stored from
|
||||||
|
# an earlier call to FetchContent_Declare().
|
||||||
|
function(FetchContent_Populate contentName)
|
||||||
|
|
||||||
|
if(NOT contentName)
|
||||||
|
message(FATAL_ERROR "Empty contentName not allowed for FetchContent_Populate()")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
string(TOLOWER ${contentName} contentNameLower)
|
||||||
|
|
||||||
|
if(ARGN)
|
||||||
|
# This is the direct population form with details fully specified
|
||||||
|
# as part of the call, so we already have everything we need
|
||||||
|
__FetchContent_directPopulate(
|
||||||
|
${contentNameLower}
|
||||||
|
SUBBUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/${contentNameLower}-subbuild"
|
||||||
|
SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/${contentNameLower}-src"
|
||||||
|
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/${contentNameLower}-build"
|
||||||
|
${ARGN} # Could override any of the above ..._DIR variables
|
||||||
|
)
|
||||||
|
|
||||||
|
# Pass source and binary dir variables back to the caller
|
||||||
|
set(${contentNameLower}_SOURCE_DIR "${${contentNameLower}_SOURCE_DIR}" PARENT_SCOPE)
|
||||||
|
set(${contentNameLower}_BINARY_DIR "${${contentNameLower}_BINARY_DIR}" PARENT_SCOPE)
|
||||||
|
|
||||||
|
# Don't set global properties, or record that we did this population, since
|
||||||
|
# this was a direct call outside of the normal declared details form.
|
||||||
|
# We only want to save values in the global properties for content that
|
||||||
|
# honours the hierarchical details mechanism so that projects are not
|
||||||
|
# robbed of the ability to override details set in nested projects.
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# No details provided, so assume they were saved from an earlier call
|
||||||
|
# to FetchContent_Declare(). Do a check that we haven't already
|
||||||
|
# populated this content before in case the caller forgot to check.
|
||||||
|
FetchContent_GetProperties(${contentName})
|
||||||
|
if(${contentNameLower}_POPULATED)
|
||||||
|
message(FATAL_ERROR "Content ${contentName} already populated in ${${contentNameLower}_SOURCE_DIR}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
string(TOUPPER ${contentName} contentNameUpper)
|
||||||
|
set(FETCHCONTENT_SOURCE_DIR_${contentNameUpper}
|
||||||
|
"${FETCHCONTENT_SOURCE_DIR_${contentNameUpper}}"
|
||||||
|
CACHE PATH "When not empty, overrides where to find pre-populated content for ${contentName}")
|
||||||
|
|
||||||
|
if(FETCHCONTENT_SOURCE_DIR_${contentNameUpper})
|
||||||
|
# The source directory has been explicitly provided in the cache,
|
||||||
|
# so no population is required
|
||||||
|
set(${contentNameLower}_SOURCE_DIR "${FETCHCONTENT_SOURCE_DIR_${contentNameUpper}}")
|
||||||
|
set(${contentNameLower}_BINARY_DIR "${FETCHCONTENT_BASE_DIR}/${contentNameLower}-build")
|
||||||
|
|
||||||
|
elseif(FETCHCONTENT_FULLY_DISCONNECTED)
|
||||||
|
# Bypass population and assume source is already there from a previous run
|
||||||
|
set(${contentNameLower}_SOURCE_DIR "${FETCHCONTENT_BASE_DIR}/${contentNameLower}-src")
|
||||||
|
set(${contentNameLower}_BINARY_DIR "${FETCHCONTENT_BASE_DIR}/${contentNameLower}-build")
|
||||||
|
|
||||||
|
else()
|
||||||
|
# Support both a global "disconnect all updates" and a per-content
|
||||||
|
# update test (either one being set disables updates for this content).
|
||||||
|
option(FETCHCONTENT_UPDATES_DISCONNECTED_${contentNameUpper}
|
||||||
|
"Enables UPDATE_DISCONNECTED behavior just for population of ${contentName}")
|
||||||
|
if(FETCHCONTENT_UPDATES_DISCONNECTED OR
|
||||||
|
FETCHCONTENT_UPDATES_DISCONNECTED_${contentNameUpper})
|
||||||
|
set(disconnectUpdates True)
|
||||||
|
else()
|
||||||
|
set(disconnectUpdates False)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(FETCHCONTENT_QUIET)
|
||||||
|
set(quietFlag QUIET)
|
||||||
|
else()
|
||||||
|
unset(quietFlag)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
__FetchContent_getSavedDetails(${contentName} contentDetails)
|
||||||
|
if("${contentDetails}" STREQUAL "")
|
||||||
|
message(FATAL_ERROR "No details have been set for content: ${contentName}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
__FetchContent_directPopulate(
|
||||||
|
${contentNameLower}
|
||||||
|
${quietFlag}
|
||||||
|
UPDATE_DISCONNECTED ${disconnectUpdates}
|
||||||
|
SUBBUILD_DIR "${FETCHCONTENT_BASE_DIR}/${contentNameLower}-subbuild"
|
||||||
|
SOURCE_DIR "${FETCHCONTENT_BASE_DIR}/${contentNameLower}-src"
|
||||||
|
BINARY_DIR "${FETCHCONTENT_BASE_DIR}/${contentNameLower}-build"
|
||||||
|
# Put the saved details last so they can override any of the
|
||||||
|
# the options we set above (this can include SOURCE_DIR or
|
||||||
|
# BUILD_DIR)
|
||||||
|
${contentDetails}
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
__FetchContent_setPopulated(
|
||||||
|
${contentName}
|
||||||
|
${${contentNameLower}_SOURCE_DIR}
|
||||||
|
${${contentNameLower}_BINARY_DIR}
|
||||||
|
)
|
||||||
|
|
||||||
|
# Pass variables back to the caller. The variables passed back here
|
||||||
|
# must match what FetchContent_GetProperties() sets when it is called
|
||||||
|
# with just the content name.
|
||||||
|
set(${contentNameLower}_SOURCE_DIR "${${contentNameLower}_SOURCE_DIR}" PARENT_SCOPE)
|
||||||
|
set(${contentNameLower}_BINARY_DIR "${${contentNameLower}_BINARY_DIR}" PARENT_SCOPE)
|
||||||
|
set(${contentNameLower}_POPULATED True PARENT_SCOPE)
|
||||||
|
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
# Arguments are assumed to be the names of dependencies that have been
|
||||||
|
# declared previously and should be populated. It is not an error if
|
||||||
|
# any of them have already been populated (they will just be skipped in
|
||||||
|
# that case). The command is implemented as a macro so that the variables
|
||||||
|
# defined by the FetchContent_GetProperties() and FetchContent_Populate()
|
||||||
|
# calls will be available to the caller.
|
||||||
|
macro(FetchContent_MakeAvailable)
|
||||||
|
|
||||||
|
foreach(contentName IN ITEMS ${ARGV})
|
||||||
|
string(TOLOWER ${contentName} contentNameLower)
|
||||||
|
FetchContent_GetProperties(${contentName})
|
||||||
|
if(NOT ${contentNameLower}_POPULATED)
|
||||||
|
FetchContent_Populate(${contentName})
|
||||||
|
|
||||||
|
# Only try to call add_subdirectory() if the populated content
|
||||||
|
# can be treated that way. Protecting the call with the check
|
||||||
|
# allows this function to be used for projects that just want
|
||||||
|
# to ensure the content exists, such as to provide content at
|
||||||
|
# a known location.
|
||||||
|
if(EXISTS ${${contentNameLower}_SOURCE_DIR}/CMakeLists.txt)
|
||||||
|
add_subdirectory(${${contentNameLower}_SOURCE_DIR}
|
||||||
|
${${contentNameLower}_BINARY_DIR})
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
endmacro()
|
28
cmake/myx/backports/FetchContent/CMakeLists.cmake.in
Normal file
28
cmake/myx/backports/FetchContent/CMakeLists.cmake.in
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||||
|
# file Copyright.txt or https://cmake.org/licensing for details.
|
||||||
|
|
||||||
|
cmake_minimum_required(VERSION ${CMAKE_VERSION})
|
||||||
|
|
||||||
|
# We name the project and the target for the ExternalProject_Add() call
|
||||||
|
# to something that will highlight to the user what we are working on if
|
||||||
|
# something goes wrong and an error message is produced.
|
||||||
|
|
||||||
|
project(${contentName}-populate NONE)
|
||||||
|
|
||||||
|
@__FETCHCONTENT_CACHED_INFO@
|
||||||
|
|
||||||
|
include(ExternalProject)
|
||||||
|
ExternalProject_Add(${contentName}-populate
|
||||||
|
${ARG_EXTRA}
|
||||||
|
SOURCE_DIR "${ARG_SOURCE_DIR}"
|
||||||
|
BINARY_DIR "${ARG_BINARY_DIR}"
|
||||||
|
CONFIGURE_COMMAND ""
|
||||||
|
BUILD_COMMAND ""
|
||||||
|
INSTALL_COMMAND ""
|
||||||
|
TEST_COMMAND ""
|
||||||
|
USES_TERMINAL_DOWNLOAD YES
|
||||||
|
USES_TERMINAL_UPDATE YES
|
||||||
|
USES_TERMINAL_PATCH YES
|
||||||
|
)
|
||||||
|
|
||||||
|
@__FETCHCONTENT_COPY_FILE@
|
12
cmake/myx/backports/IncludeGuard.cmake
Normal file
12
cmake/myx/backports/IncludeGuard.cmake
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
# Защита для однократного включения файла *.cmake
|
||||||
|
# Функция include_guard() реализована в версии 3.10
|
||||||
|
# Макрос реализован для обратной совместимости
|
||||||
|
if(${CMAKE_VERSION} VERSION_LESS "3.10.0")
|
||||||
|
macro(include_guard)
|
||||||
|
if (CMAKE_FILE_${CMAKE_CURRENT_LIST_FILE}_ALREADY_INCLUDED)
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
set(CMAKE_FILE_${CMAKE_CURRENT_LIST_FILE}_ALREADY_INCLUDED TRUE)
|
||||||
|
endmacro()
|
||||||
|
endif()
|
||||||
|
|
10
cmake/myx/backports/TopLevelProject.cmake
Normal file
10
cmake/myx/backports/TopLevelProject.cmake
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
include_guard(GLOBAL)
|
||||||
|
|
||||||
|
if(${CMAKE_VERSION} VERSION_LESS 3.21)
|
||||||
|
get_property(nt DIRECTORY PROPERTY PARENT_DIRECTORY)
|
||||||
|
if(NOT nt)
|
||||||
|
set(PROJECT_IS_TOP_LEVEL true)
|
||||||
|
endif()
|
||||||
|
unset(nt)
|
||||||
|
endif()
|
||||||
|
|
22
cmake/myx/lib/AddExecutable.cmake
Normal file
22
cmake/myx/lib/AddExecutable.cmake
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#[=======================================================================[.rst:
|
||||||
|
myx_add_executable
|
||||||
|
------------------
|
||||||
|
|
||||||
|
Вспомогательная функция для создания исполняемого файла::
|
||||||
|
|
||||||
|
myx_add_executable(NAME)
|
||||||
|
|
||||||
|
Используется для совместимости с версиями CMake раньше 3.11,
|
||||||
|
в которых было необходимо указать хотя бы один файл с исходными текстами.
|
||||||
|
|
||||||
|
#]=======================================================================]
|
||||||
|
|
||||||
|
include_guard(GLOBAL)
|
||||||
|
|
||||||
|
function(myx_add_executable NAME)
|
||||||
|
if(${CMAKE_VERSION} VERSION_LESS "3.11.0")
|
||||||
|
add_executable(${NAME} ${ARGN} "")
|
||||||
|
else()
|
||||||
|
add_executable(${NAME} ${ARGN})
|
||||||
|
endif()
|
||||||
|
endfunction()
|
227
cmake/myx/lib/AddLibrary.cmake
Normal file
227
cmake/myx/lib/AddLibrary.cmake
Normal file
@ -0,0 +1,227 @@
|
|||||||
|
#[=======================================================================[.rst:
|
||||||
|
myx_add_library
|
||||||
|
---------------
|
||||||
|
|
||||||
|
Вспомогательная функция для создания библиотеки::
|
||||||
|
|
||||||
|
myx_add_library(NAME TYPE
|
||||||
|
[ OUTPUT_NAME output_name ] |
|
||||||
|
[ EXPORT_FILE_NAME file_name ] |
|
||||||
|
[ EXPORT_BASE_NAME base_name ])
|
||||||
|
|
||||||
|
Обязательные параметры: `NAME` - имя библиотеки и `TYPE` - тип цели.
|
||||||
|
Параметр `OUTPUT_NAME` определяет базовое имя выходных файлов.
|
||||||
|
Параметр `EXPORT_FILE_NAME` задаёт имя заголовочного файла экспортируемых
|
||||||
|
переменных, а `EXPORT_BASE_NAME` - базовый суффикс для формирования имён переменных.
|
||||||
|
Все остальные параметры передаются в стандартную функцию `add_library()`
|
||||||
|
|
||||||
|
#]=======================================================================]
|
||||||
|
|
||||||
|
include_guard(GLOBAL)
|
||||||
|
|
||||||
|
include(CMakePackageConfigHelpers)
|
||||||
|
include(GenerateExportHeader)
|
||||||
|
|
||||||
|
if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
|
||||||
|
set(MYX_CMAKE_LIB_DIR_BACKPORT "${CMAKE_CURRENT_LIST_DIR}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
function(myx_add_library NAME TYPE)
|
||||||
|
if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
|
||||||
|
set(CMAKE_CURRENT_FUNCTION_LIST_DIR ${MYX_CMAKE_LIB_DIR_BACKPORT})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(options)
|
||||||
|
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})
|
||||||
|
|
||||||
|
if(TYPE STREQUAL "INTERFACE")
|
||||||
|
# Библиотека, состоящая только из заголовочных файлов не требует сборки.
|
||||||
|
# Стандартные пути к заголовочным файлам
|
||||||
|
target_include_directories(${NAME}
|
||||||
|
INTERFACE
|
||||||
|
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
|
||||||
|
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
||||||
|
)
|
||||||
|
else()
|
||||||
|
string(TOUPPER ${NAME} PROJECT_NAME_UPPER)
|
||||||
|
# Опция для разрешения сборки динамической библиотеки
|
||||||
|
cmake_dependent_option(${PROJECT_NAME_UPPER}_BUILD_SHARED
|
||||||
|
"Build shared library for ${NAME}" ON "BUILD_SHARED_LIBS" OFF)
|
||||||
|
# Опция для разрешения сборки статической библиотеки
|
||||||
|
cmake_dependent_option(${PROJECT_NAME_UPPER}_BUILD_STATIC
|
||||||
|
"Build static library for ${NAME}" ON "NOT BUILD_SHARED_LIBS" OFF)
|
||||||
|
|
||||||
|
# Стандартные пути к заголовочным файлам
|
||||||
|
target_include_directories(${NAME}
|
||||||
|
PUBLIC
|
||||||
|
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
|
||||||
|
PRIVATE
|
||||||
|
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>
|
||||||
|
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
||||||
|
)
|
||||||
|
|
||||||
|
# Сборка позиционно-независимых объектных файлов нужна
|
||||||
|
# для создания динамической библиотеки
|
||||||
|
set_target_properties(${NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
||||||
|
|
||||||
|
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 ${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
|
||||||
|
)
|
||||||
|
set_property(TARGET ${NAME} APPEND PROPERTY INTERFACE_HEADER_FILES "${ARG_EXPORT_FILE_NAME}")
|
||||||
|
|
||||||
|
# Цель для создания динамической библиотеки из объектных файлов
|
||||||
|
if(${PROJECT_NAME_UPPER}_BUILD_SHARED)
|
||||||
|
# Для создания динамической библиотеки используются объектные файлы цели ${NAME}
|
||||||
|
add_library(${NAME}_shared SHARED $<TARGET_OBJECTS:${NAME}>)
|
||||||
|
# Установка дополнительных свойств для цели ${NAME}_shared
|
||||||
|
# VERSION: версия библиотеки
|
||||||
|
# SOVERSION: мажорная версия библиотеки
|
||||||
|
# LIBRARY_OUTPUT_DIRECTORY: каталог для записи результатов сборки
|
||||||
|
# OUTPUT_NAME: базовое имя выходного файла (без учёта расширения)
|
||||||
|
set_target_properties(${NAME}_shared
|
||||||
|
PROPERTIES
|
||||||
|
VERSION ${PROJECT_VERSION}
|
||||||
|
SOVERSION ${PROJECT_VERSION_MAJOR}
|
||||||
|
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}
|
||||||
|
OUTPUT_NAME ${ARG_OUTPUT_NAME})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Цель для создания статической библиотеки из объектных файлов
|
||||||
|
if(${PROJECT_NAME_UPPER}_BUILD_STATIC)
|
||||||
|
# Для создания статической библиотеки используются объектные файлы цели ${NAME}
|
||||||
|
add_library(${NAME}_static STATIC $<TARGET_OBJECTS:${NAME}>)
|
||||||
|
# Установка дополнительных свойств для цели ${NAME}_static
|
||||||
|
# ARCHIVE_OUTPUT_DIRECTORY: каталог для записи результатов сборки
|
||||||
|
# OUTPUT_NAME: базовое имя выходного файла (без учёта расширения)
|
||||||
|
set_target_properties(${NAME}_static
|
||||||
|
PROPERTIES
|
||||||
|
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}
|
||||||
|
OUTPUT_NAME ${ARG_OUTPUT_NAME})
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Если вызов был выполнен не из проекта верхнего уровня,
|
||||||
|
# то созданная цель исключается из цели `all`.
|
||||||
|
# При этом сама цель `${NAME}` может участвовать в сборке,
|
||||||
|
# если окажется в перечне зависимостей.
|
||||||
|
if(NOT PROJECT_IS_TOP_LEVEL)
|
||||||
|
set_target_properties(${NAME} PROPERTIES EXCLUDE_FROM_ALL True)
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Правила для установки библиотек и относящихся к ним файлов.
|
||||||
|
# Если вызов был выполнен не из проекта верхнего уровня,
|
||||||
|
# то эти правила не обрабатываются.
|
||||||
|
write_basic_package_version_file(
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/${NAME}ConfigVersion.cmake
|
||||||
|
VERSION ${PROJECT_VERSION}
|
||||||
|
COMPATIBILITY AnyNewerVersion
|
||||||
|
)
|
||||||
|
|
||||||
|
configure_package_config_file(
|
||||||
|
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/library-config.cmake.in
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/${NAME}Config.cmake
|
||||||
|
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${NAME}
|
||||||
|
NO_SET_AND_CHECK_MACRO
|
||||||
|
NO_CHECK_REQUIRED_COMPONENTS_MACRO
|
||||||
|
)
|
||||||
|
|
||||||
|
install(EXPORT ${NAME}Targets
|
||||||
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${NAME}
|
||||||
|
COMPONENT dev
|
||||||
|
)
|
||||||
|
|
||||||
|
install(
|
||||||
|
FILES
|
||||||
|
${PROJECT_BINARY_DIR}/${NAME}ConfigVersion.cmake
|
||||||
|
${PROJECT_BINARY_DIR}/${NAME}Config.cmake
|
||||||
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${NAME}
|
||||||
|
COMPONENT dev
|
||||||
|
)
|
||||||
|
|
||||||
|
# Формирование файла для pkg-config
|
||||||
|
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 "${PROJECT_BINARY_DIR}/${NAME}.pc"
|
||||||
|
"libdir=${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}\n")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
file(APPEND "${PROJECT_BINARY_DIR}/${NAME}.pc"
|
||||||
|
"\n"
|
||||||
|
"Name: ${NAME}\n"
|
||||||
|
"Description: ${NAME} library\n"
|
||||||
|
"Version: ${PROJECT_VERSION}\n"
|
||||||
|
"\n"
|
||||||
|
"Requires:\n"
|
||||||
|
"Cflags: -I${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}\n")
|
||||||
|
|
||||||
|
if(NOT TYPE STREQUAL "INTERFACE")
|
||||||
|
file(APPEND "${PROJECT_BINARY_DIR}/${NAME}.pc"
|
||||||
|
"Libs: -L${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR} -l${NAME}\n")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Установка файла для pkg-config
|
||||||
|
install(
|
||||||
|
FILES "${PROJECT_BINARY_DIR}/${NAME}.pc"
|
||||||
|
COMPONENT dev
|
||||||
|
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
|
||||||
|
|
||||||
|
if(TYPE STREQUAL "OBJECT")
|
||||||
|
# Установка динамической библиотеки
|
||||||
|
if(TARGET ${NAME}_shared)
|
||||||
|
install(
|
||||||
|
TARGETS ${NAME}_shared
|
||||||
|
EXPORT ${NAME}Targets
|
||||||
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
|
COMPONENT lib
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(TARGET ${NAME}_static)
|
||||||
|
# Установка статической библиотеки
|
||||||
|
install(
|
||||||
|
TARGETS ${NAME}_static
|
||||||
|
EXPORT ${NAME}Targets
|
||||||
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
|
COMPONENT static
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(TYPE STREQUAL "INTERFACE")
|
||||||
|
# Установка библиотеки из заголовочных файлов
|
||||||
|
install(
|
||||||
|
TARGETS ${NAME}
|
||||||
|
EXPORT ${NAME}Targets
|
||||||
|
COMPONENT lib
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
endfunction()
|
56
cmake/myx/lib/ColoredMessages.cmake
Normal file
56
cmake/myx/lib/ColoredMessages.cmake
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
#[=======================================================================[.rst:
|
||||||
|
|
||||||
|
Обёртки для функции `message()`, которые в терминале UNIX
|
||||||
|
подсвечиают сообщения в зависимости от важности.
|
||||||
|
|
||||||
|
#]=======================================================================]
|
||||||
|
|
||||||
|
include_guard(GLOBAL)
|
||||||
|
|
||||||
|
if(DEFINED ENV{TERM} AND UNIX)
|
||||||
|
string(ASCII 27 Esc)
|
||||||
|
set(MyxColorReset "${Esc}[m")
|
||||||
|
set(MyxColorBold "${Esc}[1m")
|
||||||
|
set(MyxColorRed "${Esc}[31m")
|
||||||
|
set(MyxColorGreen "${Esc}[32m")
|
||||||
|
set(MyxColorYellow "${Esc}[33m")
|
||||||
|
set(MyxColorBlue "${Esc}[34m")
|
||||||
|
set(MyxColorMagenta "${Esc}[35m")
|
||||||
|
set(MyxColorCyan "${Esc}[36m")
|
||||||
|
set(MyxColorWhite "${Esc}[37m")
|
||||||
|
set(MyxColorBoldRed "${Esc}[1;31m")
|
||||||
|
set(MyxColorBoldGreen "${Esc}[1;32m")
|
||||||
|
set(MyxColorBoldYellow "${Esc}[1;33m")
|
||||||
|
set(MyxColorBoldBlue "${Esc}[1;34m")
|
||||||
|
set(MyxColorBoldMagenta "${Esc}[1;35m")
|
||||||
|
set(MyxColorBoldCyan "${Esc}[1;36m")
|
||||||
|
set(MyxColorBoldWhite "${Esc}[1;37m")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
function(myx_message_fatal_error)
|
||||||
|
message(FATAL_ERROR ${MyxColorBoldRed}${ARGV}${MyxColorReset})
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
function(myx_message_send_error)
|
||||||
|
message(SEND_ERROR ${MyxColorBoldRed}${ARGV}${MyxColorReset})
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
function(myx_message_warning)
|
||||||
|
message(WARNING ${MyxColorRed}${ARGV}${MyxColorReset})
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
function(myx_message_deprecation)
|
||||||
|
message(DEPRECATION ${MyxColorBoldMagenta}${ARGV}${MyxColorReset})
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
function(myx_message_status)
|
||||||
|
message(STATUS ${MyxColorMagenta}${ARGV}${MyxColorReset})
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
function(myx_message_notice)
|
||||||
|
message(${MyxColorBold}${ARGV}${MyxColorReset})
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
function(myx_message)
|
||||||
|
message(${MyxColorReset}${ARGV}${MyxColorReset})
|
||||||
|
endfunction()
|
19
cmake/myx/lib/CurrentDate.cmake
Normal file
19
cmake/myx/lib/CurrentDate.cmake
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
include_guard(GLOBAL)
|
||||||
|
|
||||||
|
if(NOT MYX_TODAY)
|
||||||
|
if(WIN32)
|
||||||
|
execute_process(COMMAND "cmd" " /C date /T" OUTPUT_VARIABLE MYX_TODAY)
|
||||||
|
else()
|
||||||
|
execute_process(COMMAND "date" "+%d/%m/%Y" OUTPUT_VARIABLE MYX_TODAY)
|
||||||
|
endif()
|
||||||
|
string(REGEX REPLACE "(..)/(..)/(....).*" "\\3-\\2-\\1" MYX_TODAY ${MYX_TODAY})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT MYX_YEAR)
|
||||||
|
if(WIN32)
|
||||||
|
execute_process(COMMAND "cmd" " /C date /T" OUTPUT_VARIABLE MYX_YEAR)
|
||||||
|
else()
|
||||||
|
execute_process(COMMAND "date" "+%d/%m/%Y" OUTPUT_VARIABLE MYX_YEAR)
|
||||||
|
endif()
|
||||||
|
string(REGEX REPLACE "(..)/(..)/(....).*" "\\3" MYX_YEAR ${MYX_YEAR})
|
||||||
|
endif()
|
53
cmake/myx/lib/DirectoriesGuards.cmake
Normal file
53
cmake/myx/lib/DirectoriesGuards.cmake
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
#[=======================================================================[.rst:
|
||||||
|
|
||||||
|
Запись результатов сборки проекта внутрь иерархии каталогов с исходными текстами
|
||||||
|
приводит к засорению файлами формируемыми на этапе сборки, которые затрудняют
|
||||||
|
разработку, поиск в оригинальных файлах и мешают ориентироваться в проекте.
|
||||||
|
При работе с несколькими типами сборки, например, отладка и выпуск, появляется
|
||||||
|
необходимость корректного полного удаления результатов предыдущего варианта.
|
||||||
|
|
||||||
|
#]=======================================================================]
|
||||||
|
|
||||||
|
include_guard(GLOBAL)
|
||||||
|
|
||||||
|
get_filename_component(cmake_source_dir "${CMAKE_SOURCE_DIR}" REALPATH)
|
||||||
|
get_filename_component(cmake_binary_dir "${CMAKE_BINARY_DIR}" REALPATH)
|
||||||
|
get_filename_component(project_source_dir "${PROJECT_SOURCE_DIR}" REALPATH)
|
||||||
|
get_filename_component(project_binary_dir "${PROJECT_BINARY_DIR}" REALPATH)
|
||||||
|
get_filename_component(cmake_install_prefix "${CMAKE_INSTALL_PREFIX}" REALPATH)
|
||||||
|
|
||||||
|
if(cmake_install_prefix STREQUAL cmake_binary_dir)
|
||||||
|
myx_message_fatal_error(
|
||||||
|
"Myx: Cannot install into build directory ${CMAKE_INSTALL_PREFIX}.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(cmake_install_prefix STREQUAL cmake_source_dir)
|
||||||
|
myx_message_fatal_error(
|
||||||
|
"Myx: Cannot install into source directory ${CMAKE_INSTALL_PREFIX}.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(cmake_install_prefix STREQUAL project_binary_dir)
|
||||||
|
myx_message_fatal_error(
|
||||||
|
"Myx: Cannot install into build directory ${CMAKE_INSTALL_PREFIX}.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(cmake_install_prefix STREQUAL project_source_dir)
|
||||||
|
myx_message_fatal_error(
|
||||||
|
"Myx: Cannot install into source directory ${CMAKE_INSTALL_PREFIX}.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(cmake_binary_dir STREQUAL cmake_source_dir)
|
||||||
|
myx_message_fatal_error(
|
||||||
|
"Myx: Cannot build in source directory ${CMAKE_SOURCE_DIR}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(project_binary_dir STREQUAL project_source_dir)
|
||||||
|
myx_message_fatal_error(
|
||||||
|
"Myx: Cannot build in source directory ${CMAKE_SOURCE_DIR}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
unset(cmake_source_dir)
|
||||||
|
unset(cmake_binary_dir)
|
||||||
|
unset(project_source_dir)
|
||||||
|
unset(project_binary_dir)
|
||||||
|
unset(cmake_install_prefix)
|
59
cmake/myx/lib/FetchContentAdd.cmake
Normal file
59
cmake/myx/lib/FetchContentAdd.cmake
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
#[=======================================================================[.rst:
|
||||||
|
FetchContent_Add
|
||||||
|
----------------
|
||||||
|
|
||||||
|
Вспомогательная функция для `FetchContent_Declare()`::
|
||||||
|
|
||||||
|
FetchContent_Add(NAME
|
||||||
|
[ GIT_REPOSITORY repo ] |
|
||||||
|
[ GIT_REMOTE remote ] |
|
||||||
|
[ GIT_PATH path ])
|
||||||
|
|
||||||
|
Обязательные параметры: `NAME` - идентификатор загружаемого ресурса.
|
||||||
|
Параметр `GIT_REPOSITORY` определяет имя репозитория по умолчанию.
|
||||||
|
Если указана пара параметров `GIT_REMOTE` и `GIT_PATH` и у git-репозитория
|
||||||
|
основного проекта указан удалённый репозиторий с именем, определяемым
|
||||||
|
переменной `GIT_REMOTE`, то адрес репозитория для получения проекта
|
||||||
|
изменяется. В этом случае загрузка будет производиться с сервера,
|
||||||
|
определяемого из адреса с меткой `GIT_REMOTE`, и по пути `GIT_PATH`.
|
||||||
|
|
||||||
|
#]=======================================================================]
|
||||||
|
|
||||||
|
include_guard(GLOBAL)
|
||||||
|
|
||||||
|
# Обязательно в глобальной области
|
||||||
|
find_package(Git)
|
||||||
|
|
||||||
|
function(FetchContent_Add NAME)
|
||||||
|
set(options "")
|
||||||
|
set(oneValueArgs GIT_REPOSITORY GIT_REMOTE GIT_PATH)
|
||||||
|
set(multiValueArgs "")
|
||||||
|
|
||||||
|
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
||||||
|
|
||||||
|
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)
|
||||||
|
string(REGEX REPLACE ":.*" "" SERVER ${REMOTE_URL})
|
||||||
|
string(FIND ${SERVER} "http" POS)
|
||||||
|
if(NOT POS EQUAL 0)
|
||||||
|
if(NOT SERVER STREQUAL REMOTE_URL)
|
||||||
|
set(ARG_GIT_REPOSITORY "${SERVER}:${ARG_GIT_PATH}")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
FetchContent_Declare(
|
||||||
|
${NAME}
|
||||||
|
${ARG_UNPARSED_ARGUMENTS}
|
||||||
|
GIT_REPOSITORY ${ARG_GIT_REPOSITORY}
|
||||||
|
GIT_SHALLOW 1
|
||||||
|
)
|
||||||
|
|
||||||
|
if(NOT ${NAME}_POPULATED)
|
||||||
|
FetchContent_Populate(${NAME})
|
||||||
|
add_subdirectory(${${NAME}_SOURCE_DIR} ${${NAME}_BINARY_DIR})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
endfunction()
|
8
cmake/myx/lib/NinjaGeneratorWarning.cmake
Normal file
8
cmake/myx/lib/NinjaGeneratorWarning.cmake
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# Версии CMake, как минимум до 3.8.0, генерируют некорректные
|
||||||
|
# правила для ninja.
|
||||||
|
|
||||||
|
include_guard(GLOBAL)
|
||||||
|
|
||||||
|
if(${CMAKE_VERSION} VERSION_LESS "3.8.0" AND CMAKE_GENERATOR MATCHES Ninja)
|
||||||
|
myx_message_error("Myx: Old CMake versions should use Makefile generator")
|
||||||
|
endif()
|
11
cmake/myx/lib/NinjaGeneratorWrapper.cmake
Normal file
11
cmake/myx/lib/NinjaGeneratorWrapper.cmake
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# Если выбран генератор Ninja, то в основном сборочном каталоге создаётся
|
||||||
|
# файл Makefile, который обрабатывается командой make и передаёт исполнение
|
||||||
|
# системе сборки ninja. Таким образом можно выполнять команду make,
|
||||||
|
# даже если правила сборки проекта сгенерированы для ninja.
|
||||||
|
|
||||||
|
include_guard(GLOBAL)
|
||||||
|
|
||||||
|
if(CMAKE_GENERATOR MATCHES Ninja AND PROJECT_IS_TOP_LEVEL)
|
||||||
|
file(WRITE ${CMAKE_BINARY_DIR}/Makefile
|
||||||
|
".PHONY: build\n" "%:\n" "\t@ninja \$@\n" "build:\n" "\t@ninja\n")
|
||||||
|
endif()
|
15
cmake/myx/lib/PopulateCMakeBinaryDir.cmake
Normal file
15
cmake/myx/lib/PopulateCMakeBinaryDir.cmake
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
include_guard(GLOBAL)
|
||||||
|
|
||||||
|
# Создание в каталоге ${CMAKE_BINARY_DIR} стандартных каталогов bin,include,lib,
|
||||||
|
# а также символических ссылок на каталоги в ${CMAKE_SOURCE_DIR}/files
|
||||||
|
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||||
|
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/include)
|
||||||
|
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
|
||||||
|
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
|
||||||
|
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/include)
|
||||||
|
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
|
||||||
|
|
||||||
|
create_symlink("${CMAKE_SOURCE_DIR}/files/etc" "${CMAKE_BINARY_DIR}/etc")
|
||||||
|
create_symlink("${CMAKE_SOURCE_DIR}/files/log" "${CMAKE_BINARY_DIR}/log")
|
||||||
|
create_symlink("${CMAKE_SOURCE_DIR}/files/share" "${CMAKE_BINARY_DIR}/share")
|
||||||
|
create_symlink("${CMAKE_SOURCE_DIR}/files/var" "${CMAKE_BINARY_DIR}/var")
|
94
cmake/myx/lib/Qt5TargetSetup.cmake
Normal file
94
cmake/myx/lib/Qt5TargetSetup.cmake
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
include_guard(GLOBAL)
|
||||||
|
|
||||||
|
function(myx_qt5_target_setup NAME)
|
||||||
|
set(options)
|
||||||
|
set(oneValueArgs)
|
||||||
|
set(multiValueArgs COMPONENTS PRIVATE PUBLIC_MOC PRIVATE_MOC UI QRC LANGS)
|
||||||
|
|
||||||
|
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
||||||
|
|
||||||
|
get_target_property(target_type ${NAME} TYPE)
|
||||||
|
|
||||||
|
foreach(iter ${ARG_COMPONENTS})
|
||||||
|
if(target_type STREQUAL "INTERFACE_LIBRARY")
|
||||||
|
target_include_directories(${NAME} INTERFACE ${Qt5${iter}_INCLUDE_DIRS})
|
||||||
|
else()
|
||||||
|
target_include_directories(${NAME} PRIVATE ${Qt5${iter}_INCLUDE_DIRS})
|
||||||
|
endif()
|
||||||
|
if(target_type STREQUAL "EXECUTABLE" AND NOT iter STREQUAL "LinguistTools")
|
||||||
|
target_link_libraries(${NAME} PRIVATE "Qt5::${iter}")
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
foreach(iter ${ARG_PRIVATE})
|
||||||
|
if(target_type STREQUAL "INTERFACE_LIBRARY")
|
||||||
|
target_include_directories(${NAME} INTERFACE ${Qt5${iter}_PRIVATE_INCLUDE_DIRS})
|
||||||
|
else()
|
||||||
|
target_include_directories(${NAME} PRIVATE ${Qt5${iter}_PRIVATE_INCLUDE_DIRS})
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
if(target_type STREQUAL "EXECUTABLE")
|
||||||
|
target_compile_options(${NAME} PRIVATE ${Qt5Core_EXECUTABLE_COMPILE_FLAGS})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(ARG_PUBLIC_MOC)
|
||||||
|
set_property(TARGET ${NAME} APPEND PROPERTY PUBLIC_HEADER_FILES "${ARG_PUBLIC_MOC}")
|
||||||
|
set_property(TARGET ${NAME} APPEND PROPERTY TR_FILES ${ARG_PUBLIC_MOC})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(ARG_PRIVATE_MOC)
|
||||||
|
set_property(TARGET ${NAME} APPEND PROPERTY PRIVATE_HEADER_FILES "${ARG_PRIVATE_MOC}")
|
||||||
|
set_property(TARGET ${NAME} APPEND PROPERTY TR_FILES ${ARG_PRIVATE_MOC})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(ARG_PUBLIC_MOC OR ARG_PRIVATE_MOC)
|
||||||
|
qt5_wrap_cpp(moc_cpp ${ARG_PUBLIC_MOC} ${ARG_PRIVATE_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})
|
||||||
|
set_property(TARGET ${NAME} APPEND PROPERTY TR_FILES ${ARG_UI})
|
||||||
|
# TODO
|
||||||
|
target_include_directories(${PROJECT_NAME} PRIVATE ${PROJECT_BINARY_DIR})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Перечень файлов, подлежащих переводу
|
||||||
|
get_target_property(tr ${NAME} TR_FILES)
|
||||||
|
# Формирование файла ресурсов с переводами
|
||||||
|
if("LinguistTools" IN_LIST ARG_COMPONENTS AND tr)
|
||||||
|
# Заглавие файла ресурсов
|
||||||
|
file(WRITE ${PROJECT_BINARY_DIR}/${NAME}_l10n.qrc "<RCC><qresource prefix=\"/qm\">\n")
|
||||||
|
# Для каждого языка, указанное в параметре LANGS
|
||||||
|
foreach(iter ${ARG_LANGS})
|
||||||
|
# Создание или обновление файла переводов в каталоге ${PROJECT_SOURCE_DIR}/l10n
|
||||||
|
# и его компиляция в каталог ${PROJECT_BINARY_DIR}
|
||||||
|
qt5_create_translation(qm ${tr} "${PROJECT_SOURCE_DIR}/l10n/${NAME}_${iter}.ts")
|
||||||
|
# Добавление записи для скомпилированного файла переводов в ресурсный файл
|
||||||
|
file(APPEND ${PROJECT_BINARY_DIR}/${NAME}_l10n.qrc
|
||||||
|
"<file alias=\"${NAME}_${iter}\">${NAME}_${iter}.qm</file>\n")
|
||||||
|
# Добавление скомпилированного файла переводов к списку зависимостей для цели
|
||||||
|
target_sources(${NAME} PRIVATE ${qm})
|
||||||
|
endforeach()
|
||||||
|
# Окончение файла ресурсов
|
||||||
|
file(APPEND ${PROJECT_BINARY_DIR}/${NAME}_l10n.qrc "</qresource></RCC>\n")
|
||||||
|
# Комплияция файла ресурсов с переводами
|
||||||
|
qt5_add_resources(qrc_l10n ${PROJECT_BINARY_DIR}/${NAME}_l10n.qrc)
|
||||||
|
target_sources(${NAME} PRIVATE ${qrc_l10n})
|
||||||
|
endif()
|
||||||
|
unset(tr)
|
||||||
|
target_sources(${NAME} PRIVATE ${ARG_PUBLIC_MOC} ${ARG_PRIVATE_MOC} ${moc_cpp} ${ui_h} ${qrc_cpp})
|
||||||
|
|
||||||
|
# Установка публичных заголовочных файлов
|
||||||
|
if(PROJECT_IS_TOP_LEVEL)
|
||||||
|
install_relative(${PROJECT_SOURCE_DIR}
|
||||||
|
FILES ${ARG_PUBLIC_MOC}
|
||||||
|
DESTINATION ${CMAKE_INSTALL_PREFIX}
|
||||||
|
COMPONENT dev
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
endfunction()
|
17
cmake/myx/lib/SemanticProjectVersion.cmake
Normal file
17
cmake/myx/lib/SemanticProjectVersion.cmake
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
include_guard(GLOBAL)
|
||||||
|
|
||||||
|
function(myx_is_semantic_project_version)
|
||||||
|
if(NOT ${PROJECT_VERSION_PATCH} MATCHES "([0-9]+)")
|
||||||
|
myx_message_error("Myx: Please set project version in X.Y.Z format")
|
||||||
|
endif()
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
function(myx_project_version_int)
|
||||||
|
# cmake-format: off
|
||||||
|
myx_is_semantic_project_version()
|
||||||
|
math(EXPR v "(${PROJECT_VERSION_MAJOR} << 32) + (${PROJECT_VERSION_MINOR} << 16) + ${PROJECT_VERSION_PATCH}")
|
||||||
|
set_property(GLOBAL PROPERTY PROJECT_VERSION_INT ${v})
|
||||||
|
# cmake-format: on
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
myx_is_semantic_project_version()
|
89
cmake/myx/lib/TargetSetup.cmake
Normal file
89
cmake/myx/lib/TargetSetup.cmake
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
include_guard(GLOBAL)
|
||||||
|
|
||||||
|
function(myx_target_setup NAME)
|
||||||
|
set(options)
|
||||||
|
set(oneValueArgs PCH)
|
||||||
|
set(multiValueArgs COMPILE_DEFINITIONS PACKAGES LINK_LIBRARIES
|
||||||
|
CPP INTERFACE_HEADERS PUBLIC_HEADERS PRIVATE_HEADERS)
|
||||||
|
|
||||||
|
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
||||||
|
|
||||||
|
if(NOT TARGET ${NAME})
|
||||||
|
myx_message_fatal_error("Target ${NAME} does not exists.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
get_target_property(target_type ${NAME} TYPE)
|
||||||
|
|
||||||
|
foreach(iter ${ARG_PACKAGES})
|
||||||
|
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_CPP)
|
||||||
|
set_property(TARGET ${NAME} APPEND PROPERTY CPP_FILES ${ARG_CPP})
|
||||||
|
set_property(TARGET ${NAME} APPEND PROPERTY TR_FILES ${ARG_CPP})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(ARG_PUBLIC_HEADERS)
|
||||||
|
set_property(TARGET ${NAME} APPEND PROPERTY PUBLIC_HEADER_FILES "${ARG_PUBLIC_HEADERS}")
|
||||||
|
set_property(TARGET ${NAME} APPEND PROPERTY TR_FILES ${ARG_PUBLIC_HEADERS})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(ARG_PRIVATE_HEADERS)
|
||||||
|
set_property(TARGET ${NAME} APPEND PROPERTY PRIVATE_HEADER_FILES "${ARG_PRIVATE_HEADERS}")
|
||||||
|
set_property(TARGET ${NAME} APPEND PROPERTY TR_FILES ${ARG_PRIVATE_HEADERS})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(ARG_PCH)
|
||||||
|
if((${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.16) AND (PROJECT_IS_TOP_LEVEL OR MYX_USE_LOCAL_DIRECTORIES))
|
||||||
|
target_precompile_headers(${NAME} PRIVATE ${ARG_PCH})
|
||||||
|
else()
|
||||||
|
target_compile_options(${NAME} PRIVATE -include ${ARG_PCH})
|
||||||
|
endif()
|
||||||
|
set_property(TARGET ${NAME} APPEND PROPERTY PRIVATE_HEADER_FILES "${ARG_PCH}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT target_type STREQUAL "INTERFACE_LIBRARY")
|
||||||
|
target_include_directories(${PROJECT_NAME} PRIVATE
|
||||||
|
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>)
|
||||||
|
|
||||||
|
if(IS_DIRECTORY "${PROJECT_SOURCE_DIR}/src")
|
||||||
|
target_include_directories(${PROJECT_NAME} PRIVATE
|
||||||
|
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(target_type STREQUAL "EXECUTABLE")
|
||||||
|
if(IS_DIRECTORY "${PROJECT_SOURCE_DIR}/include")
|
||||||
|
target_include_directories(${PROJECT_NAME} PRIVATE
|
||||||
|
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set_target_properties(${NAME} PROPERTIES
|
||||||
|
POSITION_INDEPENDENT_CODE ON
|
||||||
|
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}
|
||||||
|
)
|
||||||
|
if(CMAKE_CXX_COMPILE_OPTIONS_PIE)
|
||||||
|
target_compile_options(${NAME} PUBLIC ${CMAKE_CXX_COMPILE_OPTIONS_PIE})
|
||||||
|
endif()
|
||||||
|
install(TARGETS ${NAME} COMPONENT main RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
target_sources(${NAME} PUBLIC $<BUILD_INTERFACE:${ARG_INTERFACE_HEADERS}>)
|
||||||
|
target_sources(${NAME} PUBLIC ${ARG_PUBLIC_HEADERS})
|
||||||
|
target_sources(${NAME} PRIVATE ${ARG_CPP} ${ARG_PCH} ${ARG_PRIVATE_HEADERS})
|
||||||
|
if(NOT target_type STREQUAL "OBJECT_LIBRARY")
|
||||||
|
target_link_libraries(${NAME} PRIVATE ${ARG_LINK_LIBRARIES})
|
||||||
|
endif()
|
||||||
|
target_compile_definitions(${NAME} PRIVATE ${ARG_COMPILE_DEFINITIONS})
|
||||||
|
|
||||||
|
# Установка публичных заголовочных файлов
|
||||||
|
if(PROJECT_IS_TOP_LEVEL)
|
||||||
|
install_relative(${PROJECT_SOURCE_DIR}
|
||||||
|
FILES ${ARG_PUBLIC_HEADERS} ${ARG_INTERFACE_HEADERS}
|
||||||
|
DESTINATION ${CMAKE_INSTALL_PREFIX}
|
||||||
|
COMPONENT dev
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
endfunction()
|
31
cmake/myx/lib/doc/Doxyfile.in
Normal file
31
cmake/myx/lib/doc/Doxyfile.in
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
PROJECT_NAME = @DOXYGEN_PROJECT_TITLE@
|
||||||
|
OUTPUT_DIRECTORY = @DOXYGEN_OUTPUT_DIRECTORY@
|
||||||
|
OUTPUT_LANGUAGE = @ARG_LANGUAGE@
|
||||||
|
STRIP_FROM_PATH = @PROJECT_SOURCE_DIR@
|
||||||
|
STRIP_FROM_INC_PATH = @PROJECT_SOURCE_DIR@
|
||||||
|
|
||||||
|
EXTRACT_ALL = YES
|
||||||
|
EXTRACT_PRIVATE = YES
|
||||||
|
EXTRACT_STATIC = YES
|
||||||
|
EXTRACT_LOCAL_METHODS = YES
|
||||||
|
|
||||||
|
INPUT = "@PROJECT_SOURCE_DIR@/doc/doxygen" "@PROJECT_SOURCE_DIR@/include" "@PROJECT_SOURCE_DIR@/src"
|
||||||
|
RECURSIVE = YES
|
||||||
|
|
||||||
|
CLANG_ASSISTED_PARSING = YES
|
||||||
|
CLANG_DATABASE_PATH = @CMAKE_BINARY_DIR@
|
||||||
|
|
||||||
|
GENERATE_HTML = @ARG_HTML@
|
||||||
|
GENERATE_TREEVIEW = YES
|
||||||
|
|
||||||
|
GENERATE_LATEX = @ARG_LATEX@
|
||||||
|
LATEX_CMD_NAME = xelatex
|
||||||
|
COMPACT_LATEX = YES
|
||||||
|
|
||||||
|
GENERATE_XML = @ARG_XML@
|
||||||
|
|
||||||
|
UML_LOOK = YES
|
||||||
|
TEMPLATE_RELATIONS = YES
|
||||||
|
CALL_GRAPH = YES
|
||||||
|
CALLER_GRAPH = YES
|
||||||
|
INTERACTIVE_SVG = YES
|
73
cmake/myx/lib/doc/Doxygen.cmake
Normal file
73
cmake/myx/lib/doc/Doxygen.cmake
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
include_guard(GLOBAL)
|
||||||
|
|
||||||
|
if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
|
||||||
|
set(MYX_CMAKE_LIB_DOC_DIR_BACKPORT "${CMAKE_CURRENT_LIST_DIR}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
function(myx_doc_doxygen NAME)
|
||||||
|
if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
|
||||||
|
set(CMAKE_CURRENT_FUNCTION_LIST_DIR ${MYX_CMAKE_LIB_DOC_DIR_BACKPORT})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
find_package(Doxygen)
|
||||||
|
if(DOXYGEN_FOUND)
|
||||||
|
set(DOXYGEN_FOUND ON CACHE STRING "Doxygen documentation generator enabled" FORCE)
|
||||||
|
set(DOXYGEN_EXECUTABLE "${DOXYGEN_EXECUTABLE}" CACHE STRING "Path to Doxygen executable")
|
||||||
|
else()
|
||||||
|
set(DOXYGEN_FOUND OFF CACHE STRING "Doxygen documentation generator disabled" FORCE)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(target "myx-doc-doxygen-${NAME}")
|
||||||
|
if(NOT DOXYGEN_FOUND)
|
||||||
|
add_custom_target(${target} VERBATIM COMMENT "Doxygen is not found. Skipping target ${target} build")
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(TARGET ${target})
|
||||||
|
myx_message_warning("Target ${target} already defined")
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(options)
|
||||||
|
set(oneValueArgs HTML LATEX XML LANGUAGE DOXYFILE_TEMPLATE)
|
||||||
|
set(multiValueArgs)
|
||||||
|
|
||||||
|
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
||||||
|
|
||||||
|
if(NOT ARG_HTML)
|
||||||
|
set(ARG_HTML NO)
|
||||||
|
endif()
|
||||||
|
if(NOT ARG_LATEX)
|
||||||
|
set(ARG_LATEX NO)
|
||||||
|
endif()
|
||||||
|
if(NOT ARG_XML)
|
||||||
|
set(ARG_XML YES)
|
||||||
|
endif()
|
||||||
|
if(NOT ARG_LANGUAGE)
|
||||||
|
set(ARG_LANGUAGE "Russian")
|
||||||
|
endif()
|
||||||
|
if(NOT ARG_DOXYFILE_TEMPLATE OR NOT EXISTS "${ARG_DOXYFILE_TEMPLATE}")
|
||||||
|
set(ARG_DOXYFILE_TEMPLATE "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/Doxyfile.in")
|
||||||
|
endif()
|
||||||
|
if(NOT DOXYGEN_PROJECT_NAME)
|
||||||
|
set(DOXYGEN_PROJECT_NAME ${PROJECT_NAME})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(work_dir ${PROJECT_BINARY_DIR}/doc/doxygen)
|
||||||
|
configure_file(${ARG_DOXYFILE_TEMPLATE} ${work_dir}/Doxyfile @ONLY)
|
||||||
|
|
||||||
|
add_custom_target(${target}
|
||||||
|
VERBATIM
|
||||||
|
WORKING_DIRECTORY ${work_dir}
|
||||||
|
COMMAND ${DOXYGEN_EXECUTABLE} ${work_dir}/Doxyfile
|
||||||
|
COMMENT "Generating API documentation with Doxygen")
|
||||||
|
if(ARG_HTML)
|
||||||
|
install(DIRECTORY ${CMAKE_BINARY_DIR}/doc/doxygen/html/
|
||||||
|
COMPONENT doc OPTIONAL
|
||||||
|
DESTINATION ${CMAKE_INSTALL_DATADIR}/doc/doxygen)
|
||||||
|
endif()
|
||||||
|
if(NOT TARGET myx-doc-doxygen)
|
||||||
|
add_custom_target(myx-doc-doxygen)
|
||||||
|
endif()
|
||||||
|
add_dependencies(myx-doc-doxygen ${target})
|
||||||
|
endfunction()
|
32
cmake/myx/lib/generators/GitInfo.cmake
Normal file
32
cmake/myx/lib/generators/GitInfo.cmake
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
cmake_policy(PUSH)
|
||||||
|
cmake_policy(SET CMP0053 NEW) # IN_LIST operator
|
||||||
|
|
||||||
|
set(ARG_PREFIX "${PREFIX}")
|
||||||
|
set(GIT_REV "N/A")
|
||||||
|
set(GIT_DIFF "")
|
||||||
|
set(GIT_TAG "N/A")
|
||||||
|
set(GIT_BRANCH "N/A")
|
||||||
|
|
||||||
|
find_package(Git)
|
||||||
|
|
||||||
|
if(GIT_EXECUTABLE)
|
||||||
|
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_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)
|
||||||
|
string(STRIP "${GIT_DIFF}" GIT_DIFF)
|
||||||
|
string(STRIP "${GIT_TAG}" GIT_TAG)
|
||||||
|
string(STRIP "${GIT_BRANCH}" GIT_BRANCH)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
configure_file("GitInfo.hpp.in" "${GIT_INFO_FILE}")
|
||||||
|
|
||||||
|
cmake_policy(POP)
|
26
cmake/myx/lib/generators/GitInfo.hpp.in
Normal file
26
cmake/myx/lib/generators/GitInfo.hpp.in
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
// -*- C++ -*-
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#if defined (@PREFIX@GIT_REV)
|
||||||
|
#error "Duplicate definition of macros @PREFIX@GIT_REV"
|
||||||
|
#else
|
||||||
|
#define @PREFIX@GIT_REV "@GIT_REV@"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined (@PREFIX@GIT_DIFF)
|
||||||
|
#error "Duplicate definition of macros @PREFIX@GIT_DIFF"
|
||||||
|
#else
|
||||||
|
#define @PREFIX@GIT_DIFF "@GIT_DIFF@"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined (@PREFIX@GIT_BRANCH)
|
||||||
|
#error "Duplicate definition of macros @PREFIX@GIT_BRANCH"
|
||||||
|
#else
|
||||||
|
#define @PREFIX@GIT_BRANCH "@GIT_BRANCH@"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined (@PREFIX@GIT_TAG)
|
||||||
|
#error "Duplicate definition of macros @PREFIX@GIT_TAG"
|
||||||
|
#else
|
||||||
|
#define @PREFIX@GIT_TAG "@GIT_TAG@"
|
||||||
|
#endif
|
53
cmake/myx/lib/generators/GitInfoHeader.cmake
Normal file
53
cmake/myx/lib/generators/GitInfoHeader.cmake
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
#[=======================================================================[.rst:
|
||||||
|
myx_generate_git_info_header
|
||||||
|
----------------------------------
|
||||||
|
|
||||||
|
Вспомогательная функция для автоматической генерации заголовочного
|
||||||
|
файла, содержащего информацию о текущем состоянии репозитория git::
|
||||||
|
|
||||||
|
myx_generate_git_info_header(TARGET BASE_FILENAME
|
||||||
|
[ PREFIX prefix ] )
|
||||||
|
|
||||||
|
Обязательные параметры: `TARGET` - имя цели, с которой связан заголовочный файл,
|
||||||
|
и `BASE_FILENAME` - имя генерируемого заголовочного файла. Дополнительный аргумент
|
||||||
|
`PREFIX` добавляет префикс к генерируемым именам переменных.
|
||||||
|
|
||||||
|
#]=======================================================================]
|
||||||
|
|
||||||
|
include_guard(GLOBAL)
|
||||||
|
|
||||||
|
if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
|
||||||
|
set(MYX_CMAKE_LIB_GENERATORS_DIR_BACKPORT "${CMAKE_CURRENT_LIST_DIR}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
function(myx_generate_git_info_header target base_filename)
|
||||||
|
if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
|
||||||
|
set(CMAKE_CURRENT_FUNCTION_LIST_DIR ${MYX_CMAKE_LIB_GENERATORS_DIR_BACKPORT})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(options)
|
||||||
|
set(oneValueArgs PREFIX)
|
||||||
|
set(multiValueArgs)
|
||||||
|
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
||||||
|
|
||||||
|
set(filename "${PROJECT_BINARY_DIR}/include/${base_filename}")
|
||||||
|
|
||||||
|
set(PREFIX "")
|
||||||
|
if(ARG_PREFIX)
|
||||||
|
string(APPEND ARG_PREFIX "_")
|
||||||
|
string(REPLACE "-" "_" PREFIX ${ARG_PREFIX})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# cmake-format: off
|
||||||
|
if(NOT TARGET ${target}-git-info-header)
|
||||||
|
add_custom_target(${target}-git-info-header ALL
|
||||||
|
${CMAKE_COMMAND} -DGIT_INFO_FILE=${filename} -DPREFIX=${PREFIX}
|
||||||
|
-P ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/GitInfo.cmake
|
||||||
|
BYPRODUCTS ${filename}
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_FUNCTION_LIST_DIR})
|
||||||
|
endif()
|
||||||
|
# cmake-format: on
|
||||||
|
|
||||||
|
set_property(TARGET ${target} APPEND PROPERTY PRIVATE_HEADER_FILES ${filename})
|
||||||
|
target_sources(${target} PRIVATE ${filename})
|
||||||
|
endfunction()
|
12
cmake/myx/lib/generators/PrivateConfig.hpp.in
Normal file
12
cmake/myx/lib/generators/PrivateConfig.hpp.in
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
// -*- C++ -*-
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define PROJECT_VERSION_STR "@PROJECT_VERSION@"
|
||||||
|
#define PROJECT_VERSION_INT @PROJECT_VERSION_INT@
|
||||||
|
|
||||||
|
#cmakedefine PROJECT_NAME "@PROJECT_NAME@"
|
||||||
|
#cmakedefine AUTHOR_NAME "@AUTHOR_NAME@"
|
||||||
|
#cmakedefine AUTHOR_EMAIL "@AUTHOR_EMAIL@"
|
||||||
|
#cmakedefine DESCRIPTION "@PROJECT_DESCRIPTION@"
|
||||||
|
#cmakedefine BUILD_TYPE "@CMAKE_BUILD_TYPE@"
|
||||||
|
#cmakedefine BUILD_DATE "@MYX_TODAY@"
|
35
cmake/myx/lib/generators/PrivateConfigHeader.cmake
Normal file
35
cmake/myx/lib/generators/PrivateConfigHeader.cmake
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
#[=======================================================================[.rst:
|
||||||
|
myx_generate_private_config_header
|
||||||
|
----------------------------------
|
||||||
|
|
||||||
|
Вспомогательная функция для автоматической генерации заголовочного
|
||||||
|
файла, содержащего информацию о проекте::
|
||||||
|
|
||||||
|
myx_generate_private_config_header(TARGET BASE_FILENAME)
|
||||||
|
|
||||||
|
Обязательные параметры: `TARGET` - имя цели, с которой связан заголовочный файл,
|
||||||
|
и `BASE_FILENAME` - имя генерируемого заголовочного файла.
|
||||||
|
|
||||||
|
#]=======================================================================]
|
||||||
|
|
||||||
|
include_guard(GLOBAL)
|
||||||
|
|
||||||
|
if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
|
||||||
|
set(MYX_CMAKE_LIB_GENERATORS_DIR_BACKPORT "${CMAKE_CURRENT_LIST_DIR}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
function(myx_generate_private_config_header target base_filename)
|
||||||
|
if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
|
||||||
|
set(CMAKE_CURRENT_FUNCTION_LIST_DIR ${MYX_CMAKE_LIB_GENERATORS_DIR_BACKPORT})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(BUILD_DATE ${MYX_TODAY})
|
||||||
|
myx_project_version_int()
|
||||||
|
get_property(PROJECT_VERSION_INT GLOBAL PROPERTY PROJECT_VERSION_INT)
|
||||||
|
|
||||||
|
set(filename "${PROJECT_BINARY_DIR}/include/${base_filename}")
|
||||||
|
configure_file("${CMAKE_CURRENT_FUNCTION_LIST_DIR}/PrivateConfig.hpp.in" ${filename})
|
||||||
|
|
||||||
|
set_property(TARGET ${target} APPEND PROPERTY PRIVATE_HEADER_FILES ${filename})
|
||||||
|
target_sources(${target} PRIVATE ${filename})
|
||||||
|
endfunction()
|
5
cmake/myx/lib/library-config.cmake.in
Normal file
5
cmake/myx/lib/library-config.cmake.in
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
@PACKAGE_INIT@
|
||||||
|
|
||||||
|
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")
|
||||||
|
|
||||||
|
check_required_components("@PROJECT_NAME@")
|
11
cmake/myx/lib/macro/CreateSymlink.cmake
Normal file
11
cmake/myx/lib/macro/CreateSymlink.cmake
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
include_guard(GLOBAL)
|
||||||
|
|
||||||
|
macro(create_symlink original linkname)
|
||||||
|
if(NOT EXISTS ${linkname})
|
||||||
|
if(${CMAKE_VERSION} VERSION_LESS "3.14.0")
|
||||||
|
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${original} ${linkname})
|
||||||
|
else()
|
||||||
|
file(CREATE_LINK ${original} ${linkname} SYMBOLIC)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endmacro(create_symlink original linkname)
|
35
cmake/myx/lib/macro/FindPackages.cmake
Normal file
35
cmake/myx/lib/macro/FindPackages.cmake
Normal 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)
|
19
cmake/myx/lib/macro/InstallRelative.cmake
Normal file
19
cmake/myx/lib/macro/InstallRelative.cmake
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#[=======================================================================[.rst:
|
||||||
|
install_relative
|
||||||
|
----------------
|
||||||
|
|
||||||
|
#]=======================================================================]
|
||||||
|
|
||||||
|
macro(install_relative STRIP_DIRECTORY)
|
||||||
|
set(options)
|
||||||
|
set(oneValueArgs DESTINATION)
|
||||||
|
set(multiValueArgs FILES)
|
||||||
|
|
||||||
|
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
||||||
|
|
||||||
|
foreach(FILE ${ARG_FILES})
|
||||||
|
get_filename_component(DIR ${FILE} DIRECTORY)
|
||||||
|
string(REPLACE ${STRIP_DIRECTORY} "" RELATIVE_DIR ${DIR})
|
||||||
|
INSTALL(FILES ${FILE} DESTINATION ${ARG_DESTINATION}/${RELATIVE_DIR} ${ARG_UNPARSED_ARGUMENTS})
|
||||||
|
endforeach()
|
||||||
|
endmacro(install_relative STRIP_DIRECTORY)
|
84
cmake/myx/lib/uncrustify/Uncrustify.cmake
Normal file
84
cmake/myx/lib/uncrustify/Uncrustify.cmake
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
include_guard(GLOBAL)
|
||||||
|
|
||||||
|
if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
|
||||||
|
set(MYX_CMAKE_LIB_UNCRUSTIFY_DIR_BACKPORT "${CMAKE_CURRENT_LIST_DIR}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
find_program(UNCRUSTIFY_EXE NAMES uncrustify)
|
||||||
|
|
||||||
|
function(myx_uncrustify target)
|
||||||
|
if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
|
||||||
|
set(CMAKE_CURRENT_FUNCTION_LIST_DIR ${MYX_CMAKE_LIB_UNCRUSTIFY_DIR_BACKPORT})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(options)
|
||||||
|
set(oneValueArgs CONFIG)
|
||||||
|
set(multiValueArgs)
|
||||||
|
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
||||||
|
|
||||||
|
if(NOT ARG_CONFIG)
|
||||||
|
set(ARG_CONFIG "${PROJECT_SOURCE_DIR}/.uncrustify.cfg")
|
||||||
|
if(NOT EXISTS ${ARG_CONFIG})
|
||||||
|
set(ARG_CONFIG "${CMAKE_SOURCE_DIR}/.uncrustify.cfg")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT EXISTS ${ARG_CONFIG})
|
||||||
|
myx_message_notice("MyxCMake: uncrustify config is not found")
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT UNCRUSTIFY_EXE)
|
||||||
|
myx_message_notice("MyxCMake: uncrustify executable is not found")
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if(NOT TARGET myx-uncrustify)
|
||||||
|
add_custom_target(myx-uncrustify)
|
||||||
|
endif()
|
||||||
|
if(NOT TARGET myx-uncrustify-check)
|
||||||
|
add_custom_target(myx-uncrustify-check)
|
||||||
|
endif()
|
||||||
|
if(NOT TARGET myx-uncrustify-append-comments)
|
||||||
|
add_custom_target(myx-uncrustify-append-comments)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Динамически сгенерированные файлы исключаются
|
||||||
|
get_target_property(s ${target} SOURCES)
|
||||||
|
foreach(iter ${s})
|
||||||
|
string(FIND ${iter} ${CMAKE_BINARY_DIR} pos)
|
||||||
|
if(pos EQUAL -1)
|
||||||
|
list(APPEND src ${iter})
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/uncrustify-${target}.cfg
|
||||||
|
COMMAND ${UNCRUSTIFY_EXE} --update-config-with-doc
|
||||||
|
-c ${ARG_CONFIG}
|
||||||
|
-o ${PROJECT_BINARY_DIR}/uncrustify-${target}.cfg)
|
||||||
|
list(APPEND UNCRUSTIFY_OPTS -c ${PROJECT_BINARY_DIR}/uncrustify-${target}.cfg)
|
||||||
|
# cmake-format: off
|
||||||
|
add_custom_target(${target}-uncrustify-check
|
||||||
|
DEPENDS ${PROJECT_BINARY_DIR}/uncrustify-${target}.cfg
|
||||||
|
COMMAND ${UNCRUSTIFY_EXE} ${UNCRUSTIFY_OPTS} --check ${src})
|
||||||
|
|
||||||
|
list(APPEND UNCRUSTIFY_OPTS --replace --no-backup)
|
||||||
|
add_custom_target(${target}-uncrustify
|
||||||
|
DEPENDS ${PROJECT_BINARY_DIR}/uncrustify-${target}.cfg
|
||||||
|
COMMAND ${UNCRUSTIFY_EXE} ${UNCRUSTIFY_OPTS} --mtime ${src})
|
||||||
|
|
||||||
|
add_custom_target(${target}-uncrustify-append-comments
|
||||||
|
DEPENDS ${PROJECT_BINARY_DIR}/uncrustify-${target}.cfg
|
||||||
|
COMMAND ${UNCRUSTIFY_EXE} ${UNCRUSTIFY_OPTS}
|
||||||
|
--set cmt_insert_class_header=${CMAKE_CURRENT_FUNCTION_LIST_DIR}/classheader.txt
|
||||||
|
--set cmt_insert_file_footer=${CMAKE_CURRENT_FUNCTION_LIST_DIR}/filefooter.txt
|
||||||
|
--set cmt_insert_file_header=${CMAKE_CURRENT_FUNCTION_LIST_DIR}/fileheader.txt
|
||||||
|
--set cmt_insert_func_header=${CMAKE_CURRENT_FUNCTION_LIST_DIR}/funcheader.txt
|
||||||
|
--set cmt_insert_before_ctor_dtor=true --mtime ${src})
|
||||||
|
# cmake-format: on
|
||||||
|
|
||||||
|
add_dependencies(myx-uncrustify ${target}-uncrustify)
|
||||||
|
add_dependencies(myx-uncrustify-check ${target}-uncrustify-check)
|
||||||
|
add_dependencies(myx-uncrustify-append-comments ${target}-uncrustify-append-comments)
|
||||||
|
endfunction()
|
5
cmake/myx/lib/uncrustify/classheader.txt
Normal file
5
cmake/myx/lib/uncrustify/classheader.txt
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
/**
|
||||||
|
* @class $(fclass)
|
||||||
|
* @brief TODO
|
||||||
|
* @details TODO
|
||||||
|
*/
|
1
cmake/myx/lib/uncrustify/filefooter.txt
Normal file
1
cmake/myx/lib/uncrustify/filefooter.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
// EOF $(filename)
|
6
cmake/myx/lib/uncrustify/fileheader.txt
Normal file
6
cmake/myx/lib/uncrustify/fileheader.txt
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
// -*- C++ -*-
|
||||||
|
/**
|
||||||
|
* @file $(filename)
|
||||||
|
* @brief TODO
|
||||||
|
* @details TODO
|
||||||
|
*/
|
5
cmake/myx/lib/uncrustify/funcheader.txt
Normal file
5
cmake/myx/lib/uncrustify/funcheader.txt
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
/**
|
||||||
|
* @fn $(fclass)::$(function)
|
||||||
|
* $(javaparam)
|
||||||
|
* @details TODO
|
||||||
|
*/
|
36
cmake/myx_setup.cmake
Normal file
36
cmake/myx_setup.cmake
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
#[=======================================================================[.rst:
|
||||||
|
Подключение дополнительных функций для CMake
|
||||||
|
|
||||||
|
По умолчанию предполагается использование версии MyxCMake,
|
||||||
|
файлы которой находятся в каталоге `cmake/myx` текущего проекта.
|
||||||
|
|
||||||
|
Для удобства разботки библиотеки MyxCMake можно указать путь
|
||||||
|
к её репозиторию с помощью переменной проекта CMake `MYX_CMAKE_DIR`
|
||||||
|
или переменной окружения `MYX_CMAKE_DIR`.
|
||||||
|
|
||||||
|
Если определена переменная `MYX_CMAKE_USE_SYSTEM`, то выполняется
|
||||||
|
поиск версии в каталогах перечисленных в переменной `CMAKE_MODULES_DIR`.
|
||||||
|
|
||||||
|
Кроме того выполняется попытка поиска (MyxxCMake)[../../../../myxx] --
|
||||||
|
расширения для библиотеки, позволяющиего в режиме разработки программного
|
||||||
|
проекта использовать дополнительные инструменты для его сопровождения.
|
||||||
|
#]=======================================================================]
|
||||||
|
|
||||||
|
if(MYX_CMAKE_DIR)
|
||||||
|
set(ENV{MYX_CMAKE_DIR} ${MYX_CMAKE_DIR})
|
||||||
|
endif()
|
||||||
|
if(DEFINED ENV{MYX_CMAKE_DIR})
|
||||||
|
find_package(MyxCMake 1.99.99 REQUIRED CONFIG PATHS $ENV{MYX_CMAKE_DIR} NO_DEFAULT_PATH)
|
||||||
|
myx_message_notice("=== MyxCMake directory: ${MyxCMake_CONFIG} ===")
|
||||||
|
else()
|
||||||
|
if(MYX_CMAKE_USE_SYSTEM)
|
||||||
|
find_package(MyxCMake 1.99.99 REQUIRED)
|
||||||
|
myx_message_notice("=== MyxCMake directory: ${MyxCMake_CONFIG} ===")
|
||||||
|
else()
|
||||||
|
include(${PROJECT_SOURCE_DIR}/cmake/myx/MyxCMakeConfig.cmake)
|
||||||
|
myx_message_notice("=== MyxCMake directory: ${PROJECT_SOURCE_DIR}/cmake/myx ===")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
find_package(MyxxCMake CONFIG PATHS "$ENV{XDG_DATA_DIR}/cmake" QUIET)
|
||||||
|
|
@ -1,32 +0,0 @@
|
|||||||
# Название основной цели и имени программы в текущем каталоге
|
|
||||||
set(TRGT myx-cmake-example-features)
|
|
||||||
|
|
||||||
# Список файлов исходных текстов
|
|
||||||
set(TRGT_cpp ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp)
|
|
||||||
|
|
||||||
# Заголовочные файлы, для которых необходима обработка препроцессором moc
|
|
||||||
# (содержат класс, унаследованный от QObject, использующий сигналы и/или слоты)
|
|
||||||
set(TRGT_moc_hpp ${CMAKE_CURRENT_SOURCE_DIR}/processor.hpp)
|
|
||||||
|
|
||||||
# Заголовочные файлы
|
|
||||||
set(TRGT_hpp)
|
|
||||||
|
|
||||||
set(TRGT_headers ${TRGT_hpp} ${TRGT_moc_hpp})
|
|
||||||
|
|
||||||
# Правило для автоматической генерации препроцессором moc
|
|
||||||
qt5_wrap_cpp(TRGT_moc_cpp ${TRGT_moc_hpp})
|
|
||||||
|
|
||||||
# Функция для создания цели, результатом которой будет сборка приложения
|
|
||||||
add_executable(${TRGT} ${TRGT_cpp} ${TRGT_headers} ${TRGT_moc_cpp})
|
|
||||||
myx_cmake_common_target_properties(${TRGT})
|
|
||||||
|
|
||||||
# Qt5: подключение заголовочных файлов
|
|
||||||
target_include_directories(${TRGT} SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS})
|
|
||||||
|
|
||||||
# Qt5: подключение библиотек
|
|
||||||
target_link_libraries(${TRGT} Qt5::Core)
|
|
||||||
|
|
||||||
# Дополнительные функции для цели ${TRGT}.
|
|
||||||
# Вызов обязательно после всех функций target_link_libraries
|
|
||||||
myx_cmake_common_target_properties_post_link(${TRGT})
|
|
||||||
|
|
@ -1,113 +0,0 @@
|
|||||||
/**
|
|
||||||
* \file Основной файл проекта
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "processor.hpp"
|
|
||||||
|
|
||||||
#include <QCoreApplication>
|
|
||||||
#include <QDebug>
|
|
||||||
#include <QFile>
|
|
||||||
#include <QRandomGenerator>
|
|
||||||
#include <QTimer>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Перевод строки в целое число
|
|
||||||
* @param Строка
|
|
||||||
* @return Целое число
|
|
||||||
*/
|
|
||||||
int qStringToInt( const QString s )
|
|
||||||
{
|
|
||||||
return( s.toInt() );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Неиспользуемая функция для тестирования анализа покрытия кода
|
|
||||||
*/
|
|
||||||
int unused( int a )
|
|
||||||
{
|
|
||||||
return( a );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Медленная функция
|
|
||||||
*/
|
|
||||||
int slowFunction()
|
|
||||||
{
|
|
||||||
constexpr int size = 16 * 1024;
|
|
||||||
double a[size];
|
|
||||||
for ( int i = 0; i < size; i++ )
|
|
||||||
{
|
|
||||||
a[i] = QRandomGenerator::global()->bounded( 4 );
|
|
||||||
for ( int j = 0; j < i; j++ ) a[i] += sin( a[j] );
|
|
||||||
a[0] += a[i];
|
|
||||||
}
|
|
||||||
return( qRound( a[0] ) );
|
|
||||||
} // slowFunction
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Быстрая функция
|
|
||||||
*/
|
|
||||||
int fastFunction()
|
|
||||||
{
|
|
||||||
constexpr int size = 8 * 1024;
|
|
||||||
double a[size];
|
|
||||||
for ( int i = 0; i < size; i++ )
|
|
||||||
{
|
|
||||||
a[i] = QRandomGenerator::global()->bounded( 4 );
|
|
||||||
for ( int j = 0; j < i; j++ ) a[i] += sin( a[j] );
|
|
||||||
a[0] += a[i];
|
|
||||||
}
|
|
||||||
return( qRound( a[0] ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Основная функция
|
|
||||||
* \param argc Количество параметров командной строки
|
|
||||||
* \param argv Массив параметров
|
|
||||||
* \return Результат выполнения QApplication::exec()
|
|
||||||
*/
|
|
||||||
int main( int argc, char** argv )
|
|
||||||
{
|
|
||||||
QCoreApplication app( argc, argv );
|
|
||||||
|
|
||||||
// qt-keywords
|
|
||||||
QList< int > il;
|
|
||||||
il << 111 << 222;
|
|
||||||
Q_FOREACH ( int i, il )
|
|
||||||
{
|
|
||||||
qDebug() << i;
|
|
||||||
}
|
|
||||||
|
|
||||||
QStringList sl;
|
|
||||||
sl << "111" << "222";
|
|
||||||
for ( auto s: sl )
|
|
||||||
{
|
|
||||||
qDebug() << s;
|
|
||||||
}
|
|
||||||
|
|
||||||
for ( auto s: qAsConst( sl ) )
|
|
||||||
{
|
|
||||||
s.append( "0" );
|
|
||||||
}
|
|
||||||
|
|
||||||
QString s { QStringLiteral( "100" ) };
|
|
||||||
auto ir = qStringToInt( s );
|
|
||||||
|
|
||||||
QFile* f = new QFile();
|
|
||||||
Processor p;
|
|
||||||
QObject::connect( &app, SIGNAL(aboutToQuit()), &p, SLOT(process()));
|
|
||||||
QTimer::singleShot( 100, &app, SLOT(quit()));
|
|
||||||
|
|
||||||
#ifdef PROFILE
|
|
||||||
qCritical() << "Slow: " << slowFunction();
|
|
||||||
qCritical() << "Fast: " << fastFunction();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int arr[3];
|
|
||||||
qCritical() << arr[2];
|
|
||||||
return( QCoreApplication::exec() );
|
|
||||||
}// main
|
|
@ -1,26 +0,0 @@
|
|||||||
/**
|
|
||||||
* \file Класс Processor
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef PROCESSOR_HPP_
|
|
||||||
#define PROCESSOR_HPP_
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <QDebug>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Класс Processor
|
|
||||||
*/
|
|
||||||
class Processor : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* \brief Слот, печатающий сообщение
|
|
||||||
*/
|
|
||||||
Q_SLOT void process() { qCritical() << "about to close"; }
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // ifndef PROCESSOR_HPP_
|
|
Loading…
Reference in New Issue
Block a user