-
Notifications
You must be signed in to change notification settings - Fork 0
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
Feature/cmake dependencies #48
Open
niklas-uhl
wants to merge
3
commits into
main
Choose a base branch
from
feature/cmake-dependencies
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
[submodule "extern/googletest"] | ||
path = extern/googletest | ||
url = https://github.com/google/googletest.git | ||
[submodule "extern/doxygen-awesome-css"] | ||
path = extern/doxygen-awesome-css | ||
url = https://github.com/jothepro/doxygen-awesome-css.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,53 @@ project( | |
LANGUAGES CXX | ||
) | ||
|
||
# dependencies | ||
include(FetchContent) | ||
if (POLICY CMP0135) | ||
cmake_policy(SET CMP0135 OLD) | ||
endif () | ||
set(fetch_content_deps googletest) | ||
|
||
set(fetch_content_supported_flags "") | ||
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.24) | ||
list(APPEND fetch_content_supported_flags OVERRIDE_FIND_PACKAGE) | ||
endif () | ||
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.25) | ||
list(APPEND fetch_content_supported_flags SYSTEM) | ||
endif () | ||
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.28) | ||
list(APPEND fetch_content_supported_flags EXCLUDE_FROM_ALL) | ||
endif () | ||
|
||
# Using CMake >= 3.24 we override find_package and it "just works". For older versions we simulate the same behavior by | ||
# first making the dependency available and then writing an empty `googletest-config.cmake` such that find_package does | ||
# not fail. | ||
# | ||
# This does not allow for easy overriding of dependencies in top-level projects because then the toplevel also has to | ||
# override the config file, but this is the price to pay for using old CMake versions. | ||
# | ||
# When using CMake >= 3.24 a library user can override the depencies by providing an earlier FetchContent_Declare | ||
# declaration with the `OVERRIDE_FIND_PACKAGE` flag enabled. Only the first call to FetchContent_Declare for each | ||
# dependency will be registered. | ||
|
||
FetchContent_Declare( | ||
googletest URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip | ||
${fetch_content_supported_flags} | ||
) | ||
|
||
function (ensure_googletest) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we should move utility functionality like this in a different file to keep the main |
||
if (CMAKE_VERSION VERSION_LESS 3.24) | ||
if (NOT googletest_POPULATED) | ||
FetchContent_MakeAvailable(googletest) | ||
set(googletest_DIR | ||
${CMAKE_BINARY_DIR}/my_pkgRedirects/ | ||
PARENT_SCOPE | ||
) | ||
file(WRITE ${CMAKE_BINARY_DIR}/my_pkgRedirects/googletest-config.cmake "") | ||
endif () | ||
endif () | ||
endfunction () | ||
|
||
if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) | ||
# folder support for IDEs | ||
set_property(GLOBAL PROPERTY USE_FOLDERS ON) | ||
|
@@ -53,51 +100,44 @@ target_include_directories(kassert_base INTERFACE include) | |
|
||
# set C++ standard to C++17 | ||
target_compile_features(kassert_base INTERFACE cxx_std_17) | ||
|
||
list( | ||
APPEND | ||
KASSERT_WARNING_FLAGS | ||
"-Wall" | ||
"-Wextra" | ||
"-Wconversion" | ||
"-Wnon-virtual-dtor" | ||
"-Woverloaded-virtual" | ||
"-Wshadow" | ||
"-Wsign-conversion" | ||
"-Wundef" | ||
"-Wunreachable-code" | ||
"-Wunused" | ||
add_library(kassert_warnings INTERFACE) | ||
target_compile_options( | ||
kassert_warnings | ||
INTERFACE "-Wall" | ||
"-Wextra" | ||
"-Wconversion" | ||
"-Wnon-virtual-dtor" | ||
"-Woverloaded-virtual" | ||
"-Wshadow" | ||
"-Wsign-conversion" | ||
"-Wundef" | ||
"-Wunreachable-code" | ||
"-Wunused" | ||
) | ||
|
||
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") | ||
list( | ||
APPEND | ||
KASSERT_WARNING_FLAGS | ||
"-Wcast-align" | ||
"-Wnull-dereference" | ||
"-Wpedantic" | ||
"-Wextra-semi" | ||
"-Wno-gnu-zero-variadic-macro-arguments" | ||
target_compile_options( | ||
kassert_warnings INTERFACE "-Wcast-align" "-Wnull-dereference" "-Wpedantic" "-Wextra-semi" | ||
"-Wno-gnu-zero-variadic-macro-arguments" | ||
) | ||
endif () | ||
|
||
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") | ||
list( | ||
APPEND | ||
KASSERT_WARNING_FLAGS | ||
"-Wcast-align" | ||
"-Wnull-dereference" | ||
"-Wpedantic" | ||
"-Wnoexcept" | ||
"-Wsuggest-attribute=const" | ||
"-Wsuggest-attribute=noreturn" | ||
"-Wsuggest-override" | ||
target_compile_options( | ||
kassert_warnings | ||
INTERFACE "-Wcast-align" | ||
"-Wnull-dereference" | ||
"-Wpedantic" | ||
"-Wnoexcept" | ||
"-Wsuggest-attribute=const" | ||
"-Wsuggest-attribute=noreturn" | ||
"-Wsuggest-override" | ||
) | ||
endif () | ||
|
||
# OFF by default. | ||
if (KASSERT_WARNINGS_ARE_ERRORS) | ||
list(APPEND KASSERT_WARNING_FLAGS "-Werror") | ||
target_compile_options(kassert_warnings INTERFACE "-Werror") | ||
endif () | ||
|
||
# Actual library target with compile definitions | ||
|
@@ -125,5 +165,6 @@ add_library(kassert::kassert ALIAS kassert) | |
|
||
# Testing and examples are only built if this is the main project or if KASSERT_BUILD_TESTS is set (OFF by default) | ||
if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME OR KASSERT_BUILD_TESTS) | ||
ensure_googletest() | ||
add_subdirectory(tests) | ||
endif () |
Submodule googletest
deleted from
af29db
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we automatically test this for different CMake versions in our GitHub action, i.e., add different CMake versions to our build matrix?