Improve CMake

This commit is contained in:
Jonathan Müller 2018-12-18 17:49:26 +01:00
commit d44571f1c8
5 changed files with 19 additions and 27 deletions

View file

@ -2,18 +2,10 @@
# This file is subject to the license terms in the LICENSE file # This file is subject to the license terms in the LICENSE file
# found in the top-level directory of this distribution. # found in the top-level directory of this distribution.
cmake_minimum_required(VERSION 3.3) cmake_minimum_required(VERSION 3.8)
project(cppast VERSION 0.0) project(cppast VERSION 0.0)
# options # options
if(CMAKE_BUILD_TYPE MATCHES Debug)
set(default_assertions ON)
else()
set(default_assertions OFF)
endif()
option(CPPAST_ENABLE_ASSERTIONS "whether or not to enable internal assertions for the cppast library" ${default_assertions})
option(CPPAST_ENABLE_PRECONDITION_CHECKS "whether or not to enable precondition checks" ON)
option(CPPAST_BUILD_TEST "whether or not to build the tests" OFF) option(CPPAST_BUILD_TEST "whether or not to build the tests" OFF)
option(CPPAST_BUILD_EXAMPLE "whether or not to build the examples" OFF) option(CPPAST_BUILD_EXAMPLE "whether or not to build the examples" OFF)
option(CPPAST_BUILD_TOOL "whether or not to build the tool" OFF) option(CPPAST_BUILD_TOOL "whether or not to build the tool" OFF)

View file

@ -5,7 +5,6 @@
function(_cppast_example name) function(_cppast_example name)
add_executable(cppast_example_${name} ${name}.cpp example_parser.hpp) add_executable(cppast_example_${name} ${name}.cpp example_parser.hpp)
target_link_libraries(cppast_example_${name} PUBLIC cppast) target_link_libraries(cppast_example_${name} PUBLIC cppast)
set_target_properties(cppast_example_${name} PROPERTIES CXX_STANDARD 11)
endfunction() endfunction()
_cppast_example(ast_printer) _cppast_example(ast_printer)

View file

@ -7,16 +7,16 @@
#include <debug_assert.hpp> #include <debug_assert.hpp>
#ifdef CPPAST_ENABLE_ASSERTIONS #ifndef CPPAST_ASSERTION_LEVEL
# define CPPAST_ASSERTION_LEVEL 1
#else
# define CPPAST_ASSERTION_LEVEL 0 # define CPPAST_ASSERTION_LEVEL 0
#endif #endif
#ifdef CPPAST_ENABLE_PRECONDITION_CHECKS #ifndef CPPAST_PRECONDITION_LEVEL
# define CPPAST_PRECONDITION_LEVEL 1 # ifdef NDEBUG
#else # define CPPAST_PRECONDITION_LEVEL 0
# define CPPAST_PRECONDITION_LEVEL 0 # else
# define CPPAST_PRECONDITION_LEVEL 1
# endif
#endif #endif
namespace cppast namespace cppast

View file

@ -102,16 +102,17 @@ set(libclang_source
libclang/variable_parser.cpp) libclang/variable_parser.cpp)
add_library(cppast ${detail_header} ${header} ${source} ${libclang_source}) add_library(cppast ${detail_header} ${header} ${source} ${libclang_source})
set_target_properties(cppast PROPERTIES CXX_STANDARD 11) target_compile_features(cppast PUBLIC cxx_std_11)
target_include_directories(cppast PUBLIC ../include) target_include_directories(cppast PRIVATE ../include SYSTEM INTERFACE ../include)
target_link_libraries(cppast PUBLIC type_safe _cppast_tiny_process _cppast_libclang) target_link_libraries(cppast PUBLIC type_safe _cppast_tiny_process _cppast_libclang)
target_compile_definitions(cppast PUBLIC target_compile_definitions(cppast PUBLIC
CPPAST_VERSION_MINOR="${cppast_VERSION_MINOR}" CPPAST_VERSION_MINOR="${cppast_VERSION_MINOR}"
CPPAST_VERSION_MAJOR="${cppast_VERSION_MAJOR}" CPPAST_VERSION_MAJOR="${cppast_VERSION_MAJOR}"
CPPAST_VERSION_STRING="${cppast_VERSION}") CPPAST_VERSION_STRING="${cppast_VERSION}")
if(CPPAST_ENABLE_ASSERTIONS) target_compile_options(cppast PRIVATE
target_compile_definitions(cppast PUBLIC CPPAST_ENABLE_ASSERTIONS) # clang/GCC warnings
endif() $<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:GNU>>:
if(CPPAST_ENABLE_PRECONDITION_CHECKS) -pedantic-errors -Werror -Wall -Wextra -Wconversion -Wsign-conversion>
target_compile_definitions(cppast PUBLIC CPPAST_ENABLE_PRECONDITION_CHECKS) # MSVC warnings
endif() $<$<CXX_COMPILER_ID:MSVC>:
/WX /W4>)

View file

@ -47,9 +47,9 @@ target_include_directories(cppast_test PRIVATE ${CMAKE_CURRENT_LIST_DIR}/../src)
target_link_libraries(cppast_test PUBLIC cppast) target_link_libraries(cppast_test PUBLIC cppast)
target_compile_definitions(cppast_test PUBLIC CPPAST_INTEGRATION_FILE="${CMAKE_CURRENT_SOURCE_DIR}/integration.cpp" target_compile_definitions(cppast_test PUBLIC CPPAST_INTEGRATION_FILE="${CMAKE_CURRENT_SOURCE_DIR}/integration.cpp"
CPPAST_COMPILE_COMMANDS="${CMAKE_BINARY_DIR}") CPPAST_COMPILE_COMMANDS="${CMAKE_BINARY_DIR}")
set_target_properties(cppast_test PROPERTIES CXX_STANDARD 11)
add_test(NAME test COMMAND cppast_test) add_test(NAME unit_test COMMAND cppast_test "~[integration]")
add_test(NAME integration_test COMMAND cppast_test "[integration]")
if(CPPAST_TEST_GCOV AND (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")) if(CPPAST_TEST_GCOV AND (CMAKE_CXX_COMPILER_ID STREQUAL "GNU"))
setup_target_for_coverage( setup_target_for_coverage(