Compare commits

..

3 Commits

Author SHA1 Message Date
bd49df9c7c Опечатка 2024-03-12 16:27:42 +03:00
205c4d7f80 Переименования 2024-03-12 16:27:30 +03:00
2077833259 Заглушка для CMake < 3.13 2024-03-12 16:23:02 +03:00
5 changed files with 55 additions and 51 deletions

View File

@ -50,31 +50,30 @@ function(myx_add_interface_library TARGET_NAME)
add_library(${TARGET_NAME} INTERFACE ${ARG_HEADERS})
endif()
foreach(__iter ${ARG_PACKAGES})
target_include_directories(${TARGET_NAME} INTERFACE ${${__iter}_INCLUDE_DIRS})
target_compile_definitions(${TARGET_NAME} INTERFACE ${${__iter}_COMPILE_DEFINITIONS})
foreach(iter ${ARG_PACKAGES})
target_include_directories(${TARGET_NAME} INTERFACE ${${iter}_INCLUDE_DIRS})
target_compile_definitions(${TARGET_NAME} INTERFACE ${${iter}_COMPILE_DEFINITIONS})
endforeach()
if(ARG_LINK_LIBRARIES)
foreach(__lib ${ARG_LINK_LIBRARIES})
if(TARGET ${__lib})
set(__exlib ${__lib})
if(${CMAKE_VERSION} VERSION_LESS "3.15.0")
get_target_property(__target_type ${__lib} TYPE)
if(__target_type STREQUAL "OBJECT_LIBRARY")
if(TARGET "${__lib}_static")
set(__exlib "${__lib}_static")
elseif(TARGET "${__lib}_shared")
set(__exlib "${__lib}_shared")
endif()
endif()
else()
install(TARGETS ${__lib}
foreach(lib ${ARG_LINK_LIBRARIES})
if(TARGET ${lib})
set(exlib ${lib})
if(${CMAKE_VERSION} VERSION_GREATER "3.13.0")
install(TARGETS ${lib}
EXPORT ${TARGET_NAME}Targets
COMPONENT DEV)
else()
get_target_property(target_type ${lib} TYPE)
if(target_type STREQUAL "OBJECT_LIBRARY")
if(TARGET "${lib}_static")
set(exlib "${lib}_static")
elseif(TARGET "${lib}_shared")
set(exlib "${lib}_shared")
endif()
target_link_libraries(${TARGET_NAME} INTERFACE ${__exlib})
endif()
endif()
target_link_libraries(${TARGET_NAME} INTERFACE ${exlib})
endif()
endforeach()
endif()
@ -116,9 +115,12 @@ function(myx_add_interface_library TARGET_NAME)
NO_CHECK_REQUIRED_COMPONENTS_MACRO
)
install(EXPORT ${TARGET_NAME}Targets
if(${CMAKE_VERSION} VERSION_GREATER "3.13.0")
install(
EXPORT ${TARGET_NAME}Targets
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${TARGET_NAME}
COMPONENT DEV)
endif()
install(
FILES
@ -148,10 +150,12 @@ function(myx_add_interface_library TARGET_NAME)
# Установка библиотеки из заголовочных файлов
target_include_directories(${TARGET_NAME} SYSTEM INTERFACE $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
if(${CMAKE_VERSION} VERSION_GREATER "3.13.0")
install(
TARGETS ${TARGET_NAME}
EXPORT ${TARGET_NAME}Targets
COMPONENT DEV)
endif()
# Установка публичных заголовочных файлов
if(PROJECT_IS_TOP_LEVEL AND ARG_HEADERS)

View File

@ -44,12 +44,12 @@ function(myx_add_object_library TARGET_NAME)
# Вызов стандартной функции `add_library()`
add_library(${TARGET_NAME} OBJECT ${ARG_UNPARSED_ARGUMENTS})
string(TOUPPER ${TARGET_NAME} __project_name_upper)
string(TOUPPER ${TARGET_NAME} project_name_upper)
# Опция для разрешения сборки динамической библиотеки
cmake_dependent_option(${__project_name_upper}_BUILD_SHARED
cmake_dependent_option(${project_name_upper}_BUILD_SHARED
"Build shared library for ${TARGET_NAME}" ON "BUILD_SHARED_LIBS" OFF)
# Опция для разрешения сборки статической библиотеки
cmake_dependent_option(${__project_name_upper}_BUILD_STATIC
cmake_dependent_option(${project_name_upper}_BUILD_STATIC
"Build static library for ${TARGET_NAME}" ON "NOT BUILD_SHARED_LIBS" OFF)
# Стандартные пути к заголовочным файлам
@ -68,7 +68,7 @@ function(myx_add_object_library TARGET_NAME)
if(NOT ARG_NO_EXPORT)
include(GenerateExportHeader)
if(NOT EXPORT_BASE_NAME)
set(ARG_EXPORT_BASE_NAME ${__project_name_upper})
set(ARG_EXPORT_BASE_NAME ${project_name_upper})
endif()
if(NOT ARG_EXPORT_FILE_NAME)
@ -89,7 +89,7 @@ function(myx_add_object_library TARGET_NAME)
endif()
# Цель для создания динамической библиотеки из объектных файлов
if(${__project_name_upper}_BUILD_SHARED)
if(${project_name_upper}_BUILD_SHARED)
# Для создания динамической библиотеки используются объектные файлы цели ${TARGET_NAME}
add_library(${TARGET_NAME}_shared SHARED $<TARGET_OBJECTS:${TARGET_NAME}>)
# Установка дополнительных свойств для цели ${TARGET_NAME}_shared
@ -105,7 +105,7 @@ function(myx_add_object_library TARGET_NAME)
endif()
# Цель для создания статической библиотеки из объектных файлов
if(${__project_name_upper}_BUILD_STATIC)
if(${project_name_upper}_BUILD_STATIC)
# Для создания статической библиотеки используются
# объектные файлы цели ${TARGET_NAME}
add_library(${TARGET_NAME}_static STATIC $<TARGET_OBJECTS:${TARGET_NAME}>)

View File

@ -5,11 +5,11 @@ include_guard(GLOBAL)
# (Файл перемещён из каталога backports в lib для myx_download_content)
#
if(${CMAKE_VERSION} VERSION_LESS 3.21)
get_property(__parent_directory DIRECTORY PROPERTY PARENT_DIRECTORY)
if(NOT __parent_directory)
get_property(pd DIRECTORY PROPERTY PARENT_DIRECTORY)
if(NOT pd)
set(PROJECT_IS_TOP_LEVEL TRUE)
else()
set(PROJECT_IS_TOP_LEVEL FALSE)
endif()
unset(__parent_directory)
unset(pd)
endif()

View File

@ -12,8 +12,8 @@ function(myx_target_setup TARGET_NAME)
myx_message_fatal_error("Target ${TARGET_NAME} does not exists.")
endif()
get_target_property(__target_type ${TARGET_NAME} TYPE)
if(${__target_type} STREQUAL "INTERFACE_LIBRARY")
get_target_property(target_type ${TARGET_NAME} TYPE)
if(${target_type} STREQUAL "INTERFACE_LIBRARY")
myx_message_fatal_error("This function will not work for interface targets.")
endif()
@ -54,7 +54,7 @@ function(myx_target_setup TARGET_NAME)
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>)
endif()
if(__target_type STREQUAL "EXECUTABLE")
if(target_type STREQUAL "EXECUTABLE")
if(IS_DIRECTORY "${PROJECT_SOURCE_DIR}/include")
target_include_directories(${PROJECT_NAME} PRIVATE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>)
@ -86,8 +86,8 @@ function(myx_target_setup TARGET_NAME)
if(${CMAKE_VERSION} VERSION_GREATER "3.11.99")
target_link_libraries(${TARGET_NAME} PRIVATE ${ARG_LINK_LIBRARIES})
else()
if((NOT ${__target_type} STREQUAL "OBJECT_LIBRARY") AND
(NOT ${__target_type} STREQUAL "EXECUTABLE"))
if((NOT ${target_type} STREQUAL "OBJECT_LIBRARY") AND
(NOT ${target_type} STREQUAL "EXECUTABLE"))
target_link_libraries(${TARGET_NAME} PRIVATE ${ARG_LINK_LIBRARIES})
else()
foreach(__link_library ${ARG_LINK_LIBRARIES})
@ -98,7 +98,7 @@ function(myx_target_setup TARGET_NAME)
if(__include_dirs)
target_include_directories(${TARGET_NAME} PUBLIC ${__include_dirs})
endif()
if(${__target_type} STREQUAL "EXECUTABLE")
if(${target_type} STREQUAL "EXECUTABLE")
if(${__lib_type} STREQUAL "OBJECT_LIBRARY")
if(TARGET ${__link_library}_static)
target_link_libraries(${TARGET_NAME} PRIVATE ${__link_library}_static)
@ -111,7 +111,7 @@ function(myx_target_setup TARGET_NAME)
endif()
endif()
else()
if((${CMAKE_VERSION} VERSION_GREATER "3.7.99") OR (NOT __target_type STREQUAL "OBJECT_LIBRARY"))
if((${CMAKE_VERSION} VERSION_GREATER "3.7.99") OR (NOT target_type STREQUAL "OBJECT_LIBRARY"))
target_link_libraries(${TARGET_NAME} PRIVATE ${__link_library})
endif()
endif()

View File

@ -16,21 +16,21 @@ function(myx_target_setup_qt TARGET_NAME)
myx_message_fatal_error("Supported Qt versions are 5 and 6")
endif()
get_target_property(__target_type ${TARGET_NAME} TYPE)
get_target_property(target_type ${TARGET_NAME} TYPE)
foreach(iter ${ARG_COMPONENTS})
if(__target_type STREQUAL "INTERFACE_LIBRARY")
if(target_type STREQUAL "INTERFACE_LIBRARY")
target_include_directories(${TARGET_NAME} INTERFACE ${Qt${myx_qt_ver}${iter}_INCLUDE_DIRS})
else()
target_include_directories(${TARGET_NAME} PRIVATE ${Qt${myx_qt_ver}${iter}_INCLUDE_DIRS})
if(NOT iter STREQUAL "LinguistTools")
if(__target_type STREQUAL "EXECUTABLE")
if(target_type STREQUAL "EXECUTABLE")
target_link_libraries(${TARGET_NAME} PRIVATE Qt${myx_qt_ver}::${iter})
endif()
if(__target_type STREQUAL "SHARED_LIBRARY")
if(target_type STREQUAL "SHARED_LIBRARY")
target_link_libraries(${TARGET_NAME} PUBLIC Qt${myx_qt_ver}::${iter})
endif()
if((${CMAKE_VERSION} VERSION_GREATER "3.8.0") AND (__target_type STREQUAL "OBJECT_LIBRARY"))
if((${CMAKE_VERSION} VERSION_GREATER "3.8.0") AND (target_type STREQUAL "OBJECT_LIBRARY"))
target_link_libraries(${TARGET_NAME} PUBLIC Qt${myx_qt_ver}::${iter})
else()
target_include_directories(${TARGET_NAME} PUBLIC ${Qt${myx_qt_ver}${iter}_INCLUDE_DIRS})
@ -40,14 +40,14 @@ function(myx_target_setup_qt TARGET_NAME)
endforeach()
foreach(iter ${ARG_PRIVATE})
if(__target_type STREQUAL "INTERFACE_LIBRARY")
if(target_type STREQUAL "INTERFACE_LIBRARY")
target_include_directories(${TARGET_NAME} INTERFACE ${Qt${myx_qt_ver}${iter}_PRIVATE_INCLUDE_DIRS})
else()
target_include_directories(${TARGET_NAME} PRIVATE ${Qt${myx_qt_ver}${iter}_PRIVATE_INCLUDE_DIRS})
endif()
endforeach()
if(__target_type STREQUAL "EXECUTABLE")
if(target_type STREQUAL "EXECUTABLE")
target_compile_options(${TARGET_NAME} PRIVATE ${Qt${myx_qt_ver}Core_EXECUTABLE_COMPILE_FLAGS})
endif()
@ -94,7 +94,7 @@ function(myx_target_setup_qt TARGET_NAME)
endif()
# Перечень файлов, подлежащих переводу
if(__target_type STREQUAL "INTERFACE_LIBRARY")
if(target_type STREQUAL "INTERFACE_LIBRARY")
get_target_property(tr ${TARGET_NAME} INTERFACE_TR_FILES)
else()
get_target_property(tr ${TARGET_NAME} TR_FILES)
@ -138,7 +138,7 @@ function(myx_target_setup_qt TARGET_NAME)
endif()
endif()
unset(tr)
if(__target_type STREQUAL "INTERFACE_LIBRARY")
if(target_type STREQUAL "INTERFACE_LIBRARY")
target_sources(${TARGET_NAME} INTERFACE ${ARG_PUBLIC_MOC} ${ARG_PRIVATE_MOC} ${moc_cpp} ${ui_h} ${qrc_cpp})
else()
target_sources(${TARGET_NAME} PRIVATE ${ARG_PUBLIC_MOC} ${ARG_PRIVATE_MOC} ${moc_cpp} ${ui_h} ${qrc_cpp})