Skip to content

Do not leak compile options outside project#1030

Closed
vocasle wants to merge 1 commit intozeux:masterfrom
vocasle:master
Closed

Do not leak compile options outside project#1030
vocasle wants to merge 1 commit intozeux:masterfrom
vocasle:master

Conversation

@vocasle
Copy link

@vocasle vocasle commented Mar 18, 2026

This change reduces the scope of compile options from other CMake targets and applies them only to targets defined in root CMakeLists.txt.

add_compile_options sets compile options to all CMake targets.
target_compile_options allows to narrow the scope to targets defined in root CMakeLists.txt.

@zeux
Copy link
Owner

zeux commented Mar 18, 2026

add_compile_options sets compile options to all CMake targets

I was under the impression that this is already scoped to targets defined in the folder (/subdirectories) of the current CMakeLists file? Iow it should not propagate to targets defined outside of meshoptimizer source.

@vocasle
Copy link
Author

vocasle commented Mar 18, 2026

My apologies. I was looking for the root cause of-Wmissing-field-initializer propagating to error and stumbled upon -Wno-missing-field-initializer, but failed to notice Wno.

This is an excerpt from compile_commands.json of executable that links with meshoptimizer, the executable does not contain any compile flags from meshoptimizer :

{
  "directory": "/Users/user/Source/meshopt-leaking-compile-options/build",
  "command": "/usr/bin/c++  -I/Users/user/Source/meshopt-leaking-compile-options/meshoptimizer/src  -arch arm64 -o CMakeFiles/test.dir/test.cpp.o -c /Users/user/Source/meshopt-leaking-compile-options/test.cpp",
  "file": "/Users/user/Source/meshopt-leaking-compile-options/test.cpp",
  "output": "CMakeFiles/test.dir/test.cpp.o"
},
{
  "directory": "/Users/user/Source/meshopt-leaking-compile-options/build/meshoptimizer",
  "command": "/usr/bin/c++    -arch arm64 -Wall -Wextra -Wshadow -Wno-missing-field-initializers -o CMakeFiles/meshoptimizer.dir/src/allocator.cpp.o -c /Users/user/Source/meshopt-leaking-compile-options/meshoptimizer/src/allocator.cpp",
  "file": "/Users/user/Source/meshopt-leaking-compile-options/meshoptimizer/src/allocator.cpp",
  "output": "meshoptimizer/CMakeFiles/meshoptimizer.dir/src/allocator.cpp.o"
}

Sorry for the hustle.
Closing PR.

@vocasle vocasle closed this Mar 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants