1.99.40
This commit is contained in:
parent
e73f664a14
commit
15624311b7
@ -1,6 +1,7 @@
|
||||
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)
|
||||
|
@ -1,4 +1,4 @@
|
||||
set(MYX_CMAKE_PACKAGE_VERSION "1.99.33")
|
||||
set(MYX_CMAKE_PACKAGE_VERSION "1.99.40")
|
||||
if(MYX_CMAKE_PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION)
|
||||
set(PACKAGE_VERSION_COMPATIBLE FALSE)
|
||||
else()
|
||||
|
@ -12,7 +12,7 @@
|
||||
|
||||
```cmake
|
||||
if(MYX_CMAKE_USE_SYSTEM)
|
||||
find_package(MyxCMake 1.99.33 REQUIRED)
|
||||
find_package(MyxCMake 1.99.40 REQUIRED)
|
||||
else()
|
||||
include(${PROJECT_SOURCE_DIR}/cmake/myx/MyxCMakeConfig.cmake)
|
||||
endif()
|
||||
|
@ -1 +1 @@
|
||||
1.99.33
|
||||
1.99.40
|
||||
|
@ -4,7 +4,8 @@ myx_add_library
|
||||
|
||||
Вспомогательная функция для создания библиотеки::
|
||||
|
||||
myx_add_library(NAME TYPE)
|
||||
myx_add_library(NAME TYPE
|
||||
[ OUTPUT_NAME output_name ])
|
||||
|
||||
Обязательные параметры: `NAME` - имя библиотеки и `TYPE` - тип цели.
|
||||
Все остальные параметры передаются стандартной функции `add_library()`
|
||||
@ -22,11 +23,15 @@ include(GenerateExportHeader)
|
||||
|
||||
function(myx_add_library NAME TYPE)
|
||||
set(options)
|
||||
set(oneValueArgs)
|
||||
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})
|
||||
|
||||
@ -60,15 +65,22 @@ function(myx_add_library NAME TYPE)
|
||||
# для создания динамической библиотеки
|
||||
set_target_properties(${NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
string(TOUPPER ${NAME} suffix)
|
||||
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 ${suffix}
|
||||
EXPORT_MACRO_NAME "EXPORT_${suffix}"
|
||||
DEPRECATED_MACRO_NAME "DEPRECATED_${suffix}"
|
||||
NO_DEPRECATED_MACRO_NAME "NO_DEPRECATED_${suffix}"
|
||||
NO_EXPORT_MACRO_NAME "NO_EXPORT_${suffix}"
|
||||
STATIC_DEFINE "STATIC_DEFINE_${suffix}"
|
||||
EXPORT_FILE_NAME "${PROJECT_SOURCE_DIR}/include/${NAME}/${NAME}_export.hpp"
|
||||
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
|
||||
)
|
||||
|
||||
@ -86,7 +98,7 @@ function(myx_add_library NAME TYPE)
|
||||
VERSION ${PROJECT_VERSION}
|
||||
SOVERSION ${PROJECT_VERSION_MAJOR}
|
||||
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}
|
||||
OUTPUT_NAME ${NAME})
|
||||
OUTPUT_NAME ${ARG_OUTPUT_NAME})
|
||||
endif()
|
||||
|
||||
# Цель для создания статической библиотеки из объектных файлов
|
||||
@ -99,7 +111,7 @@ function(myx_add_library NAME TYPE)
|
||||
set_target_properties(${NAME}_static
|
||||
PROPERTIES
|
||||
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}
|
||||
OUTPUT_NAME ${NAME})
|
||||
OUTPUT_NAME ${ARG_OUTPUT_NAME})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
@ -152,6 +164,7 @@ function(myx_add_library NAME TYPE)
|
||||
"prefix=${CMAKE_INSTALL_PREFIX}\n"
|
||||
"exec_prefix=${CMAKE_INSTALL_PREFIX}\n"
|
||||
"includedir=${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}\n")
|
||||
|
||||
if(NOT TYPE STREQUAL "INTERFACE")
|
||||
file(APPEND "${CMAKE_BINARY_DIR}/${NAME}.pc"
|
||||
"libdir=${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}\n")
|
||||
@ -165,6 +178,7 @@ function(myx_add_library NAME TYPE)
|
||||
"\n"
|
||||
"Requires:\n"
|
||||
"Cflags: -I${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}\n")
|
||||
|
||||
if(NOT TYPE STREQUAL "INTERFACE")
|
||||
file(APPEND "${CMAKE_BINARY_DIR}/${NAME}.pc"
|
||||
"Libs: -L${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR} -l${NAME}\n")
|
||||
|
@ -3,12 +3,16 @@ include_guard(GLOBAL)
|
||||
function(myx_qt5_target_setup NAME)
|
||||
set(options)
|
||||
set(oneValueArgs)
|
||||
set(multiValueArgs COMPONENTS PRIVATE SOURCES MOC UI QRC LANGS)
|
||||
set(multiValueArgs COMPONENTS PRIVATE CPP HPP MOC UI QRC LANGS SOURCES)
|
||||
|
||||
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
||||
|
||||
get_target_property(type ${NAME} TYPE)
|
||||
|
||||
if(ARG_SOURCES)
|
||||
myx_message_deprecation("MyxCMake: Use CPP and HPP arguments instead of SOURCES")
|
||||
endif()
|
||||
|
||||
if(ARG_COMPONENTS)
|
||||
find_package(Qt5 COMPONENTS ${ARG_COMPONENTS} REQUIRED)
|
||||
foreach(iter ${ARG_COMPONENTS})
|
||||
@ -29,9 +33,23 @@ function(myx_qt5_target_setup NAME)
|
||||
target_compile_options(${NAME} PRIVATE ${Qt5Core_EXECUTABLE_COMPILE_FLAGS})
|
||||
endif()
|
||||
|
||||
qt5_wrap_cpp(moc_cpp ${ARG_MOC})
|
||||
qt5_add_resources(qrc_cpp ${ARG_QRC})
|
||||
if("Widgets" IN_LIST ARG_COMPONENTS)
|
||||
if(ARG_CPP)
|
||||
set_target_properties(${NAME} PROPERTIES CPP_FILES ${ARG_CPP})
|
||||
endif()
|
||||
|
||||
if(ARG_HPP)
|
||||
set_target_properties(${NAME} PROPERTIES HPP_FILES ${ARG_HPP})
|
||||
endif()
|
||||
|
||||
if(ARG_MOC)
|
||||
qt5_wrap_cpp(moc_cpp ${ARG_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})
|
||||
endif()
|
||||
|
||||
@ -46,6 +64,6 @@ function(myx_qt5_target_setup NAME)
|
||||
unset(qm)
|
||||
endif()
|
||||
|
||||
target_sources(${NAME} PRIVATE ${ARG_SOURCES} ${ARG_MOC} ${moc_cpp} ${ui_h} ${qrc_cpp})
|
||||
target_sources(${NAME} PRIVATE ${ARG_HPP} ${ARG_CPP} ${ARG_SOURCES} ${ARG_MOC} ${moc_cpp} ${ui_h} ${qrc_cpp})
|
||||
|
||||
endfunction()
|
||||
|
@ -3,7 +3,7 @@ include_guard(GLOBAL)
|
||||
function(myx_target_setup NAME)
|
||||
set(options)
|
||||
set(oneValueArgs PCH)
|
||||
set(multiValueArgs COMPILE_DEFINITIONS FIND_PACKAGES LINK_LIBRARIES SOURCES)
|
||||
set(multiValueArgs COMPILE_DEFINITIONS FIND_PACKAGES LINK_LIBRARIES CPP HPP SOURCES)
|
||||
|
||||
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
||||
|
||||
@ -14,21 +14,36 @@ function(myx_target_setup NAME)
|
||||
get_target_property(type ${NAME} TYPE)
|
||||
|
||||
foreach(iter ${ARG_FIND_PACKAGES})
|
||||
find_package(${iter} REQUIRED)
|
||||
target_include_directories(${NAME} PRIVATE ${${iter}_INCLUDE_DIRS})
|
||||
target_compile_definitions(${NAME} PRIVATE ${${iter}_COMPILE_DEFINITIONS})
|
||||
find_package(${iter} REQUIRED)
|
||||
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_SOURCES)
|
||||
myx_message_deprecation("MyxCMake: Use CPP and HPP arguments instead of SOURCES")
|
||||
endif()
|
||||
|
||||
if(ARG_CPP)
|
||||
set_target_properties(${NAME} PROPERTIES CPP_FILES ${ARG_CPP})
|
||||
endif()
|
||||
|
||||
if(ARG_HPP)
|
||||
set_target_properties(${NAME} PROPERTIES HPP_FILES ${ARG_HPP})
|
||||
endif()
|
||||
|
||||
if(ARG_PCH)
|
||||
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.16)
|
||||
target_precompile_headers(${NAME} PRIVATE "${PROJECT_SOURCE_DIR}/${ARG_PCH}")
|
||||
target_precompile_headers(${NAME} PRIVATE ${ARG_PCH})
|
||||
else()
|
||||
target_compile_options(${NAME} PRIVATE -include "${PROJECT_SOURCE_DIR}/${ARG_PCH}")
|
||||
target_compile_options(${NAME} PRIVATE -include ${ARG_PCH})
|
||||
endif()
|
||||
target_sources(${NAME} PRIVATE "${PROJECT_SOURCE_DIR}/${ARG_PCH}")
|
||||
target_sources(${NAME} PRIVATE ${ARG_PCH})
|
||||
endif()
|
||||
|
||||
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>)
|
||||
@ -50,7 +65,7 @@ function(myx_target_setup NAME)
|
||||
install(TARGETS ${NAME} COMPONENT main RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
endif()
|
||||
|
||||
target_sources(${NAME} PRIVATE ${ARG_SOURCES})
|
||||
target_sources(${NAME} PRIVATE ${ARG_CPP} ${ARG_HPP} ${ARG_SOURCES})
|
||||
target_link_libraries(${NAME} PRIVATE ${ARG_LINK_LIBRARIES})
|
||||
target_compile_definitions(${NAME} PRIVATE ${ARG_COMPILE_DEFINITIONS})
|
||||
endfunction()
|
||||
|
Loading…
Reference in New Issue
Block a user