CMake和自定义项目结构问题

时间:2018-07-23 19:04:50

标签: c++ cmake

我正在尝试使用CMake为我的项目创建Makefile,但是我得到了

CMake Error: Cannot determine link language for target "mylib".
CMake Error: CMake can not determine linker language for target: mylib

错误。

项目结构如下:

.
├── CMakeLists.txt
├── build
├── doc
├── include
│   ├── headers_library1
│   │   ├── headers1.hpp
│   │   ├── headers2.hpp
│   │   └── headers3.hpp
│   └── headers_library2
│       ├── dir1
│       ├── dir2
│       ├── dir3
│       ├── headers1.h
│       ├── headers2.h
.
.       many header files
.
│       ├── headers20.h
│       └── headers21.h
├── lib
│   └── CMakeLists.txt
└── src
    └── example.cpp

headers_library1中的标头包括系统共享库(即libcurl和libcryptopp)和仅标头的库headers_library2

CMakeLists.txt包含:

cmake_minimum_required (VERSION 3.12)
project (example)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

add_subdirectory(lib)

# TARGET example
add_executable (example src/example.cpp)
target_link_libraries (example PRIVATE mylib)
target_include_directories (example PUBLIC include)
target_compile_options(example PRIVATE -Wall)

lib/CMakeLists.txt包含:

file(GLOB_RECURSE HDRS_H ${PROJECT_SOURCE_DIR}/include/*.h)
file(GLOB_RECURSE HDRS_HPP ${PROJECT_SOURCE_DIR}/include/*.hpp)

# TARGET mylib
add_library (mylib STATIC ${HDRS_H} ${HDRS_HPP})
target_include_directories (mylib PUBLIC ${PROJECT_SOURCE_DIR}/include)
set_target_properties(mylib PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib)

首先,我想构建 static mylib并将其放入/lib目录中。然后,我想构建example可执行文件并将其与mylib库链接。

0 个答案:

没有答案