Skip to content

Use CMake target_compile_options and target_compile_definitions - #2248

Merged
Rangi42 merged 2 commits into
gbdev:masterfrom
Rangi42:cmake-target-specific
Nov 21, 2026
Merged

Rangi42 merged 2 commits into
gbdev:masterfrom
Rangi42:cmake-target-specific

Conversation

@Rangi42

@Rangi42 Rangi42 commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Follow-up to #2243. I'm attempting to use target-specific compile options/definitions for our warning/diagnostic flags after all, because they're sometimes interfering with CI builds. At least, the unix (ubuntu-26.04-arm, g++, cmake) is inconsistently but repeatedly breaking due to our -Werror=undef:

Example: https://github.com/gbdev/rgbds/actions/runs/44775063206/job/136439699907?pr=2247

[1/146] Scanning /usr/include/c++/15/bits/std.compat.cc for CXX dependencies
FAILED: [code=1] src/CMakeFiles/@cmake_cxx_std@synth_0.dir/f6733e1179a8.bmi.ddi 
/usr/bin/g++   -Og -fno-omit-frame-pointer -fno-optimize-sibling-calls -g -std=gnu++20 -fdiagnostics-color=always -fsanitize=address,undefined,float-divide-by-zero,float-cast-overflow,pointer-compare,pointer-subtract -Wall -pedantic -Wno-unknown-warning-option -fno-exceptions -fno-rtti -Wextra -Walloc-zero -Wcast-align -Wcast-qual -Wduplicated-branches -Wduplicated-cond -Wfloat-equal -Wlogical-op -Wnull-dereference -Wold-style-cast -Wshift-overflow=2 -Wstringop-overflow=4 -Wtrampolines -Wundef -Wuninitialized -Wunused -Wshadow -Wformat=2 -Wformat-overflow=2 -Wformat-truncation=1 -Wno-format-nonliteral -Wno-strict-overflow -Wno-type-limits -Wno-tautological-constant-out-of-range-compare -Wvla -Wno-unused-but-set-variable -Wno-gnu-zero-variadic-macro-arguments -Werror -fmodule-only -E -x c++ /usr/include/c++/15/bits/std.compat.cc -MT src/CMakeFiles/@cmake_cxx_std@synth_0.dir/f6733e1179a8.bmi.ddi -MD -MF src/CMakeFiles/@cmake_cxx_std@synth_0.dir/f6733e1179a8.bmi.ddi.d -fmodules-ts -fdeps-file=src/CMakeFiles/@cmake_cxx_std@synth_0.dir/f6733e1179a8.bmi.ddi -fdeps-target=src/CMakeFiles/@cmake_cxx_std@synth_0.dir/f6733e1179a8.bmi -fdeps-format=p1689r5 -o src/CMakeFiles/@cmake_cxx_std@synth_0.dir/f6733e1179a8.bmi.ddi.i
/usr/include/c++/15/bits/std.compat.cc:356:5: error: ‘__cpp_lib_math_special_functions’ is not defined, evaluates to ‘0’ [-Werror=undef]
  356 | #if __cpp_lib_math_special_functions && !defined(STD_COMPAT)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/15/bits/std.compat.cc:547:5: error: ‘_GLIBCXX_USE_TMPNAM’ is not defined, evaluates to ‘0’ [-Werror=undef]
  547 | #if _GLIBCXX_USE_TMPNAM
      |     ^~~~~~~~~~~~~~~~~~~
...

(#2246 had the same failure yesterday until I re-ran it once or twice.)

@Rangi42 Rangi42 added this to the 1.0.5 milestone Nov 20, 2026
@Rangi42
Rangi42 requested a review from ISSOtm November 20, 2026 17:30
@Rangi42 Rangi42 added meta This isn't related to the tools directly: repo organization, maintainership... builds This affects the build process or release artifacts labels Nov 20, 2026
@Rangi42

Rangi42 commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

Note, even if this isn't solving the issue I was trying to solve, I like the use of add_compile_definitions(_CRT_SECURE_NO_WARNINGS) (abstracts out the /D) and reformatting the indentation of long warning options.

@Rangi42
Rangi42 force-pushed the cmake-target-specific branch 2 times, most recently from efa1edd to d74efae Compare November 20, 2026 18:14

@ISSOtm ISSOtm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, that is not breaking due to our -Werror=undef, it's CMake attempting to compile files internal to libstdc++ that aren't meant to be compiled stand-alone. Please leave the compile option logic as-is, but if you want to make formatting changes, I'll be happy to merge them :)

I'll investigate the CMake issue, but I think it's a CMake bug, not our fault.

@Rangi42
Rangi42 force-pushed the cmake-target-specific branch from d74efae to b1a3138 Compare November 21, 2026 03:35
@Rangi42
Rangi42 requested a review from ISSOtm November 21, 2026 03:37
@Rangi42

Rangi42 commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor Author

Thank you for testing on your own machine and narrowing the cause down to C++ modules! Glad it turned out to be a one-line fix. (Or workaround, since it's CMake's bug.)

@Rangi42
Rangi42 merged commit d510d93 into gbdev:master Nov 21, 2026
31 checks passed
@Rangi42
Rangi42 deleted the cmake-target-specific branch November 21, 2026 03:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

builds This affects the build process or release artifacts meta This isn't related to the tools directly: repo organization, maintainership...

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants