From 6122828198f896849fe12c988bd374502731a5b0 Mon Sep 17 00:00:00 2001 From: Allen Byrne <50328838+byrnHDF@users.noreply.github.com> Date: Fri, 25 Oct 2024 10:03:35 -0500 Subject: [PATCH] Split out compiler flags into specific compiler files (#4974) * Split CMake HDFCompileFlags into specific compiler files * Separate out CXX Flags * Add Fortran compiler specific files * Merge in #4816 changes and close #4816 * fix hanging endif --------- Co-authored-by: Larry Knox --- .github/workflows/cmake-analysis.yml | 8 +- .github/workflows/cmake-script.yml | 14 +- CMakeLists.txt | 4 +- config/cmake/HDFCXXCompilerFlags.cmake | 362 --------------------- config/cmake/HDFClangCXXFlags.cmake | 52 +++ config/cmake/HDFClangFlags.cmake | 73 +++++ config/cmake/HDFCompilerCXXFlags.cmake | 162 +++++++++ config/cmake/HDFCompilerFlags.cmake | 292 +++-------------- config/cmake/HDFCompilerFortranFlags.cmake | 86 +++++ config/cmake/HDFFortranCompilerFlags.cmake | 158 --------- config/cmake/HDFGnuCXXFlags.cmake | 192 +++++++++++ config/cmake/HDFGnuFlags.cmake | 195 +++++++++++ config/cmake/HDFGnuFortranFlags.cmake | 90 +++++ config/cmake/HDFIntelCXXFlags.cmake | 93 ++++++ config/cmake/HDFIntelFlags.cmake | 106 ++++++ config/cmake/HDFIntelFortranFlags.cmake | 65 ++++ config/cmake/HDFMsvcCXXFlags.cmake | 26 ++ config/cmake/HDFMsvcFlags.cmake | 25 ++ config/cmake/HDFNvhpcCXXFlags.cmake | 33 ++ config/cmake/HDFNvhpcFlags.cmake | 28 ++ config/cmake/HDFNvhpcFortranFlags.cmake | 38 +++ release_docs/RELEASE.txt | 18 + src/H5build_settings.cmake.c.in | 6 +- src/libhdf5.settings.cmake.in | 6 +- 24 files changed, 1345 insertions(+), 787 deletions(-) delete mode 100644 config/cmake/HDFCXXCompilerFlags.cmake create mode 100644 config/cmake/HDFClangCXXFlags.cmake create mode 100644 config/cmake/HDFClangFlags.cmake create mode 100644 config/cmake/HDFCompilerCXXFlags.cmake create mode 100644 config/cmake/HDFCompilerFortranFlags.cmake delete mode 100644 config/cmake/HDFFortranCompilerFlags.cmake create mode 100644 config/cmake/HDFGnuCXXFlags.cmake create mode 100644 config/cmake/HDFGnuFlags.cmake create mode 100644 config/cmake/HDFGnuFortranFlags.cmake create mode 100644 config/cmake/HDFIntelCXXFlags.cmake create mode 100644 config/cmake/HDFIntelFlags.cmake create mode 100644 config/cmake/HDFIntelFortranFlags.cmake create mode 100644 config/cmake/HDFMsvcCXXFlags.cmake create mode 100644 config/cmake/HDFMsvcFlags.cmake create mode 100644 config/cmake/HDFNvhpcCXXFlags.cmake create mode 100644 config/cmake/HDFNvhpcFlags.cmake create mode 100644 config/cmake/HDFNvhpcFortranFlags.cmake diff --git a/.github/workflows/cmake-analysis.yml b/.github/workflows/cmake-analysis.yml index 36dea0dc39e..a978205b303 100644 --- a/.github/workflows/cmake-analysis.yml +++ b/.github/workflows/cmake-analysis.yml @@ -106,7 +106,7 @@ jobs: - name: Run ctest (Linux_coverage) run: | cd "${{ runner.workspace }}/hdf5" - ctest -S HDF5config.cmake,CTEST_SITE_EXT=GH_COV,LOCAL_SUBMIT=ON,NINJA=TRUE,BUILD_GENERATOR=Unix,CTEST_SOURCE_NAME=${{ steps.set-file-base.outputs.SOURCE_BASE }} -C Debug -VV -O hdf5.log + ctest -S HDF5config.cmake,CTEST_SITE_EXT=${{ github.event.repository.full_name }}_COV,LOCAL_SUBMIT=ON,NINJA=TRUE,BUILD_GENERATOR=Unix,CTEST_SOURCE_NAME=${{ steps.set-file-base.outputs.SOURCE_BASE }} -C Debug -VV -O hdf5.log shell: bash continue-on-error: true @@ -206,7 +206,7 @@ jobs: - name: Run ctest (Linux_Leak) run: | cd "${{ runner.workspace }}/hdf5" - ctest -S HDF5config.cmake,CTEST_SITE_EXT=GH-LEAK,LOCAL_SUBMIT=ON,NINJA=TRUE,BUILD_GENERATOR=Unix,CTEST_SOURCE_NAME=${{ steps.set-file-base.outputs.SOURCE_BASE }} -C Debug -VV -O hdf5.log + ctest -S HDF5config.cmake,CTEST_SITE_EXT=${{ github.event.repository.full_name }}-LEAK,LOCAL_SUBMIT=ON,NINJA=TRUE,BUILD_GENERATOR=Unix,CTEST_SOURCE_NAME=${{ steps.set-file-base.outputs.SOURCE_BASE }} -C Debug -VV -O hdf5.log shell: bash continue-on-error: true @@ -306,7 +306,7 @@ jobs: - name: Run ctest (Linux_Address) run: | cd "${{ runner.workspace }}/hdf5" - ctest -S HDF5config.cmake,CTEST_SITE_EXT=GH-ADDR,LOCAL_SUBMIT=ON,NINJA=TRUE,BUILD_GENERATOR=Unix,CTEST_SOURCE_NAME=${{ steps.set-file-base.outputs.SOURCE_BASE }} -C Debug -VV -O hdf5.log + ctest -S HDF5config.cmake,CTEST_SITE_EXT=${{ github.event.repository.full_name }}-ADDR,LOCAL_SUBMIT=ON,NINJA=TRUE,BUILD_GENERATOR=Unix,CTEST_SOURCE_NAME=${{ steps.set-file-base.outputs.SOURCE_BASE }} -C Debug -VV -O hdf5.log shell: bash continue-on-error: true @@ -406,7 +406,7 @@ jobs: - name: Run ctest (Linux_UndefinedBehavior) run: | cd "${{ runner.workspace }}/hdf5" - ctest -S HDF5config.cmake,CTEST_SITE_EXT=GH-UNDEF,LOCAL_SUBMIT=ON,NINJA=TRUE,BUILD_GENERATOR=Unix,CTEST_SOURCE_NAME=${{ steps.set-file-base.outputs.SOURCE_BASE }} -C Debug -VV -O hdf5.log + ctest -S HDF5config.cmake,CTEST_SITE_EXT=${{ github.event.repository.full_name }}-UNDEF,LOCAL_SUBMIT=ON,NINJA=TRUE,BUILD_GENERATOR=Unix,CTEST_SOURCE_NAME=${{ steps.set-file-base.outputs.SOURCE_BASE }} -C Debug -VV -O hdf5.log shell: bash continue-on-error: true diff --git a/.github/workflows/cmake-script.yml b/.github/workflows/cmake-script.yml index f30504f10da..617eb4b0236 100644 --- a/.github/workflows/cmake-script.yml +++ b/.github/workflows/cmake-script.yml @@ -111,7 +111,7 @@ jobs: - name: Run ctest script (Windows) run: | cd "${{ runner.workspace }}/hdf5" - ctest -S HDF5config.cmake,CTEST_SITE_EXT=GH,LOCAL_SUBMIT=ON,NINJA=TRUE,BUILD_GENERATOR=VS202264,CTEST_SOURCE_NAME=${{ steps.set-file-base.outputs.SOURCE_BASE }} -C Release -VV -O hdf5.log + ctest -S HDF5config.cmake,CTEST_SITE_EXT=${{ github.event.repository.full_name }},LOCAL_SUBMIT=ON,NINJA=TRUE,BUILD_GENERATOR=VS202264,CTEST_SOURCE_NAME=${{ steps.set-file-base.outputs.SOURCE_BASE }} -C Release -VV -O hdf5.log shell: bash continue-on-error: true @@ -200,7 +200,7 @@ jobs: - name: Run ctest (Linux) run: | cd "${{ runner.workspace }}/hdf5" - ctest -S HDF5config.cmake,CTEST_SITE_EXT=GH-GCC,LOCAL_SUBMIT=ON,NINJA=TRUE,BUILD_GENERATOR=Unix,CTEST_SOURCE_NAME=${{ steps.set-file-base.outputs.SOURCE_BASE }} -C Release -VV -O hdf5.log + ctest -S HDF5config.cmake,CTEST_SITE_EXT=${{ github.event.repository.full_name }}-GCC,LOCAL_SUBMIT=ON,NINJA=TRUE,BUILD_GENERATOR=Unix,CTEST_SOURCE_NAME=${{ steps.set-file-base.outputs.SOURCE_BASE }} -C Release -VV -O hdf5.log shell: bash continue-on-error: true @@ -302,7 +302,7 @@ jobs: id: run-ctest run: | cd "${{ runner.workspace }}/hdf5" - ctest -S HDF5config.cmake,CTEST_SITE_EXT=GH-Clang,LOCAL_SUBMIT=ON,NINJA=TRUE,BUILD_GENERATOR=Unix,CTEST_SOURCE_NAME=${{ steps.set-file-base.outputs.SOURCE_BASE }} -C Release -VV -O hdf5.log + ctest -S HDF5config.cmake,CTEST_SITE_EXT=${{ github.event.repository.full_name }}-Clang,LOCAL_SUBMIT=ON,NINJA=TRUE,BUILD_GENERATOR=Unix,CTEST_SOURCE_NAME=${{ steps.set-file-base.outputs.SOURCE_BASE }} -C Release -VV -O hdf5.log shell: bash continue-on-error: true @@ -387,7 +387,7 @@ jobs: - name: Run ctest (Linux S3) run: | cd "${{ runner.workspace }}/hdf5" - ctest -S HDF5config.cmake,CTEST_SITE_EXT=GH-S3,LOCAL_SUBMIT=ON,NINJA=TRUE,BUILD_GENERATOR=Unix,CTEST_SOURCE_NAME=${{ steps.set-file-base.outputs.SOURCE_BASE }} -C Release -VV -O hdf5.log + ctest -S HDF5config.cmake,CTEST_SITE_EXT=${{ github.event.repository.full_name }}-S3,LOCAL_SUBMIT=ON,NINJA=TRUE,BUILD_GENERATOR=Unix,CTEST_SOURCE_NAME=${{ steps.set-file-base.outputs.SOURCE_BASE }} -C Release -VV -O hdf5.log shell: bash continue-on-error: true @@ -493,7 +493,7 @@ jobs: CXX: ${{ steps.setup-fortran.outputs.cc }} run: | cd "${{ runner.workspace }}/hdf5" - ctest -S HDF5config.cmake,CTEST_SITE_EXT=GH-Intel,LOCAL_SUBMIT=ON,NINJA=TRUE,BUILD_GENERATOR=VS202264,CTEST_SOURCE_NAME=${{ steps.set-file-base.outputs.SOURCE_BASE }} -C Release -VV -O hdf5.log + ctest -S HDF5config.cmake,CTEST_SITE_EXT=${{ github.event.repository.full_name }}-Intel,LOCAL_SUBMIT=ON,NINJA=TRUE,BUILD_GENERATOR=VS202264,CTEST_SOURCE_NAME=${{ steps.set-file-base.outputs.SOURCE_BASE }} -C Release -VV -O hdf5.log shell: pwsh continue-on-error: true @@ -588,7 +588,7 @@ jobs: CXX: ${{ steps.setup-fortran.outputs.cxx }} run: | cd "${{ runner.workspace }}/hdf5" - ctest -S HDF5config.cmake,CTEST_SITE_EXT=GH-Intel,LOCAL_SUBMIT=ON,NINJA=TRUE,BUILD_GENERATOR=Unix,CTEST_SOURCE_NAME=${{ steps.set-file-base.outputs.SOURCE_BASE }} -C Release -VV -O hdf5.log + ctest -S HDF5config.cmake,CTEST_SITE_EXT=${{ github.event.repository.full_name }}-Intel,LOCAL_SUBMIT=ON,NINJA=TRUE,BUILD_GENERATOR=Unix,CTEST_SOURCE_NAME=${{ steps.set-file-base.outputs.SOURCE_BASE }} -C Release -VV -O hdf5.log shell: bash continue-on-error: true @@ -682,7 +682,7 @@ jobs: - name: Run ctest (Linux_clang) run: | cd "${{ runner.workspace }}/hdf5" - ctest -S HDF5config.cmake,CTEST_SITE_EXT=GH-Clang,LOCAL_SUBMIT=ON,NINJA=TRUE,BUILD_GENERATOR=Unix,CTEST_SOURCE_NAME=${{ steps.set-file-base.outputs.SOURCE_BASE }} -C Release -VV -O hdf5.log + ctest -S HDF5config.cmake,CTEST_SITE_EXT=${{ github.event.repository.full_name }}-Clang,LOCAL_SUBMIT=ON,NINJA=TRUE,BUILD_GENERATOR=Unix,CTEST_SOURCE_NAME=${{ steps.set-file-base.outputs.SOURCE_BASE }} -C Release -VV -O hdf5.log shell: bash continue-on-error: true diff --git a/CMakeLists.txt b/CMakeLists.txt index 1a60d9c0c5c..863b8561a67 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1133,7 +1133,7 @@ if (EXISTS "${HDF5_SOURCE_DIR}/fortran" AND IS_DIRECTORY "${HDF5_SOURCE_DIR}/for option (HDF5_BUILD_FORTRAN "Build FORTRAN support" OFF) if (HDF5_BUILD_FORTRAN) message (VERBOSE "Fortran compiler ID is ${CMAKE_Fortran_COMPILER_ID}") - include (${HDF_RESOURCES_DIR}/HDFFortranCompilerFlags.cmake) + include (${HDF_RESOURCES_DIR}/HDFCompilerFortranFlags.cmake) include (${HDF_RESOURCES_DIR}/HDF5UseFortran.cmake) set (LINK_Fortran_LIBS ${LINK_LIBS}) @@ -1193,7 +1193,7 @@ if (EXISTS "${HDF5_SOURCE_DIR}/c++" AND IS_DIRECTORY "${HDF5_SOURCE_DIR}/c++") endif () endif () - include (${HDF_RESOURCES_DIR}/HDFCXXCompilerFlags.cmake) + include (${HDF_RESOURCES_DIR}/HDFCompilerCXXFlags.cmake) add_subdirectory (c++) if (HDF5_BUILD_HL_LIB) diff --git a/config/cmake/HDFCXXCompilerFlags.cmake b/config/cmake/HDFCXXCompilerFlags.cmake deleted file mode 100644 index b6c14efd931..00000000000 --- a/config/cmake/HDFCXXCompilerFlags.cmake +++ /dev/null @@ -1,362 +0,0 @@ -# -# Copyright by The HDF Group. -# All rights reserved. -# -# This file is part of HDF5. The full HDF5 copyright notice, including -# terms governing use, modification, and redistribution, is contained in -# the LICENSE file, which can be found at the root of the source code -# distribution tree, or in https://www.hdfgroup.org/licenses. -# If you do not have access to either file, you may request a copy from -# help@hdfgroup.org. -# -ENABLE_LANGUAGE (CXX) - -set (CMAKE_CXX_STANDARD 11) -set (CMAKE_CXX_STANDARD_REQUIRED TRUE) - -set (CMAKE_CXX_EXTENSIONS OFF) - -set (CMAKE_CXX_FLAGS "${CMAKE_CXX_SANITIZER_FLAGS} ${CMAKE_CXX_FLAGS}") -message (VERBOSE "Warnings Configuration: CXX default: ${CMAKE_CXX_FLAGS}") -#----------------------------------------------------------------------------- -# Compiler specific flags : Shouldn't there be compiler tests for these -#----------------------------------------------------------------------------- -if (WIN32 AND (CMAKE_CXX_COMPILER_ID STREQUAL "Intel" OR CMAKE_CXX_COMPILER_ID MATCHES "IntelLLVM")) - set (_INTEL_WINDOWS 1) -endif () - -if (WIN32 AND CMAKE_CXX_COMPILER_ID MATCHES "[Cc]lang" AND "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC") - set (_CLANG_MSVC_WINDOWS 1) -endif() - -# MSVC 14.28 enables C5105, but the Windows SDK 10.0.18362.0 triggers it. -if ((_CLANG_MSVC_WINDOWS OR CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") AND CMAKE_CXX_COMPILER_LOADED) - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc") - if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.28) - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -wd5105") - endif () -endif () - -if (CMAKE_CXX_COMPILER_ID STREQUAL SunPro AND CMAKE_CXX_COMPILER_LOADED) - if (NOT DEFINED CMAKE_CXX${CMAKE_CXX_STANDARD}_STANDARD_COMPILE_OPTION) - if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.13) - if (NOT CMAKE_CXX_STANDARD OR CMAKE_CXX_STANDARD EQUAL 98) - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++03") - endif () - else () - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -library=stlport4") - endif () - endif () -endif () - -if (CMAKE_CXX_COMPILER_ID STREQUAL "NVHPC" AND CMAKE_CXX_COMPILER_LOADED) - if (NOT DEFINED CMAKE_CXX${CMAKE_CXX_STANDARD}_STANDARD_COMPILE_OPTION) - if (NOT CMAKE_CXX_STANDARD OR CMAKE_CXX_STANDARD EQUAL 11) - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_C11_STANDARD_COMPILE_OPTION}") - endif () - endif () - if (NOT ${HDF_CFG_NAME} MATCHES "Debug" AND NOT ${HDF_CFG_NAME} MATCHES "Developer") - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Minform=warn") - if (NOT ${HDF_CFG_NAME} MATCHES "RelWithDebInfo") - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s") - endif () - else () - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Mbounds -gopt -g") - endif () -endif () - -if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_LOADED) - set (CMAKE_CXX_FLAGS "${CMAKE_ANSI_CFLAGS} ${CMAKE_CXX_FLAGS}") - if (${HDF_CFG_NAME} MATCHES "Debug" OR ${HDF_CFG_NAME} MATCHES "Developer") - if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0) - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Og -ftrapv -fno-common") - endif () - else () - if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0) - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstdarg-opt") - endif () - if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 10.0) - if (HDF5_ENABLE_BUILD_DIAGS) - message (STATUS "... default color and URL extended diagnostic messages enabled") - else () - message (STATUS "... disable color and URL extended diagnostic messages") - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-urls=never -fno-diagnostics-color") - endif () - endif () - endif () -endif () - -#----------------------------------------------------------------------------- -# Option to allow the user to disable compiler warnings -#----------------------------------------------------------------------------- -if (HDF5_DISABLE_COMPILER_WARNINGS) - message (STATUS "....Compiler warnings are suppressed") - # MSVC uses /w to suppress warnings. It also complains if another - # warning level is given, so remove it. - if (MSVC) - set (HDF5_WARNINGS_BLOCKED 1) - if (CMAKE_CXX_COMPILER_LOADED) - string (REGEX REPLACE "(^| )([/-])W[0-9]( |$)" " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W0") - endif () - endif () - if (WIN32) - add_definitions (-D_CRT_SECURE_NO_WARNINGS) - endif () - - # Most compilers use -w to suppress warnings. - if (NOT HDF5_WARNINGS_BLOCKED) - if (CMAKE_CXX_COMPILER_LOADED) - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w") - endif () - endif () -endif () - -#----------------------------------------------------------------------------- -# HDF5 library compile options - to be made available to all targets -#----------------------------------------------------------------------------- - -if (${CMAKE_SYSTEM_NAME} MATCHES "SunOS") - list (APPEND HDF5_CMAKE_CXX_FLAGS "-erroff=%none -DBSD_COMP") -else () - # General flags - # - # Note that some of the flags listed here really should be developer - # flags (listed in a separate variable, below) but we put them here - # because they are not raised by the current code and we'd like to - # know if they do start showing up. - # - # NOTE: Don't add -Wpadded here since we can't/won't fix the (many) - # warnings that are emitted. If you need it, add it at configure time. - if (CMAKE_CXX_COMPILER_ID STREQUAL "Intel") - if (_INTEL_WINDOWS) - ADD_H5_FLAGS (HDF5_CMAKE_CXX_FLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/classic/win-general") - else () - ADD_H5_FLAGS (HDF5_CMAKE_CXX_FLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/classic/general") - endif() - if (NOT _INTEL_WINDOWS) - if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 15.0) - ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/classic/15") - endif() - if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 18.0) - ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/classic/18") - endif() - endif() - elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_LOADED - AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 4.8) - # add the general CXX flags for g++ compiler versions 4.8 and above. - ADD_H5_FLAGS (HDF5_CMAKE_CXX_FLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/cxx-general") - ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/cxx-error-general") - endif () - elseif (CMAKE_CXX_COMPILER_ID MATCHES "IntelLLVM") - if (_INTEL_WINDOWS) - ADD_H5_FLAGS (HDF5_CMAKE_CXX_FLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/oneapi/win-general") - else () - ADD_H5_FLAGS (HDF5_CMAKE_CXX_FLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/oneapi/general") - endif() - elseif (CMAKE_CXX_COMPILER_ID MATCHES "[Cc]lang") - ADD_H5_FLAGS (HDF5_CMAKE_CXX_FLAGS "${HDF5_SOURCE_DIR}/config/clang-warnings/general") - elseif (CMAKE_CXX_COMPILER_ID STREQUAL "PGI") - list (APPEND HDF5_CMAKE_CXX_FLAGS "-Minform=inform") - endif () - message (VERBOSE "CMAKE_CXX_FLAGS_GENERAL=${HDF5_CMAKE_CXX_FLAGS}") -endif () - -#----------------------------------------------------------------------------- -# Option to allow the user to enable developer warnings -# Developer warnings (suggestions from gcc, not code problems) -#----------------------------------------------------------------------------- -if (HDF5_ENABLE_DEV_WARNINGS) - message (STATUS "....HDF5 developer group warnings are enabled") - if (CMAKE_CXX_COMPILER_ID STREQUAL "Intel") - if (_INTEL_WINDOWS) - ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/classic/win-developer-general") - else () - ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/classic/developer-general") - endif() - elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - # Use the C warnings as CXX warnings are the same - ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/developer-general") - elseif (CMAKE_CXX_COMPILER_ID MATCHES "IntelLLVM") - if (_INTEL_WINDOWS) - ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/oneapi/win-developer-general") - else () - ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/oneapi/developer-general") - endif() - elseif (CMAKE_CXX_COMPILER_ID MATCHES "[Cc]lang") - ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/clang-warnings/developer-general") - endif () -else () - if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - # Use the C warnings as CXX warnings are the same - ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/no-developer-general") - elseif (CMAKE_CXX_COMPILER_ID MATCHES "[Cc]lang") - ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/clang-warnings/no-developer-general") - endif () -endif () - -if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - # Technically, variable-length arrays are part of the C99 standard, but - # we should approach them a bit cautiously... Only needed for gcc 4.X - if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0 AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 4.8) - # Use the C warnings as CXX warnings are the same - ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/4.8-4.last") - endif () - - # Append more extra warning flags that only gcc 4.8+ knows about - if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8) - ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/cxx-4.8") - if (HDF5_ENABLE_DEV_WARNINGS) - # Use the C warnings as CXX warnings are the same - ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/cxx-developer-4.8") - else () - ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/no-cxx-developer-4.8") - endif () - endif () - - # Append more extra warning flags that only gcc 4.9+ knows about - if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9) - # Use the C warnings as CXX warnings are the same - ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/cxx-4.9") - endif () - - # Append more extra warning flags that only gcc 5.1+ knows about - if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0) - # autotools always add the C flags with the CXX flags - ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/cxx-5") - ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/cxx-error-5") - endif () - - # Append more extra warning flags that only gcc 6.x+ knows about - if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.0) - # Use the C warnings as CXX warnings are the same - ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/6") - endif () - - # Append more extra warning flags that only gcc 7.x+ knows about - if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0) - # Use the C warnings as CXX warnings are the same - ADD_H5_FLAGS (H5_CXxFLAGS2 "${HDF5_SOURCE_DIR}/config/gnu-warnings/7") - if (HDF5_ENABLE_DEV_WARNINGS) - # Use the C warnings as CXX warnings are the same - ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/developer-7") - #else () - # ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/no-developer-7") - endif () - endif () - - # Append more extra warning flags that only gcc 8.x+ knows about - if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.0) - # Use the C warnings as CXX warnings are the same - ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/8") - ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/error-8") - if (HDF5_ENABLE_DEV_WARNINGS) - # Use the C warnings as CXX warnings are the same - ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/developer-8") - else () - # autotools always add the C flags with the CXX flags - ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/no-developer-8") - endif () - endif () - - # Append more extra warning flags that only gcc 9.x+ knows about - if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0) - # Use the C warnings as CXX warnings are the same - ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/cxx-9") - endif () - - # Append more extra warning flags that only gcc 9.3+ knows about - if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.3) - # do not use C warnings, gnu-warnings 9.3, no cxx warnings - # ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/9.3") - endif () - - # Append more extra warning flags that only gcc 10.x+ knows about - if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 10.0) - if (HDF5_ENABLE_DEV_WARNINGS) - # Use the C warnings as CXX warnings are the same - ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/developer-10") - #else () - # ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/no-developer-10") - endif () - endif () -endif () - -#----------------------------------------------------------------------------- -# Option to allow the user to enable all warnings -#----------------------------------------------------------------------------- -if (HDF5_ENABLE_ALL_WARNINGS) - message (STATUS "....All Warnings are enabled") - if (MSVC) - if (HDF5_ENABLE_DEV_WARNINGS) - if (CMAKE_CXX_COMPILER_LOADED) - string (REGEX REPLACE "(^| )([/-])W[0-9]( |$)" " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - list (APPEND HDF5_CMAKE_CXX_FLAGS "/Wall" "/wd4668") - endif () - else () - if (CMAKE_CXX_COMPILER_LOADED) - string (REGEX REPLACE "(^| )([/-])W[0-9]( |$)" " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - list (APPEND HDF5_CMAKE_CXX_FLAGS "/W3" "/wd4100" "/wd4706" "/wd4127") - endif () - endif () - else () - if (CMAKE_CXX_COMPILER_LOADED) - list (APPEND HDF5_CMAKE_CXX_FLAGS ${H5_CXXFLAGS}) - endif () - endif () -endif () - -#----------------------------------------------------------------------------- -# This is in here to help some of the GCC based IDES like Eclipse -# and code blocks parse the compiler errors and warnings better. -#----------------------------------------------------------------------------- -if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_LOADED) - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fmessage-length=0") -endif () - -#----------------------------------------------------------------------------- -# Option for --enable-symbols -# This option will force/override the default setting for all configurations -#----------------------------------------------------------------------------- -if (HDF5_ENABLE_SYMBOLS MATCHES "YES") - if (CMAKE_CXX_COMPILER_LOADED) - if (CMAKE_CXX_COMPILER_ID STREQUAL "Intel" AND NOT _INTEL_WINDOWS) - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g") - elseif (CMAKE_C_COMPILER_ID MATCHES "IntelLLVM" AND NOT _INTEL_WINDOWS) - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g") - elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g") - endif () - endif () -elseif (HDF5_ENABLE_SYMBOLS MATCHES "NO") - if (CMAKE_CXX_COMPILER_LOADED) - if (CMAKE_CXX_COMPILER_ID STREQUAL "Intel" AND NOT _INTEL_WINDOWS) - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,-s") - elseif (CMAKE_CXX_COMPILER_ID MATCHES "IntelLLVM" AND NOT _INTEL_WINDOWS) - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,-s") - elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s") - endif () - endif () -endif () - -#----------------------------------------------------------------------------- -# Option for --enable-profiling -# This option will force/override the default setting for all configurations -#----------------------------------------------------------------------------- -if (HDF5_ENABLE_PROFILING) - if (CMAKE_CXX_COMPILER_LOADED) - list (APPEND HDF5_CMAKE_CXX_FLAGS "${PROFILE_CXXFLAGS}") - endif () -endif () - -#----------------------------------------------------------------------------- -# Option for --enable-optimization -# This option will force/override the default setting for all configurations -#----------------------------------------------------------------------------- -if (HDF5_ENABLE_OPTIMIZATION) - if (CMAKE_CXX_COMPILER_LOADED) - list (APPEND HDF5_CMAKE_CXX_FLAGS "${OPTIMIZE_CXXFLAGS}") - endif () -endif () diff --git a/config/cmake/HDFClangCXXFlags.cmake b/config/cmake/HDFClangCXXFlags.cmake new file mode 100644 index 00000000000..90b2f07a33f --- /dev/null +++ b/config/cmake/HDFClangCXXFlags.cmake @@ -0,0 +1,52 @@ +# +# Copyright by The HDF Group. +# All rights reserved. +# +# This file is part of HDF5. The full HDF5 copyright notice, including +# terms governing use, modification, and redistribution, is contained in +# the COPYING file, which can be found at the root of the source code +# distribution tree, or in https://www.hdfgroup.org/licenses. +# If you do not have access to either file, you may request a copy from +# help@hdfgroup.org. +# + +############################################################################### +# This file included from HDFCompilerFlags.cmake with +# if (CMAKE_CXX_COMPILER_ID MATCHES "[Cc]lang") +############################################################################### + +#----------------------------------------------------------------------------- +# Compiler specific flags +#----------------------------------------------------------------------------- +if (WIN32 AND "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC") + set (_CLANG_MSVC_WINDOWS 1) +endif() + +#----------------------------------------------------------------------------- +# HDF5 library compile options - to be made available to all targets +#----------------------------------------------------------------------------- + +if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "SunOS") + # General flags + # + # Note that some of the flags listed here really should be developer + # flags (listed in a separate variable, below) but we put them here + # because they are not raised by the current code and we'd like to + # know if they do start showing up. + # + # NOTE: Don't add -Wpadded here since we can't/won't fix the (many) + # warnings that are emitted. If you need it, add it at configure time. + ADD_H5_FLAGS (HDF5_CMAKE_CXX_FLAGS "${HDF5_SOURCE_DIR}/config/clang-warnings/general") + message (VERBOSE "CMAKE_CXX_FLAGS_GENERAL=${HDF5_CMAKE_CXX_FLAGS}") +endif () + +#----------------------------------------------------------------------------- +# Option to allow the user to enable developer warnings +# Developer warnings (suggestions from gcc, not code problems) +#----------------------------------------------------------------------------- +if (HDF5_ENABLE_DEV_WARNINGS) + message (STATUS "....HDF5 CXX developer group warnings are enabled") + ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/clang-warnings/developer-general") +else () + ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/clang-warnings/no-developer-general") +endif () diff --git a/config/cmake/HDFClangFlags.cmake b/config/cmake/HDFClangFlags.cmake new file mode 100644 index 00000000000..8b931d965fa --- /dev/null +++ b/config/cmake/HDFClangFlags.cmake @@ -0,0 +1,73 @@ +# +# Copyright by The HDF Group. +# All rights reserved. +# +# This file is part of HDF5. The full HDF5 copyright notice, including +# terms governing use, modification, and redistribution, is contained in +# the COPYING file, which can be found at the root of the source code +# distribution tree, or in https://www.hdfgroup.org/licenses. +# If you do not have access to either file, you may request a copy from +# help@hdfgroup.org. +# + +############################################################################### +# This file included from HDFCompilerFlags.cmake with +# if (CMAKE_C_COMPILER_ID MATCHES "[Cc]lang") +############################################################################### + +#----------------------------------------------------------------------------- +# Compiler specific flags +#----------------------------------------------------------------------------- +if (WIN32 AND "x${CMAKE_C_SIMULATE_ID}" STREQUAL "xMSVC") + set (_CLANG_MSVC_WINDOWS 1) + if("x${CMAKE_C_COMPILER_FRONTEND_VARIANT}" STREQUAL "xGNU") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Xlinker -stack:20000000") + endif() +endif () + +# Disable deprecation warnings for standard C functions. +# really only needed for newer versions of VS, but should +# not hurt other versions, and this will work into the +# future +if (MSVC OR _CLANG_MSVC_WINDOWS) + add_definitions (-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE) +endif () + +#----------------------------------------------------------------------------- +# HDF5 library compile options - to be made available to all targets +#----------------------------------------------------------------------------- + +if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "SunOS") + # General flags + # + # Note that some of the flags listed here really should be developer + # flags (listed in a separate variable, below) but we put them here + # because they are not raised by the current code and we'd like to + # know if they do start showing up. + # + # NOTE: Don't add -Wpadded here since we can't/won't fix the (many) + # warnings that are emitted. If you need it, add it at configure time. + ADD_H5_FLAGS (HDF5_CMAKE_C_FLAGS "${HDF5_SOURCE_DIR}/config/clang-warnings/general") + ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/clang-warnings/error-general") + message (VERBOSE "CMAKE_C_FLAGS_GENERAL=${HDF5_CMAKE_C_FLAGS}") +endif () + +#----------------------------------------------------------------------------- +# Option to allow the user to enable developer warnings +# Developer warnings (suggestions from gcc, not code problems) +#----------------------------------------------------------------------------- +if (HDF5_ENABLE_DEV_WARNINGS) + message (STATUS "....HDF5 developer group warnings are enabled") + ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/clang-warnings/developer-general") + + # Turn on -Winline warnings now only for non-Debug and + # non-Developer builds. For at least GNU compilers this + # flag appears to conflict specifically with the -Og + # optimization flag and will produce warnings about functions + # not being considered for inlining + if (NOT ${HDF_CFG_NAME} MATCHES "Debug" AND NOT ${HDF_CFG_NAME} MATCHES "Developer") + list (APPEND H5_CFLAGS "-Winline") + endif () +else () + ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/clang-warnings/no-developer-general") +endif () diff --git a/config/cmake/HDFCompilerCXXFlags.cmake b/config/cmake/HDFCompilerCXXFlags.cmake new file mode 100644 index 00000000000..1a8ffed0ee7 --- /dev/null +++ b/config/cmake/HDFCompilerCXXFlags.cmake @@ -0,0 +1,162 @@ +# +# Copyright by The HDF Group. +# All rights reserved. +# +# This file is part of HDF5. The full HDF5 copyright notice, including +# terms governing use, modification, and redistribution, is contained in +# the COPYING file, which can be found at the root of the source code +# distribution tree, or in https://www.hdfgroup.org/licenses. +# If you do not have access to either file, you may request a copy from +# help@hdfgroup.org. +# +ENABLE_LANGUAGE (CXX) + +set (CMAKE_CXX_STANDARD 11) +set (CMAKE_CXX_STANDARD_REQUIRED TRUE) + +set (CMAKE_CXX_EXTENSIONS OFF) + +set (CMAKE_CXX_FLAGS "${CMAKE_CXX_SANITIZER_FLAGS} ${CMAKE_CXX_FLAGS}") +message (VERBOSE "Warnings Configuration: CXX default: ${CMAKE_CXX_FLAGS}") +#----------------------------------------------------------------------------- +# Compiler specific flags +#----------------------------------------------------------------------------- +# MSVC 14.28 enables C5105, but the Windows SDK 10.0.18362.0 triggers it. +if ((_CLANG_MSVC_WINDOWS OR CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") AND CMAKE_CXX_COMPILER_LOADED) + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc") + if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.28) + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -wd5105") + endif () +endif () + +if (CMAKE_CXX_COMPILER_ID STREQUAL SunPro AND CMAKE_CXX_COMPILER_LOADED) + if (NOT DEFINED CMAKE_CXX${CMAKE_CXX_STANDARD}_STANDARD_COMPILE_OPTION) + if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.13) + if (NOT CMAKE_CXX_STANDARD OR CMAKE_CXX_STANDARD EQUAL 98) + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++03") + endif () + else () + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -library=stlport4") + endif () + endif () +endif () + +#----------------------------------------------------------------------------- +# Option to allow the user to disable compiler warnings +#----------------------------------------------------------------------------- +if (CMAKE_CXX_COMPILER_LOADED) + if (HDF5_DISABLE_COMPILER_WARNINGS) + message (STATUS "....Compiler warnings are suppressed") + # MSVC uses /w to suppress warnings. It also complains if another + # warning level is given, so remove it. + if (MSVC) + set (HDF5_WARNINGS_BLOCKED 1) + string (REGEX REPLACE "(^| )([/-])W[0-9]( |$)" " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W0") + endif () + if (WIN32) + add_definitions (-D_CRT_SECURE_NO_WARNINGS) + endif () + + # Most compilers use -w to suppress warnings. + if (NOT HDF5_WARNINGS_BLOCKED) + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w") + endif () + endif () + + if (CMAKE_CXX_COMPILER_ID MATCHES "NVHPC" ) + include (${HDF_RESOURCES_DIR}/HDFNvhpcCXXFlags.cmake) + endif () + + if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") + include (${HDF_RESOURCES_DIR}/HDFGnuCXXFlags.cmake) + endif () + + if (CMAKE_CXX_COMPILER_ID MATCHES "Intel") + include (${HDF_RESOURCES_DIR}/HDFIntelCXXFlags.cmake) + endif () + + if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC") + include (${HDF_RESOURCES_DIR}/HDFMsvcCXXFlags.cmake) + endif () + + #because this will match other compilers with clang in the name this should be checked last + if (CMAKE_CXX_COMPILER_ID MATCHES "[Cc]lang") + include (${HDF_RESOURCES_DIR}/HDFClangCXXFlags.cmake) + endif () + + #----------------------------------------------------------------------------- + # HDF5 library compile options - to be made available to all targets + #----------------------------------------------------------------------------- + + if (${CMAKE_SYSTEM_NAME} MATCHES "SunOS") + list (APPEND HDF5_CMAKE_CXX_FLAGS "-erroff=%none -DBSD_COMP") + else () + # General flags + # + # Note that some of the flags listed here really should be developer + # flags (listed in a separate variable, below) but we put them here + # because they are not raised by the current code and we'd like to + # know if they do start showing up. + # + # NOTE: Don't add -Wpadded here since we can't/won't fix the (many) + # warnings that are emitted. If you need it, add it at configure time. + if (CMAKE_CXX_COMPILER_ID STREQUAL "PGI") + list (APPEND HDF5_CMAKE_CXX_FLAGS "-Minform=inform") + endif () + message (VERBOSE "CMAKE_CXX_FLAGS_GENERAL=${HDF5_CMAKE_CXX_FLAGS}") + endif () + + #----------------------------------------------------------------------------- + # Option to allow the user to enable all warnings + #----------------------------------------------------------------------------- + if (HDF5_ENABLE_ALL_WARNINGS) + message (STATUS "....All Warnings are enabled") + if (MSVC) + if (HDF5_ENABLE_DEV_WARNINGS) + string (REGEX REPLACE "(^| )([/-])W[0-9]( |$)" " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + list (APPEND HDF5_CMAKE_CXX_FLAGS "/Wall" "/wd4668") + else () + string (REGEX REPLACE "(^| )([/-])W[0-9]( |$)" " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + list (APPEND HDF5_CMAKE_CXX_FLAGS "/W3" "/wd4100" "/wd4706" "/wd4127") + endif () + else () + list (APPEND HDF5_CMAKE_CXX_FLAGS ${H5_CXXFLAGS}) + endif () + endif () + + #----------------------------------------------------------------------------- + # Option for --enable-profiling + # This option will force/override the default setting for all configurations + #----------------------------------------------------------------------------- + if (HDF5_ENABLE_PROFILING) + list (APPEND HDF5_CMAKE_CXX_FLAGS "${PROFILE_CXXFLAGS}") + endif () + + #----------------------------------------------------------------------------- + # Option for --enable-optimization + # This option will force/override the default setting for all configurations + #----------------------------------------------------------------------------- + if (HDF5_ENABLE_OPTIMIZATION) + list (APPEND HDF5_CMAKE_CXX_FLAGS "${OPTIMIZE_CXXFLAGS}") + endif () +endif () + +#----------------------------------------------------------------------------- +# The build mode flags are not added to CMAKE_CXX_FLAGS, so create a separate +# variable for them so they can be written out to libhdf5.settings and +# H5build_settings.c +#----------------------------------------------------------------------------- +if ("${HDF_CFG_NAME}" STREQUAL "Debug") + set (HDF5_BUILD_MODE_CXX_FLAGS "${CMAKE_CXX_FLAGS_DEBUG}") +elseif ("${HDF_CFG_NAME}" STREQUAL "Developer") + set (HDF5_BUILD_MODE_CXX_FLAGS "${CMAKE_CXX_FLAGS_DEVELOPER}") +elseif ("${HDF_CFG_NAME}" STREQUAL "Release") + set (HDF5_BUILD_MODE_CXX_FLAGS "${CMAKE_CXX_FLAGS_RELEASE}") +elseif ("${HDF_CFG_NAME}" STREQUAL "MinSizeRel") + set (HDF5_BUILD_MODE_CXX_FLAGS "${CMAKE_CXX_FLAGS_MINSIZEREL}") +elseif ("${HDF_CFG_NAME}" STREQUAL "RelWithDebInfo") + set (HDF5_BUILD_MODE_CXX_FLAGS "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}") +else () + set (HDF5_BUILD_MODE_CXX_FLAGS "") +endif () diff --git a/config/cmake/HDFCompilerFlags.cmake b/config/cmake/HDFCompilerFlags.cmake index 78aa3c37027..d00fd8209de 100644 --- a/config/cmake/HDFCompilerFlags.cmake +++ b/config/cmake/HDFCompilerFlags.cmake @@ -16,77 +16,17 @@ set (CMAKE_C_FLAGS "${CMAKE_C11_STANDARD_COMPILE_OPTION} ${CMAKE_C_FLAGS}") set (CMAKE_C_FLAGS "${CMAKE_C_SANITIZER_FLAGS} ${CMAKE_C_FLAGS}") message (VERBOSE "Warnings Configuration: C default: ${CMAKE_C_FLAGS}") #----------------------------------------------------------------------------- -# Compiler specific flags : Shouldn't there be compiler tests for these +# Compiler specific flags #----------------------------------------------------------------------------- -if (WIN32 AND (CMAKE_C_COMPILER_ID STREQUAL "Intel" OR CMAKE_C_COMPILER_ID MATCHES "IntelLLVM")) - set (_INTEL_WINDOWS 1) -endif () - -if (WIN32 AND CMAKE_C_COMPILER_ID MATCHES "[Cc]lang" AND "x${CMAKE_C_SIMULATE_ID}" STREQUAL "xMSVC") - set (_CLANG_MSVC_WINDOWS 1) -endif () - # Disable deprecation warnings for standard C functions. # really only needed for newer versions of VS, but should # not hurt other versions, and this will work into the # future -if (MSVC OR _INTEL_WINDOWS OR _CLANG_MSVC_WINDOWS) - add_definitions (-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE) -endif () - if (MSVC) + add_definitions (-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE) set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stack:10000000") endif () -# MSVC 14.28 enables C5105, but the Windows SDK 10.0.18362.0 triggers it. -if (CMAKE_C_COMPILER_ID STREQUAL "MSVC" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 19.28) - set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -wd5105") -endif () - -if(_CLANG_MSVC_WINDOWS AND "x${CMAKE_C_COMPILER_FRONTEND_VARIANT}" STREQUAL "xGNU") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Xlinker -stack:20000000") -endif() - -if (CMAKE_C_COMPILER_ID STREQUAL "NVHPC" ) - set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Minform=warn") - if (NOT ${HDF_CFG_NAME} MATCHES "Debug" AND NOT ${HDF_CFG_NAME} MATCHES "Developer") - if (NOT ${HDF_CFG_NAME} MATCHES "RelWithDebInfo") - set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -s") - endif () - else () - set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Mbounds -gopt") - endif () -endif () - -if (CMAKE_C_COMPILER_ID STREQUAL "GNU") - set (CMAKE_C_FLAGS "${CMAKE_ANSI_CFLAGS} ${CMAKE_C_FLAGS}") - if (${HDF_CFG_NAME} MATCHES "Debug" OR ${HDF_CFG_NAME} MATCHES "Developer") - if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 5.0) - set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Og -ftrapv -fno-common") - endif () - else () - if (CMAKE_C_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 5.0 AND - NOT CMAKE_C_CLANG_TIDY) - # `clang-tidy` does not understand -fstdarg-opt - set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstdarg-opt") - endif () - if (CMAKE_C_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 10.0) - #----------------------------------------------------------------------------- - # Option to allow the user to enable build extended diagnostics - # - # This should NOT be on by default as it can cause process issues. - #----------------------------------------------------------------------------- - option (HDF5_ENABLE_BUILD_DIAGS "Enable color and URL extended diagnostic messages" OFF) - mark_as_advanced (HDF5_ENABLE_BUILD_DIAGS) - if (HDF5_ENABLE_BUILD_DIAGS) - message (STATUS "... default color and URL extended diagnostic messages enabled") - else () - message (STATUS "... disable color and URL extended diagnostic messages") - set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fdiagnostics-urls=never -fno-diagnostics-color") - endif () - endif () - endif () -endif () #----------------------------------------------------------------------------- # Option to allow the user to disable compiler warnings @@ -116,6 +56,27 @@ if (HDF5_DISABLE_COMPILER_WARNINGS) endif () endif () +if (CMAKE_C_COMPILER_ID MATCHES "NVHPC" ) + include (${HDF_RESOURCES_DIR}/HDFNvhpcFlags.cmake) +endif () + +if (CMAKE_C_COMPILER_ID MATCHES "GNU") + include (${HDF_RESOURCES_DIR}/HDFGnuFlags.cmake) +endif () + +if (CMAKE_C_COMPILER_ID MATCHES "Intel") + include (${HDF_RESOURCES_DIR}/HDFIntelFlags.cmake) +endif () + +if (CMAKE_C_COMPILER_ID MATCHES "MSVC") + include (${HDF_RESOURCES_DIR}/HDFMsvcFlags.cmake) +endif () + +#because this will match other compilers with clang in the name this should be checked last +if (CMAKE_C_COMPILER_ID MATCHES "[Cc]lang") + include (${HDF_RESOURCES_DIR}/HDFClangFlags.cmake) +endif () + #----------------------------------------------------------------------------- # HDF5 library compile options - to be made available to all targets #----------------------------------------------------------------------------- @@ -144,43 +105,7 @@ else () # # NOTE: Don't add -Wpadded here since we can't/won't fix the (many) # warnings that are emitted. If you need it, add it at configure time. - if (CMAKE_C_COMPILER_ID STREQUAL "Intel") - if (_INTEL_WINDOWS) - ADD_H5_FLAGS (HDF5_CMAKE_C_FLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/classic/win-general") - else () - ADD_H5_FLAGS (HDF5_CMAKE_C_FLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/classic/general") - endif() - if (NOT _INTEL_WINDOWS) - if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 15.0) - ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/classic/15") - endif () - # this is just a failsafe - list (APPEND H5_CFLAGS "-finline-functions") - if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 18.0) - ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/classic/18") - endif () - endif () - elseif (CMAKE_C_COMPILER_ID STREQUAL "GNU") - # Add general CFlags for GCC versions 4.8 and above - if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 4.8) - ADD_H5_FLAGS (HDF5_CMAKE_C_FLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/general") - ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/error-general") - endif () - # gcc automatically inlines based on the optimization level - # this is just a failsafe - list (APPEND H5_CFLAGS "-finline-functions") - elseif (CMAKE_C_COMPILER_ID MATCHES "IntelLLVM") - if (_INTEL_WINDOWS) - ADD_H5_FLAGS (HDF5_CMAKE_C_FLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/oneapi/win-general") - else () - # this is just a failsafe - list (APPEND H5_CFLAGS "-finline-functions") - ADD_H5_FLAGS (HDF5_CMAKE_C_FLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/oneapi/general") - endif () - elseif (CMAKE_C_COMPILER_ID MATCHES "[Cc]lang") - ADD_H5_FLAGS (HDF5_CMAKE_C_FLAGS "${HDF5_SOURCE_DIR}/config/clang-warnings/general") - ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/clang-warnings/error-general") - elseif (CMAKE_C_COMPILER_ID STREQUAL "PGI") + if (CMAKE_C_COMPILER_ID STREQUAL "PGI") list (APPEND HDF5_CMAKE_C_FLAGS "-Minform=inform") endif () message (VERBOSE "CMAKE_C_FLAGS_GENERAL=${HDF5_CMAKE_C_FLAGS}") @@ -195,134 +120,6 @@ if (${HDF_CFG_NAME} MATCHES "Developer") # Developer build modes should always have these types of warnings enabled set (HDF5_ENABLE_DEV_WARNINGS ON CACHE BOOL "Enable HDF5 developer group warnings" FORCE) endif () -if (HDF5_ENABLE_DEV_WARNINGS) - message (STATUS "....HDF5 developer group warnings are enabled") - if (CMAKE_C_COMPILER_ID STREQUAL "Intel") - if (_INTEL_WINDOWS) - ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/classic/win-developer-general") - else () - ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/classic/developer-general") - endif () - elseif (CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 4.8) - ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/developer-general") - elseif (CMAKE_C_COMPILER_ID MATCHES "IntelLLVM") - if (_INTEL_WINDOWS) - ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/oneapi/win-developer-general") - else () - ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/oneapi/developer-general") - endif () - elseif (CMAKE_C_COMPILER_ID MATCHES "[Cc]lang") - ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/clang-warnings/developer-general") - endif () - - # Turn on -Winline warnings now only for non-Debug and - # non-Developer builds. For at least GNU compilers this - # flag appears to conflict specifically with the -Og - # optimization flag and will produce warnings about functions - # not being considered for inlining - if (NOT ${HDF_CFG_NAME} MATCHES "Debug" AND NOT ${HDF_CFG_NAME} MATCHES "Developer") - if (CMAKE_C_COMPILER_ID STREQUAL "GNU") - list (APPEND H5_CFLAGS "-Winline") - elseif (CMAKE_C_COMPILER_ID STREQUAL "Intel" AND NOT _INTEL_WINDOWS) - list (APPEND H5_CFLAGS "-Winline") - elseif (CMAKE_C_COMPILER_ID MATCHES "IntelLLVM" AND NOT _INTEL_WINDOWS) - list (APPEND H5_CFLAGS "-Winline") - elseif (CMAKE_C_COMPILER_ID MATCHES "[Cc]lang") - list (APPEND H5_CFLAGS "-Winline") - endif () - endif () -else () - if (CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 4.8) - ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/no-developer-general") - elseif (CMAKE_C_COMPILER_ID MATCHES "[Cc]lang") - ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/clang-warnings/no-developer-general") - endif () -endif () - -if (CMAKE_C_COMPILER_ID STREQUAL "GNU") - # Technically, variable-length arrays are part of the C99 standard, but - # we should approach them a bit cautiously... Only needed for gcc 4.X - if (CMAKE_C_COMPILER_VERSION VERSION_LESS 5.0 AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 4.8) - ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/4.8-4.last") - endif () - - # Append more extra warning flags that only gcc 4.8+ knows about - if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.8) - ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/4.8") - if (HDF5_ENABLE_DEV_WARNINGS) - ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/developer-4.8") - else () - ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/no-developer-4.8") - endif () - endif () - - # Append more extra warning flags that only gcc 4.9+ knows about - if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.9) - ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/4.9") - endif () - - # Append more extra warning flags that only gcc 5.x+ knows about - if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 5.0) - ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/5") - ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/error-5") - endif () - - # Append more extra warning flags that only gcc 6.x+ knows about - if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 6.0) - ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/6") - endif () - - # Append more extra warning flags that only gcc 7.x+ knows about - if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 7.0) - ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/7") - ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/error-7") - if (HDF5_ENABLE_DEV_WARNINGS) - ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/developer-7") - #else () - # ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/no-developer-7") - endif () - endif () - - # Append more extra warning flags that only gcc 8.x+ knows about - if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 8.0) - ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/8") - ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/error-8") - if (HDF5_ENABLE_DEV_WARNINGS) - ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/developer-8") - else () - ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/no-developer-8") - endif () - endif () - - # Append more extra warning flags that only gcc 9.x+ knows about - if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 9.0) - ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/9") - endif () - - # Append more extra warning flags that only gcc 9.3+ knows about - if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 9.3) - ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/9.3") - endif () - - # Append more extra warning flags that only gcc 10.x+ knows about - if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 10.0) - if (HDF5_ENABLE_DEV_WARNINGS) - ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/developer-10") - #else () - # ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/no-developer-10") - endif () - endif () - - # Append more extra warning flags that only gcc 12.x+ knows about - # or which should only be enabled for gcc 12.x+ - if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 12.0) - if (HDF5_ENABLE_DEV_WARNINGS) - ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/developer-12") - #else () - # ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/no-developer-12") - endif () - endif () -endif () #----------------------------------------------------------------------------- # Option to allow the user to enable debug output @@ -363,14 +160,6 @@ if (HDF5_ENABLE_ALL_WARNINGS) endif () endif () -#----------------------------------------------------------------------------- -# This is in here to help some of the GCC based IDES like Eclipse -# and code blocks parse the compiler errors and warnings better. -#----------------------------------------------------------------------------- -if (CMAKE_C_COMPILER_ID STREQUAL "GNU") - set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fmessage-length=0") -endif () - #----------------------------------------------------------------------------- # Option for --enable-asserts # By default, CMake adds NDEBUG to CMAKE_${lang}_FLAGS for Release build types @@ -393,19 +182,6 @@ MARK_AS_ADVANCED (HDF5_ENABLE_ASSERTS) #option (HDF5_ENABLE_SYMBOLS "Add debug symbols to the library independent of the build mode and optimization level." OFF) set (HDF5_ENABLE_SYMBOLS "OFF" CACHE STRING "Add debug symbols to the library independent of the build mode and optimization level (OFF NO YES)") set_property (CACHE HDF5_ENABLE_SYMBOLS PROPERTY STRINGS OFF NO YES) -if (HDF5_ENABLE_SYMBOLS MATCHES "YES") - if (CMAKE_C_COMPILER_ID STREQUAL "Intel" AND NOT _INTEL_WINDOWS) - set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g") - elseif (CMAKE_C_COMPILER_ID STREQUAL "GNU") - set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -fno-omit-frame-pointer") - endif () -elseif (HDF5_ENABLE_SYMBOLS MATCHES "NO") - if (CMAKE_C_COMPILER_ID STREQUAL "Intel" AND NOT _INTEL_WINDOWS) - set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,-s") - elseif (CMAKE_C_COMPILER_ID STREQUAL "GNU") - set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -s") - endif () -endif () MARK_AS_ADVANCED (HDF5_ENABLE_SYMBOLS) #----------------------------------------------------------------------------- @@ -427,3 +203,23 @@ 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 +#----------------------------------------------------------------------------- +if ("${HDF_CFG_NAME}" STREQUAL "Debug") + set (HDF5_BUILD_MODE_C_FLAGS "${CMAKE_C_FLAGS_DEBUG}") +elseif ("${HDF_CFG_NAME}" STREQUAL "Developer") + set (HDF5_BUILD_MODE_C_FLAGS "${CMAKE_C_FLAGS_DEVELOPER}") +elseif ("${HDF_CFG_NAME}" STREQUAL "Release") + set (HDF5_BUILD_MODE_C_FLAGS "${CMAKE_C_FLAGS_RELEASE}") +elseif ("${HDF_CFG_NAME}" STREQUAL "MinSizeRel") + set (HDF5_BUILD_MODE_C_FLAGS "${CMAKE_C_FLAGS_MINSIZEREL}") +elseif ("${HDF_CFG_NAME}" STREQUAL "RelWithDebInfo") + set (HDF5_BUILD_MODE_C_FLAGS "${CMAKE_C_FLAGS_RELWITHDEBINFO}") +else () + set (HDF5_BUILD_MODE_C_FLAGS "") +endif () + diff --git a/config/cmake/HDFCompilerFortranFlags.cmake b/config/cmake/HDFCompilerFortranFlags.cmake new file mode 100644 index 00000000000..17d7af3ede5 --- /dev/null +++ b/config/cmake/HDFCompilerFortranFlags.cmake @@ -0,0 +1,86 @@ +# +# Copyright by The HDF Group. +# All rights reserved. +# +# This file is part of HDF5. The full HDF5 copyright notice, including +# terms governing use, modification, and redistribution, is contained in +# the COPYING file, which can be found at the root of the source code +# distribution tree, or in https://www.hdfgroup.org/licenses. +# If you do not have access to either file, you may request a copy from +# help@hdfgroup.org. +# + +message (VERBOSE "Warnings Configuration: default Fortran: ${CMAKE_Fortran_FLAGS}") + +#----------------------------------------------------------------------------- +# Option to allow the user to disable compiler warnings +#----------------------------------------------------------------------------- +if (HDF5_DISABLE_COMPILER_WARNINGS) + message (STATUS "....Compiler warnings are suppressed") + # MSVC uses /w to suppress warnings. It also complains if another + # warning level is given, so remove it. + if (MSVC) + set (HDF5_WARNINGS_BLOCKED 1) + endif () + if (WIN32) + add_definitions (-D_CRT_SECURE_NO_WARNINGS) + endif () + # Borland uses -w- to suppress warnings. + if (BORLAND) + set (HDF5_WARNINGS_BLOCKED 1) + set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -w-") + endif () + + # Most compilers use -w to suppress warnings. + if (NOT HDF5_WARNINGS_BLOCKED) + set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -w") + endif () +endif () + +if (CMAKE_Fortran_COMPILER_ID MATCHES "NVHPC" ) + include (${HDF_RESOURCES_DIR}/HDFNvhpcFortranFlags.cmake) +endif () + +if (CMAKE_Fortran_COMPILER_ID MATCHES "GNU") + include (${HDF_RESOURCES_DIR}/HDFGnuFortranFlags.cmake) +endif () + +if (CMAKE_Fortran_COMPILER_ID MATCHES "Intel") + include (${HDF_RESOURCES_DIR}/HDFIntelFortranFlags.cmake) +endif () + +#----------------------------------------------------------------------------- +# HDF5 library compile options - to be made available to all targets +#----------------------------------------------------------------------------- +if (CMAKE_Fortran_COMPILER_ID STREQUAL "NAG") + message (STATUS "... Select IEEE floating-point mode full") + list (APPEND HDF5_CMAKE_Fortran_FLAGS "-ieee=full") +endif () + +if (NOT MSVC AND NOT MINGW) + # General flags + if (CMAKE_Fortran_COMPILER_ID STREQUAL "PGI") + list (APPEND HDF5_CMAKE_Fortran_FLAGS "-Mfreeform" "-Mdclchk" "-Mstandard" "-Mallocatable=03") + endif () + message (VERBOSE "HDF5_CMAKE_Fortran_FLAGS=${HDF5_CMAKE_Fortran_FLAGS}") +endif () + +#----------------------------------------------------------------------------- +# The build mode flags are not added to CMAKE_Fortran_FLAGS, so create a separate +# variable for them so they can be written out to libhdf5.settings and +# H5build_settings.c +#----------------------------------------------------------------------------- +if ("${HDF_CFG_NAME}" STREQUAL "Debug") + set (HDF5_BUILD_MODE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS_DEBUG}") +elseif ("${HDF_CFG_NAME}" STREQUAL "Developer") + set (HDF5_BUILD_MODE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS_DEVELOPER}") +elseif ("${HDF_CFG_NAME}" STREQUAL "Release") + set (HDF5_BUILD_MODE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS_RELEASE}") +elseif ("${HDF_CFG_NAME}" STREQUAL "MinSizeRel") + set (HDF5_BUILD_MODE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS_MINSIZEREL}") +elseif ("${HDF_CFG_NAME}" STREQUAL "RelWithDebInfo") + set (HDF5_BUILD_MODE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS_RELWITHDEBINFO}") +else () + set (HDF5_BUILD_MODE_Fortran_FLAGS "") +endif () + diff --git a/config/cmake/HDFFortranCompilerFlags.cmake b/config/cmake/HDFFortranCompilerFlags.cmake deleted file mode 100644 index f238c7e82cc..00000000000 --- a/config/cmake/HDFFortranCompilerFlags.cmake +++ /dev/null @@ -1,158 +0,0 @@ -# -# Copyright by The HDF Group. -# All rights reserved. -# -# This file is part of HDF5. The full HDF5 copyright notice, including -# terms governing use, modification, and redistribution, is contained in -# the LICENSE file, which can be found at the root of the source code -# distribution tree, or in https://www.hdfgroup.org/licenses. -# If you do not have access to either file, you may request a copy from -# help@hdfgroup.org. -# - -message (VERBOSE "Warnings Configuration: default Fortran: ${CMAKE_Fortran_FLAGS}") - -#----------------------------------------------------------------------------- -# Option to allow the user to disable compiler warnings -#----------------------------------------------------------------------------- -if (HDF5_DISABLE_COMPILER_WARNINGS) - message (STATUS "....Compiler warnings are suppressed") - # MSVC uses /w to suppress warnings. It also complains if another - # warning level is given, so remove it. - if (MSVC) - set (HDF5_WARNINGS_BLOCKED 1) - if (CMAKE_Fortran_COMPILER_ID STREQUAL "Intel") - set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} /warn:none") - elseif (CMAKE_Fortran_COMPILER_ID MATCHES "IntelLLVM") - set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} /warn:none") - endif () - endif () - if (WIN32) - add_definitions (-D_CRT_SECURE_NO_WARNINGS) - endif () - # Borland uses -w- to suppress warnings. - if (BORLAND) - set (HDF5_WARNINGS_BLOCKED 1) - set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -w-") - endif () - - # Most compilers use -w to suppress warnings. - if (NOT HDF5_WARNINGS_BLOCKED) - set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -w") - endif () -endif () - -#----------------------------------------------------------------------------- -# HDF5 library compile options - to be made available to all targets -#----------------------------------------------------------------------------- -if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 10.0) - if (HDF5_ENABLE_BUILD_DIAGS) - message (STATUS "... default color and URL extended diagnostic messages enabled") - else () - message (STATUS "... disable color and URL extended diagnostic messages") - set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fdiagnostics-urls=never -fno-diagnostics-color") - endif () -endif () - -if (CMAKE_Fortran_COMPILER_ID STREQUAL "NAG") - message (STATUS "... Select IEEE floating-point mode full") - list (APPEND HDF5_CMAKE_Fortran_FLAGS "-ieee=full") -endif () -if (CMAKE_Fortran_COMPILER_ID STREQUAL "NVHPC") - if (NOT ${HDF_CFG_NAME} MATCHES "Debug" AND NOT ${HDF_CFG_NAME} MATCHES "Developer") - set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -Mnoframe") - if (NOT ${HDF_CFG_NAME} MATCHES "RelWithDebInfo") - set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -s") - endif () - else () - set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -Mbounds -Mchkptr -Mdclchk -g") - endif () -endif () - -if (NOT MSVC AND NOT MINGW) - # General flags - if (CMAKE_Fortran_COMPILER_ID STREQUAL "Intel") - if (_INTEL_WINDOWS) - ADD_H5_FLAGS (HDF5_CMAKE_Fortran_FLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/classic/win-ifort-general") - else () - ADD_H5_FLAGS (HDF5_CMAKE_Fortran_FLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/classic/ifort-general") - endif() - list (APPEND HDF5_CMAKE_Fortran_FLAGS "-free") - elseif (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU") - ADD_H5_FLAGS (HDF5_CMAKE_Fortran_FLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/gfort-general") - if (HDF5_ENABLE_DEV_WARNINGS) - ADD_H5_FLAGS (HDF5_CMAKE_Fortran_FLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/gfort-developer-general") - else () - ADD_H5_FLAGS (HDF5_CMAKE_Fortran_FLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/gfort-no-developer-general") - endif () - list (APPEND HDF5_CMAKE_Fortran_FLAGS "-ffree-form" "-fimplicit-none") - if (CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 8.0 AND NOT CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 4.6) - list (APPEND HDF5_CMAKE_Fortran_FLAGS "-std=f2008ts") - else () - list (APPEND HDF5_CMAKE_Fortran_FLAGS "-std=f2008") - endif () - elseif (CMAKE_Fortran_COMPILER_ID MATCHES "IntelLLVM") - if (_INTEL_WINDOWS) - ADD_H5_FLAGS (HDF5_CMAKE_Fortran_FLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/oneapi/win-ifort-general") - else () - ADD_H5_FLAGS (HDF5_CMAKE_Fortran_FLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/oneapi/ifort-general") - endif() - list (APPEND HDF5_CMAKE_Fortran_FLAGS "-free") - elseif (CMAKE_Fortran_COMPILER_ID STREQUAL "PGI") - list (APPEND HDF5_CMAKE_Fortran_FLAGS "-Mfreeform" "-Mdclchk" "-Mstandard" "-Mallocatable=03") - endif () - message (VERBOSE "HDF5_CMAKE_Fortran_FLAGS=${HDF5_CMAKE_Fortran_FLAGS}") - - if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU") - # Append more extra warning flags that only gcc 4.8+ knows about - if (NOT CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 4.8) - ADD_H5_FLAGS (HDF5_CMAKE_Fortran_FLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/gfort-4.8") - if (HDF5_ENABLE_DEV_WARNINGS) - ADD_H5_FLAGS (HDF5_CMAKE_Fortran_FLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/gfort-developer-4.8") - else () - ADD_H5_FLAGS (HDF5_CMAKE_Fortran_FLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/gfort-no-developer-4.8") - endif () - endif () - - # Append more extra warning flags that only gcc 4.9+ knows about - #if (NOT CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 4.9) - # ADD_H5_FLAGS (HDF5_CMAKE_Fortran_FLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/gfort-4.9") - #endif () - - # Append more extra warning flags that only gcc 5.x+ knows about - if (NOT CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 5.0) - if (HDF5_ENABLE_DEV_WARNINGS) - ADD_H5_FLAGS (HDF5_CMAKE_Fortran_FLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/gfort-developer-5") - endif () - endif () - - # Append more extra warning flags that only gcc 6.x+ knows about - if (NOT CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 6.0) - ADD_H5_FLAGS (HDF5_CMAKE_Fortran_FLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/gfort-6") - endif () - - # Append more extra warning flags that only gcc 7.x+ knows about - #if (NOT CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 7.0) - # ADD_H5_FLAGS (HDF5_CMAKE_Fortran_FLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/gfort-7") - #endif () - - # Append more extra warning flags that only gcc 8.x+ knows about - if (NOT CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 8.0) - ADD_H5_FLAGS (HDF5_CMAKE_Fortran_FLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/gfort-8") - endif () - - # Append more extra warning flags that only gcc 9.x+ knows about - #if (NOT CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 9.0) - # ADD_H5_FLAGS (HDF5_CMAKE_Fortran_FLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/gfort-9") - #endif () - endif () -else () - if (CMAKE_Fortran_COMPILER_ID STREQUAL "Intel") - ADD_H5_FLAGS (HDF5_CMAKE_Fortran_FLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/classic/win-ifort-general") - list (APPEND HDF5_CMAKE_Fortran_FLAGS "/stand:f03" "/free") - elseif (CMAKE_Fortran_COMPILER_ID MATCHES "IntelLLVM") - ADD_H5_FLAGS (HDF5_CMAKE_Fortran_FLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/oneapi/win-ifort-general") - list (APPEND HDF5_CMAKE_Fortran_FLAGS "/stand:f03" "/free") - endif () -endif () - diff --git a/config/cmake/HDFGnuCXXFlags.cmake b/config/cmake/HDFGnuCXXFlags.cmake new file mode 100644 index 00000000000..99aec322229 --- /dev/null +++ b/config/cmake/HDFGnuCXXFlags.cmake @@ -0,0 +1,192 @@ +# +# Copyright by The HDF Group. +# All rights reserved. +# +# This file is part of HDF5. The full HDF5 copyright notice, including +# terms governing use, modification, and redistribution, is contained in +# the COPYING file, which can be found at the root of the source code +# distribution tree, or in https://www.hdfgroup.org/licenses. +# If you do not have access to either file, you may request a copy from +# help@hdfgroup.org. +# + +############################################################################### +# This file included from HDFCompilerFlags.cmake with +# if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") +############################################################################### +#----------------------------------------------------------------------------- +# Compiler specific flags +#----------------------------------------------------------------------------- + + set (CMAKE_CXX_FLAGS "${CMAKE_ANSI_CFLAGS} ${CMAKE_CXX_FLAGS}") + if (${HDF_CFG_NAME} MATCHES "Debug" OR ${HDF_CFG_NAME} MATCHES "Developer") + if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0) + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Og -ftrapv -fno-common") + endif () + else () + if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0) + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstdarg-opt") + endif () + if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 10.0) + if (HDF5_ENABLE_BUILD_DIAGS) + message (STATUS "... default color and URL extended diagnostic messages enabled") + else () + message (STATUS "... disable color and URL extended diagnostic messages") + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-urls=never -fno-diagnostics-color") + endif () + endif () + endif () + +#----------------------------------------------------------------------------- +# HDF5 library compile options - to be made available to all targets +#----------------------------------------------------------------------------- + +if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "SunOS") + # General flags + # + # Note that some of the flags listed here really should be developer + # flags (listed in a separate variable, below) but we put them here + # because they are not raised by the current code and we'd like to + # know if they do start showing up. + # + # NOTE: Don't add -Wpadded here since we can't/won't fix the (many) + # warnings that are emitted. If you need it, add it at configure time. + if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 4.8) + # add the general CXX flags for g++ compiler versions 4.8 and above. + ADD_H5_FLAGS (HDF5_CMAKE_CXX_FLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/cxx-general") + ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/cxx-error-general") + endif () + message (VERBOSE "CMAKE_CXX_FLAGS_GENERAL=${HDF5_CMAKE_CXX_FLAGS}") +endif () + +#----------------------------------------------------------------------------- +# Option to allow the user to enable developer warnings +# Developer warnings (suggestions from gcc, not code problems) +#----------------------------------------------------------------------------- +if (HDF5_ENABLE_DEV_WARNINGS) + message (STATUS "....HDF5 CXX developer group warnings are enabled") + # Use the C warnings as CXX warnings are the same + ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/developer-general") +else () + # Use the C warnings as CXX warnings are the same + ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/no-developer-general") +endif () + + # Technically, variable-length arrays are part of the C99 standard, but + # we should approach them a bit cautiously... Only needed for gcc 4.X + if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0 AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 4.8) + # Use the C warnings as CXX warnings are the same + ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/4.8-4.last") + endif () + + # Append more extra warning flags that only gcc 4.8+ knows about + if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8) + ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/cxx-4.8") + if (HDF5_ENABLE_DEV_WARNINGS) + # Use the C warnings as CXX warnings are the same + ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/cxx-developer-4.8") + else () + ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/no-cxx-developer-4.8") + endif () + endif () + + # Append more extra warning flags that only gcc 4.9+ knows about + if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9) + # Use the C warnings as CXX warnings are the same + ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/cxx-4.9") + endif () + + # Append more extra warning flags that only gcc 5.1+ knows about + if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0) + # autotools always add the C flags with the CXX flags + ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/cxx-5") + ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/cxx-error-5") + endif () + + # Append more extra warning flags that only gcc 6.x+ knows about + if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.0) + # Use the C warnings as CXX warnings are the same + ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/6") + endif () + + # Append more extra warning flags that only gcc 7.x+ knows about + if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0) + # Use the C warnings as CXX warnings are the same + ADD_H5_FLAGS (H5_CXxFLAGS2 "${HDF5_SOURCE_DIR}/config/gnu-warnings/7") + if (HDF5_ENABLE_DEV_WARNINGS) + # Use the C warnings as CXX warnings are the same + ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/developer-7") + #else () + # ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/no-developer-7") + endif () + endif () + + # Append more extra warning flags that only gcc 8.x+ knows about + if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.0) + # Use the C warnings as CXX warnings are the same + ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/8") + ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/error-8") + if (HDF5_ENABLE_DEV_WARNINGS) + # Use the C warnings as CXX warnings are the same + ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/developer-8") + else () + # autotools always add the C flags with the CXX flags + ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/no-developer-8") + endif () + endif () + + # Append more extra warning flags that only gcc 9.x+ knows about + if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0) + # Use the C warnings as CXX warnings are the same + ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/cxx-9") + endif () + + # Append more extra warning flags that only gcc 9.3+ knows about + if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.3) + # do not use C warnings, gnu-warnings 9.3, no cxx warnings + # ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/9.3") + endif () + + # Append more extra warning flags that only gcc 10.x+ knows about + if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 10.0) + if (HDF5_ENABLE_DEV_WARNINGS) + # Use the C warnings as CXX warnings are the same + ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/developer-10") + #else () + # ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/no-developer-10") + endif () + endif () + +#----------------------------------------------------------------------------- +# Option to allow the user to enable all warnings +#----------------------------------------------------------------------------- +if (HDF5_ENABLE_ALL_WARNINGS) + message (STATUS "....All CXX Warnings are enabled") + if (MSVC) + if (HDF5_ENABLE_DEV_WARNINGS) + string (REGEX REPLACE "(^| )([/-])W[0-9]( |$)" " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + list (APPEND HDF5_CMAKE_CXX_FLAGS "/Wall" "/wd4668") + else () + string (REGEX REPLACE "(^| )([/-])W[0-9]( |$)" " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + list (APPEND HDF5_CMAKE_CXX_FLAGS "/W3" "/wd4100" "/wd4706" "/wd4127") + endif () + else () + list (APPEND HDF5_CMAKE_CXX_FLAGS ${H5_CXXFLAGS}) + endif () +endif () + +#----------------------------------------------------------------------------- +# This is in here to help some of the GCC based IDES like Eclipse +# and code blocks parse the compiler errors and warnings better. +#----------------------------------------------------------------------------- + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fmessage-length=0") + +#----------------------------------------------------------------------------- +# Option for --enable-symbols +# This option will force/override the default setting for all configurations +#----------------------------------------------------------------------------- +if (HDF5_ENABLE_SYMBOLS MATCHES "YES") + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g") +elseif (HDF5_ENABLE_SYMBOLS MATCHES "NO") + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s") +endif () diff --git a/config/cmake/HDFGnuFlags.cmake b/config/cmake/HDFGnuFlags.cmake new file mode 100644 index 00000000000..5367c5237d8 --- /dev/null +++ b/config/cmake/HDFGnuFlags.cmake @@ -0,0 +1,195 @@ +# +# Copyright by The HDF Group. +# All rights reserved. +# +# This file is part of HDF5. The full HDF5 copyright notice, including +# terms governing use, modification, and redistribution, is contained in +# the COPYING file, which can be found at the root of the source code +# distribution tree, or in https://www.hdfgroup.org/licenses. +# If you do not have access to either file, you may request a copy from +# help@hdfgroup.org. +# + +############################################################################### +# This file included from HDFCompilerFlags.cmake with +# if (CMAKE_C_COMPILER_ID STREQUAL "GNU") +############################################################################### +#----------------------------------------------------------------------------- +# Compiler specific flags +#----------------------------------------------------------------------------- + + set (CMAKE_C_FLAGS "${CMAKE_ANSI_CFLAGS} ${CMAKE_C_FLAGS}") + if (${HDF_CFG_NAME} MATCHES "Debug" OR ${HDF_CFG_NAME} MATCHES "Developer") + if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 5.0) + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Og -ftrapv -fno-common") + endif () + else () + if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 5.0 AND + NOT CMAKE_C_CLANG_TIDY) + # `clang-tidy` does not understand -fstdarg-opt + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstdarg-opt") + endif () + if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 10.0) + #----------------------------------------------------------------------------- + # Option to allow the user to enable build extended diagnostics + # + # This should NOT be on by default as it can cause process issues. + #----------------------------------------------------------------------------- + option (HDF5_ENABLE_BUILD_DIAGS "Enable color and URL extended diagnostic messages" OFF) + mark_as_advanced (HDF5_ENABLE_BUILD_DIAGS) + if (HDF5_ENABLE_BUILD_DIAGS) + message (STATUS "... default color and URL extended diagnostic messages enabled") + else () + message (STATUS "... disable color and URL extended diagnostic messages") + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fdiagnostics-urls=never -fno-diagnostics-color") + endif () + endif () + endif () + +#----------------------------------------------------------------------------- +# HDF5 library compile options - to be made available to all targets +#----------------------------------------------------------------------------- + +if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "SunOS") + # General flags + # + # Note that some of the flags listed here really should be developer + # flags (listed in a separate variable, below) but we put them here + # because they are not raised by the current code and we'd like to + # know if they do start showing up. + # + # NOTE: Don't add -Wpadded here since we can't/won't fix the (many) + # warnings that are emitted. If you need it, add it at configure time. + # Add general CFlags for GCC versions 4.8 and above + if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 4.8) + ADD_H5_FLAGS (HDF5_CMAKE_C_FLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/general") + ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/error-general") + endif () + # gcc automatically inlines based on the optimization level + # this is just a failsafe + list (APPEND H5_CFLAGS "-finline-functions") + message (VERBOSE "CMAKE_C_FLAGS_GENERAL=${HDF5_CMAKE_C_FLAGS}") +endif () + +#----------------------------------------------------------------------------- +# Option to allow the user to enable developer warnings +# Developer warnings (suggestions from gcc, not code problems) +#----------------------------------------------------------------------------- +if (HDF5_ENABLE_DEV_WARNINGS) + message (STATUS "....HDF5 developer group warnings are enabled") + if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 4.8) + ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/developer-general") + endif () + + # Turn on -Winline warnings now only for non-Debug and + # non-Developer builds. For at least GNU compilers this + # flag appears to conflict specifically with the -Og + # optimization flag and will produce warnings about functions + # not being considered for inlining + if (NOT ${HDF_CFG_NAME} MATCHES "Debug" AND NOT ${HDF_CFG_NAME} MATCHES "Developer") + list (APPEND H5_CFLAGS "-Winline") + endif () +else () + if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 4.8) + ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/no-developer-general") + endif () +endif () + + # Technically, variable-length arrays are part of the C99 standard, but + # we should approach them a bit cautiously... Only needed for gcc 4.X + if (CMAKE_C_COMPILER_VERSION VERSION_LESS 5.0 AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 4.8) + ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/4.8-4.last") + endif () + + # Append more extra warning flags that only gcc 4.8+ knows about + if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.8) + ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/4.8") + if (HDF5_ENABLE_DEV_WARNINGS) + ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/developer-4.8") + else () + ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/no-developer-4.8") + endif () + endif () + + # Append more extra warning flags that only gcc 4.9+ knows about + if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.9) + ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/4.9") + endif () + + # Append more extra warning flags that only gcc 5.x+ knows about + if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 5.0) + ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/5") + ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/error-5") + endif () + + # Append more extra warning flags that only gcc 6.x+ knows about + if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 6.0) + ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/6") + endif () + + # Append more extra warning flags that only gcc 7.x+ knows about + if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 7.0) + ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/7") + ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/error-7") + if (HDF5_ENABLE_DEV_WARNINGS) + ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/developer-7") + #else () + # ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/no-developer-7") + endif () + endif () + + # Append more extra warning flags that only gcc 8.x+ knows about + if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 8.0) + ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/8") + ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/error-8") + if (HDF5_ENABLE_DEV_WARNINGS) + ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/developer-8") + else () + ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/no-developer-8") + endif () + endif () + + # Append more extra warning flags that only gcc 9.x+ knows about + if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 9.0) + ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/9") + endif () + + # Append more extra warning flags that only gcc 9.3+ knows about + if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 9.3) + ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/9.3") + endif () + + # Append more extra warning flags that only gcc 10.x+ knows about + if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 10.0) + if (HDF5_ENABLE_DEV_WARNINGS) + ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/developer-10") + #else () + # ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/no-developer-10") + endif () + endif () + + # Append more extra warning flags that only gcc 12.x+ knows about + # or which should only be enabled for gcc 12.x+ + if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 12.0) + if (HDF5_ENABLE_DEV_WARNINGS) + ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/developer-12") + #else () + # ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/no-developer-12") + endif () + endif () + +#----------------------------------------------------------------------------- +# This is in here to help some of the GCC based IDES like Eclipse +# and code blocks parse the compiler errors and warnings better. +#----------------------------------------------------------------------------- + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fmessage-length=0") + +#----------------------------------------------------------------------------- +# Option for --enable-symbols +# This option will force/override the default setting for all configurations +#----------------------------------------------------------------------------- +if (HDF5_ENABLE_SYMBOLS MATCHES "YES") + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -fno-omit-frame-pointer") +elseif (HDF5_ENABLE_SYMBOLS MATCHES "NO") + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -s") +endif () diff --git a/config/cmake/HDFGnuFortranFlags.cmake b/config/cmake/HDFGnuFortranFlags.cmake new file mode 100644 index 00000000000..a114ceb0e08 --- /dev/null +++ b/config/cmake/HDFGnuFortranFlags.cmake @@ -0,0 +1,90 @@ +# +# Copyright by The HDF Group. +# All rights reserved. +# +# This file is part of HDF5. The full HDF5 copyright notice, including +# terms governing use, modification, and redistribution, is contained in +# the COPYING file, which can be found at the root of the source code +# distribution tree, or in https://www.hdfgroup.org/licenses. +# If you do not have access to either file, you may request a copy from +# help@hdfgroup.org. +# + +############################################################################### +# This file included from HDFCompilerFortranFlags.cmake with +# if (CMAKE_Fortran_COMPILER_ID MATCHES "GNU" ) +############################################################################### + +message (VERBOSE "Warnings Configuration: default Fortran: ${CMAKE_Fortran_FLAGS}") + +#----------------------------------------------------------------------------- +# HDF5 library compile options - to be made available to all targets +#----------------------------------------------------------------------------- +if (NOT CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 10.0) + if (HDF5_ENABLE_BUILD_DIAGS) + message (STATUS "... default color and URL extended diagnostic messages enabled") + else () + message (STATUS "... disable color and URL extended diagnostic messages") + set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fdiagnostics-urls=never -fno-diagnostics-color") + endif () +endif () + +if (NOT MSVC AND NOT MINGW) + # General flags + ADD_H5_FLAGS (HDF5_CMAKE_Fortran_FLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/gfort-general") + if (HDF5_ENABLE_DEV_WARNINGS) + ADD_H5_FLAGS (HDF5_CMAKE_Fortran_FLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/gfort-developer-general") + else () + ADD_H5_FLAGS (HDF5_CMAKE_Fortran_FLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/gfort-no-developer-general") + endif () + list (APPEND HDF5_CMAKE_Fortran_FLAGS "-ffree-form" "-fimplicit-none") + if (CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 8.0 AND NOT CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 4.6) + list (APPEND HDF5_CMAKE_Fortran_FLAGS "-std=f2008ts") + else () + list (APPEND HDF5_CMAKE_Fortran_FLAGS "-std=f2008") + endif () + message (VERBOSE "HDF5_CMAKE_Fortran_FLAGS=${HDF5_CMAKE_Fortran_FLAGS}") + + # Append more extra warning flags that only gcc 4.8+ knows about + if (NOT CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 4.8) + ADD_H5_FLAGS (HDF5_CMAKE_Fortran_FLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/gfort-4.8") + if (HDF5_ENABLE_DEV_WARNINGS) + ADD_H5_FLAGS (HDF5_CMAKE_Fortran_FLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/gfort-developer-4.8") + else () + ADD_H5_FLAGS (HDF5_CMAKE_Fortran_FLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/gfort-no-developer-4.8") + endif () + endif () + + # Append more extra warning flags that only gcc 4.9+ knows about + #if (NOT CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 4.9) + # ADD_H5_FLAGS (HDF5_CMAKE_Fortran_FLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/gfort-4.9") + #endif () + + # Append more extra warning flags that only gcc 5.x+ knows about + if (NOT CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 5.0) + if (HDF5_ENABLE_DEV_WARNINGS) + ADD_H5_FLAGS (HDF5_CMAKE_Fortran_FLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/gfort-developer-5") + endif () + endif () + + # Append more extra warning flags that only gcc 6.x+ knows about + if (NOT CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 6.0) + ADD_H5_FLAGS (HDF5_CMAKE_Fortran_FLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/gfort-6") + endif () + + # Append more extra warning flags that only gcc 7.x+ knows about + #if (NOT CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 7.0) + # ADD_H5_FLAGS (HDF5_CMAKE_Fortran_FLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/gfort-7") + #endif () + + # Append more extra warning flags that only gcc 8.x+ knows about + if (NOT CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 8.0) + ADD_H5_FLAGS (HDF5_CMAKE_Fortran_FLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/gfort-8") + endif () + + # Append more extra warning flags that only gcc 9.x+ knows about + #if (NOT CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 9.0) + # ADD_H5_FLAGS (HDF5_CMAKE_Fortran_FLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/gfort-9") + #endif () +endif () + diff --git a/config/cmake/HDFIntelCXXFlags.cmake b/config/cmake/HDFIntelCXXFlags.cmake new file mode 100644 index 00000000000..02220b51d46 --- /dev/null +++ b/config/cmake/HDFIntelCXXFlags.cmake @@ -0,0 +1,93 @@ +# +# Copyright by The HDF Group. +# All rights reserved. +# +# This file is part of HDF5. The full HDF5 copyright notice, including +# terms governing use, modification, and redistribution, is contained in +# the COPYING file, which can be found at the root of the source code +# distribution tree, or in https://www.hdfgroup.org/licenses. +# If you do not have access to either file, you may request a copy from +# help@hdfgroup.org. +# + +############################################################################### +# This file included from HDFCompilerFlags.cmake with +# if (CMAKE_CXX_COMPILER_ID MATCHES "Intel") +############################################################################### + +#----------------------------------------------------------------------------- +# Compiler specific flags +#----------------------------------------------------------------------------- +if (WIN32) + set (_INTEL_WINDOWS 1) +endif () + +#----------------------------------------------------------------------------- +# HDF5 library compile options - to be made available to all targets +#----------------------------------------------------------------------------- +if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "SunOS") + # General flags + # + # Note that some of the flags listed here really should be developer + # flags (listed in a separate variable, below) but we put them here + # because they are not raised by the current code and we'd like to + # know if they do start showing up. + # + # NOTE: Don't add -Wpadded here since we can't/won't fix the (many) + # warnings that are emitted. If you need it, add it at configure time. + if (CMAKE_CXX_COMPILER_ID STREQUAL "Intel") + if (_INTEL_WINDOWS) + ADD_H5_FLAGS (HDF5_CMAKE_CXX_FLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/classic/win-general") + else () + ADD_H5_FLAGS (HDF5_CMAKE_CXX_FLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/classic/general") + endif() + if (NOT _INTEL_WINDOWS) + if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 15.0) + ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/classic/15") + endif () + if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 18.0) + ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/classic/18") + endif () + endif () + elseif (CMAKE_CXX_COMPILER_ID MATCHES "IntelLLVM") + if (_INTEL_WINDOWS) + ADD_H5_FLAGS (HDF5_CMAKE_CXX_FLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/oneapi/win-general") + else () + ADD_H5_FLAGS (HDF5_CMAKE_CXX_FLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/oneapi/general") + endif () + endif () + message (VERBOSE "CMAKE_CXX_FLAGS_GENERAL=${HDF5_CMAKE_CXX_FLAGS}") +endif () + +#----------------------------------------------------------------------------- +# Option to allow the user to enable developer warnings +# Developer warnings (suggestions from gcc, not code problems) +#----------------------------------------------------------------------------- +if (HDF5_ENABLE_DEV_WARNINGS) + message (STATUS "....HDF5 CXX developer group warnings are enabled") + if (CMAKE_CXX_COMPILER_ID STREQUAL "Intel") + if (_INTEL_WINDOWS) + ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/classic/win-developer-general") + else () + ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/classic/developer-general") + endif () + elseif (CMAKE_CXX_COMPILER_ID MATCHES "IntelLLVM") + if (_INTEL_WINDOWS) + ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/oneapi/win-developer-general") + else () + ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/oneapi/developer-general") + endif () + endif () +endif () + +#----------------------------------------------------------------------------- +# Option for --enable-symbols +# This option will force/override the default setting for all configurations +#----------------------------------------------------------------------------- +if (NOT _INTEL_WINDOWS) + if (HDF5_ENABLE_SYMBOLS MATCHES "YES") + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g") + elseif (HDF5_ENABLE_SYMBOLS MATCHES "NO") + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,-s") + endif () +endif () diff --git a/config/cmake/HDFIntelFlags.cmake b/config/cmake/HDFIntelFlags.cmake new file mode 100644 index 00000000000..dbdbb616c15 --- /dev/null +++ b/config/cmake/HDFIntelFlags.cmake @@ -0,0 +1,106 @@ +# +# Copyright by The HDF Group. +# All rights reserved. +# +# This file is part of HDF5. The full HDF5 copyright notice, including +# terms governing use, modification, and redistribution, is contained in +# the COPYING file, which can be found at the root of the source code +# distribution tree, or in https://www.hdfgroup.org/licenses. +# If you do not have access to either file, you may request a copy from +# help@hdfgroup.org. +# + +############################################################################### +# This file included from HDFCompilerFlags.cmake with +# if (CMAKE_C_COMPILER_ID MATCHES "Intel") +############################################################################### + +#----------------------------------------------------------------------------- +# Compiler specific flags +#----------------------------------------------------------------------------- +if (WIN32) + set (_INTEL_WINDOWS 1) +endif () + +# Disable deprecation warnings for standard C functions. +# really only needed for newer versions of VS, but should +# not hurt other versions, and this will work into the +# future +if (MSVC OR _INTEL_WINDOWS) + add_definitions (-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE) +endif () + +#----------------------------------------------------------------------------- +# HDF5 library compile options - to be made available to all targets +#----------------------------------------------------------------------------- +if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "SunOS") + # General flags + # + # Note that some of the flags listed here really should be developer + # flags (listed in a separate variable, below) but we put them here + # because they are not raised by the current code and we'd like to + # know if they do start showing up. + # + # NOTE: Don't add -Wpadded here since we can't/won't fix the (many) + # warnings that are emitted. If you need it, add it at configure time. + if (CMAKE_C_COMPILER_ID STREQUAL "Intel") + if (_INTEL_WINDOWS) + ADD_H5_FLAGS (HDF5_CMAKE_C_FLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/classic/win-general") + else () + ADD_H5_FLAGS (HDF5_CMAKE_C_FLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/classic/general") + endif() + if (NOT _INTEL_WINDOWS) + if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 15.0) + ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/classic/15") + endif () + # this is just a failsafe + list (APPEND H5_CFLAGS "-finline-functions") + if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 18.0) + ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/classic/18") + endif () + endif () + elseif (CMAKE_C_COMPILER_ID MATCHES "IntelLLVM") + if (_INTEL_WINDOWS) + ADD_H5_FLAGS (HDF5_CMAKE_C_FLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/oneapi/win-general") + else () + # this is just a failsafe + list (APPEND H5_CFLAGS "-finline-functions") + ADD_H5_FLAGS (HDF5_CMAKE_C_FLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/oneapi/general") + endif () + endif () + message (VERBOSE "CMAKE_C_FLAGS_GENERAL=${HDF5_CMAKE_C_FLAGS}") +endif () + +#----------------------------------------------------------------------------- +# Option to allow the user to enable developer warnings +# Developer warnings (suggestions from gcc, not code problems) +#----------------------------------------------------------------------------- +if (HDF5_ENABLE_DEV_WARNINGS) + message (STATUS "....HDF5 developer group warnings are enabled") + if (CMAKE_C_COMPILER_ID STREQUAL "Intel") + if (_INTEL_WINDOWS) + ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/classic/win-developer-general") + else () + ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/classic/developer-general") + endif () + elseif (CMAKE_C_COMPILER_ID MATCHES "IntelLLVM") + if (_INTEL_WINDOWS) + ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/oneapi/win-developer-general") + else () + ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/oneapi/developer-general") + endif () + endif () +endif () + +# Turn on -Winline warnings now only for non-Debug and +# non-Developer builds. For at least GNU compilers this +# flag appears to conflict specifically with the -Og +# optimization flag and will produce warnings about functions +# not being considered for inlining +if (NOT ${HDF_CFG_NAME} MATCHES "Debug" AND NOT ${HDF_CFG_NAME} MATCHES "Developer") + if (CMAKE_C_COMPILER_ID STREQUAL "Intel" AND NOT _INTEL_WINDOWS) + list (APPEND H5_CFLAGS "-Winline") + elseif (CMAKE_C_COMPILER_ID MATCHES "IntelLLVM" AND NOT _INTEL_WINDOWS) + list (APPEND H5_CFLAGS "-Winline") + endif () +endif () diff --git a/config/cmake/HDFIntelFortranFlags.cmake b/config/cmake/HDFIntelFortranFlags.cmake new file mode 100644 index 00000000000..8f55badf699 --- /dev/null +++ b/config/cmake/HDFIntelFortranFlags.cmake @@ -0,0 +1,65 @@ +# +# Copyright by The HDF Group. +# All rights reserved. +# +# This file is part of HDF5. The full HDF5 copyright notice, including +# terms governing use, modification, and redistribution, is contained in +# the COPYING file, which can be found at the root of the source code +# distribution tree, or in https://www.hdfgroup.org/licenses. +# If you do not have access to either file, you may request a copy from +# help@hdfgroup.org. +# + +############################################################################### +# This file included from HDFCompilerFortranFlags.cmake with +# if (CMAKE_Fortran_COMPILER_ID MATCHES "Intel" ) +############################################################################### + +message (VERBOSE "Warnings Configuration: default Fortran: ${CMAKE_Fortran_FLAGS}") + +#----------------------------------------------------------------------------- +# Option to allow the user to disable compiler warnings +#----------------------------------------------------------------------------- +if (HDF5_DISABLE_COMPILER_WARNINGS) + # MSVC uses /w to suppress warnings. It also complains if another + # warning level is given, so remove it. + if (MSVC) + if (CMAKE_Fortran_COMPILER_ID STREQUAL "Intel") + set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} /warn:none") + elseif (CMAKE_Fortran_COMPILER_ID MATCHES "IntelLLVM") + set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} /warn:none") + endif () + endif () +endif () + +#----------------------------------------------------------------------------- +# HDF5 library compile options - to be made available to all targets +#----------------------------------------------------------------------------- +if (NOT MSVC AND NOT MINGW) + # General flags + if (CMAKE_Fortran_COMPILER_ID STREQUAL "Intel") + if (_INTEL_WINDOWS) + ADD_H5_FLAGS (HDF5_CMAKE_Fortran_FLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/classic/win-ifort-general") + else () + ADD_H5_FLAGS (HDF5_CMAKE_Fortran_FLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/classic/ifort-general") + endif() + list (APPEND HDF5_CMAKE_Fortran_FLAGS "-free") + elseif (CMAKE_Fortran_COMPILER_ID MATCHES "IntelLLVM") + if (_INTEL_WINDOWS) + ADD_H5_FLAGS (HDF5_CMAKE_Fortran_FLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/oneapi/win-ifort-general") + else () + ADD_H5_FLAGS (HDF5_CMAKE_Fortran_FLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/oneapi/ifort-general") + endif() + list (APPEND HDF5_CMAKE_Fortran_FLAGS "-free") + endif () + message (VERBOSE "HDF5_CMAKE_Fortran_FLAGS=${HDF5_CMAKE_Fortran_FLAGS}") +else () + if (CMAKE_Fortran_COMPILER_ID STREQUAL "Intel") + ADD_H5_FLAGS (HDF5_CMAKE_Fortran_FLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/classic/win-ifort-general") + list (APPEND HDF5_CMAKE_Fortran_FLAGS "/stand:f03" "/free") + elseif (CMAKE_Fortran_COMPILER_ID MATCHES "IntelLLVM") + ADD_H5_FLAGS (HDF5_CMAKE_Fortran_FLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/oneapi/win-ifort-general") + list (APPEND HDF5_CMAKE_Fortran_FLAGS "/stand:f03" "/free") + endif () +endif () + diff --git a/config/cmake/HDFMsvcCXXFlags.cmake b/config/cmake/HDFMsvcCXXFlags.cmake new file mode 100644 index 00000000000..4970622cc3d --- /dev/null +++ b/config/cmake/HDFMsvcCXXFlags.cmake @@ -0,0 +1,26 @@ +# +# Copyright by The HDF Group. +# All rights reserved. +# +# This file is part of HDF5. The full HDF5 copyright notice, including +# terms governing use, modification, and redistribution, is contained in +# the COPYING file, which can be found at the root of the source code +# distribution tree, or in https://www.hdfgroup.org/licenses. +# If you do not have access to either file, you may request a copy from +# help@hdfgroup.org. +# + +############################################################################### +# This file included from HDFCompilerFlags.cmake with +# if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC") +############################################################################### + +#----------------------------------------------------------------------------- +# Compiler specific flags +#----------------------------------------------------------------------------- + +# MSVC 14.28 enables C5105, but the Windows SDK 10.0.18362.0 triggers it. + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc") + if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.28) + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -wd5105") + endif () diff --git a/config/cmake/HDFMsvcFlags.cmake b/config/cmake/HDFMsvcFlags.cmake new file mode 100644 index 00000000000..a0ca9290f93 --- /dev/null +++ b/config/cmake/HDFMsvcFlags.cmake @@ -0,0 +1,25 @@ +# +# Copyright by The HDF Group. +# All rights reserved. +# +# This file is part of HDF5. The full HDF5 copyright notice, including +# terms governing use, modification, and redistribution, is contained in +# the COPYING file, which can be found at the root of the source code +# distribution tree, or in https://www.hdfgroup.org/licenses. +# If you do not have access to either file, you may request a copy from +# help@hdfgroup.org. +# + +############################################################################### +# This file included from HDFCompilerFlags.cmake with +# if (CMAKE_C_COMPILER_ID MATCHES "MSVC") +############################################################################### + +#----------------------------------------------------------------------------- +# Compiler specific flags +#----------------------------------------------------------------------------- + +# MSVC 14.28 enables C5105, but the Windows SDK 10.0.18362.0 triggers it. +if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 19.28) + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -wd5105") +endif () diff --git a/config/cmake/HDFNvhpcCXXFlags.cmake b/config/cmake/HDFNvhpcCXXFlags.cmake new file mode 100644 index 00000000000..eab491bf01e --- /dev/null +++ b/config/cmake/HDFNvhpcCXXFlags.cmake @@ -0,0 +1,33 @@ +# +# Copyright by The HDF Group. +# All rights reserved. +# +# This file is part of HDF5. The full HDF5 copyright notice, including +# terms governing use, modification, and redistribution, is contained in +# the COPYING file, which can be found at the root of the source code +# distribution tree, or in https://www.hdfgroup.org/licenses. +# If you do not have access to either file, you may request a copy from +# help@hdfgroup.org. +# + +############################################################################### +# This file included from HDFCompilerFlags.cmake with +# if (CMAKE_CXX_COMPILER_ID MATCHES "NVHPC" ) +############################################################################### + +#----------------------------------------------------------------------------- +# Compiler specific flags +#----------------------------------------------------------------------------- +if (NOT DEFINED CMAKE_CXX${CMAKE_CXX_STANDARD}_STANDARD_COMPILE_OPTION) + if (NOT CMAKE_CXX_STANDARD OR CMAKE_CXX_STANDARD EQUAL 11) + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_C11_STANDARD_COMPILE_OPTION}") + endif () +endif () +if (NOT ${HDF_CFG_NAME} MATCHES "Debug" AND NOT ${HDF_CFG_NAME} MATCHES "Developer") + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Minform=warn") + if (NOT ${HDF_CFG_NAME} MATCHES "RelWithDebInfo") + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s") + endif () +else () + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Mbounds -gopt -g") +endif () diff --git a/config/cmake/HDFNvhpcFlags.cmake b/config/cmake/HDFNvhpcFlags.cmake new file mode 100644 index 00000000000..77443942064 --- /dev/null +++ b/config/cmake/HDFNvhpcFlags.cmake @@ -0,0 +1,28 @@ +# +# Copyright by The HDF Group. +# All rights reserved. +# +# This file is part of HDF5. The full HDF5 copyright notice, including +# terms governing use, modification, and redistribution, is contained in +# the COPYING file, which can be found at the root of the source code +# distribution tree, or in https://www.hdfgroup.org/licenses. +# If you do not have access to either file, you may request a copy from +# help@hdfgroup.org. +# + +############################################################################### +# This file included from HDFCompilerFlags.cmake with +# if (CMAKE_C_COMPILER_ID MATCHES "NVHPC" ) +############################################################################### + +#----------------------------------------------------------------------------- +# Compiler specific flags +#----------------------------------------------------------------------------- +set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Minform=warn") +if (NOT ${HDF_CFG_NAME} MATCHES "Debug" AND NOT ${HDF_CFG_NAME} MATCHES "Developer") + if (NOT ${HDF_CFG_NAME} MATCHES "RelWithDebInfo") + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -s") + endif () +else () + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Mbounds -gopt") +endif () diff --git a/config/cmake/HDFNvhpcFortranFlags.cmake b/config/cmake/HDFNvhpcFortranFlags.cmake new file mode 100644 index 00000000000..a6ae6930262 --- /dev/null +++ b/config/cmake/HDFNvhpcFortranFlags.cmake @@ -0,0 +1,38 @@ +# +# Copyright by The HDF Group. +# All rights reserved. +# +# This file is part of HDF5. The full HDF5 copyright notice, including +# terms governing use, modification, and redistribution, is contained in +# the COPYING file, which can be found at the root of the source code +# distribution tree, or in https://www.hdfgroup.org/licenses. +# If you do not have access to either file, you may request a copy from +# help@hdfgroup.org. +# + +############################################################################### +# This file included from HDFCompilerFortranFlags.cmake with +# if (CMAKE_Fortran_COMPILER_ID MATCHES "NVHPC" ) +############################################################################### + +message (VERBOSE "Warnings Configuration: default Fortran: ${CMAKE_Fortran_FLAGS}") + +#----------------------------------------------------------------------------- +# HDF5 library compile options - to be made available to all targets +#----------------------------------------------------------------------------- +if (CMAKE_Fortran_COMPILER_ID STREQUAL "NVHPC") + if (NOT ${HDF_CFG_NAME} MATCHES "Debug" AND NOT ${HDF_CFG_NAME} MATCHES "Developer") + set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -Mnoframe") + if (NOT ${HDF_CFG_NAME} MATCHES "RelWithDebInfo") + set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -s") + endif () + else () + set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -Mbounds -Mchkptr -Mdclchk -g") + endif () +endif () + +if (NOT MSVC AND NOT MINGW) + # General flags + message (VERBOSE "HDF5_CMAKE_Fortran_FLAGS=${HDF5_CMAKE_Fortran_FLAGS}") +endif () + diff --git a/release_docs/RELEASE.txt b/release_docs/RELEASE.txt index a92e2ed9be8..a83f2ea2cf0 100644 --- a/release_docs/RELEASE.txt +++ b/release_docs/RELEASE.txt @@ -47,6 +47,24 @@ New Features 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__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). + + - CMake: Split compiler specific flags into separate files + + The compiler specific flags have been split into separate files to make + it easier to maintain and add new compiler flags. The flags for NVHPC, + Intel, GNU and Clang compilers are now in separate files included from + the current compiler flags files; HDFCompilerFlags.cmake. + - Added a configuration option for internal threading/concurrency support: CMake: HDF5_ENABLE_THREADS (ON/OFF) (Default: ON) diff --git a/src/H5build_settings.cmake.c.in b/src/H5build_settings.cmake.c.in index 6dac78d27b1..e9b24f3f8a2 100644 --- a/src/H5build_settings.cmake.c.in +++ b/src/H5build_settings.cmake.c.in @@ -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" @@ -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" @@ -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" diff --git a/src/libhdf5.settings.cmake.in b/src/libhdf5.settings.cmake.in index 2f9b5f5c960..5ed5be70160 100644 --- a/src/libhdf5.settings.cmake.in +++ b/src/libhdf5.settings.cmake.in @@ -38,7 +38,7 @@ 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@ @@ -46,7 +46,7 @@ Languages: 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@ @@ -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@