Newer
Older
cmake_minimum_required(VERSION 3.14)
project(exple_cmake_build CXX)
option(DOWNLOAD_DEPS "Enable automatic download of dependencies" ON)
set(COMMON_LIB_URL "http://tesla.parallel.ru/vonopr/explelibx-common.git"
CACHE STRING "Git repository URL of the downloaded 'explelibx-common' dependency; used if DOWNLOAD_DEPS enabled")
set(COMMON_LIB_TAG "e45b60782a6414125c7300d9b7a77d34a8404d6e"
CACHE STRING "Specify the branch name, tag name or commit hash of the downloaded 'explelibx-common' dependency; used if DOWNLOAD_DEPS enabled")
set(GRID_LIB_URL "http://tesla.parallel.ru/vonopr/explelibx-mgrid.git"
CACHE STRING "Git repository URL of the downloaded 'explelibx-mgrid' dependency; used if DOWNLOAD_DEPS enabled")
set(GRID_LIB_TAG "c345859b9ebca2227e3b3faea4cc2380fdbb054f"
CACHE STRING "Specify the branch name, tag name or commit hash of the downloaded 'explelibx-mgrid' dependency; used if DOWNLOAD_DEPS enabled")
# download dependency 'explelibx_common' or find it locally
if (DOWNLOAD_DEPS)
include(FetchContent)
FetchContent_Declare(
explelibx_common
GIT_REPOSITORY "${COMMON_LIB_URL}"
GIT_TAG "${COMMON_LIB_TAG}")
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 "${GRID_LIB_URL}"
GIT_TAG "${GRID_LIB_TAG}")
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
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}")
add_custom_command(TARGET exple_add_numbers POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${PROJECT_SOURCE_DIR}/exple-cmake-build/config-examples" "$<TARGET_FILE_DIR:exple_add_numbers>/config-examples")
# 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}")