我之前从未使用过CMake,所以请原谅。
我的项目有一个“unity”文件夹,其中包含2.3.0版的单元测试库。 unity_fixture.h包含“#define TEST(...”,其使用如下:
#include "unity_fixture.h"
...
TEST(xformatc, Simple) {
char output[20];
TEST_ASSERT_EQUAL(13, testFormat(output, "Hello world\r\n"));
TEST_ASSERT_EQUAL_STRING("Hello world\r\n", output);
}
我在我的CMakeLists.txt文件中添加了“include_directories($ {CMAKE_SOURCE_DIR} / unity)”。仍然CLION没有找到TEST的声明,我得到了大量的错误。 我确实试图用set(SOURCE_FILES unity / unity_fixture.h ......)添加所有统一文件,但这也不起作用。
编辑08.09.2015 我发现了一些奇怪的东西。如果我从命令行调用cmake,它会创建一个文件“DependInfo.cmake”,其中包含以下内容:
# The set of languages for which implicit dependencies are needed:
set(CMAKE_DEPENDS_LANGUAGES
)
# The set of files for implicit dependencies of each language:
# Targets to which this target links.
set(CMAKE_TARGET_LINKED_INFO_FILES
)
# The include file search paths:
set(CMAKE_C_TARGET_INCLUDE_PATH
"unity"
"cmsis/inc"
"freertos/inc"
)
set(CMAKE_CXX_TARGET_INCLUDE_PATH ${CMAKE_C_TARGET_INCLUDE_PATH})
set(CMAKE_Fortran_TARGET_INCLUDE_PATH ${CMAKE_C_TARGET_INCLUDE_PATH})
set(CMAKE_ASM_TARGET_INCLUDE_PATH ${CMAKE_C_TARGET_INCLUDE_PATH})
# Targets to which this target links.
set(CMAKE_TARGET_LINKED_INFO_FILES
)
# The include file search paths:
set(CMAKE_C_TARGET_INCLUDE_PATH
"unity"
"cmsis/inc"
"freertos/inc"
)
set(CMAKE_CXX_TARGET_INCLUDE_PATH ${CMAKE_C_TARGET_INCLUDE_PATH})
set(CMAKE_Fortran_TARGET_INCLUDE_PATH ${CMAKE_C_TARGET_INCLUDE_PATH})
set(CMAKE_ASM_TARGET_INCLUDE_PATH ${CMAKE_C_TARGET_INCLUDE_PATH})
CLion创建的文件中缺少CMAKE_C_TARGET_INCLUDE_PATH。我相信这就是它找不到标题的原因。问题是如何告诉CLion创建CMAKE_C_TARGET_INCLUDE_PATH的东西?
答案 0 :(得分:1)
我假设你的项目结构是:
project root
├── CMakeLists.txt
├── Some source files
└── unity
└── unity_fixture.h
如果您使用CMake包含文件:
set(INCLUDE_DIR ./unity)
include_directories(${INCLUDE_DIR})
您的收件人必须是:#include <unity_fixture.h>
或者您可以在不使用CMake的情况下使用以包含目录:#include "unity/unity_fixture.h"