Skip to content

Introduced CMake options for the Fortran-API and compiler warnings - #299

Closed
Niklas997 wants to merge 11 commits into
trixi-framework:mainfrom
Niklas997:main
Closed

Niklas997 wants to merge 11 commits into
trixi-framework:mainfrom
Niklas997:main

Conversation

@Niklas997

Copy link
Copy Markdown

Thank you for developing libtrixi! I wanted to use it with t8code and only needed the C-interface, therefore, I added some CMake-Options to exclude building the Fortran-interface. Additionally, the -Wall -Wextra -Werror options have been set obligatory, which has led to errors for me (Ubuntu 24.04. (WSL2), GCC-Version: 13.3.0) due to some unused parameters in the garbage-collection-interface, e.g. "~/.julia/juliaup/julia-1.12.2+0.x64.linux.gnu/include/julia/gc-interface.h:243:47: warning: unused parameter ‘parent’ [-Wunused-parameter]", which is why I added some switches for those options as well.

The following options with the given default values have been introduced: LIBTRIXI_BUILD_FORTRAN_API=ON; LIBTRIXI_WITH_T8CODE=OFF; LIBTRIXI_ENABLE_WARNINGS=OFF; LIBTRIXI_ENABLE_WERROR=OFF; LIBTRIXI_ENABLE_TESTING=OFF
Maybe the changes are interesting for libtrixi, but I am not sure, if I covered everything and if that is the intended way for libtrixi.

@benegee benegee left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks a lot for your contribution @Niklas997 !

I like the added options! About the warning I am not sure yet.

Comment thread examples/CMakeLists.txt Outdated
Comment thread CMakeLists.txt
Comment thread README.md
Comment thread README.md Outdated
Comment thread examples/CMakeLists.txt Outdated
Comment thread README.md Outdated

@benegee benegee left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Oh no, I just realized one of my comments was still pending in github. @Niklas997

Comment thread README.md
or debug code.
- By default the Fortran-Interface is built; it may be excluded with `DLIBTRIXI_BUILD_FORTRAN_API=OFF`.
- Optional compiler options `-Wall -Wextra` are specified with `-DLIBTRIXI_ENABLE_WARNINGS=ON`.
- Optional compiler option `-Werror` is specified with `-DLIBTRIXI_ENABLE_WERROR=ON`.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

So far, we have been very strict with respect to warning, because we could. I would thus like to keep it this way, or at least have them on by default.

Regarding the Julia 1.12 issue: #259 (comment)
Currently I would set -DCMAKE_C_FLAGS="-Wno-error=unused-parameter" when running cmake.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Any strong opinions on this @sloede ?

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.

See my reply above

@codecov

codecov Bot commented Jul 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.11%. Comparing base (3fb7a70) to head (04737e9).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #299   +/-   ##
=======================================
  Coverage   96.11%   96.11%           
=======================================
  Files          25       25           
  Lines        1260     1260           
  Branches       74       74           
=======================================
  Hits         1211     1211           
  Misses         45       45           
  Partials        4        4           
Flag Coverage Δ
unittests 96.11% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread README.md
- Optional specification of build type sets some default compiler options for optimized
or debug code.
- Building with t8code support is optional. It requires to pass
- By default the Fortran-Interface is built; it may be excluded with `DLIBTRIXI_BUILD_FORTRAN_API=OFF`.

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.

Suggested change
- By default the Fortran-Interface is built; it may be excluded with `DLIBTRIXI_BUILD_FORTRAN_API=OFF`.
- By default the Fortran-Interface is built; it may be excluded with `-DLIBTRIXI_BUILD_FORTRAN_API=OFF`.

Comment thread CMakeLists.txt
Comment on lines 166 to 167
# Include directories
target_include_directories( ${PROJECT_NAME} PRIVATE src ${JULIA_INCLUDE_DIRS} )

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.

Suggested change
# Include directories
target_include_directories( ${PROJECT_NAME} PRIVATE src ${JULIA_INCLUDE_DIRS} )
# Include directories
# PRIVATE: Do not include internal directory in projects building against libtrixi
# SYSTEM: Disable warnings/error from upstream libraries
target_include_directories( ${PROJECT_NAME} PRIVATE src )
target_include_directories( ${PROJECT_NAME} SYSTEM PRIVATE ${JULIA_INCLUDE_DIRS} )

Instead of disabling warnings/errors, I recommend to just mark the Julia include dirs as "SYSTEM" includes such that GCC/Clang suppress warnings on them (see also the CMake docs.

If this works as expected, I'd also recommend reverting the option of disabling warnings/errors: In practice this leads too often to issues that remain unfixed, and if the "SYSTEM" switch suppresses the warning, we can remove a lot of code complexity from the build system again

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Checked in #319 where I also switched to Julia 1.12, which caused the warnings. It seems to work!

Comment thread README.md
or debug code.
- By default the Fortran-Interface is built; it may be excluded with `DLIBTRIXI_BUILD_FORTRAN_API=OFF`.
- Optional compiler options `-Wall -Wextra` are specified with `-DLIBTRIXI_ENABLE_WARNINGS=ON`.
- Optional compiler option `-Werror` is specified with `-DLIBTRIXI_ENABLE_WERROR=ON`.

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.

See my reply above

Comment thread CMakeLists.txt
# Enable C and Fortran
enable_language(C Fortran)
# Additional configuration options
option( LIBTRIXI_BUILD_FORTRAN_API "Enable the build of the Fortran interface" ON )

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.

If this is added as an option, you could think about adding also a test - or at least a smoke test - to ensure that builds still succeed with the Fortran interface turned off (I don't think running tests is necessary). It's not super high priority though, so you might also skip the tests 🤷‍♂️

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Done in #319

Comment thread CMakeLists.txt
add_library ( ${PROJECT_NAME}_tls OBJECT
src/tls.c
)
target_include_directories( ${PROJECT_NAME}_tls PRIVATE ${JULIA_INCLUDE_DIRS} )

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.

Suggested change
target_include_directories( ${PROJECT_NAME}_tls PRIVATE ${JULIA_INCLUDE_DIRS} )
target_include_directories( ${PROJECT_NAME}_tls SYSTEM PRIVATE ${JULIA_INCLUDE_DIRS} ))

As above

@benegee

benegee commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator

@Niklas997 We just merged #319, which allows to disable the Fortran tests.

Regarding the warning we introduced cmake's SYSTEM keyword. If this is fine with you, we can close this PR-

@benegee benegee closed this Oct 15, 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.

4 participants