├── CMakeLists.txt
├── src
│ └── main.cpp
└── templates
└── fooConf.h.in
cmake_minimum_required(VERSION 3.2)
project(foo)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(PROJECT_SOURCE_DIR src)
set(PROJECT_TEMPLATE_DIR templates)
set(SOURCE_FILES ${PROJECT_SOURCE_DIR}/main.cpp)
set(${PROJECT_NAME}_MAJOR 0)
set(${PROJECT_NAME}_MINOR 1)
set(${PROJECT_NAME}_MICRO 1)
configure_file (
"${PROJECT_TEMPLATE_DIR}/fooConf.h.in"
"${PROJECT_SOURCE_DIR}/fooConf.h"
)
add_executable(foo ${SOURCE_FILES})
#define @PROJECT_NAME@_VERSION_MAJOR @PROJECT_NAME@@_VERSION_MAJOR@
#define @PROJECT_NAME@_VERSION_MINOR @PROJECT_NAME@@_VERSION_MINOR@
#define @PROJECT_NAME@_VERSION_MICRO @PROJECT_NAME@@_VERSION_MICRO@
#include <iostream>
#include "src/fooConf.h"
// Also tried: "fooConf.h"
int main() {
std::cout << foo_VERSION_MAJOR;
return 0;
}
fatal error: src/fooConf.h: No such file or directory
答案 0 :(得分:4)
您的fooConf.h
标头文件是在二进制树中生成的(正好在${CMAKE_BINARY_DIR}/src/
下)。因此,您应该发出相应的include_directories()
命令,以便在#include
中使用该文件。 E.g:
<强>的CMakeLists.txt 强>
....
include_directories(${CMAKE_BINARY_DIR})
add_executable(foo ${SOURCE_FILES})
<强>的src / main.cpp中强>
....
#include "src/fooConf.h"