Skip to content

Commit

Permalink
Add proper CMake setup
Browse files Browse the repository at this point in the history
This adds a CMake library and a test for it. We now explicitly pull in a
specific version of GTest for testing.
  • Loading branch information
bbannier committed Sep 2, 2024
1 parent f4acaf4 commit e62fc37
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
33 changes: 33 additions & 0 deletions cc/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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 ()
2 changes: 1 addition & 1 deletion cc/src/tokenpool_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#include "tokenpool.h"

#include "test.h"
#include "gtest/gtest.h"

#ifdef _WIN32
#include <windows.h>
Expand Down

0 comments on commit e62fc37

Please sign in to comment.