Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CMake build mode flags to hdf5lib.settings #4816

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions config/cmake/HDF5DeveloperBuild.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@ set (CMAKE_CXX_FLAGS_DEVELOPER ${CMAKE_CXX_FLAGS_DEBUG} CACHE STRING
"Flags used by the C++ compiler during developer builds." FORCE
)

# Set CMake C flags based off of Debug build flags. Add in -Og
# option to disable some GCC optimizations that might affect
# debugging negatively and also include some GCC compiler passes
# that collect debugging information
set (CMAKE_C_FLAGS_DEVELOPER "${CMAKE_C_FLAGS_DEBUG} -Og" CACHE STRING
# Set CMake C flags based off of Debug build flags
set (CMAKE_C_FLAGS_DEVELOPER "${CMAKE_C_FLAGS_DEBUG}" CACHE STRING
Copy link
Member Author

Choose a reason for hiding this comment

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

This is already set in the debug flags

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is CMAKE_C_FLAGS_DEBUG, which will only capture the debug flags that are added by default by CMake, or explicitly added at configure time by the user. Not the flags that we add separately in the library's configuration.

Copy link
Collaborator

@jhendersonHDF jhendersonHDF Sep 9, 2024

Choose a reason for hiding this comment

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

That said, some compilers don't have -Og, so this does need to be refactored at some point, but I still find it useful.

"Flags used by the C compiler during developer builds." FORCE
)

Expand Down
30 changes: 30 additions & 0 deletions config/cmake/HDFCompilerFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -465,3 +465,33 @@ if (HDF5_ENABLE_OPTIMIZATION)
list (APPEND HDF5_CMAKE_C_FLAGS "${OPTIMIZE_CFLAGS}")
endif ()
MARK_AS_ADVANCED (HDF5_ENABLE_OPTIMIZATION)

#-----------------------------------------------------------------------------
# The build mode flags are not added to CMAKE_C_FLAGS, so create a separate
# variable for them so they can be written out to libhdf5.settings and
# H5build_settings.c
#-----------------------------------------------------------------------------
set (HDF5_BUILD_MODE_C_FLAGS "")
set (HDF5_BUILD_MODE_Fortran_FLAGS "")
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't the Fortran and CXX flags be set in the HDFFortranCompilerFlags.cmake and HDFCXXCompilerFlags.cmake files?

Copy link
Member Author

Choose a reason for hiding this comment

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

I can do that

set (HDF5_BUILD_MODE_CXX_FLAGS "")
if ("${HDF_CFG_NAME}" STREQUAL "Debug")
set (HDF5_BUILD_MODE_C_FLAGS "${CMAKE_C_FLAGS_DEBUG}")
set (HDF5_BUILD_MODE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS_DEBUG}")
set (HDF5_BUILD_MODE_CXX_FLAGS "${CMAKE_CXX_FLAGS_DEBUG}")
elseif ("${HDF_CFG_NAME}" STREQUAL "Developer")
set (HDF5_BUILD_MODE_C_FLAGS "${CMAKE_C_FLAGS_DEVELOPER}")
set (HDF5_BUILD_MODE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS_DEBUG}")
set (HDF5_BUILD_MODE_CXX_FLAGS "${CMAKE_CXX_FLAGS_DEBUG}")
elseif ("${HDF_CFG_NAME}" STREQUAL "Release")
set (HDF5_BUILD_MODE_C_FLAGS "${CMAKE_C_FLAGS_RELEASE}")
set (HDF5_BUILD_MODE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS_RELEASE}")
set (HDF5_BUILD_MODE_CXX_FLAGS "${CMAKE_CXX_FLAGS_RELEASE}")
elseif ("${HDF_CFG_NAME}" STREQUAL "MinSizeRel")
set (HDF5_BUILD_MODE_C_FLAGS "${CMAKE_C_FLAGS_MINSIZEREL}")
set (HDF5_BUILD_MODE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS_MINSIZEREL}")
set (HDF5_BUILD_MODE_CXX_FLAGS "${CMAKE_CXX_FLAGS_MINSIZEREL}")
elseif ("${HDF_CFG_NAME}" STREQUAL "RelWithDebInfo")
set (HDF5_BUILD_MODE_C_FLAGS "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
set (HDF5_BUILD_MODE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS_RELWITHDEBINFO}")
set (HDF5_BUILD_MODE_CXX_FLAGS "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
endif ()
11 changes: 11 additions & 0 deletions release_docs/RELEASE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1767,6 +1767,17 @@ Bug Fixes since HDF5-1.14.0 release

Configuration
-------------
- Added CMake build mode flags to the libhdf5.settings file

Flags from the CMake build mode (e.g., optimization) are not a part of
CMAKE_<language>_FLAGS and were not exported to the libhdf5.settings file. This
has been fixed and the C, Fortran, and C++ build mode flags are now exported to
the file.

This also affects the text output of H5check_version() and the libhdf5.settings
string stored in the library (for those who use strings(1), etc. to get
build info from the binary).

- Changed name of libhdf5hl_fortran installed by autotools to libhdf5_hl_fortran. The
new name is consistent with the name of the lib when installed by CMake and with the
other hl libs.
Expand Down
6 changes: 3 additions & 3 deletions src/H5build_settings.cmake.c.in
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const char H5build_settings[]=
" CPPFLAGS: @CPPFLAGS@\n"
" H5_CPPFLAGS: @H5_CPPFLAGS@\n"
" AM_CPPFLAGS: @AM_CPPFLAGS@\n"
" C Flags: @CMAKE_C_FLAGS@\n"
" C Flags: @CMAKE_C_FLAGS@ @HDF5_BUILD_MODE_C_FLAGS@\n"
" H5 C Flags: @HDF5_CMAKE_C_FLAGS@\n"
" AM C Flags: @AM_CFLAGS@\n"
" Shared C Library: @H5_ENABLE_SHARED_LIB@\n"
Expand All @@ -65,7 +65,7 @@ const char H5build_settings[]=
"\n"
" Fortran: @HDF5_BUILD_FORTRAN@\n"
" Fortran Compiler: @CMAKE_Fortran_COMPILER@ @CMAKE_Fortran_COMPILER_VERSION@\n"
" Fortran Flags: @CMAKE_Fortran_FLAGS@\n"
" Fortran Flags: @CMAKE_Fortran_FLAGS@ @HDF5_BUILD_MODE_Fortran_FLAGS@\n"
" H5 Fortran Flags: @HDF5_CMAKE_Fortran_FLAGS@\n"
" AM Fortran Flags: @AM_FCFLAGS@\n"
" Shared Fortran Library: @H5_ENABLE_SHARED_LIB@\n"
Expand All @@ -74,7 +74,7 @@ const char H5build_settings[]=
"\n"
" C++: @HDF5_BUILD_CPP_LIB@\n"
" C++ Compiler: @CMAKE_CXX_COMPILER@ @CMAKE_CXX_COMPILER_VERSION@\n"
" C++ Flags: @CMAKE_CXX_FLAGS@\n"
" C++ Flags: @CMAKE_CXX_FLAGS@ @HDF5_BUILD_MODE_CXX_FLAGS@\n"
" H5 C++ Flags: @HDF5_CMAKE_CXX_FLAGS@\n"
" AM C++ Flags: @AM_CXXFLAGS@\n"
" Shared C++ Library: @H5_ENABLE_SHARED_LIB@\n"
Expand Down
6 changes: 3 additions & 3 deletions src/libhdf5.settings.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ Languages:
CPPFLAGS: @CPPFLAGS@
H5_CPPFLAGS: @H5_CPPFLAGS@
AM_CPPFLAGS: @AM_CPPFLAGS@
CFLAGS: @CMAKE_C_FLAGS@
CFLAGS: @CMAKE_C_FLAGS@ @HDF5_BUILD_MODE_C_FLAGS@
H5_CFLAGS: @HDF5_CMAKE_C_FLAGS@
AM_CFLAGS: @AM_CFLAGS@
Shared C Library: @H5_ENABLE_SHARED_LIB@
Static C Library: @H5_ENABLE_STATIC_LIB@

Fortran: @HDF5_BUILD_FORTRAN@
Fortran Compiler: @CMAKE_Fortran_COMPILER@ @CMAKE_Fortran_COMPILER_VERSION@
Fortran Flags: @CMAKE_Fortran_FLAGS@
Fortran Flags: @CMAKE_Fortran_FLAGS@ @HDF5_BUILD_MODE_Fortran_FLAGS@
H5 Fortran Flags: @HDF5_CMAKE_Fortran_FLAGS@
AM Fortran Flags: @AM_FCFLAGS@
Shared Fortran Library: @H5_ENABLE_SHARED_LIB@
Expand All @@ -55,7 +55,7 @@ Languages:

C++: @HDF5_BUILD_CPP_LIB@
C++ Compiler: @CMAKE_CXX_COMPILER@ @CMAKE_CXX_COMPILER_VERSION@
C++ Flags: @CMAKE_CXX_FLAGS@
C++ Flags: @CMAKE_CXX_FLAGS@ @HDF5_BUILD_MODE_CXX_FLAGS@
H5 C++ Flags: @HDF5_CMAKE_CXX_FLAGS@
AM C++ Flags: @AM_CXXFLAGS@
Shared C++ Library: @H5_ENABLE_SHARED_LIB@
Expand Down
Loading