CMAKE thrift generated files compiler options - c++

I'm trying to compile generated thrift code into my source. The thrift stuff is generated into CMAKE_CURRENT_BINARY_DIR then I add generated cpp files into my library, with SET_SOURCE_FILES_PROPERTIES(${ThriftGeneratedFiles} PROPERTIES
GENERATED 1
COMPILE_OPTIONS ""
)
Then I add the include path to generated files using TARGET_INCLUDE_DIRECTORIES with SYSTEM keyword. When I'm trying to compile it, since my module compiles with -Wsuggest-override it fails to compile the generated cpp file with can be marked override [-Werror=suggest-override]. I dont get why, isnt the SET_SOURCE_FILES_PROPERTIES should solve this problem?CMake file snippet
ADD_COMPILE_OPTIONS(
...
...
-Wsuggest-override
...
...
)
FIND_PROGRAM(THRIFT_COMPILER thrift ${_VCPKG_ROOT_DIR}/buildtrees/thrift/x64-linux-rel/compiler/cpp/bin/ NO_DEFAULT_PATH)
SET(ThriftOutputDir ${CMAKE_CURRENT_BINARY_DIR}/thrift/gen/)
FILE(MAKE_DIRECTORY ${ThriftOutputDir})
SET(ThriftGeneratedFiles
${ThriftOutputDir}/MyServer.cpp
${ThriftOutputDir}/My_types.cpp
${ThriftOutputDir}/My_constants.cpp
)
ADD_CUSTOM_COMMAND(
OUTPUT
generated.timestamp
COMMAND
${THRIFT_COMPILER} --gen cpp:no_default_operators -out ${ThriftOutputDir} ${CMAKE_SOURCE_DIR}/protocols/My.thrift
WORKING_DIRECTORY
${CMAKE_BINARY_DIR}
COMMENT "Generating source code from Thrift definition")
ADD_CUSTOM_TARGET(RunThriftCompiler
DEPENDS
generated.timestamp
COMMENT "Checking if re-generation is required")
ADD_LIBRARY(MyProject SHARED
${SOURCES}
${ThriftGeneratedFiles}
)
SET_SOURCE_FILES_PROPERTIES(${ThriftGeneratedFiles} PROPERTIES
GENERATED 1
COMPILE_OPTIONS ""
)
TARGET_INCLUDE_DIRECTORIES(MyProject SYSTEM PRIVATE
${PROTOBUF_INCLUDE_DIR}
${ThriftOutputDir}
)
Compilation message:
cd
/home/user/Development/Project/Project16/cmake-build-debug/lib/MyProject
&& /usr/bin/c++ -DCARES_STATICLIB -DMyProject_EXPORTS
-I/home/user/Development/Project/Project16/lib/include/MyProject -I/home/user/Development/Project/Project16/lib/include -isystem /home/user/Development/Project/Project16/cmake-build-debug/ext/etcd
-isystem /home/user/Development/Project/Project16/cmake-build-debug/protocols
-isystem /home/user/Development/Project/Project16/ext/spdk/include -isystem /home/user/Development/vcpkg/installed/x64-linux/include -isystem /home/user/Development/Project/Project16/cmake-build-debug/lib/MyProject/thrift/gen
-g -fPIC -include MyProject.h -fPIC -fstrict-aliasing -ffunction-sections -fno-omit-frame-pointer -mtune=core-avx-i -mavx -march=core-avx-i -fno-plt -g -fstack-protector-all -fstack-check -rdynamic -Wno-error=unused-parameter -Wno-error=unused -Wno-error=unused-but-set-parameter -Wshadow -Werror=address -Werror=array-bounds -Werror=char-subscripts -Werror=enum-compare -Werror=implicit-int -Werror=implicit-function-declaration -Werror=comment -Werror=format -Werror=main -Werror=missing-braces -Werror=nonnull -Werror=pointer-sign -Werror=reorder -Werror=return-type -Werror=sequence-point -Wstrict-aliasing=1 -Werror=strict-overflow=1 -Werror=switch -Werror=trigraphs -Werror=uninitialized -Werror=unknown-pragmas -Wunused-function -Wunused-label -Wunused-value -Werror=volatile-register-var -Werror=clobbered -Werror=empty-body -Werror=ignored-qualifiers -Werror=sign-compare -Werror=type-limits -Werror -Wempty-body -Wuninitialized -Winit-self -Wmissing-declarations -Wswitch-bool -Wlogical-not-parentheses -Wsizeof-array-argument -Wbool-compare -Wtype-limits -Waddress -Wmisleading-indentation -Wshift-negative-value -Wtautological-compare -Wnull-dereference -Wduplicated-cond -Wnonnull -Wnonnull-compare -Wignored-qualifiers -Wmissing-braces -Wmissing-include-dirs -Wparentheses -Wsequence-point -Wno-return-local-addr -Wreturn-type -Wtrigraphs -Wunused-local-typedefs -Winvalid-memory-model -Wmaybe-uninitialized -Wunknown-pragmas -Wframe-address -Wtrampolines -Wfloat-equal -Wno-free-nonheap-object -Wold-style-cast -Wunused-parameter -Wunused -Wunused-but-set-parameter -Wframe-larger-than=1100000 -Wpointer-arith -Wwrite-strings -Wclobbered -Wenum-compare -Wsizeof-pointer-memaccess -Wmemset-transposed-args -Wlogical-op -Wredundant-decls -Winvalid-pch -Wvarargs -Wvector-operation-performance -Wvolatile-register-var -Wdisabled-optimization -Wcast-align -Wcast-qual -Wnon-virtual-dtor -Woverloaded-virtual -Wodr -Wplacement-new=2 -Wdelete-incomplete -Wsized-deallocation -Wno-virtual-move-assign -Wsuggest-override -DBOOST_COROUTINES_NO_DEPRECATION_WARNING -DGTEST_LINKED_AS_SHARED_LIBRARY -D_GNU_SOURCE -DIGNORE_VALIDATION= -std=gnu++1z -o CMakeFiles/MyProject.dir/thrift/gen/MyProject_constants.cpp.o -c
/home/user/Development/Project/Project16/cmake-build-debug/lib/MyProject/thrift/gen/MyProject_constants.cpp
In file included from
/home/user/Development/Project/Project16/cmake-build-debug/lib/MyProject/thrift/gen/MyProject_types.cpp:7:0:
/home/user/Development/Project/Project16/cmake-build-debug/lib/MyProject/thrift/gen/MyProject_types.h:72:15:
error: ‘virtual const char* MyProject::ThriftCapiException::what()
const’ can be marked override [-Werror=suggest-override] const
char* what() const throw();
As seen, all compilation flags are applied.

