-
-
Notifications
You must be signed in to change notification settings - Fork 180
✨️ A medley of CMake improvements #1899
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
base: master
Are you sure you want to change the base?
Changes from all commits
b277eac
f085a73
dc2f432
9e98839
6462610
e083838
59ecc71
2a9ef90
9373e83
bbf12f7
0a9e548
80c13c4
7f22892
c1f5804
2d7b5e1
0c713db
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ | |
| CMakeCache.txt | ||
| CMakeFiles/ | ||
| cmake_install.cmake | ||
| CMakeUserPresets.json | ||
| build/ | ||
| *.dSYM/ | ||
| callgrind.out.* | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,11 +1,12 @@ | ||||||||||||||||||||||||||||||||||||||||||||||
| # SPDX-License-Identifier: MIT | ||||||||||||||||||||||||||||||||||||||||||||||
| ## SPDX-License-Identifier: MIT | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| # 3.9 required for LTO checks | ||||||||||||||||||||||||||||||||||||||||||||||
| # 3.17 optional for CMAKE_CTEST_ARGUMENTS | ||||||||||||||||||||||||||||||||||||||||||||||
| cmake_minimum_required(VERSION 3.9..3.17 FATAL_ERROR) | ||||||||||||||||||||||||||||||||||||||||||||||
| # 3.17 required for LTO checks messages | ||||||||||||||||||||||||||||||||||||||||||||||
| cmake_minimum_required(VERSION 3.17...4.2 FATAL_ERROR) | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| project(rgbds | ||||||||||||||||||||||||||||||||||||||||||||||
| LANGUAGES CXX) | ||||||||||||||||||||||||||||||||||||||||||||||
| LANGUAGES CXX | ||||||||||||||||||||||||||||||||||||||||||||||
| DESCRIPTION "Game Boy assembly toolchain" | ||||||||||||||||||||||||||||||||||||||||||||||
| HOMEPAGE_URL "https://rgbds.gbdev.io") | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| include(CTest) | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -20,31 +21,33 @@ if(srcdir STREQUAL bindir) | |||||||||||||||||||||||||||||||||||||||||||||
| message(FATAL_ERROR "Terminating configuration") | ||||||||||||||||||||||||||||||||||||||||||||||
| endif() | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| option(SANITIZERS "Build with sanitizers enabled" OFF) # Ignored on MSVC | ||||||||||||||||||||||||||||||||||||||||||||||
| option(MORE_WARNINGS "Turn on more warnings" OFF) # Ignored on MSVC | ||||||||||||||||||||||||||||||||||||||||||||||
| include(CMakeDependentOption) | ||||||||||||||||||||||||||||||||||||||||||||||
| option(SANITIZERS "Build with sanitizers enabled" OFF) | ||||||||||||||||||||||||||||||||||||||||||||||
| cmake_dependent_option(MORE_WARNINGS "Turn on more warnings" OFF !MSVC OFF) | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| if(MSVC) | ||||||||||||||||||||||||||||||||||||||||||||||
| # MSVC's own standard library triggers warning C5105, | ||||||||||||||||||||||||||||||||||||||||||||||
| # "macro expansion producing 'defined' has undefined behavior". | ||||||||||||||||||||||||||||||||||||||||||||||
| # Warning C5030 is about unknown attributes (`[[gnu::ATTR]]`), none of ours being load-bearing. | ||||||||||||||||||||||||||||||||||||||||||||||
| # Warning C4996 is about using POSIX names, which we want to do for portability. | ||||||||||||||||||||||||||||||||||||||||||||||
| # We also opt into the C++20-conformant preprocessor. | ||||||||||||||||||||||||||||||||||||||||||||||
| add_compile_options(/MP /wd5105 /wd5030 /wd4996 /Zc:preprocessor) | ||||||||||||||||||||||||||||||||||||||||||||||
| add_compile_options( | ||||||||||||||||||||||||||||||||||||||||||||||
| /MP # Build multiple files in parallel. | ||||||||||||||||||||||||||||||||||||||||||||||
| # /wd5105 # MSVC's own standard library triggers warning C5105, "macro expansion producing 'defined' has undefined behavior". | ||||||||||||||||||||||||||||||||||||||||||||||
| /wd5030 # Warning C5030 is about unknown attributes (`[[gnu::ATTR]]`), none of ours being load-bearing. | ||||||||||||||||||||||||||||||||||||||||||||||
| /wd4996 # Warning C4996 is about using POSIX names, which we want to do for portability. | ||||||||||||||||||||||||||||||||||||||||||||||
| /Zc:preprocessor # Opt into the C++20-conformant preprocessor. | ||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+29
to
+35
Contributor
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. These are long enough that they could be header-style not inline-style (like the comment on
Suggested change
Member
Author
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. Since the CMakeLists is quite long, I was trying to keep it more compact. But if you think that this is nonetheless better, I'd be fine with you committing this. |
||||||||||||||||||||||||||||||||||||||||||||||
| add_definitions(/D_CRT_SECURE_NO_WARNINGS) | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| if(SANITIZERS) | ||||||||||||||||||||||||||||||||||||||||||||||
| message(STATUS "ASan enabled") | ||||||||||||||||||||||||||||||||||||||||||||||
Rangi42 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||
| set(SAN_FLAGS /fsanitize=address) | ||||||||||||||||||||||||||||||||||||||||||||||
| add_compile_options(${SAN_FLAGS}) | ||||||||||||||||||||||||||||||||||||||||||||||
| add_link_options(${SAN_FLAGS}) | ||||||||||||||||||||||||||||||||||||||||||||||
| endif() | ||||||||||||||||||||||||||||||||||||||||||||||
| else() | ||||||||||||||||||||||||||||||||||||||||||||||
| add_compile_options(-Wall -pedantic) | ||||||||||||||||||||||||||||||||||||||||||||||
| if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") | ||||||||||||||||||||||||||||||||||||||||||||||
| # C++20 allows macros to take zero variadic arguments, but Clang (aka AppleClang on macOS) | ||||||||||||||||||||||||||||||||||||||||||||||
| # does not recognize this yet. | ||||||||||||||||||||||||||||||||||||||||||||||
| add_compile_options(-Wno-gnu-zero-variadic-macro-arguments) | ||||||||||||||||||||||||||||||||||||||||||||||
| endif() | ||||||||||||||||||||||||||||||||||||||||||||||
| add_compile_options(-Wall -pedantic | ||||||||||||||||||||||||||||||||||||||||||||||
| # C++20 allows macros to take zero variadic arguments. | ||||||||||||||||||||||||||||||||||||||||||||||
| # Some versions of Clang don't recognize this, and treat them as a GNU extension. | ||||||||||||||||||||||||||||||||||||||||||||||
| -Wno-gnu-zero-variadic-macro-arguments) | ||||||||||||||||||||||||||||||||||||||||||||||
| if(SANITIZERS) | ||||||||||||||||||||||||||||||||||||||||||||||
| message(STATUS "ASan and UBSan enabled") | ||||||||||||||||||||||||||||||||||||||||||||||
Rangi42 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||
| set(SAN_FLAGS -fsanitize=address -fsanitize=undefined | ||||||||||||||||||||||||||||||||||||||||||||||
| -fsanitize=float-divide-by-zero) | ||||||||||||||||||||||||||||||||||||||||||||||
| add_compile_options(${SAN_FLAGS}) | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -102,8 +105,6 @@ add_subdirectory(src) | |||||||||||||||||||||||||||||||||||||||||||||
| set(CMAKE_CTEST_ARGUMENTS "--verbose") | ||||||||||||||||||||||||||||||||||||||||||||||
| add_subdirectory(test) | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| # By default, build in Release mode; Debug mode must be explicitly requested | ||||||||||||||||||||||||||||||||||||||||||||||
| # (You may want to augment it with the options above) | ||||||||||||||||||||||||||||||||||||||||||||||
| if(CMAKE_BUILD_TYPE STREQUAL "Release") | ||||||||||||||||||||||||||||||||||||||||||||||
| message(CHECK_START "Checking if LTO is supported") | ||||||||||||||||||||||||||||||||||||||||||||||
| include(CheckIPOSupported) | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,16 +2,11 @@ | |
|
|
||
| option(USE_NONFREE_TESTS "run tests that build nonfree codebases" ON) | ||
| option(USE_EXTERNAL_TESTS "run tests that build external codebases" ON) | ||
| set(TESTS_OS_NAME "" CACHE STRING "skip running tests known to fail on this OS") | ||
ISSOtm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if(NOT USE_NONFREE_TESTS) | ||
| set(ONLY_FREE "--only-free") | ||
| endif() | ||
| if(NOT USE_EXTERNAL_TESTS) | ||
| set(ONLY_INTERNAL "--only-internal") | ||
| endif() | ||
| if(DEFINED OS) | ||
| set(OS_NAME "--os" "${OS}") | ||
| endif() | ||
| set(ONLY_FREE $<IF:$<BOOL:USE_NONFREE_TESTS>,,--only-free>) | ||
| set(ONLY_INTERNAL $<IF:$<BOOL:USE_EXTERNAL_TESTS>,,--only-internal>) | ||
| set(OS_NAME "$<IF:$<STREQUAL:${TESTS_OS_NAME},>,,--os;${TESTS_OS_NAME}>") | ||
|
Comment on lines
+7
to
+9
Contributor
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. That's some abstruse ternary syntax, but sure.
Contributor
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. Actually, it might be breaking in FreeBSD? I'd be fine with using ordinary
Member
Author
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. I agree this ternary synax looks a little icky, but I was trying to avoid five lines of conditional logic per option here, for readability. Tradeoffs tradeoffs... |
||
|
|
||
| add_executable(randtilegen gfx/randtilegen.cpp) | ||
| add_executable(rgbgfx_test gfx/rgbgfx_test.cpp) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.