Skip to content

Commit

Permalink
cmake tweating
Browse files Browse the repository at this point in the history
- setting compiler flags via interface library. There are flags for the
  library and the tests
- showing which version of external lib (catch2) is being fetched
  • Loading branch information
opokatech committed Jan 28, 2024
1 parent 1540035 commit 89b741e
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON) # ensure -std=c++...
set(CMAKE_CXX_EXTENSIONS OFF) # avoid -std=g++...

include(cmake/compile_flags.cmake)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

Expand Down
5 changes: 5 additions & 0 deletions cmake/compile_flags.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
add_library(options_compile_flags INTERFACE)
target_compile_options(options_compile_flags INTERFACE -Wall -Wextra -Wpedantic)

add_library(options_tests_compile_flags INTERFACE)
target_compile_options(options_tests_compile_flags INTERFACE -Wall -Wextra -Wpedantic)
4 changes: 0 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
# if either tests or example should be built - then add some extra flags
if(USE_TESTS OR USE_EXAMPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_DEBUG} -Wall -Wextra -Wunused-variable")
endif()

add_subdirectory(options)

if(USE_TESTS)
Expand Down
2 changes: 1 addition & 1 deletion src/example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
add_executable(example example.cpp)
target_link_libraries(example PRIVATE options)
target_link_libraries(example PRIVATE options options_compile_flags)
1 change: 1 addition & 0 deletions src/options/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
add_library(options STATIC Converters.cpp Option.cpp Options.cpp)
target_include_directories(options PUBLIC ..)
target_link_libraries(options PRIVATE options_compile_flags)
7 changes: 4 additions & 3 deletions src/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
include(FetchContent)

set(CATCH2_GIT_TAG v3.5.2)
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.5.2
GIT_TAG ${CATCH2_GIT_TAG}
GIT_SHALLOW TRUE)

message(STATUS "Making Catch2 available...")
message(STATUS "Making Catch2 ${CATCH2_GIT_TAG} available...")
FetchContent_MakeAvailable(Catch2)
message(STATUS "Catch2 ready")

enable_testing()

add_executable(${PROJECT_NAME}_tests Option_Test.cpp Options_Test.cpp)
target_link_libraries(${PROJECT_NAME}_tests PRIVATE options Catch2WithMain)
target_link_libraries(${PROJECT_NAME}_tests PRIVATE options options_tests_compile_flags Catch2WithMain)

0 comments on commit 89b741e

Please sign in to comment.