CMake如何添加仅用于编译而不是链接的标志

时间:2020-11-08 02:17:44

标签: cmake llvm

例如,我想将final ClientId _userAccountCredentials = new ClientId( "XXXXX.apps.googleusercontent.com", ""); void prompt(String url) async { if (await canLaunch(url)) { await launch(url); } else { throw 'Could not launch $url'; } } void getCalendarEventsOnline() { clientViaUserConsent(_userAccountCredentials, scopes, prompt).then((AuthClient client) { var calendar = calendarapi.CalendarApi(client); var calEvents = calendar.events.list("primary"); calEvents.then((calendarapi.Events events) { /// some logic within }); client.close(); }); } 标志传递给-mllvm --color -mllvm --inline-threshold=1000中的clang

但是,如果我使用CMakeLists.txt,则编译会很好,但是在链接期间会收到警告:

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mllvm --color -mllvm --inline-threshold=1000")

仅在编译而不是链接时附加args的最佳方法是什么?

注意:[2/2] Linking CXX executable test clang: warning: argument unused during compilation: '-mllvm --color' [-Wunused-command-line-argument] clang: warning: argument unused during compilation: '-mllvm --inline-threshold=1000' [-Wunused-command-line-argument] 不起作用。参见Pass compound compiler options using cmake

1 个答案:

答案 0 :(得分:0)

您就是这样吗?您就是通过这种方式将药品传递给-mllvm吗?

 -mllvm <value>          Additional arguments to forward to LLVM's option processing

似乎--color应该只是颜色。但是我可能错了。

add_compile_options和target_compile_options是设置编译器标志的两个首选方法。 CMAKE_CXX_FLAGS是较不理想的旧方法。因此,除非您传递错误的信息,否则我看不出cmake会在链接期间尝试使用这些标志的任何原因。