Compare commits

..

2 Commits

Author SHA1 Message Date
9214b8adf0 Обновление MyxCMake 2023-07-30 12:35:20 +03:00
ae17b77582 Обновление MyxCMake 2023-07-30 12:35:00 +03:00
9 changed files with 238 additions and 27 deletions

View File

@ -5,52 +5,35 @@ cmake_minimum_required(VERSION 3.6 FATAL_ERROR)
cmake_policy(VERSION 3.6..3.7) cmake_policy(VERSION 3.6..3.7)
# Название и версия проекта и используемые языки программирования # Название и версия проекта и используемые языки программирования
project(znk-results VERSION 0.4.0 LANGUAGES C CXX) project(myx-example-qt5-console VERSION 0.4.0 LANGUAGES C CXX)
# Рекомендуемый способ подключения MyxCMake # Рекомендуемый способ подключения MyxCMake
include(cmake/myx_setup.cmake) include(cmake/myx_setup.cmake)
# Поиск пакетов # Поиск пакетов
myx_find_required_packages( myx_find_required_packages(
PACKAGES Eigen3 Qt5 Core
Qt5 Core Sql
Qt5Private Core) Qt5Private Core)
FetchContent_Add(myx-handy-paths
GIT_REPOSITORY git@gitlab.2:myx/libs/myx-handy-paths
GIT_PATH myx/libs/myx-handy-paths
GIT_REMOTE origin
)
FetchContent_Add(myx-handy-yaml
GIT_REPOSITORY git@gitlab.2:myx/libs/myx-handy-yaml
GIT_PATH myx/libs/myx-handy-yaml
GIT_REMOTE origin
)
FetchContent_Add(myx-qt-database
GIT_REPOSITORY git@gitlab.2:myx/libs/myx-qt-database
GIT_PATH myx/libs/myx-qt-database
GIT_REMOTE origin
)
# Цель для создания исполняемого файла # Цель для создания исполняемого файла
myx_add_executable(${PROJECT_NAME}) myx_add_executable(${PROJECT_NAME})
# Настройка свойств цели # Настройка свойств цели
myx_target_setup(${PROJECT_NAME} myx_target_setup(${PROJECT_NAME}
PACKAGES Eigen3
CPP CPP
${PROJECT_SOURCE_DIR}/src/${PROJECT_NAME}/main.cpp ${PROJECT_SOURCE_DIR}/src/${PROJECT_NAME}/main.cpp
LINK_LIBRARIES myx-handy-paths myx-qt-database Eigen3::Eigen
) )
# Настройка Qt для цели # Настройка Qt для цели
myx_qt5_target_setup(${PROJECT_NAME} myx_qt5_target_setup(${PROJECT_NAME}
COMPONENTS Core Sql COMPONENTS Core
PRIVATE Core PRIVATE Core)
)
# Автоматически генерируемый файл с информацией о репозитории
myx_generate_git_info_header(${PROJECT_NAME} "git_info_p.hpp")
# Автоматически генерируемый приватный заголовочный файл
myx_generate_private_config_header(${PROJECT_NAME} "config_p.hpp")
# Форматирование исходных текстов с помощью uncrustify # Форматирование исходных текстов с помощью uncrustify
myx_uncrustify(${PROJECT_NAME}) myx_uncrustify(${PROJECT_NAME})

View File

