1From a50fc9bde098e4e89584a5da9f94f620c11b6733 Mon Sep 17 00:00:00 2001
2From: Fabrice Fontaine <fontaine.fabrice@gmail.com>
3Date: Sun, 16 Aug 2020 12:31:46 +0200
4Subject: [PATCH] CMakeLists.txt: add C language to project statement
5MIME-Version: 1.0
6Content-Type: text/plain; charset=UTF-8
7Content-Transfer-Encoding: 8bit
8
9This will fix the detection of atomic:
10
11-- Performing Test HAVE_CXX_ATOMICS64_WITHOUT_LIB
12-- Performing Test HAVE_CXX_ATOMICS64_WITHOUT_LIB - Failed
13-- Looking for __atomic_load_8 in atomic
14-- Looking for __atomic_load_8 in atomic - not found
15CMake Error at CMakeModules/CheckAtomic.cmake:76 (message):
16  Host compiler appears to require libatomic for 64-bit operations, but
17  cannot find it.
18Call Stack (most recent call first):
19  CMakeLists.txt:19 (include)
20
21Indeed if C language is not enabled, the test will be run with the C++
22compiler resulting in the following error:
23
24Building CXX object CMakeFiles/cmTC_fad22.dir/CheckFunctionExists.cxx.o
25/tmp/instance-0/output-1/host/bin/mipsel-linux-g++ --sysroot=/tmp/instance-0/output-1/host/mipsel-buildroot-linux-gnu/sysroot    -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Os -D_FORTIFY_SOURCE=1 -Wall -Wconversion -pedantic -Wextra -Wno-missing-field-initializers -DCHECK_FUNCTION_EXISTS=__atomic_load_8  -DNDEBUG   -o CMakeFiles/cmTC_fad22.dir/CheckFunctionExists.cxx.o -c /tmp/instance-0/output-1/build/pistache-f2f5a50fbfb5b8ef6cf1d3d2a9d442a8270e375d/CMakeFiles/CheckLibraryExists/CheckFunctionExists.cxx
26<command-line>: error: new declaration 'char __atomic_load_8()' ambiguates built-in declaration 'long long unsigned int __atomic_load_8(const volatile void*, int)' [-fpermissive]
27/tmp/instance-0/output-1/build/pistache-f2f5a50fbfb5b8ef6cf1d3d2a9d442a8270e375d/CMakeFiles/CheckLibraryExists/CheckFunctionExists.cxx:7:3: note: in expansion of macro 'CHECK_FUNCTION_EXISTS'
28   CHECK_FUNCTION_EXISTS(void);
29   ^~~~~~~~~~~~~~~~~~~~~
30/tmp/instance-0/output-1/build/pistache-f2f5a50fbfb5b8ef6cf1d3d2a9d442a8270e375d/CMakeFiles/CheckLibraryExists/CheckFunctionExists.cxx: In function 'int main(int, char**)':
31/tmp/instance-0/output-1/build/pistache-f2f5a50fbfb5b8ef6cf1d3d2a9d442a8270e375d/CMakeFiles/CheckLibraryExists/CheckFunctionExists.cxx:17:25: error: too few arguments to function 'long long unsigned int __atomic_load_8(const volatile void*, int)'
32   CHECK_FUNCTION_EXISTS();
33                         ^
34
35whereas with a C compiler, we'll get:
36
37Building C object CMakeFiles/cmTC_4b0f4.dir/CheckFunctionExists.c.o
38/home/fabrice/buildroot/output/host/bin/riscv32-linux-gcc --sysroot=/home/fabrice/buildroot/output/host/riscv32-buildroot-linux-gnu/sysroot   -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Os -DCHECK_FUNCTION_EXISTS=__atomic_load_8  -DNDEBUG   -o CMakeFiles/cmTC_4b0f4.dir/CheckFunctionExists.c.o   -c /usr/share/cmake-3.16/Modules/CheckFunctionExists.c
39<command-line>: warning: conflicting types for built-in function ‘__atomic_load_8’ [-Wbuiltin-declaration-mismatch]
40/usr/share/cmake-3.16/Modules/CheckFunctionExists.c:7:3: note: in expansion of macro ‘CHECK_FUNCTION_EXISTS’
41   CHECK_FUNCTION_EXISTS(void);
42   ^~~~~~~~~~~~~~~~~~~~~
43Linking C executable cmTC_4b0f4
44/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_4b0f4.dir/link.txt --verbose=1
45/home/fabrice/buildroot/output/host/bin/riscv32-linux-gcc --sysroot=/home/fabrice/buildroot/output/host/riscv32-buildroot-linux-gnu/sysroot -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Os -DCHECK_FUNCTION_EXISTS=__atomic_load_8  -DNDEBUG    CMakeFiles/cmTC_4b0f4.dir/CheckFunctionExists.c.o  -o cmTC_4b0f4  -latomic
46
47Fixes:
48 - http://autobuild.buildroot.org/results/2bf06c6a9e55b449ec5875cf9415a9e55b2065d6
49
50Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
51---
52 CMakeLists.txt | 2 +-
53 1 file changed, 1 insertion(+), 1 deletion(-)
54
55diff --git a/CMakeLists.txt b/CMakeLists.txt
56index edc73c5..0286647 100644
57--- a/CMakeLists.txt
58+++ b/CMakeLists.txt
59@@ -9,7 +9,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
60 set(CMAKE_CXX_EXTENSIONS OFF)
61
62 project (pistache
63-    LANGUAGES CXX)
64+    LANGUAGES C CXX)
65
66 include(GNUInstallDirs)
67
68--
692.27.0
70
71