From e62fc377a4dc5c51168bc4a5622a47a64795ed62 Mon Sep 17 00:00:00 2001 From: Benjamin Bannier Date: Mon, 2 Sep 2024 10:33:28 +0200 Subject: [PATCH] Add proper CMake setup This adds a CMake library and a test for it. We now explicitly pull in a specific version of GTest for testing. --- cc/src/CMakeLists.txt | 33 +++++++++++++++++++++++++++++++++ cc/src/tokenpool_test.cc | 2 +- 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 cc/src/CMakeLists.txt diff --git a/cc/src/CMakeLists.txt b/cc/src/CMakeLists.txt new file mode 100644 index 0000000..665ae2c --- /dev/null +++ b/cc/src/CMakeLists.txt @@ -0,0 +1,33 @@ +cmake_minimum_required(VERSION 3.14) +project(gnumake-tokenpool LANGUAGES CXX) + +add_library( + gnumake-tokenpool + tokenpool-gnu-make-posix.cc + # tokenpool-gnu-make-win32.cc # TODO: Add this file iff building on win32. + tokenpool-gnu-make.cc) +target_include_directories(gnumake-tokenpool PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) + +option(GNUMAKE_TOKENPOOL_BUILD_TESTS "build gnumake-tokenpool tests" ON) + +if (GNUMAKE_TOKENPOOL_BUILD_TESTS) + # GoogleTest requires at least C++14 + set(CMAKE_CXX_STANDARD 14) + set(CMAKE_CXX_STANDARD_REQUIRED ON) + + include(FetchContent) + FetchContent_Declare( + googletest + URL https://github.com/google/googletest/releases/download/v1.15.2/googletest-1.15.2.tar.gz) + # For Windows: Prevent overriding the parent project's compiler/linker settings + set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) + FetchContent_MakeAvailable(googletest) + + add_executable(gnumake-tokenpool-test tokenpool_test.cc) + target_link_libraries(gnumake-tokenpool-test gnumake-tokenpool gtest_main) + + enable_testing() + + include(GoogleTest) + gtest_discover_tests(gnumake-tokenpool-test) +endif () diff --git a/cc/src/tokenpool_test.cc b/cc/src/tokenpool_test.cc index 42b2ef3..c73ecaa 100644 --- a/cc/src/tokenpool_test.cc +++ b/cc/src/tokenpool_test.cc @@ -14,7 +14,7 @@ #include "tokenpool.h" -#include "test.h" +#include "gtest/gtest.h" #ifdef _WIN32 #include