1
0
mirror of synced 2024-11-10 15:08:54 +01:00
modern-cmake/examples/extended-project/CMakeLists.txt
Henry Schreiner 570c7b64bf
chore: bump to CMake 3.23
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
2022-03-29 16:41:40 -04:00

2.0 KiB

Works with 3.11 and tested through 3.23

cmake_minimum_required(VERSION 3.11...3.23)

Project name and a few useful settings. Other commands can pick up the results

project( ModernCMakeExample VERSION 0.1 DESCRIPTION "An example project with CMake" LANGUAGES CXX)

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)

Optionally set things like CMAKE_CXX_STANDARD, CMAKE_POSITION_INDEPENDENT_CODE here

Let's ensure -std=c++xx instead of -std=g++xx

set(CMAKE_CXX_EXTENSIONS OFF)

Let's nicely support folders in IDEs

set_property(GLOBAL PROPERTY USE_FOLDERS ON)

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)

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()

FetchContent added in CMake 3.11, downloads during the configure step

include(FetchContent)

FetchContent_MakeAvailable was not added until CMake 3.14; use our shim

if(${CMAKE_VERSION} VERSION_LESS 3.14) include(cmake/add_FetchContent_MakeAvailable.cmake) 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 GIT_TAG 5.3.0) 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

if((CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME OR MODERN_CMAKE_BUILD_TESTING) AND BUILD_TESTING) add_subdirectory(tests) endif()