@ -0,0 +1,79 @@
#[=======================================================================[.rst:
myx_add_external_target
-----------------------
Функция для подключения целей из внешних проектов::
myx_add_external_target(TARGET_NAME
[ MODULES_PATH modules_path ] |
[ GIT_REPOSITORY url ] |
[ GIT_TAG tag ] |
[ LOCAL_PATH local_path ] )
Обязательный параметр: `TARGET_NAME` - имя цели, содержащейся во внешнем проекте.
Параметр `MODULES_PATH` содержит имя каталога, в который будут загружаться
внешние проекты (по умолчанию `modules`). Параметр `GIT_REPOSITORY` содержит
адрес внешнего проекта, который нужно загрузить с помощью git. Параметр `GIT_TAG`
содержит используемые метку, идентификатор коммита или ветку в репозитории.
Параметр `LOCAL_PATH` используется для указания пути к подкаталогу, находящемуся
вне текущего проекта. Его следует указывать только при вызове функции из
вспомогательного файла `external_targets.cmake`.
#]=======================================================================]
find_package(Git)
function(myx_add_external_target TARGET_NAME)
set(options)
set(oneValueArgs)
set(multiValueArgs MODULES_PATH GIT_REPOSITORY GIT_TAG LOCAL_PATH)
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if(TARGET ${TARGET_NAME})
return()
endif()
if(ARG_LOCAL_PATH)
myx_message_notice("Using directory ${ARG_LOCAL_PATH} to build target ${TARGET_NAME}")
add_subdirectory(${ARG_LOCAL_PATH} ${CMAKE_BINARY_DIR}/${TARGET_NAME} EXCLUDE_FROM_ALL)
return()
endif()
if(NOT ARG_MODULES_PATH)
set(ARG_MODULES_PATH modules)
endif()
if(CMAKE_SCRIPT_MODE_FILE)
set(PROJECT_SOURCE_DIR ${CMAKE_SOURCE_DIR})
endif()
set(ARG_MODULES_PATH ${PROJECT_SOURCE_DIR}/${ARG_MODULES_PATH})
if(NOT IS_DIRECTORY ${ARG_MODULES_PATH})
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${ARG_MODULES_PATH})
endif()
if(GIT_EXECUTABLE)
if(NOT IS_DIRECTORY ${ARG_MODULES_PATH}/${TARGET_NAME})
execute_process(COMMAND ${GIT_EXECUTABLE} clone ${ARG_GIT_REPOSITORY} ${TARGET_NAME}
WORKING_DIRECTORY ${ARG_MODULES_PATH})
else()
execute_process(COMMAND ${GIT_EXECUTABLE} fetch
WORKING_DIRECTORY ${ARG_MODULES_PATH}/${TARGET_NAME})
endif()
execute_process(COMMAND ${GIT_EXECUTABLE} checkout ${ARG_GIT_TAG}
WORKING_DIRECTORY ${ARG_MODULES_PATH}/${TARGET_NAME})
endif()
if(NOT CMAKE_SCRIPT_MODE_FILE)
add_subdirectory(${ARG_MODULES_PATH}/${TARGET_NAME} EXCLUDE_FROM_ALL)
endif()
if(NOT TARGET ${TARGET_NAME})
myx_message_fatal_error("Target ${TARGET_NAME} is not found.")
endif()
endfunction(myx_add_external_target)
include("${PROJECT_SOURCE_DIR}/external_targets.cmake" OPTIONAL)

View File

