Skip to content

Commit

Permalink
build: add MY_FIBONACCI_ENABLE_TESTS option (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
threeal authored Jul 10, 2024
1 parent acd9e39 commit 185a218
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Configure Project
uses: threeal/cmake-action@v1.3.0
with:
options: BUILD_TESTING=ON
options: MY_FIBONACCI_ENABLE_TESTS=ON

- name: Check Formatting
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Configure Project
uses: threeal/cmake-action@v1.3.0
with:
options: BUILD_TESTING=ON
options: MY_FIBONACCI_ENABLE_TESTS=ON

- name: Build Project
run: cmake --build build
Expand Down
10 changes: 4 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ project(
LANGUAGES CXX
)

option(MY_FIBONACCI_ENABLE_TESTS "Enable test targets.")
option(MY_FIBONACCI_ENABLE_INSTALL "Enable install targets."
"${PROJECT_IS_TOP_LEVEL}")

Expand All @@ -22,8 +23,7 @@ function(cpmaddpackage)
cpmaddpackage(${ARGN})
endfunction()

# Enable warning checks if it is not a subproject and testing is enabled.
if(PROJECT_IS_TOP_LEVEL AND BUILD_TESTING)
if(MY_FIBONACCI_ENABLE_TESTS)
find_package(CheckWarning QUIET)
if(NOT CheckWarning_FOUND)
cpmaddpackage(gh:threeal/CheckWarning.cmake@2.1.1)
Expand All @@ -50,8 +50,7 @@ target_compile_features(sequence PRIVATE cxx_std_11)
add_executable(generate_sequence src/main.cpp)
target_link_libraries(generate_sequence PUBLIC argparse::argparse sequence)

# Declare test targets if it is not a subproject and testing is enabled.
if(PROJECT_IS_TOP_LEVEL AND BUILD_TESTING)
if(MY_FIBONACCI_ENABLE_TESTS)
enable_testing()

find_package(ut QUIET)
Expand All @@ -77,8 +76,7 @@ if(PROJECT_IS_TOP_LEVEL AND BUILD_TESTING)
add_test(NAME "Sequence Test" COMMAND sequence_test)
endif()

# Enable automatic formatting if it is not a subproject and testing is enabled.
if(PROJECT_IS_TOP_LEVEL AND BUILD_TESTING)
if(MY_FIBONACCI_ENABLE_TESTS)
find_package(FixFormat QUIET)
if(NOT FixFormat_FOUND)
cpmaddpackage(gh:threeal/FixFormat.cmake@1.1.1)
Expand Down

0 comments on commit 185a218

Please sign in to comment.