mirror of
1
0
Fork 0
modern-cmake/examples/extended-project/CMakeLists.txt

69 lines
2.0 KiB
CMake
Raw Normal View History

2020-08-12 20:29:56 +02:00
# Works with 3.11 and tested through 3.18
cmake_minimum_required(VERSION 3.11...3.18)
2019-08-07 07:06:55 +02:00
# Project name and a few useful settings. Other commands can pick up the results
2020-08-04 00:16:52 +02:00
project(
ModernCMakeExample
VERSION 0.1
DESCRIPTION "An example project with CMake"
LANGUAGES CXX)
2019-08-07 07:06:55 +02:00
# Only do these if this is the main project, and not if it is included through add_subdirectory
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
2020-08-04 00:16:52 +02:00
# Optionally set things like CMAKE_CXX_STANDARD, CMAKE_POSITION_INDEPENDENT_CODE here
2019-08-07 07:06:55 +02:00
2020-08-04 00:16:52 +02:00
# Let's ensure -std=c++xx instead of -std=g++xx
set(CMAKE_CXX_EXTENSIONS OFF)
2019-08-07 07:06:55 +02:00
2020-08-04 00:16:52 +02:00
# Let's nicely support folders in IDEs
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
2019-08-07 07:06:55 +02:00
2020-08-04 00:16:52 +02:00
# Testing only available if this is the main app
# Note this needs to be done in the main CMakeLists
# since it calls enable_testing, which must be in the
# main CMakeLists.
include(CTest)
2019-08-07 07:06:55 +02:00
2020-08-04 00:16:52 +02:00
# Docs only available if this is the main app
find_package(Doxygen)
if(Doxygen_FOUND)
add_subdirectory(docs)
else()
message(STATUS "Doxygen not found, not building docs")
endif()
endif()
2019-08-07 07:06:55 +02:00
# FetchContent added in CMake 3.11, downloads during the configure step
include(FetchContent)
2020-06-09 16:59:07 +02:00
# FetchContent_MakeAvailable was not added until CMake 3.14; use our shim
2019-08-07 07:06:55 +02:00
if(${CMAKE_VERSION} VERSION_LESS 3.14)
2020-08-04 00:16:52 +02:00
include(cmake/add_FetchContent_MakeAvailable.cmake)
2019-08-07 07:06:55 +02:00
endif()
# Accumulator library
# This is header only, so could be replaced with git submodules or FetchContent
find_package(Boost REQUIRED)
# Adds Boost::boost
# Formatting library
FetchContent_Declare(
fmtlib
GIT_REPOSITORY https://github.com/fmtlib/fmt.git
2020-08-04 00:16:52 +02:00
GIT_TAG 5.3.0)
2019-08-07 07:06:55 +02:00
FetchContent_MakeAvailable(fmtlib)
# Adds fmt::fmt
# The compiled library code is here
add_subdirectory(src)
# The executable code is here
add_subdirectory(apps)
# Testing only available if this is the main app
# Emergency override MODERN_CMAKE_BUILD_TESTING provided as well
2020-08-04 00:16:52 +02:00
if((CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME OR MODERN_CMAKE_BUILD_TESTING)
AND BUILD_TESTING)
add_subdirectory(tests)
2019-08-07 07:06:55 +02:00
endif()