我想弄清楚要创建一个小的cmake文件。目录struture包括4个子文件夹,其中包含src和头文件。根目录下没有src或头文件。我想要的是通过编译这四个文件夹来使用cmake创建一个共享库。 根目录下的CMakeLists.txt
cmake_minimum_required (VERSION 2.8.7)
Project(NEWPROJ)
set(${PROJECT_NAME}_MAJOR_VERSION 00)
set(${PROJECT_NAME}_MINOR_VERSION 01)
set(${PROJECT_NAME} 0)
set(${PROJECT_NAME}_VERSION
${${PROJECT_NAME}_MAJOR_VERSION}.${${PROJECT_NAME}_MINOR_VERSION}.${${PROJECT_NAME}_PATCH_VERSION})
set(${PROJECT_NAME}_SOVERSION ${${PROJECT_NAME}_MAJOR_VERSION}.${${PROJECT_NAME}_MINOR_VERSION})
Message ( Root )
include_directories("${PROJECT_SOURCE_DIR}/Folder1/include")
include_directories("${PROJECT_SOURCE_DIR}/Folder2/include")
include_directories("${PROJECT_SOURCE_DIR}/Folder3/include")
include_directories("${PROJECT_SOURCE_DIR}/Folder4/include")
add_subdirectory ("${PROJECT_SOURCE_DIR}/Folder1")
add_subdirectory ("${PROJECT_SOURCE_DIR}/Folder2")
add_subdirectory ("${PROJECT_SOURCE_DIR}/Folder3")
add_subdirectory ("${PROJECT_SOURCE_DIR}/Folder4")
add_library( ${PROJECT_NAME} SHARED ${SOURCE} ${HEADERS})
Folder1中的CMakeLists.txt
MESSAGE(Folder1)
set(SOURCE
${SOURCE}
${CMAKE_CURRENT_SOURCE_DIR}/src/file1.cc
${CMAKE_CURRENT_SOURCE_DIR}/src/file2.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/file3.cc
PARENT_SCOPE
)
set(HEADERS
${HEADERS}
${CMAKE_CURRENT_SOURCE_DIR}/include/file1.h
${CMAKE_CURRENT_SOURCE_DIR}/include/file2.h
${CMAKE_CURRENT_SOURCE_DIR}/include/file3.h
${CMAKE_CURRENT_SOURCE_DIR}/include/file4.h
PARENT_SCOPE
)
cmake ..成功
make folder1 / src / file1.cc:1:20:致命错误:file1.h:没有这样的文件或目录
file1.cc
#include "file1.h"
...