cmake_minimum_required(VERSION 3.14) project(exple_cmake_build CXX) option(DOWNLOAD_DEPS ON) # download dependency 'explelibx_common' or find it locally if (DOWNLOAD_DEPS) include(FetchContent) FetchContent_Declare( explelibx_common GIT_REPOSITORY http://tesla.parallel.ru/vonopr/explelibx-common.git GIT_TAG e45b60782a6414125c7300d9b7a77d34a8404d6e) FetchContent_MakeAvailable(explelibx_common) set(COMMON_DIR "${explelibx_common_SOURCE_DIR}") else() if (NOT DEFINED COMMON_DIR) file(REAL_PATH "${PROJECT_SOURCE_DIR}/../../explelibx-common" COMMON_DIR) endif() if (NOT EXISTS ${COMMON_DIR}) message(WARNING "Failed to locate 'explelibx-common' project. Variable COMMON_DIR points to non-existent directory.\ Set COMMON_DIR to point a valid directory or enable dependencies download with '-DDOWNLOAD_DEPS=ON' (e.g. cmake . -DDOWNLOAD_DEPS=ON)") endif() message("-- Path to 'explelibx-common' project") message(" COMMON_DIR: ${COMMON_DIR}") endif() # download dependency 'explelibx_mgrid' or find it locally if (DOWNLOAD_DEPS) include(FetchContent) FetchContent_Declare( explelibx_mgrid GIT_REPOSITORY http://tesla.parallel.ru/vonopr/explelibx-mgrid.git GIT_TAG c345859b9ebca2227e3b3faea4cc2380fdbb054f) FetchContent_MakeAvailable(explelibx_mgrid) set(GRID_DIR "${explelibx_mgrid_SOURCE_DIR}") else() if (NOT DEFINED GRID_DIR) file(REAL_PATH "${PROJECT_SOURCE_DIR}/../../explelibx-mgrid" GRID_DIR) endif() if (NOT EXISTS ${GRID_DIR}) message(WARNING "Failed to locate 'explelibx-mgrid' project. Variable GRID_DIR points to non-existent directory.\ Set GRID_DIR to point a valid directory or enable dependencies download with '-DDOWNLOAD_DEPS=ON' (e.g. cmake . -DDOWNLOAD_DEPS=ON)") endif() message("-- Path to 'explelibx-mgrid' project") message(" GRID_DIR: ${GRID_DIR}") endif() # set paths to 'explelibx-common' sources set(COMMON_SOURCE_DIR "${COMMON_DIR}/explelibx-common") set(COMMON_HEADER_DIR "${COMMON_DIR}/explelibx-common") set(COMMON_SOURCES exple-add.cpp) set(COMMON_HEADERS exple-add.h) list(TRANSFORM COMMON_SOURCES PREPEND "${COMMON_SOURCE_DIR}/") list(TRANSFORM COMMON_HEADERS PREPEND "${COMMON_HEADER_DIR}/") # set paths to 'explelibx-mgrid' sources set(GRID_SOURCE_DIR "${GRID_DIR}/explelibx-mgrid") set(GRID_HEADER_DIR "${GRID_DIR}/explelibx-mgrid") set(GRID_SOURCES exple-mul.cpp) set(GRID_HEADERS exple-mul.h) list(TRANSFORM GRID_SOURCES PREPEND "${GRID_SOURCE_DIR}/") list(TRANSFORM GRID_HEADERS PREPEND "${GRID_HEADER_DIR}/") # set paths to current project's sources set(SOURCE_DIR "${PROJECT_SOURCE_DIR}/exple-cmake-build") set(HEADER_DIR "${PROJECT_SOURCE_DIR}/exple-cmake-build") set(CURRENT_SOURCES main.cpp) set(CURRENT_HEADERS exple-expr.hpp) list(TRANSFORM CURRENT_SOURCES PREPEND "${SOURCE_DIR}/") list(TRANSFORM CURRENT_HEADERS PREPEND "${HEADER_DIR}/") # set targets add_executable(exple_add_numbers "${CURRENT_SOURCES}" "${CURRENT_HEADERS}" "${COMMON_SOURCES}" "${COMMON_HEADERS}" "${GRID_SOURCES}" "${GRID_HEADERS}") # headers should be explicitly added to the target to be shown in IDEs after mentioned in source_group() # if using Visual Studio switch to project's target representation set_property(TARGET exple_add_numbers PROPERTY OUTPUT_NAME "exple-add-numbers") target_include_directories(exple_add_numbers PRIVATE "${HEADER_DIR}" "${COMMON_HEADER_DIR}" "${GRID_HEADER_DIR}") # set groups for better source representation in IDEs source_group("Common\\Sources" FILES "${COMMON_SOURCES}") source_group("Common\\Headers" FILES "${COMMON_HEADERS}") source_group("Grid\\Sources" FILES "${GRID_SOURCES}") source_group("Grid\\Headers" FILES "${GRID_HEADERS}") source_group("CMake-Build\\Sources" FILES "${CURRENT_SOURCES}") source_group("CMake-Build\\Headers" FILES "${CURRENT_HEADERS}")