Skip to content

Commit

Permalink
Require C++17 in autotools and cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
lballabio committed Jul 23, 2024
1 parent 250bd38 commit 3f98c71
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 44 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/linux-full-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,6 @@ jobs:
cc: clang
cxx: clang++
cxxflags: -Wno-deprecated-declarations
- name: "C++14 mode"
shortname: c++14
tag: rolling
cc: gcc
cxx: g++
cxxflags: "-std=c++14"
- name: "C++17 mode"
shortname: c++17
tag: rolling
Expand Down
7 changes: 0 additions & 7 deletions .github/workflows/linux-nondefault.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,6 @@ jobs:
cc: clang
cxx: clang++
cxxflags: -Wno-deprecated-declarations
- name: "C++14 mode"
shortname: c++14
tag: rolling
cc: gcc
cxx: g++
cxxflags: "-std=c++14"
- name: "C++17 mode"
shortname: c++17
tag: rolling
Expand All @@ -125,7 +119,6 @@ jobs:
tag: rolling
cc: gcc
cxx: g++
cxxflags: "-std=c++17"
configureflags: --disable-std-function --disable-std-tuple --enable-std-pointers --enable-std-any --enable-std-optional
- name: "OpenMP enabled"
shortname: openmp
Expand Down
6 changes: 0 additions & 6 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@ jobs:
cxx: clang++
cxxflags: -Wno-deprecated-declarations
tests: true
- name: "C++14 mode"
shortname: c++14
tag: rolling
cc: gcc
cxx: g++
cxxflags: "-std=c++14"
- name: "C++17 mode"
shortname: c++17
tag: rolling
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/macos-nondefault.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ jobs:
classes: [boost, std]
include:
- classes: std
cxxflags: "-std=c++17"
configureflags: --disable-std-function --disable-std-tuple --enable-std-pointers --enable-std-optional --enable-std-any
steps:
- uses: actions/checkout@v4
Expand All @@ -28,7 +27,7 @@ jobs:
- name: Build
run: |
./autogen.sh
./configure --disable-shared --with-boost-include=`brew --prefix`/include --enable-error-lines --enable-error-functions --enable-tracing --enable-indexed-coupons --enable-extra-safety-checks --enable-sessions --enable-thread-safe-observer-pattern --enable-intraday --disable-faster-lazy-objects --enable-throwing-in-cycles --enable-null-as-functions ${{ matrix.configureflags }} CC="clang" CXX="clang++" CXXFLAGS="-O2 -g0 -Wall -Werror ${{ matrix.cxxflags }}"
./configure --disable-shared --with-boost-include=`brew --prefix`/include --enable-error-lines --enable-error-functions --enable-tracing --enable-indexed-coupons --enable-extra-safety-checks --enable-sessions --enable-thread-safe-observer-pattern --enable-intraday --disable-faster-lazy-objects --enable-throwing-in-cycles --enable-null-as-functions ${{ matrix.configureflags }} CC="clang" CXX="clang++" CXXFLAGS="-O2 -g0 -Wall -Werror"
make -j 3
- name: Run tests
run: |
Expand Down
10 changes: 5 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,16 @@ set(QL_EXTERNAL_SUBDIRECTORIES "" CACHE STRING "Optional list of external source
# set -lpapi here
set(QL_EXTRA_LINK_LIBRARIES "" CACHE STRING "Optional extra link libraries to add to QuantLib")

# Require C++14 or higher
# Require C++17 or higher
if (NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
elseif(CMAKE_CXX_STANDARD LESS 14)
message(FATAL_ERROR "Please specify CMAKE_CXX_STANDARD of 14 or higher")
set(CMAKE_CXX_STANDARD 17)
elseif(CMAKE_CXX_STANDARD LESS 17)
message(FATAL_ERROR "Please specify CMAKE_CXX_STANDARD of 17 or higher")
endif()
if (NOT DEFINED CMAKE_CXX_STANDARD_REQUIRED)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
endif()
# Avoid use of compiler language extensions, i.e. -std=c++14 not -std=gnu++14
# Avoid use of compiler language extensions, i.e. -std=c++17 not -std=gnu++17
if (NOT DEFINED CMAKE_CXX_EXTENSIONS)
set(CMAKE_CXX_EXTENSIONS FALSE)
endif()
Expand Down
26 changes: 12 additions & 14 deletions acinclude.m4
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@

# QL_CHECK_CPP14
# QL_CHECK_CPP17
# --------------------
# Check whether C++14 features are supported by default.
# If not (e.g., with Clang on Mac OS) add -std=c++14
AC_DEFUN([QL_CHECK_CPP14],
[AC_MSG_CHECKING([for C++14 support])
# Check whether C++17 features are supported by default.
# If not (e.g., with Clang on Mac OS) add -std=c++17
AC_DEFUN([QL_CHECK_CPP17],
[AC_MSG_CHECKING([for C++17 support])
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM(
[[@%:@include <memory>
class C {
public:
C(int) noexcept;
auto f() { return std::make_unique<C>(1); }
};
[[@%:@include <optional>
int main() {
auto x = std::optional<int>{42};
}
]],
[[]])],
[AC_MSG_RESULT([yes])],
[AC_MSG_RESULT([no: adding -std=c++14 to CXXFLAGS])
AC_SUBST([CPP14_CXXFLAGS],["-std=c++14"])
AC_SUBST([CXXFLAGS],["${CXXFLAGS} -std=c++14"])
[AC_MSG_RESULT([no: adding -std=c++17 to CXXFLAGS])
AC_SUBST([CPP17_CXXFLAGS],["-std=c++17"])
AC_SUBST([CXXFLAGS],["${CXXFLAGS} -std=c++17"])
])
])

Expand Down
4 changes: 2 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ if test "$ql_openmp" = "yes" ; then
AC_SUBST([CXXFLAGS],["${CXXFLAGS} ${OPENMP_CXXFLAGS}"])
fi

# Check for C++14 support
QL_CHECK_CPP14
# Check for C++17 support
QL_CHECK_CPP17

# Check for other compiler flags
QL_CHECK_SYSTEM_HEADER_PREFIX
Expand Down
2 changes: 1 addition & 1 deletion quantlib-config.in
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ while test $# -gt 0; do
echo @PACKAGE_VERSION@
;;
--cflags)
echo -I@includedir@ @BOOST_INCLUDE@ @OPENMP_CXXFLAGS@ @PTHREAD_CXXFLAGS@ @CPP14_CXXFLAGS@
echo -I@includedir@ @BOOST_INCLUDE@ @OPENMP_CXXFLAGS@ @PTHREAD_CXXFLAGS@ @CPP17_CXXFLAGS@
;;
--libs)
echo -L@libdir@ -lQuantLib @OPENMP_CXXFLAGS@ @PTHREAD_LIB@
Expand Down
2 changes: 1 addition & 1 deletion quantlib.pc.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ includedir=@includedir@
Name: QuantLib
Description: The free/open-source library for quantitative finance.
Version: @PACKAGE_VERSION@
Cflags: -I@includedir@ @BOOST_INCLUDE@ @OPENMP_CXXFLAGS@ @PTHREAD_CXXFLAGS@ @CPP14_CXXFLAGS@
Cflags: -I@includedir@ @BOOST_INCLUDE@ @OPENMP_CXXFLAGS@ @PTHREAD_CXXFLAGS@ @CPP17_CXXFLAGS@
Libs: -L@libdir@ -lQuantLib @OPENMP_CXXFLAGS@ @PTHREAD_LIB@

0 comments on commit 3f98c71

Please sign in to comment.