libtree/CMakeLists.txt

92 lines
2.3 KiB
CMake
Raw Normal View History

2019-04-03 21:21:22 +02:00
cmake_minimum_required (VERSION 3.1 FATAL_ERROR)
project (libtree++ VERSION 0.1.0 LANGUAGES CXX)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules)
include(GNUInstallDirs)
enable_testing()
#cmake options for the project
option(DOXYGEN "Also build the doxygen documentation" OFF)
# set the required c++ standard
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
include(CTest)
find_package(Git)
2019-04-04 10:22:41 +02:00
#check for git submodules
if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
# Update submodules as needed
option(GIT_SUBMODULE "Check submodules during build" ON)
if(GIT_SUBMODULE AND NOT hasParent)
message(STATUS "Submodule update")
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GIT_SUBMOD_RESULT)
if(NOT GIT_SUBMOD_RESULT EQUAL "0")
message(FATAL_ERROR "git submodule update --init failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
endif()
endif()
endif()
2019-04-03 21:21:22 +02:00
INCLUDE(ProcessDOXYGEN)
INCLUDE(ProcessGIT)
INCLUDE(add_my_test)
IF(CMAKE_BUILD_TYPE MATCHES DEBUG)
set(DEBUG 1)
ENDIF(CMAKE_BUILD_TYPE MATCHES DEBUG)
configure_file(${PROJECT_SOURCE_DIR}/src/config.hpp.in ${PROJECT_SOURCE_DIR}/src/config.hpp @ONLY)
set(generated "${PROJECT_SOURCE_DIR}/src/config.hpp")
add_custom_target(clean-generated COMMAND rm -f ${generated})
add_library(tree STATIC
src/config.hpp
include/Tree/tree.hpp
src/Tree/tree.cpp
)
target_include_directories(tree PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
PRIVATE src
)
IF(CMAKE_BUILD_TYPE MATCHES DEBUG)
target_compile_options(tree PUBLIC -Wall -g -O0 )
ELSE()
target_compile_options(tree PUBLIC -O4)
target_compile_options(tree PUBLIC -O4)
ENDIF()
#
# Everything TEST related
#
add_my_test(TEST test_base
SOURCES tests/test_base.cpp
LIBS tree
)
add_my_test(TEST test_add_child
SOURCES tests/test_add_child.cpp
LIBS tree
)
get_property(_mytests GLOBAL PROPERTY _mytests)
FOREACH( _test ${_mytests})
IF(CMAKE_BUILD_TYPE MATCHES DEBUG)
target_compile_options(${_test} PUBLIC -Wall -g -O0)
ELSE()
target_compile_options(${_test} PUBLIC -O4)
ENDIF()
ENDFOREACH()