c++ - 如何强制在cmake中包含标头?
问题描述
我正在将项目从 Makefile 移植到 cmake。Makefile 中有一个 CFLAG/CXXFLAG -include "SystemTest.h"
。我试图将它直接添加到我的工具链文件中CMAKE_C_FLAGS
,CMAKE_CXX_FLAGS
但随后测试编译失败,因为它找不到SystemTest.h
.
我搜索并找到了这样的答案:我可以强制 cmake 将我的头文件包含在特定目标中吗?并且cmake 在每个看起来很有希望但对我不起作用的源文件中包含头文件。
这是我使用 add_executable 的行。注释代码是我已经尝试过的:
add_executable(my_target ${SRC})
if (WIN32)
target_link_libraries(my_target PRIVATE module_a module_b module_c module_d module_e module_f)
elseif(UNIX)
target_link_libraries(my_target PRIVATE module_a module_b module_c module_d module_e module_f ${CURSES_LIBRARIES})
else(WIN32)
message(FATAL_ERROR "Not supported OS.")
endif(WIN32)
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -include SystemTest.h")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -include SystemTest.h")
# add_definitions(-include SystemTest.h)
# target_compile_definitions(cherrySim_runner
# PRIVATE $<$<COMPILE_LANGUAGE:C>:-include SystemTest.h>
# $<$<COMPILE_LANGUAGE:CXX>:-include SystemTest.h>
# )
# target_compile_definitions(cherrySim_runner "-include SystemTest.h")
CMake/gcc 在编译文件时module_b
抱怨应该来自SystemTest.h
.
解决方案
推荐阅读
- reactjs - 在 onClick 中反应处理这个
- python - 如何从图像中获取文本
- optimization - 我可以使用哪些优化技术来最大化单位超立方体中每个点到其他点的最小距离之和?
- quartz-scheduler - 对于重复的 cron 表达式,触发器仅触发一次
- javascript - Sequelize bulkCreate 返回不正确的值?
- php - preg_replace通过它的 id="" 如果它出现超过 5 次
- windows - 将按钮添加到 Windows 任务栏缩略图 JavaFX?
- elasticsearch - Elasticsearch 排序决胜局
- java - IntelliJ IDEA Windows 上 JavaFX 的“图形设备初始化失败:d3d,sw”
- node.js - 无法从 Office 加载项访问节点服务器