aboutsummaryrefslogtreecommitdiff
path: root/package/mraa/0002-CMakeLists.txt-add-BUILDCPP-option.patch
blob: fbadfe79ef75e10ccb82e8690a37f0849f561253 (plain)
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
From cb88e4dd1fbbb9d24e625dba2768b88ed99da309 Mon Sep 17 00:00:00 2001
From: Fabrice Fontaine <fontaine.fabrice@gmail.com>
Date: Sat, 13 Jun 2020 22:51:37 +0200
Subject: [PATCH] CMakeLists.txt: add BUILDCPP option

C++ is a mandatory dependency since version 1.4.0 and
https://github.com/eclipse/mraa/commit/122cab1f1e53b7c9c7cd82905b962071f9bad9dc

As a result, build on embedded toolchains that do not support C++ fails
on:

CMake Error at CMakeLists.txt:2 (project):
  The CMAKE_CXX_COMPILER:

    /home/naourr/work/instance-1/output-1/per-package/mraa/host/bin/arm-linux-g++

  is not a full path to an existing compiler tool.

Fixes:
 - http://autobuild.buildroot.org/results/31086422e03611c16ab59c4418e3669b580bc0c0

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
[Retrieved from:
https://github.com/eclipse/mraa/commit/cb88e4dd1fbbb9d24e625dba2768b88ed99da309]
---
 CMakeLists.txt                | 69 +++++++++++++++++++----------------
 src/java/CMakeLists.txt       |  4 +-
 src/javascript/CMakeLists.txt | 34 +++++++++--------
 3 files changed, 59 insertions(+), 48 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 250d9106e..90c0dc920 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,5 +1,5 @@
 cmake_minimum_required (VERSION 2.8.11)
-project (mraa C CXX)
+project (mraa C)
 
 FIND_PACKAGE (Threads REQUIRED)
 
@@ -11,6 +11,8 @@ else ()
   set (CMAKE_C_STANDARD 99)
 endif ()
 
+option (BUILDCPP "Enable C++ (needed by FTDI4222 and tests)" ON)
+
 ###############################################################################
 # Detect supported warning flags
 # Modified from work By Dan Liew (fpbench - MIT)
@@ -33,15 +35,18 @@ set (MRAA_C_WARNING_FLAGS
   -Werror=missing-parameter-type
 )
 
-# Warning flags for the C++ compiler only
-set (MRAA_CXX_WARNING_FLAGS
-  -Wnon-virtual-dtor
-  -Woverloaded-virtual
-  -Wreorder
-)
-
 include (CheckCCompilerFlag)
-include (CheckCXXCompilerFlag)
+if (BUILDCPP)
+  # Warning flags for the C++ compiler only
+  set (MRAA_CXX_WARNING_FLAGS
+    -Wnon-virtual-dtor
+    -Woverloaded-virtual
+    -Wreorder
+  )
+
+  enable_language (CXX)
+  include (CheckCXXCompilerFlag)
+endif ()
 function (MRAA_SANITIZE_FLAG_NAME OUTPUT_VAR FLAG)
   string (REPLACE "-" "_" SANITIZED_FLAG_NAME "${FLAG}")
   string (REPLACE "/" "_" SANITIZED_FLAG_NAME "${SANITIZED_FLAG_NAME}")
@@ -62,28 +67,30 @@ foreach (flag ${MRAA_BOTH_WARNING_FLAGS} ${MRAA_C_WARNING_FLAGS})
   endif ()
 endforeach ()
 
-# Globally set C++ compiler warning flags that are supported and emit
-# a warning about unsupported flags
-foreach (flag ${MRAA_BOTH_WARNING_FLAGS} ${MRAA_CXX_WARNING_FLAGS})
-  MRAA_SANITIZE_FLAG_NAME (SANITIZED_FLAG_NAME "${flag}")
-  CHECK_CXX_COMPILER_FLAG ("${flag}" HAS_CXX_${SANITIZED_FLAG_NAME})
-  if (HAS_CXX_${SANITIZED_FLAG_NAME})
-    set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
-  else ()
-    message (WARNING "C++ compiler does not support flag \"${flag}\"")
-  endif ()
-endforeach ()
-
-# This function adds the c++11 flag to a c++ target (if supported)
-function(use_cxx_11 targetname)
-  include(CheckCXXCompilerFlag)
-  CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
-  if (COMPILER_SUPPORTS_CXX11)
-    set_target_properties(${targetname} PROPERTIES COMPILE_FLAGS "-std=c++11")
-  else()
-    message(FATAL_ERROR "Target '${targetname}' requires c++11 which is not supported by this compiler")
-  endif()
-endfunction()
+if (BUILDCPP)
+  # Globally set C++ compiler warning flags that are supported and emit
+  # a warning about unsupported flags
+  foreach (flag ${MRAA_BOTH_WARNING_FLAGS} ${MRAA_CXX_WARNING_FLAGS})
+    MRAA_SANITIZE_FLAG_NAME (SANITIZED_FLAG_NAME "${flag}")
+    CHECK_CXX_COMPILER_FLAG ("${flag}" HAS_CXX_${SANITIZED_FLAG_NAME})
+    if (HAS_CXX_${SANITIZED_FLAG_NAME})
+      set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
+    else ()
+      message (WARNING "C++ compiler does not support flag \"${flag}\"")
+    endif ()
+  endforeach ()
+
+  # This function adds the c++11 flag to a c++ target (if supported)
+  function(use_cxx_11 targetname)
+    include(CheckCXXCompilerFlag)
+    CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
+    if (COMPILER_SUPPORTS_CXX11)
+      set_target_properties(${targetname} PROPERTIES COMPILE_FLAGS "-std=c++11")
+    else()
+      message(FATAL_ERROR "Target '${targetname}' requires c++11 which is not supported by this compiler")
+    endif()
+  endfunction()
+endif()
 
 # Set CMAKE_INSTALL_LIBDIR if not defined
 include(GNUInstallDirs)
diff --git a/src/java/CMakeLists.txt b/src/java/CMakeLists.txt
index 231c755fa..cfa72a0df 100644
--- a/src/java/CMakeLists.txt
+++ b/src/java/CMakeLists.txt
@@ -16,7 +16,9 @@ include_directories (
 set_source_files_properties (mraajava.i PROPERTIES SWIG_FLAGS ";-package;mraa;-I${CMAKE_BINARY_DIR}/src")
 set_source_files_properties (mraajava.i PROPERTIES CPLUSPLUS ON)
 
-set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive -DJAVACALLBACK")
+if (BUILDCPP)
+  set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive -DJAVACALLBACK")
+endif()
 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DJAVACALLBACK")
 
 if (NOT DEFINED ENV{JAVA_HOME_NATIVE})
diff --git a/src/javascript/CMakeLists.txt b/src/javascript/CMakeLists.txt
index 25fd36275..99a96b49d 100644
--- a/src/javascript/CMakeLists.txt
+++ b/src/javascript/CMakeLists.txt
@@ -36,25 +36,27 @@ set_target_properties (mraajs PROPERTIES
 )
 
 message (STATUS "INFO - swig Version ${SWIG_VERSION}")
-message (STATUS "INFO - CXX compiler Version ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}")
+if (BUILDCPP)
+  message (STATUS "INFO - CXX compiler Version ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}")
 
-if (${V8_VERSION_MAJOR} GREATER 3)
-  message (STATUS "INFO - Using V8 version > 3 so requiring C++11 compiler")
-  # Node 0.12.x V8 engine major version is '3'.
-  # Node 2.1.0  V8 engine major version is '4'.
-  set_property (TARGET mraajs PROPERTY CXX_STANDARD 11)
-  set_property (TARGET mraajs PROPERTY CXX_STANDARD_REQUIRED ON)
-  if (CMAKE_VERSION VERSION_LESS "3.1")
-    message (WARNING "Need to use CMAKE version 3.1+, but it is ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}, using a workaround.")
-    if (CMAKE_COMPILER_IS_GNUCXX)
-      if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.7")
-        message (FATAL_ERROR "GNU gcc compiler is also too old (need 4.7+, but ${CMAKE_CXX_COMPILER_VERSION}) and does not support C++11 standard.")
+  if (${V8_VERSION_MAJOR} GREATER 3)
+    message (STATUS "INFO - Using V8 version > 3 so requiring C++11 compiler")
+    # Node 0.12.x V8 engine major version is '3'.
+    # Node 2.1.0  V8 engine major version is '4'.
+    set_property (TARGET mraajs PROPERTY CXX_STANDARD 11)
+    set_property (TARGET mraajs PROPERTY CXX_STANDARD_REQUIRED ON)
+    if (CMAKE_VERSION VERSION_LESS "3.1")
+      message (WARNING "Need to use CMAKE version 3.1+, but it is ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}, using a workaround.")
+      if (CMAKE_COMPILER_IS_GNUCXX)
+        if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.7")
+          message (FATAL_ERROR "GNU gcc compiler is also too old (need 4.7+, but ${CMAKE_CXX_COMPILER_VERSION}) and does not support C++11 standard.")
+        endif ()
+        set (MRAA_CXX11_WORKAROUND_OPTION "-std=gnu++11")
+      else ()
+        set (MRAA_CXX11_WORKAROUND_OPTION "-std=c++11")
       endif ()
-      set (MRAA_CXX11_WORKAROUND_OPTION "-std=gnu++11")
-    else ()
-      set (MRAA_CXX11_WORKAROUND_OPTION "-std=c++11")
+      set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MRAA_CXX11_WORKAROUND_OPTION} ")
     endif ()
-    set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MRAA_CXX11_WORKAROUND_OPTION} ")
   endif ()
 endif ()