From 57a579758f5c301c9467faa28648c674b46f340e Mon Sep 17 00:00:00 2001 From: Clovis Durand Date: Fri, 22 Nov 2019 11:54:04 +0100 Subject: [PATCH] [#9, #15] Added main CMakeLists.txt file Signed-off-by: Clovis Durand --- CMakeLists.txt | 112 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..72a0306 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,112 @@ +# +# Copyright (C) 2019 Clovis Durand +# +# ----------------------------------------------------------------------------- + +# CMake version required ---------------------------------- +cmake_minimum_required(VERSION 3.0) +project(LTBL) + +if(NOT DEFINED PRJ_VERSION) + set(PRJ_VERSION "1.0.0") +endif(NOT DEFINED PRJ_VERSION) + +# Build type +if(NOT CMAKE_BUILD_TYPE) +set(CMAKE_BUILD_TYPE Debug CACHE STRING + "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." + FORCE) +endif(NOT CMAKE_BUILD_TYPE) + +# CASE OF C PROJECT +set(CMAKE_C_STANDARD 99) +if(NOT CMAKE_C_FLAGS) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat-security" CACHE STRING "C99 compilation flags" FORCE) +endif(NOT CMAKE_C_FLAGS) + +# CASE OF CPP PROJECT +set(CMAKE_CXX_STANDARD 17) +if(NOT CMAKE_CXX_FLAGS) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wformat-security" CACHE STRING "C++11 compilation flags" FORCE) +endif(NOT CMAKE_CXX_FLAGS) + +#------------------------------------------------------------------------------ +# Project definition, variable and dependencies +#------------------------------------------------------------------------------ + +set(CMAKE_PROJECT_NAME ${PROJECT_NAME}) +set(CMAKE_SYSTEM_NAME ESP8266) + +set(CMAKE_PROJECT_BRIEF "LTBL") + +# Allow CTest +enable_testing() + +find_package(Doxygen) +option(ENABLE_DOCS "Build API documentation" ${DOXYGEN_FOUND}) + +#------------------------------------------------------------------------------ +# Project version +#------------------------------------------------------------------------------ + +# Get the latest abbreviated commit hash of the working branch +execute_process( + COMMAND git log -1 --format=%h + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_COMMIT_HASH + OUTPUT_STRIP_TRAILING_WHITESPACE +) + +string(REGEX REPLACE + "^([\\.0-9]+).*" + "\\1" + tmp_VERSION + "${PRJ_VERSION}" +) + +string(REGEX REPLACE + "^([0-9]+)\\..*" + "\\1" + tmp_SOVERSION + "${tmp_VERSION}" +) + +# Major version is for product/marketing purpose +# Minor version is incremented everytime it gets public +set(MAJ_MIN_VERSION ${tmp_VERSION} CACHE STRING "Major and minor version" FORCE) + +# Release version is incremented everytime it gets use inside the company +set(RELEASE_VERSION ${tmp_SOVERSION} CACHE STRING "Release version" FORCE) + +# Build version is generated using the hash of the current commit build with +set(BUILD_VERSION ${GIT_COMMIT_HASH} CACHE STRING "Build version" FORCE) + +#------------------------------------------------------------------------------ +# pkgconfig +#------------------------------------------------------------------------------ + +#------------------------------------------------------------------------------ +# Project configuration +#------------------------------------------------------------------------------ + +#------------------------------------------------------------------------------ +# Sub-directories +#------------------------------------------------------------------------------ + +# Main build +# add_subdirectory(src) # TODO : Build main project w/ CMake + +# Builds dependent on main build +if(ENABLE_TESTS) +message(STATUS "TESTS enabled") +add_subdirectory(software/tests) +else() +message(STATUS "TESTS disabled") +endif(ENABLE_TESTS) + +if(ENABLE_DOCS) +message(STATUS "DOCS enabled") +add_subdirectory(software/docs) +else() +message(STATUS "DOCS disabled") +endif (ENABLE_DOCS)