AdventOfCode/02/CMakeLists.txt

53 lines
1.6 KiB
CMake

cmake_minimum_required(VERSION 3.14)
# Generate compile_commands.json
set(PROJECT_NAME 02)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Turn on testing by default
option(BUILD_TESTING "Build tests" ON)
# Turn off documentation build by default
option(BUILD_DOC "Build documentation" OFF)
# 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(CMAKE_C_FLAGS_DEBUG "-std=c99 -Wall -Wextra -Wunreachable-code -g -O0")
# 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)
if(BUILD_DOC)
add_subdirectory(docs)
endif()