This commit is contained in:
Andrei Astafev 2022-09-29 17:54:13 +03:00
parent 3e8648a045
commit e625864248
5 changed files with 33 additions and 16 deletions

View File

@ -23,6 +23,7 @@ include(${MYX_CMAKE_LIB_DIR}/NinjaGeneratorWrapper.cmake)
include(${MYX_CMAKE_LIB_DIR}/AddLibrary.cmake)
include(${MYX_CMAKE_LIB_DIR}/InstallLibrary.cmake)
include(${MYX_CMAKE_LIB_DIR}/TargetSetup.cmake)
include(${MYX_CMAKE_LIB_DIR}/Qt5TargetSetup.cmake)
unset(MYX_CMAKE_SOURCE_DIR)

View File

@ -1,4 +1,4 @@
set(MYX_CMAKE_PACKAGE_VERSION "1.99.8")
set(MYX_CMAKE_PACKAGE_VERSION "1.99.9")
if(MYX_CMAKE_PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION)
set(PACKAGE_VERSION_COMPATIBLE FALSE)
else()

View File

@ -11,6 +11,6 @@
`project` добавить строку:
```cmake
find_package(MyxCMake 1.99.8 PATHS cmake/myx NO_DEFAULT_PATH QUIET REQUIRED)
find_package(MyxCMake 1.99.9 PATHS cmake/myx NO_DEFAULT_PATH QUIET REQUIRED)
```

View File

@ -4,8 +4,8 @@ include(GenerateExportHeader)
function(myx_add_library NAME)
set(options)
set(oneValueArgs PCH TYPE)
set(multiValueArgs SOURCES LINK_LIBRARIES COMPILE_DEFINITIONS)
set(oneValueArgs TYPE)
set(multiValueArgs SOURCES)
cmake_parse_arguments(arg "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if(NOT arg_TYPE)
@ -74,16 +74,4 @@ function(myx_add_library NAME)
OUTPUT_NAME ${NAME})
endif()
endif()
if(arg_PCH)
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.16)
target_precompile_headers(${NAME} PRIVATE ${PROJECT_SOURCE_DIR}/${arg_PCH})
else()
target_compile_options(${NAME} PRIVATE -include ${PROJECT_SOURCE_DIR}/${arg_PCH})
endif()
endif()
target_sources(${NAME} PRIVATE ${arg_SOURCES} ${PROJECT_SOURCE_DIR}/${arg_PCH})
target_compile_definitions(${NAME} PRIVATE ${arg_COMPILE_DEFINITIONS})
target_link_libraries(${NAME} PRIVATE ${arg_LINK_LIBRARIES})
endfunction()

28
lib/TargetSetup.cmake Normal file
View File

@ -0,0 +1,28 @@
include_guard(GLOBAL)
function(myx_target_setup NAME)
set(options)
set(oneValueArgs PCH)
set(multiValueArgs COMPILE_DEFINITIONS FIND_PACKAGES LINK_LIBRARIES SOURCES)
cmake_parse_arguments(arg "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
foreach(iter ${arg_FIND_PACKAGES})
find_package(${iter} CONFIG 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_PCH)
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.16)
target_precompile_headers(${NAME} PRIVATE ${PROJECT_SOURCE_DIR}/${arg_PCH})
else()
target_compile_options(${NAME} PRIVATE -include ${PROJECT_SOURCE_DIR}/${arg_PCH})
endif()
target_sources(${NAME} PRIVATE ${PROJECT_SOURCE_DIR}/${arg_PCH})
endif()
target_sources(${NAME} PRIVATE ${arg_SOURCES})
target_link_libraries(${NAME} PRIVATE ${arg_LINK_LIBRARIES})
target_compile_definitions(${NAME} PRIVATE ${arg_COMPILE_DEFINITIONS})
endfunction()