相关疑难解决方法(0)

使用CMake将编译器标志附加到文件

如何使用cmake向单个翻译单元添加编译器标志(我想将其附加,而不是覆盖其他标记)?

我试过了

set_source_files_properties(MyFile.cpp PROPERTIES CMAKE_CXX_FLAGS "-msse4.1")
Run Code Online (Sandbox Code Playgroud)

但它没有工作..有关如何做的任何建议?

c++ cmake

10
推荐指数
1
解决办法
6868
查看次数

在2.8.12之前的target_include_directories?

我们CMakeList.txt有一个target_include_directories在蠕动.它打破了我们的下级客户端,如Ubuntu LTS,CentOS的和Solaris.

我知道我可以用以下内容来保护它(感谢ZW),但我需要Cmake版本2.8.11及更早版本(???)的内容.

cmake_minimum_required(VERSION 2.8.5 FATAL_ERROR)
...

if (NOT CMAKE_VERSION VERSION_LESS 2.8.12)
  target_include_directories(...)
else()
  ???
endif()
Run Code Online (Sandbox Code Playgroud)

我们的目录结构非常简单.有一个目录中包含头文件,同一目录中包含源文件.这是设计使用户在调试器下没有麻烦.

给出我们的配置可以使用以下内容(如果@steveire答案适用于我们,我不清楚):

if (NOT CMAKE_VERSION VERSION_LESS 2.8.12)
  target_include_directories(...)
else()
  include_directories("${ROOT_SOURCE_DIR}")
endif()
Run Code Online (Sandbox Code Playgroud)

如果没有,应该用什么代替target_include_directories2.8.11及更早版本?

versioning cmake

4
推荐指数
1
解决办法
2421
查看次数

多个 CMake 目标的 target_compile_definitions?

有人 告诉我,CFLAGS直接在 CMake 中进行设置是不好的做法,相反,我应该使用该target_compile_definitions()命令。

好的,但是 - 如果我想对多个(独立)目标使用相似/相同的定义怎么办?我不想一遍又一遍地重复自己。

idioms dry cmake compiler-options

3
推荐指数
1
解决办法
3464
查看次数

如何使用CMake将输出二进制文件的名称更改为非a.out?

我将在CMakeLists.txt中去哪里以更改生成文件的名称?

cmake

2
推荐指数
2
解决办法
3178
查看次数

标签 统计

cmake ×4

c++ ×1

compiler-options ×1

dry ×1

idioms ×1

versioning ×1