@ -0,0 +1,56 @@
include_guard(GLOBAL)
if(CMAKE_SYSTEM_NAME STREQUAL Linux)
set(MYX_CMAKE_LSB_DISTRIBUTOR_ID "unknown")
set(MYX_CMAKE_LSB_CODENAME "unknown")
set(MYX_CMAKE_LSB_RELEASE_VERSION "unknown")
if(CMAKE_CROSSCOMPILING)
return()
endif()
if(EXISTS /etc/mcst_version)
set(MYX_CMAKE_LSB_DISTRIBUTOR_ID "ElbrusD")
set(MYX_CMAKE_LSB_CODENAME "Jessie")
execute_process(COMMAND cat /etc/mcst_version
OUTPUT_VARIABLE MYX_CMAKE_LSB_RELEASE_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE)
else()
find_program(LSB_RELEASE_EXECUTABLE lsb_release)
# cmake-format: off
if(LSB_RELEASE_EXECUTABLE)
execute_process(COMMAND ${LSB_RELEASE_EXECUTABLE} -si
OUTPUT_VARIABLE MYX_CMAKE_LSB_DISTRIBUTOR_ID
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${LSB_RELEASE_EXECUTABLE} -sc
OUTPUT_VARIABLE MYX_CMAKE_LSB_CODENAME
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${LSB_RELEASE_EXECUTABLE} -sr
OUTPUT_VARIABLE MYX_CMAKE_LSB_RELEASE_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
# cmake-format: on
endif()
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
include("${MYX_CMAKE_TOOLCHAINS_DIR}/GCC.cmake")
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
include("${MYX_CMAKE_TOOLCHAINS_DIR}/Clang.cmake")
endif()
if((MYX_CMAKE_LSB_DISTRIBUTOR_ID STREQUAL "AstraLinuxSE") AND
(MYX_CMAKE_LSB_CODENAME STREQUAL "smolensk") AND
(MYX_CMAKE_LSB_RELEASE_VERSION STREQUAL "1.5"))
include("${MYX_CMAKE_TOOLCHAINS_DIR}/AstraLinuxSE-1.5.cmake")
return()
endif()
if((MYX_CMAKE_LSB_DISTRIBUTOR_ID STREQUAL "ElbrusD") AND
(MYX_CMAKE_LSB_CODENAME STREQUAL "Jessie") AND
(MYX_CMAKE_LSB_RELEASE_VERSION VERSION_GREATER "1.4"))
include("${MYX_CMAKE_TOOLCHAINS_DIR}/ElbrusD-1.4.cmake")
return()
endif()

View File

@ -0,0 +1,30 @@
include_guard(GLOBAL)
macro(myx_add_gtest TARGET_NAME)
set(options)
set(oneValueArgs)
set(multiValueArgs)
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
add_executable(${TARGET_NAME} ${ARG_UNPARSED_ARGUMENTS})
find_package(GTest)
if(GTest_FOUND)
target_link_libraries(${TARGET_NAME} PRIVATE GTest::GTest GTest::Main)
else()
if((NOT TARGET gtest) AND (NOT TARGET gtest_main))
add_subdirectory(/usr/src/googletest/googletest ${CMAKE_BINARY_DIR}/gtest)
endif()
target_link_libraries(${TARGET_NAME} PRIVATE gtest gtest_main)
endif()
add_test(NAME ${TARGET_NAME} COMMAND ${TARGET_NAME})
foreach(__iter IN LISTS oneValueArgs multiValueArgs)
unset(ARG_${__iter})
endforeach()
unset(ARG_UNPARSED_ARGUMENTS)
unset(multiValueArgs)
unset(oneValueArgs)
unset(options)
endmacro()

View File

@ -0,0 +1,40 @@
include_guard(GLOBAL)
macro(myx_add_qtest TARGET_NAME)
set(options)
set(oneValueArgs)
set(multiValueArgs)
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
find_package(Qt5 COMPONENTS Core Test REQUIRED)
if(NOT Qt5Test_FOUND)
myx_message_fatal_error("Qt testing framework is not found")
return()
endif()
foreach(filename ${ARG_UNPARSED_ARGUMENTS})
get_filename_component(basename ${filename} NAME_WE)
list(APPEND cpps "${basename}.cpp")
list(APPEND hpps "${basename}.hpp")
qt5_wrap_cpp(moc "${basename}.hpp")
list(APPEND mocs "${moc}")
endforeach()
add_executable(${TARGET_NAME} ${mocs} ${cpps} ${hpps})
target_link_libraries(${TARGET_NAME} Qt5::Core Qt5::Test)
add_test(NAME ${TARGET_NAME} COMMAND ${TARGET_NAME})
unset(cpps)
unset(hpps)
unset(moc)
unset(mocs)
foreach(__iter IN LISTS oneValueArgs multiValueArgs)
unset(ARG_${__iter})
endforeach()
unset(ARG_UNPARSED_ARGUMENTS)
unset(multiValueArgs)
unset(oneValueArgs)
unset(options)
endmacro()

View File

@ -0,0 +1,8 @@
find_program(CMAKE_AR NAMES "/usr/bin/x86_64-linux-gnu-gcc-ar-4.7")
find_program(CMAKE_NM NAMES "/usr/bin/x86_64-linux-gnu-gcc-nm-4.7")
find_program(CMAKE_RANLIB NAMES "/usr/bin/x86_64-linux-gnu-gcc-ranlib-4.7")
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_EXTENSIONS ON)
check_enable_cxx_compiler_flag(-Wno-shadow)

View File

@ -0,0 +1,3 @@
if(CMAKE_COLOR_MAKEFILE)
check_enable_cxx_compiler_flag(-fcolor-diagnostics)
endif()

View File

@ -0,0 +1,9 @@
find_program(CMAKE_AR NAMES "/usr/${CMAKE_SYSTEM_PROCESSOR}-linux/bin/ar")
find_program(CMAKE_NM NAMES "/usr/${CMAKE_SYSTEM_PROCESSOR}-linux/bin/nm")
find_program(CMAKE_RANLIB NAMES "/usr/${CMAKE_SYSTEM_PROCESSOR}-linux/bin/ranlib")
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_EXTENSIONS ON)
check_enable_cxx_compiler_flag(-Wno-invalid-offsetof)
list(APPEND CMAKE_LIBRARY_PATH "/usr/lib/e2k-linux-gnu")

View File

@ -0,0 +1,3 @@
if(CMAKE_COLOR_MAKEFILE)
check_enable_cxx_compiler_flag(-fdiagnostics-color=auto)
endif()