2023-12-10 01:25:53 +01:00
|
|
|
cmake_minimum_required(VERSION 3.14)
|
|
|
|
# Generate compile_commands.json
|
|
|
|
set(PROJECT_NAME 01)
|
|
|
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|
|
|
|
|
|
|
# Turn on testing by default
|
|
|
|
option(BUILD_TESTING "Build tests" ON)
|
2023-12-10 04:14:17 +01:00
|
|
|
# Turn off documentation build by default
|
|
|
|
option(BUILD_DOC "Build documentation" OFF)
|
2023-12-10 01:25:53 +01:00
|
|
|
# Turn off coverage by default
|
|
|
|
option(ENABLE_COVERAGE "Enable test coverage" ON)
|
|
|
|
|
|
|
|
# Set C standard to C99
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
|
|
|
|
|
|
|
|
# Set the project name and version number. This allows for a user of your
|
|
|
|
project(${PROJECT_NAME} VERSION 0.1)
|
|
|
|
set(${PROJECT_NAME} 0.1)
|
|
|
|
|
|
|
|
# Function to prepend the subdirectory to source files in subdirectories
|
|
|
|
FUNCTION(PREPEND var )
|
|
|
|
SET(listVar "")
|
|
|
|
FOREACH(f ${${var}})
|
|
|
|
LIST(APPEND listVar "${CMAKE_CURRENT_SOURCE_DIR}/${f}")
|
|
|
|
ENDFOREACH(f)
|
|
|
|
SET(${var} "${listVar}" PARENT_SCOPE)
|
|
|
|
ENDFUNCTION(PREPEND)
|
|
|
|
|
|
|
|
# Include source code and headers. This calls the CMakeLists.txt in each
|
|
|
|
# subdirectory. These can define their own libraries, executables, etc. as targets,
|
|
|
|
# but here we define all exportable targets in the root CMakeLists.txt.
|
|
|
|
add_subdirectory(src)
|
|
|
|
add_subdirectory(include)
|
|
|
|
|
|
|
|
# enable unit testing via "make test" once the code has been compiled.
|
|
|
|
# TODO: Google Test
|
|
|
|
|
|
|
|
if(BUILD_TESTING)
|
|
|
|
message("Testing enabled")
|
|
|
|
enable_testing()
|
|
|
|
add_subdirectory(tests)
|
|
|
|
target_include_directories(tests PRIVATE include)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Add PROJECT_NAME as an executable target.
|
|
|
|
add_executable(${PROJECT_NAME} ${SRC} ${INC})
|
|
|
|
target_include_directories(${PROJECT_NAME} PRIVATE include)
|
|
|
|
|
2023-12-10 04:14:17 +01:00
|
|
|
if(BUILD_DOC)
|
|
|
|
add_subdirectory(docs)
|
|
|
|
endif()
|