Skip to content

Commit

Permalink
refactor: use CPM for dependency management
Browse files Browse the repository at this point in the history
  • Loading branch information
abdes committed Mar 15, 2022
1 parent fa8131f commit 8c12b88
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 62 deletions.
55 changes: 34 additions & 21 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,28 @@ message(
"-- Building for ${CMAKE_BUILD_TYPE} with OPTION_CONTRACT_MODE : ${OPTION_CONTRACT_MODE}"
)

include(FetchContent)
# ------------------------------------------------------------------------------
# RPATH setup
# ------------------------------------------------------------------------------

if(APPLE)
set(CMAKE_MACOSX_RPATH ON)
endif()

# Set runtime path
set(CMAKE_SKIP_BUILD_RPATH FALSE) # Add absolute path to all dependencies for
# BUILD
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE)

if(NOT SYSTEM_DIR_INSTALL)
set(CMAKE_INSTALL_RPATH "$ORIGIN/${ASAP_INSTALL_LIB}")
endif()

# ---- Add dependencies via CPM ----
# see https://github.com/TheLartians/CPM.cmake for more info

include(cmake/CPM.cmake)
# We make sure that we have 'third_party' in the name so that the targets get
# excluded from the generated target lists for the various tools.
set(FETCHCONTENT_BASE_DIR ${CMAKE_BINARY_DIR}/third_party_deps)
Expand All @@ -165,28 +186,20 @@ if(ASAP_BUILD_TESTS)
asap_add_code_coverage_all_targets(EXCLUDE */test/* *googlemock* *googletest*
/usr/*)
include(Valgrind)
include(FetchGoogleTest)
include(GoogleTest)
include(CTest)
endif()

# ------------------------------------------------------------------------------
# RPATH setup
# ------------------------------------------------------------------------------

# Set runtime path
set(CMAKE_SKIP_BUILD_RPATH FALSE) # Add absolute path to all dependencies for
# BUILD
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE)
cpmaddpackage(
NAME
googletest
GIT_TAG
main
GITHUB_REPOSITORY
google/googletest
OPTIONS
"gtest_force_shared_crt ON"
"INSTALL_GTEST OFF")

if(NOT SYSTEM_DIR_INSTALL)
# Find libraries relative to binary
if(APPLE)
set(CMAKE_INSTALL_RPATH "@loader_path/../../../${ASAP_INSTALL_LIB}")
else()
set(CMAKE_INSTALL_RPATH "$ORIGIN/${ASAP_INSTALL_LIB}")
endif()
include(GoogleTest)
include(CTest)
endif()

# ------------------------------------------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"installDir": "${sourceDir}/out/install/${presetName}",
"environment": {
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
"CPM_SOURCE_CACHE": "$env{HOME}/.cache/CPM",
"caexcludepath": "${sourceDir}/third_party;${sourceDir}/out"
},
"cacheVariables": {
Expand Down Expand Up @@ -430,4 +431,4 @@
"configurePreset": "dev-gcc"
}
]
}
}
21 changes: 21 additions & 0 deletions cmake/CPM.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
set(CPM_DOWNLOAD_VERSION 0.35.0)

if(CPM_SOURCE_CACHE)
# Expand relative path. This is important if the provided path contains a tilde (~)
get_filename_component(CPM_SOURCE_CACHE ${CPM_SOURCE_CACHE} ABSOLUTE)
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
elseif(DEFINED ENV{CPM_SOURCE_CACHE})
set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
else()
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
endif()

if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION}))
message(STATUS "Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION}")
file(DOWNLOAD
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
${CPM_DOWNLOAD_LOCATION}
)
endif()

include(${CPM_DOWNLOAD_LOCATION})
25 changes: 0 additions & 25 deletions cmake/FetchGoogleTest.cmake

This file was deleted.

28 changes: 13 additions & 15 deletions third_party/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,26 @@ message("=> [third-party modules]")
# asap::common
# ------------------------------------------------------------------------------

FetchContent_Declare(
asap_common
GIT_REPOSITORY https://github.com/asap-projects/asap-common.git
GIT_TAG origin/master)
FetchContent_MakeAvailable(asap_common)
cpmaddpackage(NAME asap_common GIT_TAG v2.0.4 GITHUB_REPOSITORY
asap-projects/asap-common)

# ------------------------------------------------------------------------------
# asap::fsm
# ------------------------------------------------------------------------------
set(ASAP_FSM_INSTALL ON)
FetchContent_Declare(

cpmaddpackage(
NAME
asap_fsm
GIT_REPOSITORY https://github.com/asap-projects/asap-fsm.git
GIT_TAG origin/master)
FetchContent_MakeAvailable(asap_fsm)
GIT_TAG
v1.0.5
GITHUB_REPOSITORY
asap-projects/asap-fsm
OPTIONS
"ASAP_FSM_INSTALL ON")

# ------------------------------------------------------------------------------
# magic_enum
# ------------------------------------------------------------------------------

FetchContent_Declare(
magic_enum
GIT_REPOSITORY https://github.com/Neargye/magic_enum.git
GIT_TAG origin/master)
FetchContent_MakeAvailable(magic_enum)
cpmaddpackage(NAME magic_enum GIT_TAG master GITHUB_REPOSITORY
Neargye/magic_enum)

0 comments on commit 8c12b88

Please sign in to comment.