# Compile options not being applied to modules

**URL:** https://discourse.cmake.org/t/compile-options-not-being-applied-to-modules/13727
**Category:** Development
**Tags:** gen:ninja
**Created:** [March 12, 2025, 1:55am UTC](https://discourse.cmake.org/t/compile-options-not-being-applied-to-modules/13727 "2025-03-12T01:55:09Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![mmoult](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mmoult/32/4408_2.png) [@mmoult](https://discourse.cmake.org/u/mmoult)
#### Post date: [March 12, 2025, 1:55am UTC](https://discourse.cmake.org/t/compile-options-not-being-applied-to-modules/13727/1 "2025-03-12T01:55:09Z")

</div>

I believe that I have encountered a bug in CMake. I am using C++ modules, and target\_compile\_options or compile\_options are only being applied to the regular C++ files, not the module files (as observed through the compile\_commands.json).

Interestingly enough, the options set through add\_compile\_definitions were applied to both file types.

I started debugging the issue and noticed divergence at `target->GetCompileOptions(config, lang)` The config and lang were the same, but the target objects were different. This is not what I expected both types of sources were connected to the same “target” as per CMake.

I don’t think this problem is exclusive to Ninja, but I am using Ninja, which is why I have filed this as such.

I am happy to provide a minimal error case, but I don’t see a good way to do that with this text-based interface. Maybe I could provide a zip or tar.gz of the files I have?

If you will forgive the style errors, this is the most important part:

```auto
cmake_minimum_required(VERSION 3.28)

add_library(test)

# Add module interface files
target_sources(test
  PUBLIC
    FILE_SET CXX_MODULES FILES
      ternary.cxx
)
# Add other source files
target_sources(test
  PUBLIC
    trie.cpp
)

string(TIMESTAMP TODAY "%Y-%m-%d")
message(STATUS "Current build date: ${TODAY}")

add_compile_definitions("UNIVERSAL")
add_compile_options("-DDATE_OPTION=${TODAY}")

add_executable(testo main.cpp)
set_target_properties(testo PROPERTIES OUTPUT_NAME "modules-test")
target_compile_options(testo PUBLIC "-DDATE_TARGET=${TODAY}")
target_compile_options(testo PUBLIC "$<$<CONFIG:DEBUG>:-Wall>")
target_link_libraries(testo test)
install(TARGETS testo)

```

“UNIVERSAL” is defined for all files as expected. However, `-DDATE_OPTION`, `-DDATE_TARGET`, and `-Wall` are only specified for `main.cpp` and `trie.cpp`. They are not provided for `ternary.cxx` as expected.
