gpt4 book ai didi

c++ - CMAKE Thrift 生成的文件编译器选项

转载 作者:行者123 更新时间:2023-11-28 04:32:25 24 4
gpt4 key购买 nike

我正在尝试将生成的 thrift 代码编译到我的源代码中。 thrift 内容生成到 CMAKE_CURRENT_BINARY_DIR 中,然后我将生成的 cpp 文件添加到我的库中,使用 SET_SOURCE_FILES_PROPERTIES(${ThriftGeneratedFiles} PROPERTIES
生成 1
COMPILE_OPTIONS“”
)

然后我使用 TARGET_INCLUDE_DIRECTORIESSYSTEM 关键字将包含路径添加到生成的文件中。当我尝试编译它时,由于我的模块使用 -Wsuggest-override 编译,因此无法使用 can be marked override [-Werror=suggest-override]< 编译生成的 cpp 文件。我不明白为什么,SET_SOURCE_FILES_PROPERTIES 不应该解决这个问题吗?

CMake 文件片段

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}
)

编译信息:

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();

如上所示,应用了所有编译标志。

最佳答案

源文件 的属性,如COMPILE_DEFINITIONSCOMPILE_FLAGS 可能只会添加 编译选项。使用这些属性不可能覆盖(删除)目标的编译选项。 (ADD_COMPILE_OPTIONS 添加的选项最终会分配给目标)。

您可以从 thrift 生成的源创建一个 OBJECT 库。对于该库,您可以设置(即清除)COMPILE_OPTIONS属性(property)。然后可以在您的主库中使用生成的目标文件:

# 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>
)

关于c++ - CMAKE Thrift 生成的文件编译器选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52517977/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com