Properties on source files like COMPILE_DEFINITIONS and COMPILE_FLAGS may only add a compile option. Using these properties it is impossible to overwrite (delete) compile options for the target. (And options added by ADD_COMPILE_OPTIONS are eventually assigned for the target).
You may create an OBJECT library from thrift-generated sources. For that library you may set (that is, clear) COMPILE_OPTIONS property. Resulted object files can be used then in your main library:
# Object files for thrift-generated sources
add_library(thriftGenerated OBJECT ${ThriftGeneratedFiles})
# For these files clear compile options which has been set before
set_property(TARGET thriftGenerated PROPERTY COMPILE_OPTIONS)
# Then use object files for thrift-generated sources in other library
add_library(MyProject SHARED
${SOURCES}
$<TARGET_OBJECTS:thriftGenerated>
)

Related

clang-tidy with precompiled headers and cmake does not work

I have a simple setup where CMake produces the following compile command:
cd /workspaces/cmake-general/tests/project/build/examples/hello-world && /usr/local/bin/cmake -E __run_co_compile
--iwyu=/usr/local/bin/include-what-you-use
--tidy="/usr/bin/clang-tidy;-extra-arg=-Wno-unknown-warning-option;-warnings-as-errors=*;--extra-arg-before=--driver-mode=g++"
--source=/workspaces/cmake-general/tests/project/build/examples/hello-world/CMakeFiles/example-hello-world.dir/cmake_pch.hxx.cxx --
/usr/bin/c++
-I/workspaces/cmake-general/tests/project/examples/hello-world/src
-I/workspaces/cmake-general/tests/project/build -O3 -DNDEBUG -stdlib=libc++
-fcolor-diagnostics -Wall -Wextra -Wshadow -Wnon-virtual-dtor -Wold-style-cast -Wcast-align -Wunused -Woverloaded-virtual -Wpedantic -Wconversion
-Wsign-conversion -Wnull-dereference -Wdouble-promotion
-Wformat=2 -Werror -std=c++20 -Winvalid-pch -fpch-instantiate-templates
-Xclang -emit-pch -Xclang -include
-Xclang /workspaces/cmake-general/tests/project/build/examples/hello-world/CMakeFiles/example-hello-world.dir/cmake_pch.hxx
-x c++-header -MD -MT examples/hello-world/CMakeFiles/example-hello-world.dir/cmake_pch.hxx.pch -MF
CMakeFiles/example-hello-world.dir/cmake_pch.hxx.pch.d -o CMakeFiles/example-hello-world.dir/cmake_pch.hxx.pch
-c /workspaces/cmake-general/tests/project/build/examples/hello-world/CMakeFiles/example-hello-world.dir/cmake_pch.hxx.cxx
which errors our with not finding
/workspaces/cmake-general/tests/project/build/examples/example-sanitizer/CMakeFiles/example-sanitizer-address.dir/cmake_pch.hxx:5:10: error: 'iostream' file not found [clang-diagnostic-error]
#include <iostream>
^
3 errors generated.
When I take --tidy="..." stuff out of the command. It fully compiles, (also if I dont specify PCHs in the CMakeLists.txt) it works.
I am not sure what the problem is exactly.
Do PCH and clang-tidy somehow not work? Why are the include directories somehow missing? I am using LLVM-12, clang-12 on Ubuntu.
Also adding -I/usr/lib/llvm-12/include/c++/v1 does not help.

