-
Notifications
You must be signed in to change notification settings - Fork 203
More Snippets
Bo Lu edited this page Apr 19, 2020
·
55 revisions
Examples on how to include popular libraries using the CPM CMake script. Feel free to extend the list with your own. Please always refer to a specific version or commit, as branches are subject to change and referencing them could impact build reproducibility.
CPMAddPackage(
NAME rang
GITHUB_REPOSITORY agauniyal/rang
GIT_TAG v3.1.0
)
if(rang_ADDED)
add_library(rang INTERFACE IMPORTED)
target_include_directories(rang INTERFACE "${rang_SOURCE_DIR}/include")
endif()
CPMAddPackage(
NAME linenoise
GIT_TAG 1.0
GITHUB_REPOSITORY antirez/linenoise
)
if(linenoise_ADDED)
add_library(linenoise ${linenoise_SOURCE_DIR}/linenoise.c)
target_include_directories(linenoise PUBLIC ${linenoise_SOURCE_DIR})
endif()
CPMAddPackage(
NAME cxxopts
GITHUB_REPOSITORY jarro2783/cxxopts
VERSION 2.2.0
OPTIONS
"CXXOPTS_BUILD_EXAMPLES Off"
"CXXOPTS_BUILD_TESTS Off"
)
CPMAddPackage(
NAME progresscpp
GITHUB_REPOSITORY prakhar1989/progress-cpp
GIT_TAG 7bfba0d22d19c41323aa35541618b6ebec9d737c
)
CPMAddPackage(
NAME tabulate
GITHUB_REPOSITORY p-ranav/tabulate
VERSION 1.0
)
CPMAddPackage(
NAME doctest
GITHUB_REPOSITORY onqtam/doctest
GIT_TAG 2.3.2
)
CPMAddPackage(
NAME Catch2
GITHUB_REPOSITORY catchorg/Catch2
VERSION 2.5.0
)
CPMAddPackage(
NAME googletest
GITHUB_REPOSITORY google/googletest
GIT_TAG release-1.8.1
VERSION 1.8.1
OPTIONS
"INSTALL_GTEST OFF"
"gtest_force_shared_crt ON"
)
CPMAddPackage(
NAME boost-cmake
GITHUB_REPOSITORY Orphis/boost-cmake
VERSION 1.67.0
)
CPMAddPackage(
NAME range-v3
URL https://github.com/ericniebler/range-v3/archive/0.5.0.zip
VERSION 0.5.0
# the range-v3 CMakeLists screws with configuration options
DOWNLOAD_ONLY True
)
if(range-v3_ADDED)
add_library(range-v3 INTERFACE IMPORTED)
target_include_directories(range-v3 INTERFACE "${range-v3_SOURCE_DIR}/include")
endif()
CPMAddPackage(
NAME variant-lite
GITHUB_REPOSITORY martinmoene/variant-lite
VERSION 1.2.2
)
CPMAddPackage(
NAME yaml-cpp
GITHUB_REPOSITORY jbeder/yaml-cpp
# 0.6.2 uses deprecated CMake syntax
VERSION 0.6.3
# 0.6.3 is not released yet, so use a recent commit
GIT_TAG 012269756149ae99745b6dafefd415843d7420bb
OPTIONS
"YAML_CPP_BUILD_TESTS Off"
"YAML_CPP_BUILD_CONTRIB Off"
"YAML_CPP_BUILD_TOOLS Off"
)
CPMAddPackage(
NAME nlohmann_json
VERSION 3.7.3
# the git repo is incredibly large, so we download the archived include directory
URL https://github.com/nlohmann/json/releases/download/v3.7.3/include.zip
URL_HASH SHA256=87b5884741427220d3a33df1363ae0e8b898099fbc59f1c451113f6732891014
)
if (nlohmann_json_ADDED)
add_library(nlohmann_json INTERFACE IMPORTED)
target_include_directories(nlohmann_json INTERFACE ${nlohmann_json_SOURCE_DIR}/include)
endif()
CPMAddPackage(
NAME cereal
VERSION 1.2.2
GITHUB_REPOSITORY USCiLab/cereal
OPTIONS
"SKIP_PORTABILITY_TEST ON"
"JUST_INSTALL_CEREAL ON"
)
CPMAddPackage(
NAME benchmark
GITHUB_REPOSITORY google/benchmark
VERSION 1.5.0
OPTIONS
"BENCHMARK_ENABLE_TESTING Off"
"BENCHMARK_USE_LIBCXX ON"
)
if (benchmark_ADDED)
# patch benchmark target
set_target_properties(benchmark PROPERTIES CXX_STANDARD 17)
endif()
CPMAddPackage(
NAME lua
GIT_REPOSITORY https://github.com/lua/lua.git
VERSION 5.3.5
DOWNLOAD_ONLY YES
)
if (lua_ADDED)
# lua has no CMake support, so we create our own target
FILE(GLOB lua_sources ${lua_SOURCE_DIR}/*.c)
add_library(lua STATIC ${lua_sources})
target_include_directories(lua
PUBLIC
$<BUILD_INTERFACE:${lua_SOURCE_DIR}>
)
endif()
CPMAddPackage(
NAME sol2
URL https://github.com/ThePhD/sol2/archive/v3.0.2.zip
VERSION 3.0.2
DOWNLOAD_ONLY YES
)
if (sol2_ADDED)
add_library(sol2 INTERFACE IMPORTED)
target_include_directories(sol2 INTERFACE ${sol2_SOURCE_DIR}/include)
target_link_libraries(sol2 INTERFACE lua)
endif()
CPMAddPackage(
NAME FileWatcher
GIT_TAG ee0b97efd206282ef8bb4b9c10c90c941de4a52b
GIT_REPOSITORY https://github.com/apetrone/simplefilewatcher.git
)
if (FileWatcher_ADDED)
file (GLOB FileWatcherSources ${FileWatcher_SOURCE_DIR}/source/*.cpp)
add_library(FileWatcher ${FileWatcherSources})
target_include_directories(FileWatcher PUBLIC ${FileWatcher_SOURCE_DIR}/include)
endif()
CPMAddPackage(
NAME fmt
GIT_TAG 6.1.2
GITHUB_REPOSITORY fmtlib/fmt
)
CPMAddPackage(
NAME EnTT
VERSION 3.1.1
GITHUB_REPOSITORY skypjack/entt
# EnTT's CMakeLists screws with configuration options
DOWNLOAD_ONLY True
)
if (EnTT_ADDED)
add_library(EnTT INTERFACE)
target_include_directories(EnTT INTERFACE ${EnTT_SOURCE_DIR}/src)
endif()
CPMAddPackage(
NAME meta
VERSION 1.4.7
GITHUB_REPOSITORY skypjack/meta
# the project's CMakeLists messes with configuration options
DOWNLOAD_ONLY True
)
if (meta_ADDED)
add_library(meta INTERFACE)
target_include_directories(meta INTERFACE ${meta_SOURCE_DIR}/src)
endif()
CPMAddPackage(
NAME rttr # link against RTTR::Core_Lib
VERSION 0.9.6
GITHUB_REPOSITORY rttrorg/rttr
OPTIONS
"BUILD_RTTR_DYNAMIC Off"
"BUILD_UNIT_TESTS Off"
"BUILD_STATIC On"
"BUILD_PACKAGE Off"
"BUILD_WITH_RTTI On"
"BUILD_EXAMPLES Off"
"BUILD_DOCUMENTATION Off"
"BUILD_INSTALLER Off"
"USE_PCH Off"
"CUSTOM_DOXYGEN_STYLE Off"
)
CPMAddPackage(
NAME Eigen
VERSION 3.2.8
URL https://gitlab.com/libeigen/eigen/-/archive/3.2.8/eigen-3.2.8.tar.gz
# Eigen's CMakelists are not intended for library use
DOWNLOAD_ONLY YES
)
if(Eigen_ADDED)
add_library(Eigen INTERFACE IMPORTED)
target_include_directories(Eigen INTERFACE ${Eigen_SOURCE_DIR})
endif()
CPMAddPackage(
NAME Format.cmake
GITHUB_REPOSITORY TheLartians/Format.cmake
VERSION 1.0
)
CPMAddPackage(
NAME GroupSourcesByFolder.cmake
GITHUB_REPOSITORY TheLartians/GroupSourcesByFolder.cmake
VERSION 1.0
)
CPMAddPackage(
NAME Ccache.cmake
GITHUB_REPOSITORY TheLartians/Ccache.cmake
VERSION 1.2
)
CPMAddPackage(
NAME Eigen
VERSION 3.2.8
URL https://gitlab.com/libeigen/eigen/-/archive/3.2.8/eigen-3.2.8.tar.gz
OPTIONS
"EIGEN_LEAVE_TEST_IN_ALL_TARGET 0"
)
CPMAddPackage(
NAME FreeImage
GITHUB_REPOSITORY Kanma/FreeImage
GIT_TAG 6bb613d9402926b3846dea1b417f20b6c596c5dc
)
if(FreeImage_ADDED)
target_include_directories(freeimage INTERFACE "${FreeImage_SOURCE_DIR}")
endif()
CPMAddPackage(
NAME freetype
GITHUB_REPOSITORY Kintek-Software/extdep-freetype
VERSION 1.3.1-cmake
)
CPMAddPackage(
NAME CLAPACK
VERSION 3.2.1
URL http://www.netlib.org/clapack/clapack-3.2.1-CMAKE.tgz
)
# we need to set proper include headers
if(CLAPACK_ADDED)
# Set include directories for the targets
target_include_directories(f2c INTERFACE "${CLAPACK_SOURCE_DIR}/INCLUDE")
target_include_directories(lapack INTERFACE "${CLAPACK_SOURCE_DIR}/INCLUDE")
endif()
CPMAddPackage(
NAME GLFW
GITHUB_REPOSITORY glfw/glfw
GIT_TAG 3.3.2
OPTIONS
"GLFW_BUILD_TESTS OFF"
"GLFW_BUILD_EXAMPLES OFF"
"GLFW_BULID_DOCS OFF"
)
CPMAddPackage(
NAME gsl
GITHUB_REPOSITORY ampl/gsl
VERSION 2.5.0
)