From 7396f77054104c378451d0066707c925f4643fd8 Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Thu, 24 Jun 2021 11:38:58 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9C=D0=BE=D0=B4=D1=83=D0=BB=D0=B8=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D0=BF=D0=BE=D0=B8=D1=81=D0=BA=D0=B0=20=D1=81=20?= =?UTF-8?q?=D0=BF=D0=BE=D0=BC=D0=BE=D1=89=D1=8C=D1=8E=20CMake?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmake/FindMyxlib.cmake | 48 +++++++++++++++++++---------- cmake/FindMyxlibThirdparty.cmake | 52 ++++++++++++++++++++++++-------- 2 files changed, 71 insertions(+), 29 deletions(-) diff --git a/cmake/FindMyxlib.cmake b/cmake/FindMyxlib.cmake index 9827bc4..74058c2 100644 --- a/cmake/FindMyxlib.cmake +++ b/cmake/FindMyxlib.cmake @@ -1,21 +1,37 @@ -set(MYXLIB_PREFIX "" CACHE PATH "The path to the previx of an myxlib installation") +if(NOT MYXLIB_PREFIX STREQUAL CMAKE_BINARY_DIR) + set(MYXLIB_PREFIX + "" + CACHE PATH "The path to the previx of an myxlib installation") -find_path(MYXLIB_INCLUDE_DIRS NAMES myx/core/config.hpp PATHS ${MYXLIB_PREFIX}/include) -find_library(MYXLIB_QT_LIBRARY NAMES myx-qt PATHS ${MYXLIB_PREFIX}/lib) -find_library(MYXLIB_FILESYSTEM_LIBRARY NAMES myx-filesystem PATHS ${MYXLIB_PREFIX}/lib) + find_path( + MYXLIB_INCLUDE_DIRS + NAMES myx/core/config.hpp + PATHS ${MYXLIB_PREFIX}/include) + find_library( + MYXLIB_QT_LIBRARY + NAMES myx-qt + PATHS ${MYXLIB_PREFIX}/lib) + find_library( + MYXLIB_FILESYSTEM_LIBRARY + NAMES myx-filesystem + PATHS ${MYXLIB_PREFIX}/lib) -if(MYXLIB_INCLUDE_DIRS AND MYXLIB_QT_LIBRARY AND MYXLIB_FILESYSTEM_LIBRARY) - get_filename_component(MYXLIB_LIBRARY_DIR ${MYXLIB_QT_LIBRARY} DIRECTORY CACHE) - set(MYXLIB_FOUND TRUE) -endif() - -if(MYXLIB_FOUND) - if(NOT MYXLIB_FIND_QUIETLY) - MESSAGE(STATUS "Found myxlib") + if(MYXLIB_INCLUDE_DIRS + AND MYXLIB_QT_LIBRARY + AND MYXLIB_FILESYSTEM_LIBRARY) + get_filename_component(MYXLIB_LIBRARY_DIR ${MYXLIB_QT_LIBRARY} DIRECTORY + CACHE) + set(MYXLIB_FOUND TRUE) endif() - set(HAVE_MYXLIB 1) -elseif(MYXLIB_FOUND) - if(MYXLIB_FIND_REQUIRED) - message(FATAL_ERROR "Could not find myxlib") + + if(MYXLIB_FOUND) + if(NOT MYXLIB_FIND_QUIETLY) + message(STATUS "Found myxlib") + endif() + set(HAVE_MYXLIB 1) + elseif(MYXLIB_FOUND) + if(MYXLIB_FIND_REQUIRED) + message(FATAL_ERROR "Could not find myxlib") + endif() endif() endif() diff --git a/cmake/FindMyxlibThirdparty.cmake b/cmake/FindMyxlibThirdparty.cmake index c9e6664..9a8d2df 100644 --- a/cmake/FindMyxlibThirdparty.cmake +++ b/cmake/FindMyxlibThirdparty.cmake @@ -1,14 +1,40 @@ -ExternalProject_Add( - myxlib - SOURCE_DIR ${CMAKE_SOURCE_DIR}/thirdparty/myxlib - INSTALL_DIR ${CMAKE_BINARY_DIR} - DOWNLOAD_COMMAND "" - CONFIGURE_COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" -DCMLIB_MAIN_DIR=${CMLIB_MAIN_DIR} ${CMLIB_EXT_PROJ_DEFAULT_ARGS} - BUILD_COMMAND true - ) +# Подключение внешних проектов +include(ExternalProject) -set(MYXLIB_PREFIX ${CMAKE_BINARY_DIR} CACHE FILEPATH "" FORCE) -set(MYXLIB_INCLUDE_DIRS ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_INCLUDEDIR} CACHE PATH "" FORCE) -set(MYXLIB_LIBRARY_DIR ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR} CACHE PATH "" FORCE) -set(MYXLIB_QT_LIBRARY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}/libmyx-qt.a CACHE FILEPATH "" FORCE) -set(MYXLIB_FILESYSTEM_LIBRARY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}/libmyx-filesystem.a CACHE FILEPATH "" FORCE) +# cmake-format: off +list(APPEND _ext_project_args + myxlib + SOURCE_DIR ${CMAKE_SOURCE_DIR}/thirdparty/myxlib + INSTALL_DIR ${CMAKE_BINARY_DIR} + DOWNLOAD_COMMAND "" + CONFIGURE_COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" + -DCMLIB_MAIN_DIR=${CMLIB_MAIN_DIR} + ${CMLIB_EXT_PROJ_DEFAULT_ARGS} + ) + +if(MyxlibThirdparty_FIND_COMPONENTS STREQUAL "headers") + list(APPEND _ext_project_args + BUILD_COMMAND true + INSTALL_COMMAND ${CMAKE_MAKE_PROGRAM} myxlib-install-headers) +endif() +ExternalProject_Add(${_ext_project_args}) +unset(_ext_project_args) + +set(MYXLIB_IS_EXTERNAL_PROJECT ON CACHE BOOL "" FORCE) +# cmake-format: on + +set(MYXLIB_PREFIX + ${CMAKE_BINARY_DIR} + CACHE FILEPATH "" FORCE) +set(MYXLIB_INCLUDE_DIRS + ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_INCLUDEDIR} + CACHE PATH "" FORCE) +set(MYXLIB_LIBRARY_DIR + ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR} + CACHE PATH "" FORCE) +set(MYXLIB_QT_LIBRARY + ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}/libmyx-qt.a + CACHE FILEPATH "" FORCE) +set(MYXLIB_FILESYSTEM_LIBRARY + ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}/libmyx-filesystem.a + CACHE FILEPATH "" FORCE)