Skip to content

Draft: CMake improvements#248

Open
caitlinross wants to merge 15 commits into
masterfrom
cmake-improvements
Open

Draft: CMake improvements#248
caitlinross wants to merge 15 commits into
masterfrom
cmake-improvements

Conversation

@caitlinross

Copy link
Copy Markdown
Member

No description provided.

- convert global add_definitions(-DUSE_*) to target_compile_definitions on codes
- drop redundant CMAKE_C_FLAGS include appends (already covered by target_include_directories)
- executables/tests inherit includes + libs transitively by linking codes
The various dependencies had some inconsistencies in how they were
handled. Some if found in PATH, could not be turned off. Now all have
three possible states: AUTO, ON, OFF. All are AUTO by default meaning
that we will attempt to find them and if found, build with them. If a
dependency is not found, there is no error or warning, we just build
without it. If a dependency is set to OFF, it won't be looked for at
all, and if a dependency is set to ON and not found, an error will be
given.

Also changed naming from USE_* to CODES_USE_* to prevent any collisions
with other projects that may use CODES.
Optional-dependency state (DUMPI, ONLINE, SWM, UNION, RECORDER, TORCH,
ZEROMQ, DARSHAN) was carried as bare -DUSE_<X> defines added PUBLIC to the
codes target, so every one of those names leaked onto the command line of
everything that links codes. That approach had two real problems:

  - The names are generic and unnamespaced. USE_ONLINE / USE_TORCH and the
    like can collide with whatever a downstream project defines, and
    USE_ONLINE was already baked into an installed public header
    (codes-workload.h) -- so the leak was part of our public surface.
  - #ifdef tests existence, not value. A stray -DUSE_X=0 would *enable* the
    feature, and any source that forgot the define or typo'd it silently
    compiled the feature off, with no diagnostic at all.

Instead, generate a single namespaced header (codes_config.h) defining
CODES_HAVE_<X> to 0/1 for each optional subsystem, install it alongside the
public headers, and query it with `#if CODES_HAVE_<X>`. Build CODES's own
targets with -Wundef.

This is strictly better than the old scheme: feature availability is
namespaced (no clashes), it lives in one installed header consumers can
actually query instead of an invisible command-line contract, and nothing
leaks onto consumer compile lines. The `#if` + -Wundef combination turns the
classic preprocessor foot-guns -- forgotten include, typo'd macro, -DFOO=0
-- into compile-time warnings rather than a silently mis-built feature.
CODES installed a static library and headers but no CMake package, so a
downstream model had no way to find_package(codes) -- it had to hard-code
CODES's include and library paths (and ROSS's, and MPI's) by hand, or vendor
the tree. That is exactly the fragile, manual coupling the rest of this
effort has been removing everywhere else.

This adds a namespaced install(EXPORT) that generates codesConfig.cmake and a
codes::codes imported target, mirroring how ROSS already exposes ROSS::ROSS
(and how CODES now consumes ROSS). A consumer does

    find_package(codes REQUIRED)
    target_link_libraries(mymodel PRIVATE codes::codes)

and inherits CODES's public include dirs plus its ROSS / MPI usage
requirements transitively -- no bespoke CODES_INCLUDE_DIRS / CODES_LIBRARIES
variables, no knowing where ROSS lives. The config re-resolves the
dependencies CODES links (find_dependency for ROSS and MPI C/CXX).

To keep the exported target relocatable, the library's public include
interface moves to BUILD_INTERFACE / INSTALL_INTERFACE generator
expressions: in-tree builds see the source/binary dirs, installed consumers
get <prefix>/include and <prefix>/include/codes, and no build-machine path
leaks into the installed codesTargets.cmake. Verified with a standalone
find_package(codes) consumer that links codes::codes and compiles a CODES
header.
@caitlinross caitlinross force-pushed the cmake-improvements branch 2 times, most recently from d9a58c3 to 5838ec3 Compare June 23, 2026 22:07
@codecov

codecov Bot commented Jun 23, 2026

Copy link
Copy Markdown

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

ℹ️ You can also turn on project coverage checks and project coverage reporting on Pull Request comment

Thanks for integrating Codecov - We've got you covered ☂️

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.

1 participant