Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate from CMake FetchContent to CMake Package Manager (CPM) #332

Merged
merged 2 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,23 @@ if(DEBUG)
)
endif(DEBUG)

# set up CPM.cmake
if(CPM_SOURCE_CACHE)
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM.cmake")
elseif(DEFINED ENV{CPM_SOURCE_CACHE})
set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM.cmake")
else()
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM.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/latest/download/CPM.cmake
${CPM_DOWNLOAD_LOCATION}
)
endif()

add_subdirectory(test)
add_subdirectory(benchmark)
add_subdirectory(examples)
Expand Down
35 changes: 13 additions & 22 deletions benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,28 @@ option(BENCHMARK "Enable Benchmark" OFF)
option(CMAKE_USE_WIN32_THREADS_INIT "using WIN32 threads" ON)

if(BENCHMARK)
include(${CPM_DOWNLOAD_LOCATION})

include(FetchContent)

FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
CPMAddPackage(
NAME googletest
GITHUB_REPOSITORY google/googletest
GIT_TAG origin/main
#GIT_TAG v1.13.0 # release-1.13.0
OPTIONS "gtest_forced_shared_crt ON CACHE BOOL "" FORCE"
)

FetchContent_Declare(
googlebenchmark
GIT_REPOSITORY https://github.com/google/benchmark.git
CPMAddPackage(
NAME googlebenchmark
GITHUB_REPOSITORY google/benchmark
GIT_TAG origin/main
)

FetchContent_Declare(
zlib
GIT_REPOSITORY https://github.com/madler/zlib.git
GIT_TAG v1.2.13
CPMAddPackage(
NAME zlib
GITHUB_REPOSITORY madler/zlib
VERSION 1.2.13
OPTIONS "CMAKE_POSITION_INDEPENDENT_CODE True"
)

set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
FetchContent_MakeAvailable(googlebenchmark)

set(SAVE_CMAKE_POSITION_INDEPENDENT_CODE ${CMAKE_POSITION_INDEPENDENT_CODE})
set(CMAKE_POSITION_INDEPENDENT_CODE True)
FetchContent_MakeAvailable(zlib)
set(CMAKE_POSITION_INDEPENDENT_CODE ${SAVE_CMAKE_POSITION_INDEPENDENT_CODE})

file (GLOB BENCHMARK_FILES "*.cpp" "*.hpp")
add_executable(benchmark_exe ${BENCHMARK_FILES})

Expand Down
28 changes: 10 additions & 18 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,23 @@ endif(CODE_COVERAGE)

option(TEST "Enable Test" OFF)
if(TEST)
include(FetchContent)
include(${CPM_DOWNLOAD_LOCATION})

FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
CPMAddPackage(
NAME googletest
GITHUB_REPOSITORY google/googletest
GIT_TAG origin/main
#GIT_TAG v1.13.0 # release-1.13.0
OPTIONS "gtest_forced_shared_crt ON CACHE BOOL "" FORCE"
)

FetchContent_Declare(
zlib
GIT_REPOSITORY https://github.com/madler/zlib.git
GIT_TAG v1.2.13
CPMAddPackage(
NAME zlib
GITHUB_REPOSITORY madler/zlib
VERSION 1.2.13
OPTIONS "CMAKE_POSITION_INDEPENDENT_CODE True"
)

set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)

set(SAVE_CMAKE_POSITION_INDEPENDENT_CODE ${CMAKE_POSITION_INDEPENDENT_CODE})
set(CMAKE_POSITION_INDEPENDENT_CODE True)
FetchContent_MakeAvailable(zlib)
set(CMAKE_POSITION_INDEPENDENT_CODE ${SAVE_CMAKE_POSITION_INDEPENDENT_CODE})

file (GLOB TEST_FILES "*.cpp" "*.hpp")

add_executable(test_exe ${TEST_FILES})

target_compile_definitions(test_exe
Expand Down
Loading