Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format and Check Warnings Only When Build Testing Is Enabled #67

Merged
merged 3 commits into from
Dec 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 25 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ cmake_minimum_required(VERSION 3.5)

project(MyFibonacci)

# Disable testing build if built as a subproject.
if(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(BUILD_TESTING OFF)
endif()

file(DOWNLOAD https://github.com/cpm-cmake/CPM.cmake/releases/download/v0.38.7/CPM.cmake
${CMAKE_BINARY_DIR}/_deps/CPM.cmake EXPECTED_MD5 14ea07dfb484cad5db4ee1c75fd6a911)
include(${CMAKE_BINARY_DIR}/_deps/CPM.cmake)
Expand All @@ -13,34 +18,36 @@ cpmgetpackage(CheckWarning.cmake)
add_library(my_fibonacci src/sequence.cpp)
target_include_directories(my_fibonacci PUBLIC include)
set_property(TARGET my_fibonacci PROPERTY CXX_STANDARD 11)
target_check_warning(my_fibonacci)
if(BUILD_TESTING)
target_check_warning(my_fibonacci)
endif()

add_executable(my_fibonacci_main src/main.cpp)
target_link_libraries(my_fibonacci_main PUBLIC argparse my_fibonacci)
set_property(TARGET my_fibonacci_main PROPERTY CXX_STANDARD 11)
target_check_warning(my_fibonacci_main)
if(BUILD_TESTING)
target_check_warning(my_fibonacci_main)
endif()

if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
cpmgetpackage(Format.cmake)
if(BUILD_TESTING)
enable_testing()

if(BUILD_TESTING)
enable_testing()
cpmgetpackage(Format.cmake)

cpmgetpackage(Catch2)
include("${Catch2_SOURCE_DIR}/extras/Catch.cmake")
cpmgetpackage(Catch2)
include("${Catch2_SOURCE_DIR}/extras/Catch.cmake")

get_target_property(my_fibonacci_SOURCES my_fibonacci SOURCES)
add_executable(my_fibonacci_test test/sequence_test.cpp ${my_fibonacci_SOURCES})
get_target_property(my_fibonacci_SOURCES my_fibonacci SOURCES)
add_executable(my_fibonacci_test test/sequence_test.cpp ${my_fibonacci_SOURCES})

get_target_property(my_fibonacci_INCLUDES my_fibonacci INCLUDE_DIRECTORIES)
target_include_directories(my_fibonacci_test PRIVATE ${my_fibonacci_INCLUDES})
get_target_property(my_fibonacci_INCLUDES my_fibonacci INCLUDE_DIRECTORIES)
target_include_directories(my_fibonacci_test PRIVATE ${my_fibonacci_INCLUDES})

target_link_libraries(my_fibonacci_test PRIVATE Catch2::Catch2WithMain)
target_link_libraries(my_fibonacci_test PRIVATE Catch2::Catch2WithMain)

target_check_warning(my_fibonacci_test)
target_compile_options(my_fibonacci_test PRIVATE --coverage -O0)
target_link_options(my_fibonacci_test PRIVATE --coverage)
target_check_warning(my_fibonacci_test)
target_compile_options(my_fibonacci_test PRIVATE --coverage -O0)
target_link_options(my_fibonacci_test PRIVATE --coverage)

catch_discover_tests(my_fibonacci_test)
endif()
catch_discover_tests(my_fibonacci_test)
endif()