cmake_minimum_required(VERSION 3.5.1) set(PROJECT_NAME Grammar) project(${PROJECT_NAME}) set(CMAKE_CXX_FLAGS "-g -Wall") set(COMMON_INCLUDES ${PROJECT_SOURCE_DIR}/include) include_directories(${COMMON_INCLUDES}) file(GLOB SRC_FILES ${PROJECT_SOURCE_DIR}/src/*.cxx) file(GLOB TEST_SRC_FILES ${PROJECT_SOURCE_DIR}/test/*.cxx) list(REMOVE_ITEM SRC_FILES ${PROJECT_SOURCE_DIR}/src/driver.cxx) set(CMAKE_CXX_STANDARD 11) add_library(Grammar_lib ${SRC_FILES}) add_executable(Grammar ${PROJECT_SOURCE_DIR}/src/driver.cxx) target_link_libraries(Grammar Grammar_lib) option(BUILD_TESTS "Build all tests." OFF) if (BUILD_TESTS) # This adds another subdirectory, which has 'project(gtest)'. add_subdirectory(ext/gtest-1.8.0) enable_testing() # Include the gtest library. gtest_SOURCE_DIR is available due to # 'project(gtest)' above. include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR}) ############## # Unit Tests ############## add_executable(runUnitTests ${TEST_SRC_FILES}) # Standard linking to gtest stuff. target_link_libraries(runUnitTests gtest gtest_main) # Extra linking for the project. target_link_libraries(runUnitTests Grammar_lib) # This is so you can do 'make test' to see all your tests run, instead of # manually running the executable runUnitTests to see those specific tests. add_test(UnitTests runUnitTests) set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/.travis/cmake) #if (CMAKE_BUILD_TYPE STREQUAL "Coverage") # include(CodeCoverage) # setup_target_for_coverage(${PROJECT_NAME}_coverage runUnitTests coverage) # # SET(CMAKE_CXX_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage") # SET(CMAKE_C_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage") #endif() #CMAKE_BUILD_TYPE STREQUAL "Coverage" endif()