From f6ff19e9f59a02f4c682623268377d0280e7f08f Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Sat, 1 Oct 2022 15:38:46 +0300 Subject: [PATCH] update --- cmake/myx/MyxCMakeConfig.cmake | 6 ++-- cmake/myx/config/Globals.cmake | 8 ----- cmake/myx/lib/FetchContentAdd.cmake | 35 +++++++++++++++++++ cmake/myx/lib/Includes.cmake | 4 +++ cmake/myx/lib/InstallLibrary.cmake | 52 ++++++++++++++++------------- 5 files changed, 70 insertions(+), 35 deletions(-) delete mode 100644 cmake/myx/config/Globals.cmake create mode 100644 cmake/myx/lib/FetchContentAdd.cmake create mode 100644 cmake/myx/lib/Includes.cmake diff --git a/cmake/myx/MyxCMakeConfig.cmake b/cmake/myx/MyxCMakeConfig.cmake index 5bb204f..842c9f7 100644 --- a/cmake/myx/MyxCMakeConfig.cmake +++ b/cmake/myx/MyxCMakeConfig.cmake @@ -3,23 +3,22 @@ cmake_policy(SET CMP0057 NEW) # IN_LIST operator 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_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}/TopLevelProject.cmake) if(${CMAKE_VERSION} VERSION_LESS "3.11.0") include(${MYX_CMAKE_BACKPORTS_DIR}/FetchContent.cmake) endif() +include(${MYX_CMAKE_LIB_DIR}/Includes.cmake) include(${MYX_CMAKE_LIB_DIR}/ColoredMessages.cmake) include(${MYX_CMAKE_LIB_DIR}/NinjaGeneratorWarning.cmake) include(${MYX_CMAKE_LIB_DIR}/DirectoriesGuards.cmake) include(${MYX_CMAKE_LIB_DIR}/SemanticProjectVersion.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}/InstallLibrary.cmake) @@ -28,7 +27,6 @@ include(${MYX_CMAKE_LIB_DIR}/Qt5TargetSetup.cmake) unset(MYX_CMAKE_SOURCE_DIR) unset(MYX_CMAKE_BACKPORTS_DIR) -unset(MYX_CMAKE_CONFIG_DIR) unset(MYX_CMAKE_LIB_DIR) cmake_policy(POP) diff --git a/cmake/myx/config/Globals.cmake b/cmake/myx/config/Globals.cmake deleted file mode 100644 index 239ce77..0000000 --- a/cmake/myx/config/Globals.cmake +++ /dev/null @@ -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) - diff --git a/cmake/myx/lib/FetchContentAdd.cmake b/cmake/myx/lib/FetchContentAdd.cmake new file mode 100644 index 0000000..e531de4 --- /dev/null +++ b/cmake/myx/lib/FetchContentAdd.cmake @@ -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() diff --git a/cmake/myx/lib/Includes.cmake b/cmake/myx/lib/Includes.cmake new file mode 100644 index 0000000..8b54c46 --- /dev/null +++ b/cmake/myx/lib/Includes.cmake @@ -0,0 +1,4 @@ +include_guard(GLOBAL) + +include(FetchContent) +include(GNUInstallDirs) diff --git a/cmake/myx/lib/InstallLibrary.cmake b/cmake/myx/lib/InstallLibrary.cmake index 3334a5b..b1b94af 100644 --- a/cmake/myx/lib/InstallLibrary.cmake +++ b/cmake/myx/lib/InstallLibrary.cmake @@ -31,12 +31,35 @@ function(myx_install_library NAME) COMPONENT dev ) - install( - TARGETS ${NAME} - EXPORT ${NAME}Targets - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - COMPONENT lib - ) + get_target_property(type ${NAME} TYPE) + if(type STREQUAL INTERFACE_LIBRARY) + install( + TARGETS ${NAME} + 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( EXPORT ${NAME}Targets @@ -52,21 +75,4 @@ function(myx_install_library NAME) 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()