Linker PIC error when statically linking a library built with PIC enabled

I'm building a library (libproj) using g++-9 and CMake (on Xenial, on Travis), so I can statically link it in a Rust crate. My build.rs sets up and runs CMake with the following config:
cmake proj-7.0.1
-DBUILD_SHARED_LIBS=ON
-DBUILD_TESTING=OFF
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_CXX_FLAGS="-std=c++11 -fPIC"
-DCMAKE_INSTALL_PREFIX=[path snipped]/out
-DCMAKE_C_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64
-DCMAKE_C_COMPILER=/usr/bin/gcc-9
-DCMAKE_CXX_COMPILER=/usr/bin/g++-9
-DCMAKE_ASM_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64
-DCMAKE_ASM_COMPILER=/usr/bin/gcc-9
Which builds and installs libproj successfully.
I then tell cargo to statically link it:
cargo:root=[path snipped]/out
cargo:rustc-link-search=native=[path snipped]/out/lib
cargo:rustc-link-lib=static=proj
However, the link step fails, saying I can't use relocation in a shared object:
note: /usr/bin/ld: [path snipped]/out/lib/libproj.a(4D_api.cpp.o): relocation
R_X86_64_32 against `.rodata.str1.8' can not be used when making a
shared object; recompile with -fPIC`
[path snipped]/out/lib/libproj.a(4D_api.cpp.o): error adding symbols: Bad value
collect2: error: ld returned 1 exit status
What am I doing wrong here? I've also tried to build libproj as a static lib by setting BUILD_SHARED_LIBS to OFF as per the install instructions, but that hasn't had any effect.
UPDATE:
I've managed to enable PIC for g++ (by default it's only enabled for gcc)
running: "cmake" "-Wdev" "--debug-output" "[snipped]/proj-7.0.1" "-DCMAKE_CXX_FLAGS=-std=c++11" "-DCMAKE_CXX_FLAGS=-fPIC" "-DBUILD_SHARED_LIBS=OFF" "-DCMAKE_INSTALL_PREFIX=[snipped]/out" "-DCMAKE_C_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64" "-DCMAKE_C_COMPILER=/usr/bin/gcc-9" "-DCMAKE_CXX_COMPILER=/usr/bin/g++-9" "-DCMAKE_ASM_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64" "-DCMAKE_ASM_COMPILER=/usr/bin/gcc-9" "-DCMAKE_BUILD_TYPE=Debug" "-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON"
Resulting in the following g++-9 invocation, which includes -fPIC:
/usr/bin/g++-9 -DCURL_ENABLED -DMUTEX_pthread -DPROJ_LIB=\"/[snip]/proj\" -DTIFF_ENABLED -I/[snip]/src -I/[snip]/include -I/[snip]/src -I/usr/include/x86_64-linux-gnu -fPIC -g -fvisibility=hidden -Wall -Wextra -Wswitch -Wshadow -Wunused-parameter -Wmissing-declarations -Wformat -Wformat-security -std=c++11 -o CMakeFiles/proj.dir/aasincos.cpp.o -c /[snip]/proj/proj-7.0.1/src/aasincos.cpp
However, I know get a completely different error (thousands of lines), that looks like my static library hasn't been correctly linked to the c++11 stdlib:
Error:
undefined reference to std::allocator<char>::allocator()
UPDATE 2:
I've managed to remove the -nodefaultlibs flag from ld. The latest g++ invocation:
/usr/bin/g++-9 -I/[snipped]/src -I/[snipped]/include -I/[snipped]/src -isystem /[snipped]/include -isystem /[snipped]/googletest -fPIC -g -fvisibility=hidden -Wall -Wextra -Wswitch -Wshadow -Wunused-parameter -Wmissing-declarations -Wformat -Wformat-security -pthread -std=c++11 -o CMakeFiles/proj_context_test.dir/proj_context_test.cpp.o -c /[snipped]/proj_context_test.cpp
And I've managed to add lstdc++ to the linker invocation:
"cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-L" "/[snip]/lib" "/home/travis/build/georust/proj-sys/target/debug/deps/proj_sys-95cbd73f2c3f0bde.20tasg77xuhsj5z6.rcgu.o" "/home/travis/build/georust/proj-sys/target/debug/deps/proj_sys-95cbd73f2c3f0bde.57y4784ihm3qw715.rcgu.o" "-o" "/[snip]/deps/proj_sys-95cbd73f2c3f0bde" "/home/travis/build/georust/proj-sys/target/debug/deps/proj_sys-95cbd73f2c3f0bde.3kiafs23968zh4mj.rcgu.o" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro" "-Wl,-znow" "-L" "/home/travis/build/georust/proj-sys/target/debug/deps" "-L" "/home/travis/build/georust/proj-sys/target/debug/build/proj-sys-aff2ac9d43b77886/out/lib" "-L" "/home/travis/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-lsqlite3" "-lcurl" "-ltiff" "-lstdc++" "-Wl,-Bstatic" "-Wl,--whole-archive" "-lproj" "-Wl,--no-whole-archive" [trimmed rlib details] "-Wl,--end-group" "/home/travis/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-2541f1e09df1c67d.rlib" "-Wl,-Bdynamic" "-ldl" "-lrt" "-lpthread" "-lgcc_s" "-lc" "-lm" "-lrt" "-lpthread" "-lutil" "-lutil"
But the undefined reference error remains.
As I can see from your example, you have quotation marks around CMAKE_CXX_FLAGS and do not have ones around CMAKE_C_FLAGS. It looks odd.
I have built libgproj myself with cmake + your flags and with make VERBOSE=1.
I can see, that C-files compiled without fPIC, m64 and fdata-sections. I suppose, that the cause is in the quotation marks around CMAKE_C_FLAGS. I saw your log in Travis, and there is configuration for cmake from cargo:
"cmake" "/home/travis/build/georust/proj-sys/PROJSRC/proj/proj-7.0.1" "-DBUILD_SHARED_LIBS=ON" "-DBUILD_TESTING=OFF" "-DCMAKE_BUILD_TYPE=Release" "-DCMAKE_CXX_FLAGS=-std=c++11 -fPIC" "-DCMAKE_INSTALL_PREFIX=/home/travis/build/georust/proj-sys/target/debug/build/proj-sys-03a5fe6428bb060a/out" "-DCMAKE_C_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64" "-DCMAKE_C_COMPILER=/usr/bin/gcc-9" "-DCMAKE_CXX_COMPILER=/usr/bin/g++-9" "-DCMAKE_ASM_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64" "-DCMAKE_ASM_COMPILER=/usr/bin/gcc-9"
Note, that -DCMAKE_C_FLAGS and CMAKE_CXX_FLAGS escaped with their values, and not values by itself. I suppose, that these options become in the shell:
cmake -DCMAKE_C_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64 -DCVMAKE_CXX_FLAGS=-std=c++11 -fPIC
I have tried this command, without quotation marks and cmake just ignored unknown options. So it will not fail.
I suggest you to add cmake option -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON to cmake configuration or VERBOSE=1 to the make options, if you can, and then you can see real compile options passed to gcc in Travis.
You will see somethig like this:
[ 19%] Building C object src/CMakeFiles/proj.dir/wkt1_generated_parser.c.o
cd [some path]/PROJ/cmake_build/src && /usr/bin/cc -DCURL_ENABLED -DMUTEX_pthread
-DPROJ_LIB=\"/usr/local/share/proj\" -DTIFF_ENABLED -I[some path]PROJ/src -I[some
path]/PROJ/include -I[some path]/PROJ/cmake_build/src -O3 -DNDEBUG -
fvisibility=hidden -Wall -Wextra -Wswitch -Wshadow -Wunused-parameter -Wmissing-
declarations -Wformat -Wformat-security -Wmissing-prototypes -std=c99 -o
CMakeFiles/proj.dir/wkt1_generated_parser.c.o -c [some
path]/PROJ/src/wkt1_generated_parser.c
Conclusion:
You can try adding verbosity to see real compile options.
You can try to escape options properly, if it's necessary after first step.
Also I want to note, that SHARED_BUILD_LIBS=ON in my test forbids building static lib, which you want to link. When I set shared libs building setting option to OFF, static lib was built.

