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.
-Wsuggest-override
" - Do you set this option viaCMAKE_CXX_FLAGS
variable? If so, the option is applied to every.cpp
file;COMPILE_OPTIONS
property doesn't include options fromCMAKE_CXX_FLAGS
variable. – TsyvarevCOMPILE_OPTIONS
for source files: cmake.org/cmake/help/v3.7/manual/…. The property exists only for targets and directories. You may create an OBJECT library from thrift-generated sources. For that library you may set (that is, clear)COMPILE_OPTIONS
property. Then, use resulted objects files in your main library. – Tsyvarev