This commit is contained in:
Andrei Astafev 2022-10-01 15:38:46 +03:00
parent 03da054787
commit f6ff19e9f5
5 changed files with 70 additions and 35 deletions

View File

@ -3,23 +3,22 @@ cmake_policy(SET CMP0057 NEW) # IN_LIST operator
get_filename_component(MYX_CMAKE_SOURCE_DIR "${CMAKE_CURRENT_LIST_FILE}" DIRECTORY) get_filename_component(MYX_CMAKE_SOURCE_DIR "${CMAKE_CURRENT_LIST_FILE}" DIRECTORY)
set(MYX_CMAKE_CONFIG_DIR "${MYX_CMAKE_SOURCE_DIR}/config")
set(MYX_CMAKE_BACKPORTS_DIR "${MYX_CMAKE_SOURCE_DIR}/backports") set(MYX_CMAKE_BACKPORTS_DIR "${MYX_CMAKE_SOURCE_DIR}/backports")
set(MYX_CMAKE_LIB_DIR "${MYX_CMAKE_SOURCE_DIR}/lib") set(MYX_CMAKE_LIB_DIR "${MYX_CMAKE_SOURCE_DIR}/lib")
include(${MYX_CMAKE_CONFIG_DIR}/Globals.cmake)
include(${MYX_CMAKE_BACKPORTS_DIR}/IncludeGuard.cmake) include(${MYX_CMAKE_BACKPORTS_DIR}/IncludeGuard.cmake)
include(${MYX_CMAKE_BACKPORTS_DIR}/TopLevelProject.cmake) include(${MYX_CMAKE_BACKPORTS_DIR}/TopLevelProject.cmake)
if(${CMAKE_VERSION} VERSION_LESS "3.11.0") if(${CMAKE_VERSION} VERSION_LESS "3.11.0")
include(${MYX_CMAKE_BACKPORTS_DIR}/FetchContent.cmake) include(${MYX_CMAKE_BACKPORTS_DIR}/FetchContent.cmake)
endif() endif()
include(${MYX_CMAKE_LIB_DIR}/Includes.cmake)
include(${MYX_CMAKE_LIB_DIR}/ColoredMessages.cmake) include(${MYX_CMAKE_LIB_DIR}/ColoredMessages.cmake)
include(${MYX_CMAKE_LIB_DIR}/NinjaGeneratorWarning.cmake) include(${MYX_CMAKE_LIB_DIR}/NinjaGeneratorWarning.cmake)
include(${MYX_CMAKE_LIB_DIR}/DirectoriesGuards.cmake) include(${MYX_CMAKE_LIB_DIR}/DirectoriesGuards.cmake)
include(${MYX_CMAKE_LIB_DIR}/SemanticProjectVersion.cmake) include(${MYX_CMAKE_LIB_DIR}/SemanticProjectVersion.cmake)
include(${MYX_CMAKE_LIB_DIR}/NinjaGeneratorWrapper.cmake) include(${MYX_CMAKE_LIB_DIR}/NinjaGeneratorWrapper.cmake)
include(${MYX_CMAKE_LIB_DIR}/FetchContentAdd.cmake)
include(${MYX_CMAKE_LIB_DIR}/AddLibrary.cmake) include(${MYX_CMAKE_LIB_DIR}/AddLibrary.cmake)
include(${MYX_CMAKE_LIB_DIR}/InstallLibrary.cmake) include(${MYX_CMAKE_LIB_DIR}/InstallLibrary.cmake)
@ -28,7 +27,6 @@ include(${MYX_CMAKE_LIB_DIR}/Qt5TargetSetup.cmake)
unset(MYX_CMAKE_SOURCE_DIR) unset(MYX_CMAKE_SOURCE_DIR)
unset(MYX_CMAKE_BACKPORTS_DIR) unset(MYX_CMAKE_BACKPORTS_DIR)
unset(MYX_CMAKE_CONFIG_DIR)
unset(MYX_CMAKE_LIB_DIR) unset(MYX_CMAKE_LIB_DIR)
cmake_policy(POP) cmake_policy(POP)

View File

@ -1,8 +0,0 @@
include(GNUInstallDirs)
#set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR} PARENT_SCOPE)
#set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR} PARENT_SCOPE)
#set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR} PARENT_SCOPE)
#set(MYX_CMAKE_SCRIPTS_PREFIX ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} PARENT_SCOPE)

View File

@ -0,0 +1,35 @@
include_guard(GLOBAL)
function(FetchContent_Add NAME)
set(options "")
set(oneValueArgs GIT_REPOSITORY GIT_REMOTE GIT_PATH)
set(multiValueArgs "")
cmake_parse_arguments(arg "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
find_package(Git)
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}
)
if(NOT ${NAME}_POPULATED)
FetchContent_Populate(${NAME})
add_subdirectory(${${NAME}_SOURCE_DIR} ${${NAME}_BINARY_DIR})
endif()
endfunction()

View File

@ -0,0 +1,4 @@
include_guard(GLOBAL)
include(FetchContent)
include(GNUInstallDirs)

View File

@ -31,12 +31,35 @@ function(myx_install_library NAME)
COMPONENT dev COMPONENT dev
) )
install( get_target_property(type ${NAME} TYPE)
TARGETS ${NAME} if(type STREQUAL INTERFACE_LIBRARY)
EXPORT ${NAME}Targets install(
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} TARGETS ${NAME}
COMPONENT lib EXPORT ${NAME}Targets
) LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT lib
)
endif()
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 lib
)
endif()
endif()
install( install(
EXPORT ${NAME}Targets EXPORT ${NAME}Targets
@ -52,21 +75,4 @@ function(myx_install_library NAME)
COMPONENT dev COMPONENT dev
) )
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 lib
)
endif()
endfunction() endfunction()