【问题标题】:How to change compilation flags for a folder with CMake?如何使用 CMake 更改文件夹的编译标志?
【发布时间】:2013-02-05 04:43:33
【问题描述】:

我正在使用 CMake 为我的项目生成 Makefile。

我想编译一些具有不同选项的文件。 例如,所有文件都带有 -fX,但 test 文件夹中的文件带有 -fno-X。

这在 CMake 中可行吗?

这是我的 CMakeLists.txt 文件中包含源文件的部分:

file(
    GLOB_RECURSE
    compiler_files
    src/*.cpp
)

file(GLOB to_remove src/eddi.cpp)
list(REMOVE_ITEM compiler_files ${to_remove})

add_library(Compiler OBJECT ${compiler_files})

add_executable(eddic $<TARGET_OBJECTS:Compiler> src/eddi.cpp)
target_link_libraries (eddic boost_program_options)

【问题讨论】:

    标签: compiler-construction cmake compiler-optimization


    【解决方案1】:

    您可以使用set_source_files_properties 命令将编译标志添加到特定文件:

    SET_SOURCE_FILES_PROPERTIES(
      ${list_of_noX_files}
      PROPERTIES
      COMPILE_FLAGS "-fno-X"
    )
    

    在这种情况下,变量list_of_noX_files 中列出的文件将在默认选项后附加-fno-X 选项进行编译。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-18
      • 1970-01-01
      相关资源
      最近更新 更多