File: 01-use-latest-available-C%2B%2B-standard.diff

package info (click to toggle)
pulseview 0.4.2-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,064 kB
  • sloc: cpp: 25,958; xml: 215; java: 42; makefile: 2
file content (82 lines) | stat: -rw-r--r-- 3,322 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
From: Gerhard Sittig
Date: Thu, 24 Nov 2022 13:48:00 +0000 (+0100)
Origin: upstream, https://sigrok.org/gitweb/?p=pulseview.git;a=commitdiff_plain;h=fa8d0fcb4cff4f19943fe3ff152dc1428b400b01
Bug-Debian: https://bugs.debian.org/1110613
Description: CMakeLists.txt: always use highest available C++17/C++14/C++11 standard
 Check for the availability of the C++17, C++14, and C++11 language
 standards. Prefer the highest available to build any of the feature
 tests or applications. Factor out common conditions into a central spot
 in the CMake build rules. Rename variables to avoid special chars in
 their name.
 .
 Setup both the CMAKE_CXX_STANDARD cmake variable which internally is
 used transparently, as well explicitly pass the -std= compile flag in
 build instructions for feature checks and application code. It's what
 the smuview build does, should also work for pulseview, and is assumed
 to not harm either in case it's redundant.
 .
 This unbreaks operation in most generic ways on platforms like MacOS 12
 (system library), and for external libraries of differing degrees of
 aggressivness (boost, glibmm, sig++).
 .
 (Jonathan McDowell: Fixed up against released CMakeLists.txt version)
---

diff --git a/CMakeLists.txt b/CMakeLists.txt
index c29fa28..3e8894f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -74,6 +74,8 @@ add_subdirectory(manual)
 #= Dependencies
 #-------------------------------------------------------------------------------
 
+include(CheckCXXCompilerFlag)
+
 list(APPEND PKGDEPS glib-2.0>=2.28.0)
 list(APPEND PKGDEPS glibmm-2.4>=2.28.0)
 
@@ -94,6 +96,26 @@ if(ANDROID)
 endif()
 
 find_package(PkgConfig)
+
+check_cxx_compiler_flag("-std=c++17" HAVE_STD_CXX_17)
+check_cxx_compiler_flag("-std=c++14" HAVE_STD_CXX_14)
+check_cxx_compiler_flag("-std=c++11" HAVE_STD_CXX_11)
+if(HAVE_STD_CXX_17)
+	message(STATUS "Using C++17 for the application build")
+	set(CMAKE_CXX_STANDARD 17)
+	set(REQUIRED_STD_CXX_FLAGS "-std=c++17")
+elseif(HAVE_STD_CXX_14)
+	message(STATUS "Using C++14 for the application build")
+	set(CMAKE_CXX_STANDARD 14)
+	set(REQUIRED_STD_CXX_FLAGS "-std=c++14")
+elseif(HAVE_STD_CXX_11)
+	message(STATUS "Using C++11 for the application build")
+	set(CMAKE_CXX_STANDARD 11)
+	set(REQUIRED_STD_CXX_FLAGS "-std=c++11")
+else()
+	message(FATAL_ERROR "Need modern C++, at least language standard 11")
+endif()
+
 pkg_check_modules(LIBSRCXX ${LIBSR_CXX_BINDING})
 if(NOT LIBSRCXX_FOUND OR NOT LIBSRCXX_VERSION)
 	message(FATAL_ERROR "libsigrok C++ bindings missing, check libsigrok's 'configure' output (missing dependencies?)")
@@ -146,7 +168,7 @@ function(check_working_cxx_atomics varname additional_lib)
   include(CheckCXXSourceCompiles)
   include(CMakePushCheckState)
   cmake_push_check_state()
-  set(CMAKE_REQUIRED_FLAGS "-std=c++11")
+  set(CMAKE_REQUIRED_FLAGS "${REQUIRED_STD_CXX_FLAGS}")
   set(CMAKE_REQUIRED_LIBRARIES "${additional_lib}")
   set(CMAKE_REQUIRED_QUIET 1)
   CHECK_CXX_SOURCE_COMPILES("
@@ -445,7 +467,7 @@ qt5_add_resources(pulseview_RESOURCES_RCC ${CMAKE_BINARY_DIR}/translations.qrc)
 add_definitions(-DQT_NO_KEYWORDS)
 add_definitions(-D__STDC_LIMIT_MACROS)
 add_definitions(-Wall -Wextra)
-add_definitions(-std=c++11)
+add_definitions(${REQUIRED_STD_CXX_FLAGS})
 add_definitions(-DBOOST_MATH_DISABLE_FLOAT128=1)
 
 if(ENABLE_FLOW)