Errors while build cpprestsdk using gcc-8.2

When I try building cpprestsdk with a cross compiler gcc I've the following issue:
cd /home/ubuntu/projects/cpprestsdk/Release/build_qamf-dev/src && /opt/qamf-dev/x86_64-qamf/bin/x86_64-qamf-linux-gnu-g++ -DCPPREST_EXCLUDE_BROTLI=1 -DCPPREST_FORCE_HTTP_CLIENT_ASIO -DCPPREST_FORCE_HTTP_LISTENER_ASIO -DCPPREST_NO_SSL_LEAK_SUPPRESS -Dcpprest_EXPORTS -I/home/ubuntu/projects/cpprestsdk/Release/include -I/home/ubuntu/projects/cpprestsdk/Release/src/pch -I/home/ubuntu/projects/cpprestsdk/Release/libs/websocketpp -isystem /opt/qamf-dev/x86_64-qamf/x86_64-qamf-linux-gnu/sysroot/usr/include -std=c++11 -fno-strict-aliasing -O3 -DNDEBUG -fPIC -Werror -pedantic -Wall -Wextra -Wunused-parameter -Wcast-align -Wcast-qual -Wconversion -Wformat=2 -Winit-self -Winvalid-pch -Wmissing-format-attribute -Wmissing-include-dirs -Wpacked -Wredundant-decls -Wunreachable-code -o CMakeFiles/cpprest.dir/http/oauth/oauth2.cpp.o -c /home/ubuntu/projects/cpprestsdk/Release/src/http/oauth/oauth2.cpp
cd /home/ubuntu/projects/cpprestsdk/Release/build_qamf-dev/src && /opt/qamf-dev/x86_64-qamf/bin/x86_64-qamf-linux-gnu-g++ -DCPPREST_EXCLUDE_BROTLI=1 -DCPPREST_FORCE_HTTP_CLIENT_ASIO -DCPPREST_FORCE_HTTP_LISTENER_ASIO -DCPPREST_NO_SSL_LEAK_SUPPRESS -Dcpprest_EXPORTS -I/home/ubuntu/projects/cpprestsdk/Release/include -I/home/ubuntu/projects/cpprestsdk/Release/src/pch -I/home/ubuntu/projects/cpprestsdk/Release/libs/websocketpp -isystem /opt/qamf-dev/x86_64-qamf/x86_64-qamf-linux-gnu/sysroot/usr/include -std=c++11 -fno-strict-aliasing -O3 -DNDEBUG -fPIC -Werror -pedantic -Wall -Wextra -Wunused-parameter -Wcast-align -Wcast-qual -Wconversion -Wformat=2 -Winit-self -Winvalid-pch -Wmissing-format-attribute -Wmissing-include-dirs -Wpacked -Wredundant-decls -Wunreachable-code -o CMakeFiles/cpprest.dir/json/json.cpp.o -c /home/ubuntu/projects/cpprestsdk/Release/src/json/json.cpp
[ 7%] Building CXX object src/CMakeFiles/cpprest.dir/http/oauth/oauth1.cpp.o
cd /home/ubuntu/projects/cpprestsdk/Release/build_qamf-dev/src && /opt/qamf-dev/x86_64-qamf/bin/x86_64-qamf-linux-gnu-g++ -DCPPREST_EXCLUDE_BROTLI=1 -DCPPREST_FORCE_HTTP_CLIENT_ASIO -DCPPREST_FORCE_HTTP_LISTENER_ASIO -DCPPREST_NO_SSL_LEAK_SUPPRESS -Dcpprest_EXPORTS -I/home/ubuntu/projects/cpprestsdk/Release/include -I/home/ubuntu/projects/cpprestsdk/Release/src/pch -I/home/ubuntu/projects/cpprestsdk/Release/libs/websocketpp -isystem /opt/qamf-dev/x86_64-qamf/x86_64-qamf-linux-gnu/sysroot/usr/include -std=c++11 -fno-strict-aliasing -O3 -DNDEBUG -fPIC -Werror -pedantic -Wall -Wextra -Wunused-parameter -Wcast-align -Wcast-qual -Wconversion -Wformat=2 -Winit-self -Winvalid-pch -Wmissing-format-attribute -Wmissing-include-dirs -Wpacked -Wredundant-decls -Wunreachable-code -o CMakeFiles/cpprest.dir/http/oauth/oauth1.cpp.o -c /home/ubuntu/projects/cpprestsdk/Release/src/http/oauth/oauth1.cpp
[ 10%] Building CXX object src/CMakeFiles/cpprest.dir/uri/uri_builder.cpp.o
[ 7%] Building CXX object src/CMakeFiles/cpprest.dir/json/json_serialization.cpp.o
[ 8%] Building CXX object src/CMakeFiles/cpprest.dir/uri/uri.cpp.o
In file included from /opt/qamf-dev/x86_64-qamf/x86_64-qamf-linux-gnu/include/c++/8.2.0/ext/string_conversions.h:41,
from /opt/qamf-dev/x86_64-qamf/x86_64-qamf-linux-gnu/include/c++/8.2.0/bits/basic_string.h:6391,
from /opt/qamf-dev/x86_64-qamf/x86_64-qamf-linux-gnu/include/c++/8.2.0/string:52,
from /home/ubuntu/projects/cpprestsdk/Release/src/pch/stdafx.h:55,
from /home/ubuntu/projects/cpprestsdk/Release/src/http/client/http_client_msg.cpp:13:
/opt/qamf-dev/x86_64-qamf/x86_64-qamf-linux-gnu/include/c++/8.2.0/cstdlib:75:15: fatal error: stdlib.h: No such file or directory
#include_next <stdlib.h>
^~~~~~~~~~
In file included from /opt/qamf-dev/x86_64-qamf/x86_64-qamf-linux-gnu/include/c++/8.2.0/ext/string_conversions.h:41,
from /opt/qamf-dev/x86_64-qamf/x86_64-qamf-linux-gnu/include/c++/8.2.0/bits/basic_string.h:6391,
from /opt/qamf-dev/x86_64-qamf/x86_64-qamf-linux-gnu/include/c++/8.2.0/string:52,
from /home/ubuntu/projects/cpprestsdk/Release/src/pch/stdafx.h:55,
from /home/ubuntu/projects/cpprestsdk/Release/src/http/client/http_client.cpp:16:
/opt/qamf-dev/x86_64-qamf/x86_64-qamf-linux-gnu/include/c++/8.2.0/cstdlib:75:15: fatal error: stdlib.h: No such file or directory
#include_next <stdlib.h>
^~~~~~~~~~
compilation terminated.
In file included from /opt/qamf-dev/x86_64-qamf/x86_64-qamf-linux-gnu/include/c++/8.2.0/ext/string_conversions.h:41,
from /opt/qamf-dev/x86_64-qamf/x86_64-qamf-linux-gnu/include/c++/8.2.0/bits/basic_string.h:6391,
from /opt/qamf-dev/x86_64-qamf/x86_64-qamf-linux-gnu/include/c++/8.2.0/string:52,
from /home/ubuntu/projects/cpprestsdk/Release/src/pch/stdafx.h:55,
from /home/ubuntu/projects/cpprestsdk/Release/src/http/common/http_compression.cpp:14:
/opt/qamf-dev/x86_64-qamf/x86_64-qamf-linux-gnu/include/c++/8.2.0/cstdlib:75:15: fatal error: stdlib.h: No such file or directory
#include_next <stdlib.h>
^~~~~~~~~~
compilation terminated.
If I replace -isystem with a simple -I everything works well...
I know the gcc is working well cos I already built zlib openssl opencv and boost 1.69.
EDIT
To avoid the problem I edited the Makefile generated by cmake and removed -isystem from cxx flags

Code base not finding standard C++ library header

I am compiling an example application from the SDK repository of a third party vendor. I receive an error that one of the C++ header's (algorithm) cannot be found:
if [ ! -d .deps/ ]; then mkdir -p .deps/; fi
/opt/llvm-3.8.0/bin/clang++ -M -isystem/opt/tbricks/sdk/include64 -I../../.. -I../../../.. -I./../../../.. -DLINUX -DLINUX64 -DTB_USE_RCU -DURCU_INLINE_SMALL_FUNCTIONS -DU_USING_ICU_NAMESPACE=0 -DNDEBUG -D_POSIX_PTHREAD_SEMANTICS -fPIC -D_GNU_SOURCE -DTB_USE_RCU -DTB_USE_RCU -D_GLIBCXX_USE_CXX11_ABI=0 -m64 --gcc-toolchain=/opt/gcc-5.2.0 -flto=full -std=gnu++14 -D_GLIBCXX_DEPRECATED= -pipe -fno-omit-frame-pointer -ffast-math -fno-finite-math-only -pthread -march=core2 -mtune=corei7 -g -O3 -Qunused-arguments -fnon-call-exceptions -fvisibility=hidden -fvisibility-inlines-hidden -Wall -Wextra -Wshadow -Wpointer-arith -Wno-self-assign -Wno-unused-function -Wno-gnu-empty-initializer -Wno-unused-parameter -Wno-ignored-qualifiers -Wno-mismatched-tags -Wno-unused-local-typedef -Wno-parentheses-equality -Wno-unused-private-field -Wno-missing-field-initializers -Wno-missing-braces -Werror=return-type -Werror=overloaded-virtual -DSTRATEGY_BUILD_PROFILE=\"release\" ../../../../shared/Helpers.cpp > .deps/Helpers.o.d
../../../../shared/Helpers.cpp:14:10: fatal error: 'algorithm' file not found
#include <algorithm>
What sets the location path to search for C++ header files, such as algorithm? Is there anything I can grep for within makefiles?
Either install g++ alongside (you need libstdc++) or use LLVM libc++ and specify it with -stdlib=libc++

Creating Xcode project from Cmake contains unwanted compiler flags

I've been unable to find a definitive answer, so apologies if the answer is out there.
I use cmake to generate project files as I tend to work cross-platform. On OSX/Xcode, I'm seeing unwanted compiler flags being used, specifically warning enable/disable. I like to compile with as many warnings on as possible, and set warnings as errors.
Consider the following:
File: CMakeLists.txt
cmake_minimum_required( VERSION 3.0 )
project( test )
set( CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -std=c++14 )
add_compile_options( "-Werror" )
add_compile_options( "-Weverything" )
add_compile_options( "-Wno-c++98-compat-pedantic" )
add_compile_options( "-Wno-padded" )
add_executable( Test main.cpp )
target_link_libraries( Test libstdc++.dylib libc++.dylib )
File: main.cpp
#include <iostream>
int main( int argc, char * const argv[] )
{
(void)argc;
(void)argv;
std::cout << "Kittens." << std::endl;
return 0;
}
If I then run cmake:
cmake -G Xcode .
(normally I'd use a builds directory, but not here for simplicity).
Then build (from the command line):
cmake --build . --config Debug --target ALL_BUILD
The simple sample will compile. If I now look at the command used to compile main.cpp I see the following:
CompileC test.build/Debug/Test.build/Objects-normal/x86_64/main.o main.cpp normal x86_64 c++ com.apple.compilers.llvm.clang.1_0.compiler
cd /Users/username/Development/test
export LANG=en_US.US-ASCII
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x c++ -arch x86_64 -fmessage-length=101 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -fcolor-diagnostics -Wno-trigraphs -fpascal-strings -O0 -Wno-missing-field-initializers -Wno-missing-prototypes -Wno-return-type -Wno-non-virtual-dtor -Wno-overloaded-virtual -Wno-exit-time-destructors -Wno-missing-braces -Wparentheses -Wswitch -Wno-unused-function -Wno-unused-label -Wno-unused-parameter -Wno-unused-variable -Wunused-value -Wno-empty-body -Wno-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wno-constant-conversion -Wno-int-conversion -Wno-bool-conversion -Wno-enum-conversion -Wno-shorten-64-to-32 -Wno-newline-eof -Wno-c++11-extensions -DCMAKE_INTDIR=\"Debug\" -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -fasm-blocks -fstrict-aliasing -Wdeprecated-declarations -Winvalid-offsetof -mmacosx-version-min=10.11 -g -Wno-sign-conversion -I/Users/username/Development/test/Debug/include -I/Users/username/Development/test/test.build/Debug/Test.build/DerivedSources/x86_64 -I/Users/username/Development/test/test.build/Debug/Test.build/DerivedSources -Wmost -Wno-four-char-constants -Wno-unknown-pragmas -F/Users/username/Development/test/Debug -std=c++14 -Werror -Weverything -Wno-c++98-compat-pedantic -Wno-padded -MMD -MT dependencies -MF /Users/username/Development/test/test.build/Debug/Test.build/Objects-normal/x86_64/main.d --serialize-diagnostics /Users/username/Development/test/test.build/Debug/Test.build/Objects-normal/x86_64/main.dia -c /Users/username/Development/test/main.cpp -o /Users/username/Development/test/test.build/Debug/Test.build/Objects-normal/x86_64/main.o
The really annoying thing here is any of the -W options.
In my CMakeLists.txt I've clearly said I want all warnings, warnings treated as errors, and whitelisted a couple of warnings.
However, if I strip out all the -W options in the compile command, I see (in addition to what I asked for):
-Wno-trigraphs
-Wno-missing-field-initializers
-Wno-missing-prototypes
-Wno-return-type
-Wno-non-virtual-dtor
-Wno-overloaded-virtual
-Wno-exit-time-destructors
-Wno-missing-braces
-Wparentheses
-Wswitch
-Wno-unused-function
-Wno-unused-label
-Wno-unused-parameter
-Wno-unused-variable
-Wunused-value
-Wno-empty-body
-Wno-uninitialized
-Wno-unknown-pragmas
-Wno-shadow
-Wno-four-char-constants
-Wno-conversion
-Wno-constant-conversion
-Wno-int-conversion
-Wno-bool-conversion
-Wno-enum-conversion
-Wno-shorten-64-to-32
-Wno-newline-eof
-Wno-c++11-extensions
-Winvalid-offsetof
-Wno-sign-conversion
-Wmost
-Wno-four-char-constants
-Wno-unknown-pragmas
Some of those things listed I really do not want disabled. I really want just the -W options I specified in the cmake file being used for compilation, but I can't see who is injecting all these extra things and from where.
Is there any way I can get cmake to tell xcode not to include all these extra -W options from compilation?
Note: using:
cmake 3.5.2
Apple LLVM version 7.3.0 (clang-703.0.31)
At project() call, CMake detects compiler (you may see corresponded messages when cmake is executed) and sets default flags for it. These flags are stored in variables CMAKE_CXX_FLAGS (common) and CMAKE_CXX_FLAGS_<CONFIG> (configuration-specific).
You may modify these variables as you want:
1) completely rewrite them
set(CMAKE_CXX_FLAGS "<desired-value>")
2) append new flags to them
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} <additional-flags>")
3) remove specific values from them
string(REPLACE "<unwanted-flag>" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
# or
string(REGEX REPLACE "<unwanted-flag-regex>" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
and so on.