Created
March 21, 2020 04:42
-
-
Save 67hz/69d8d5d788c152518b31e83573d052fe to your computer and use it in GitHub Desktop.
C++ CMake starter - loads Gtest and Boost into deps - Change MainMain to whatever your app name is
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmake_minimum_required(VERSION 3.13.0) | |
set(CMAKE_CXX_STANDARD 17) | |
set(CMAKE_CXX_STANDARD_REQUIRED ON) | |
set(CMAKE_CXX_EXTENSIONS ON) | |
# for gdb - remove before prod | |
# this is left to developer | |
# run: cmake -DCMAKE_BUILD_TYPE=Debug .. | |
set(CMAKE_BUILD_TYPE Debug) | |
add_compile_options(-Wall -Wextra -Wpedantic) | |
set(CMAKE_EXPORT_COMPILE_COMMANDS 1) | |
include(FetchContent) | |
FetchContent_Declare( | |
googletest | |
GIT_REPOSITORY https://github.com/google/googletest.git | |
GIT_TAG release-1.8.0 | |
) | |
FetchContent_MakeAvailable(googletest) | |
project(MainMain) | |
include_directories( | |
${PROJECT_SOURCE_DIR}/src | |
) | |
file(GLOB all_srcs | |
"${PROJECT_SOURCE_DIR}/src/*.cpp" | |
"${PROJECT_SOURCE_DIR}/src/*.hpp" | |
) | |
add_executable(MainMain ${all_srcs}) | |
set(Boost_USE_STATIC_LIBS ON) | |
set(Boost_USE_RELEASE_LIBS ON) | |
find_package(Boost 1.67.0) | |
if(Boost_FOUND) | |
include_directories(${Boost_INCLUDE_DIRS}) | |
link_directories(${Boost_LIBRARY_DIR}) | |
target_link_libraries(MainMain ${Boost_LIBRARIES}) | |
endif() | |
set(PROJECT_TEST_DIR ${PROJECT_SOURCE_DIR}/src/test) | |
file(GLOB test_srcs | |
"${PROJECT_TEST_DIR}/*.cpp" | |
"${PROJECT_TEST_DIR}/*.hpp" | |
) | |
enable_testing() | |
################################ | |
# Unit Tests | |
# Add test cpp file | |
add_executable(runUnitTests ${test_srcs}) | |
# Link test executable against gtest & gtest_main | |
target_link_libraries(runUnitTests gtest gtest_main) | |
add_test(runUnitTests runUnitTests) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment