|
| 1 | +# |
| 2 | +# Copyright (C) 2022 Nikolas Koesling <nikolas@koesling.info>. |
| 3 | +# This program is free software. You can redistribute it and/or modify it under the terms of the MIT License. |
| 4 | +# |
| 5 | + |
| 6 | +cmake_minimum_required(VERSION 3.13.4 FATAL_ERROR) |
| 7 | + |
| 8 | +project(cxxitimer LANGUAGES CXX VERSION 0.0.0) |
| 9 | +set(CMAKE_CXX_STANDARD 17) |
| 10 | + |
| 11 | +set(Target cxxitimer) |
| 12 | + |
| 13 | +add_library(${Target}) |
| 14 | +install(TARGETS ${Target}) |
| 15 | + |
| 16 | +add_subdirectory("src") |
| 17 | +add_subdirectory("include") |
| 18 | +target_include_directories(${Target} PUBLIC include) |
| 19 | + |
| 20 | +include(warnings.cmake) |
| 21 | +include(define.cmake) |
| 22 | + |
| 23 | +set_target_properties(${Target} PROPERTIES |
| 24 | + CXX_STANDARD ${CMAKE_CXX_STANDARD} |
| 25 | + CXX_STANDARD_REQUIRED ON |
| 26 | + CXX_EXTENSIONS OFF |
| 27 | + ) |
| 28 | + |
| 29 | +# Determine whether this is a standalone project or included by other projects |
| 30 | +set(STANDALONE_PROJECT OFF) |
| 31 | +if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) |
| 32 | + set(STANDALONE_PROJECT ON) |
| 33 | +endif() |
| 34 | + |
| 35 | +if(STANDALONE_PROJECT) |
| 36 | + enable_warnings(${Target}) |
| 37 | +else() |
| 38 | + disable_warnings(${Target}) |
| 39 | +endif() |
| 40 | + |
| 41 | +set_definitions(${Target}) |
| 42 | + |
| 43 | + |
| 44 | +if(STANDALONE_PROJECT) |
| 45 | + # doxygen documentation (https://vicrucann.github.io/tutorials/quick-cmake-doxygen/) |
| 46 | + # check if Doxygen is installed |
| 47 | + find_package(Doxygen) |
| 48 | + if (DOXYGEN_FOUND) |
| 49 | + # set input and output files |
| 50 | + set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in) |
| 51 | + set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile) |
| 52 | + |
| 53 | + if(EXISTS ${DOXYGEN_IN}) |
| 54 | + # request to configure the file |
| 55 | + configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY) |
| 56 | + message(STATUS "Doxygen configured") |
| 57 | + |
| 58 | + # note the option ALL which allows to build the docs together with the application |
| 59 | + add_custom_target( doc_doxygen ALL |
| 60 | + COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT} |
| 61 | + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
| 62 | + COMMENT "Generating API documentation with Doxygen" |
| 63 | + VERBATIM ) |
| 64 | + message(STATUS "Added target doc_doxygen") |
| 65 | + else() |
| 66 | + message(WARNING "doxygen documentation requested, but file ${DOXYGEN_IN} does not exist.") |
| 67 | + endif() |
| 68 | + else (DOXYGEN_FOUND) |
| 69 | + message(WARNING "Doxygen need to be installed and accessible to generate the doxygen documentation.") |
| 70 | + endif (DOXYGEN_FOUND) |
| 71 | + |
| 72 | + # add clang format target |
| 73 | + set(CLANG_FORMAT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/.clang-format) |
| 74 | + |
| 75 | + if(EXISTS ${CLANG_FORMAT_FILE}) |
| 76 | + set(CLANG_FORMAT_ENABLED ON) |
| 77 | + include(ClangFormat.cmake) |
| 78 | + target_clangformat_setup(${Target}) |
| 79 | + message(STATUS "Added clang format target(s)") |
| 80 | + else() |
| 81 | + message(WARNING "Clang format enabled, but file ${CLANG_FORMAT_FILE} does not exist") |
| 82 | + endif() |
| 83 | + |
| 84 | + # add test targets |
| 85 | + enable_testing() |
| 86 | + add_subdirectory(test) |
| 87 | +endif() |
0 commit comments