我正在尝试使用CMake在C ++中构建一个库。但是,我无法在正在测试的位置(使用googletest)中包含内置库的标头。
项目结构
CMakeLists.txt
cmake_minimum_required(VERSION 3.11)
project(Simulaton)
add_subdirectory(sim)
add_subdirectory(googletest)
enable_testing()
sim / CMakeLists.txt
file(GLOB SIM_SRCS *.cpp)
file(GLOB_RECURSE SIM_TEST_FILES test/*.cpp)
file(GLOB_RECURSE SIM_HEADERS *.h)
add_library(simulaton STATIC ${SIM_SRCS} ${SIM_HEADERS})
add_subdirectory(test)
install(TARGETS simulaton EXPORT sim DESTINATION lib)
install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
DESTINATION include
FILES_MATCHING PATTERN ".h")
sim / test / CMakeLists.txt
file(GLOB_RECURSE SIM_TEST_FILES *.cpp)
add_executable(testrunner ${SIM_TEST_FILES})
target_link_libraries(testrunner simulaton gtest_main)
add_test(NAME testing COMMAND testrunner)
“ cmake ..”有效(或至少不会引发任何错误),但是 抛出:
/home/.../simulaton/sim/test/heaptest.cpp:25:10: fatal error: simulaton/heap.h: No such file or directory
#include <simulaton/heap.h>
^~~~~~~~~~~~~~~~~~
compilation terminated.
请注意,我可以成功包含/使用安装在同一位置的googletest