Skip to content

Commit

Permalink
Avoid checking out gtest if package is found.
Browse files Browse the repository at this point in the history
  • Loading branch information
rturrado committed Mar 20, 2024
1 parent 141609d commit 1b7225d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
8 changes: 3 additions & 5 deletions examples/directory/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@ add_executable(directory-example
)

target_include_directories(directory-example
# This directory for primitives.hpp
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}"
# Binary directory for directory.hpp
PRIVATE "${CMAKE_CURRENT_BINARY_DIR}"
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}" # Current directory for primitives.hpp
PRIVATE "${CMAKE_CURRENT_BINARY_DIR}" # Binary directory for directory.hpp
)

target_link_libraries(directory-example
tree-gen-lib
PRIVATE tree-gen-lib
)

# The following lines only serve to register the example as a test,
Expand Down
8 changes: 3 additions & 5 deletions examples/interpreter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,12 @@ add_executable(interpreter-example

target_include_directories(
interpreter-example
# This directory for primitives.hpp
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}"
# Binary directory for interpreter.hpp
PRIVATE "${CMAKE_CURRENT_BINARY_DIR}"
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}" # Current directory for primitives.hpp
PRIVATE "${CMAKE_CURRENT_BINARY_DIR}" # Binary directory for interpreter.hpp
)

target_link_libraries(interpreter-example
tree-gen-lib
PRIVATE tree-gen-lib
)

# The following lines only serve to register the example as a test,
Expand Down
21 changes: 11 additions & 10 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ cmake_minimum_required(VERSION 3.12 FATAL_ERROR)

# Packages
include(FetchContent)
FetchContent_Declare(googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG "61720589cbef9707b3c5247d02141a7c31e2876f"
)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(
googletest
)
find_package(GTest)
if(NOT GTest_FOUND)
FetchContent_Declare(gtest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG "61720589cbef9707b3c5247d02141a7c31e2876f"
)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(gtest)
endif()
include(GoogleTest)

# Test executable
Expand All @@ -32,8 +33,8 @@ target_include_directories(${PROJECT_NAME}_test PRIVATE

# Target options
target_link_libraries(${PROJECT_NAME}_test PRIVATE
tree-gen-lib
gtest
PRIVATE tree-gen-lib
PRIVATE gtest::gtest
)
if(CMAKE_COMPILER_IS_GNUCXX)
target_compile_options(${PROJECT_NAME}_test PRIVATE
Expand Down

0 comments on commit 1b7225d

Please sign in to comment.