53 lines
1.7 KiB
Text
53 lines
1.7 KiB
Text
|
cmake_minimum_required(VERSION 3.14)
|
||
|
# Generate compile_commands.json
|
||
|
set(PROJECT_NAME cTemplate)
|
||
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||
|
|
||
|
# Turn on testing by default
|
||
|
option(BUILD_TESTING "Build tests" ON)
|
||
|
# 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)
|
||
|
|
||
|
# After a normal build, we can specify the location of various outputs of the
|
||
|
# build. We put executables and static libraries outside the build directory in
|
||
|
# bin/ and lib/, respectively.
|
||
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin")
|
||
|
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/lib")
|
||
|
|
||
|
# 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)
|
||
|
|