• <tfoot id='1gg8L'></tfoot>
    <i id='1gg8L'><tr id='1gg8L'><dt id='1gg8L'><q id='1gg8L'><span id='1gg8L'><b id='1gg8L'><form id='1gg8L'><ins id='1gg8L'></ins><ul id='1gg8L'></ul><sub id='1gg8L'></sub></form><legend id='1gg8L'></legend><bdo id='1gg8L'><pre id='1gg8L'><center id='1gg8L'></center></pre></bdo></b><th id='1gg8L'></th></span></q></dt></tr></i><div id='1gg8L'><tfoot id='1gg8L'></tfoot><dl id='1gg8L'><fieldset id='1gg8L'></fieldset></dl></div>
  • <small id='1gg8L'></small><noframes id='1gg8L'>

      <legend id='1gg8L'><style id='1gg8L'><dir id='1gg8L'><q id='1gg8L'></q></dir></style></legend>
        <bdo id='1gg8L'></bdo><ul id='1gg8L'></ul>

        如何在 CMake 中仅为一个可执行文件更改编译器标志?

        How to change a compiler flag for just one executable in CMake?(如何在 CMake 中仅为一个可执行文件更改编译器标志?)
          <tbody id='UDKxv'></tbody>

              <tfoot id='UDKxv'></tfoot>

              <small id='UDKxv'></small><noframes id='UDKxv'>

              <i id='UDKxv'><tr id='UDKxv'><dt id='UDKxv'><q id='UDKxv'><span id='UDKxv'><b id='UDKxv'><form id='UDKxv'><ins id='UDKxv'></ins><ul id='UDKxv'></ul><sub id='UDKxv'></sub></form><legend id='UDKxv'></legend><bdo id='UDKxv'><pre id='UDKxv'><center id='UDKxv'></center></pre></bdo></b><th id='UDKxv'></th></span></q></dt></tr></i><div id='UDKxv'><tfoot id='UDKxv'></tfoot><dl id='UDKxv'><fieldset id='UDKxv'></fieldset></dl></div>

                <bdo id='UDKxv'></bdo><ul id='UDKxv'></ul>
                1. <legend id='UDKxv'><style id='UDKxv'><dir id='UDKxv'><q id='UDKxv'></q></dir></style></legend>
                  本文介绍了如何在 CMake 中仅为一个可执行文件更改编译器标志?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个 CMake 项目,它通过 MP 标志支持 Visual Studio 中的多处理器编译.

                  I have a CMake project that supports multiple processor compilation in Visual Studio through the MP flag.

                  由于只是在项目构建的众多可执行文件之一中,我需要将 MP 标志设置为 false(或禁用它,因为我在导入 .tlb代码>文件),我如何为这个目标设置不同的标志?

                  Since in just one of the many executable that the project builds, I need to set the MP flag to false (or disable it because I get errors importing a .tlb file), how can I set the flags for this target different?

                  add_executable(MyProgram myprogram.cpp)
                  target_link_libraries(MyProgram MyLibraries)
                  

                  我应该给一些 set_target_properties 给 cmake 还是专门从整个项目中删除标志?谢谢!

                  Should I give some set_target_properties to cmake or specifically remove the flag from the whole project? Thank you!

                  推荐答案

                  您可以使用 set_source_files_properties 添加COMPILE_FLAGS 用于 myprogram.cpp.例如:

                  You can use set_source_files_properties to add COMPILE_FLAGS for myprogram.cpp. For example:

                  add_executable(MyProgram myprogram.cpp)
                  
                  # Add the -std=c++11 flag as an example
                  set_source_files_properties( myprogram.cpp PROPERTIES COMPILE_FLAGS "-std=c++11" )
                  target_link_libraries(MyProgram MyLibraries)
                  

                  如果您需要为 MyProgram 目标中的所有源文件设置这些标志,您可以使用 set_target_properties 带有目标属性 COMPILE_FLAGS:

                  If you need those flags for all source files in the MyProgram target, you could use set_target_properties with the target property COMPILE_FLAGS:

                  add_executable(MyProgram myprogram.cpp)
                  # Add the -std=c++11 flag as an example
                  target_link_libraries(MyProgram MyLibraries)
                  set_target_properties( MyProgram PROPERTIES COMPILE_FLAGS "-std=c++11" )
                  

                  更新:要删除单个属性,您可以先获取所有属性,然后从列表中手动删除违规标志.例如 get_source_file_property:

                  Update: To remove a single property, you can first get all the properties and manually remove the offending flag from the list. For example with get_source_file_property:

                  get_source_file_property( MYPROPS myprogram.cpp COMPILE_FLAGS )
                  STRING( REPLACE "/MP1" "" MYPROPS ${MYPROPS} )
                  set_source_files_properties( myprogram.cpp COMPILE_FLAGS ${MYPROPS} )
                  

                  但是,我建议将您的源文件一分为二.一个包含所有带有 MP 标志的源文件,另一个只有 myprogram.cpp

                  However, I would recommend splitting your source files in two. One with all the source files with the MP flag and another with only myprogram.cpp

                  这篇关于如何在 CMake 中仅为一个可执行文件更改编译器标志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  What is inside .lib file of Static library, Statically linked dynamic library and dynamically linked dynamic library?(静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么?)
                  How do I load a C DLL from the SXS in Python?(如何从 Python 中的 SXS 加载 C DLL?)
                  Can Cython code be compiled to a dll so C++ application can call it?(Cython 代码可以编译成 dll 以便 C++ 应用程序可以调用它吗?)
                  Delay Loading DLLs(延迟加载 DLL)
                  Throwing C++ exceptions across DLL boundaries(跨 DLL 边界抛出 C++ 异常)
                  Loading a dll from a dll?(从 dll 加载 dll?)

                      <tbody id='YSZ88'></tbody>
                  • <tfoot id='YSZ88'></tfoot>
                        <bdo id='YSZ88'></bdo><ul id='YSZ88'></ul>

                          <i id='YSZ88'><tr id='YSZ88'><dt id='YSZ88'><q id='YSZ88'><span id='YSZ88'><b id='YSZ88'><form id='YSZ88'><ins id='YSZ88'></ins><ul id='YSZ88'></ul><sub id='YSZ88'></sub></form><legend id='YSZ88'></legend><bdo id='YSZ88'><pre id='YSZ88'><center id='YSZ88'></center></pre></bdo></b><th id='YSZ88'></th></span></q></dt></tr></i><div id='YSZ88'><tfoot id='YSZ88'></tfoot><dl id='YSZ88'><fieldset id='YSZ88'></fieldset></dl></div>

                          <small id='YSZ88'></small><noframes id='YSZ88'>

                        1. <legend id='YSZ88'><style id='YSZ88'><dir id='YSZ88'><q id='YSZ88'></q></dir></style></legend>