为什么使用cmake进行安装后包含文件夹为空?

时间:2018-12-11 06:10:18

标签: c++ build cmake

我正在尝试创建一个lib并将其包含在我的项目中,以便其他人可以使用我的项目。 所以我的项目结构为

├── mlce
   ├── CMakeLists.txt
   ├── README.txt
   ├── include
   ├── lib
   └── src
       ├── io
       │   └── IO.h
       └── mesh
           ├── Mesh.cpp
           └── Mesh.h

当前include和lib为空。我手动创建了它们,以便稍后在make install时填充它们。

我的CMakeLists.txt看起来像

cmake_minimum_required(VERSION 3.0.2)
project(mlcelib)

set (SOURCE
    ${SOURCE}
    ${CMAKE_CURRENT_SOURCE_DIR}/src/mesh/Mesh.cpp
)

set (HEADER
    ${HEADER}
    ${CMAKE_CURRENT_SOURCE_DIR}/src/mesh/Mesh.h
    ${CMAKE_CURRENT_SOURCE_DIR}/src/io/IO.h
)

find_package (Eigen3 3.3 REQUIRED NO_MODULE)

add_library(${PROJECT_NAME} SHARED ${SOURCE})

target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)

target_link_libraries (${PROJECT_NAME} Eigen3::Eigen)
message(${CMAKE_INSTALL_INCLUDEDIR})
install(TARGETS ${PROJECT_NAME}
        LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
        PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) # <--- I was hoping
          # this  "PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}" would place all the header file of my project inside include folder. 
          # But apparently it is not doing that. The include folder is empty.

那我要做的是:

mkdir build
cd build
cmake -DCMAKE_INSTALL_LIBDIR=/path/to/mlce/lib -DCMAKE_INSTALL_INCLUDEDIR=/path/to/mlce/include ..
make 
make install

因此,当我进行安装时,共享库只会填充该库,而安装不会。

├── include
├── lib
│   └── libmlcelib.dylib

我期望include将包含mesh / Mesh.h和IO / IO.h

0 个答案:

没有答案