|
| 1 | +# This file specifies how the project should be built, using CMake. |
| 2 | +# If you are unfamiliar with CMake, don't worry about all the details. |
| 3 | +# The sections you might want to edit are marked as such, and |
| 4 | +# the comments should hopefully make most of it clear. |
| 5 | +# |
| 6 | +# For many purposes, you may not need to change anything about this file. |
| 7 | + |
| 8 | +cmake_minimum_required(VERSION 3.8.2) |
| 9 | + |
| 10 | +# Set project name, version and laguages here. (change as needed) |
| 11 | +# Version numbers are available by including "exampleConfig.h" in |
| 12 | +# the source. See exampleConfig.h.in for some more details. |
| 13 | +project(CPP_BOILERPLATE VERSION 1.2.3.4 LANGUAGES CXX) |
| 14 | + |
| 15 | + |
| 16 | +# Options: Things you can set via commandline options to cmake (e.g. -DENABLE_LTO=[ON|OFF]) |
| 17 | +option(ENABLE_WARNINGS_SETTINGS "Allow target_set_warnings to add flags and defines. |
| 18 | + Set this to OFF if you want to provide your own warning parameters." ON) |
| 19 | +option(ENABLE_LTO "Enable link time optimization" ON) |
| 20 | +option(ENABLE_DOCTESTS "Include tests in the library. Setting this to OFF will remove all doctest related code. |
| 21 | + Tests in tests/*.cpp will still be enabled." ON) |
| 22 | + |
| 23 | +# Include stuff. No change needed. |
| 24 | +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/") |
| 25 | +include(ConfigSafeGuards) |
| 26 | +include(Colors) |
| 27 | +include(CTest) |
| 28 | +include(Doctest) |
| 29 | +include(Documentation) |
| 30 | +include(LTO) |
| 31 | +include(Misc) |
| 32 | +include(Warnings) |
| 33 | + |
| 34 | +# Check for LTO support. |
| 35 | +find_lto(CXX) |
| 36 | + |
| 37 | +# -------------------------------------------------------------------------------- |
| 38 | +# Locate files (change as needed). |
| 39 | +# -------------------------------------------------------------------------------- |
| 40 | +set(SOURCES # All .cpp files in src/ |
| 41 | + src/example.cpp |
| 42 | +) |
| 43 | +set(TESTFILES # All .cpp files in tests/ |
| 44 | + tests/main.cpp |
| 45 | +) |
| 46 | +set(LIBRARY_NAME engine) # Default name for the library built from src/*.cpp (change if you wish) |
| 47 | + |
| 48 | +# -------------------------------------------------------------------------------- |
| 49 | +# Build! (Change as needed) |
| 50 | +# -------------------------------------------------------------------------------- |
| 51 | +# Compile all sources into a library. |
| 52 | +add_library(${LIBRARY_NAME} OBJECT ${SOURCES}) |
| 53 | + |
| 54 | +# Lib needs its header files, and users of the library must also see these (PUBLIC). (No change needed) |
| 55 | +target_include_directories(${LIBRARY_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/include) |
| 56 | + |
| 57 | +# There's also (probably) doctests within the library, so we need to see this as well. |
| 58 | +target_link_libraries(${LIBRARY_NAME} PUBLIC doctest) |
| 59 | + |
| 60 | +# Set the compile options you want (change as needed). |
| 61 | +target_set_warnings(${LIBRARY_NAME} ENABLE ALL AS_ERROR ALL DISABLE Annoying) |
| 62 | +# target_compile_options(${LIBRARY_NAME} ... ) # For setting manually. |
| 63 | + |
| 64 | +# Add an executable for the file app/main.cpp. |
| 65 | +# If you add more executables, copy these lines accordingly. |
| 66 | +add_executable(main app/main.cpp) # Name of exec. and location of file. |
| 67 | +target_link_libraries(main PRIVATE ${LIBRARY_NAME}) # Link the executable to library (if it uses it). |
| 68 | +target_set_warnings(main ENABLE ALL AS_ERROR ALL DISABLE Annoying) # Set warnings (if needed). |
| 69 | +target_enable_lto(main optimized) # enable link-time-optimization if available for non-debug configurations |
| 70 | + |
| 71 | +# Set the properties you require, e.g. what C++ standard to use. Here applied to library and main (change as needed). |
| 72 | +set_target_properties( |
| 73 | + ${LIBRARY_NAME} main |
| 74 | + PROPERTIES |
| 75 | + CXX_STANDARD 17 |
| 76 | + CXX_STANDARD_REQUIRED YES |
| 77 | + CXX_EXTENSIONS NO |
| 78 | +) |
| 79 | + |
| 80 | +# Set up tests (see tests/CMakeLists.txt). |
| 81 | +add_subdirectory(tests) |
0 commit comments