我的项目结构如下:
--root: main.cpp CMakeLists.txt
--src: function.cpp CMakeLists.txt
--include: function.h
main.cpp中:
#include <iostream>
#include "function.h"
using namespace std;
int main(int argc, char *argv[])
{
//call module in function.hpp
return 0;
}
根目录中的CMakeLists.txt:
project(t1)
cmake_minimum_required(VERSION 2.8)
add_subdirectory(src)
file(GLOB_RECURSE SOURCES
include/function.h
src/function.cpp)
add_executable(${PROJECT_NAME} ${SOURCES})
src目录中的CmakeLists.txt:
include_directories(${PROJECT_SOURCE_DIR}/include)
如何在root和src目录中编写CMakelists来实现函数的单独实现?而且,如何在主要中调用它们。 CMake not finding proper header/include files in include_directories中的可能解决方案。但它仍然与我的情况不符。
答案 0 :(得分:5)
:
project(t1)
cmake_minimum_required(VERSION 2.8)
include_directories(include)
add_subdirectory(src)
在src中:
set(TARGET target_name)
add_executable(${TARGET} main.cpp function.cpp)