使用cmake创建共享库 [英] create a shared library with cmake
问题描述
我写了一个库,我用自编的Makefile编译,但现在我想切换到cmake。树看起来像这样(我删除了所有不相关的文件):
I have written a library that I used to compile using a self-written Makefile, but now I want to switch to cmake. The tree looks like this (I removed all the irrelevant files):
.
├── include
│ ├── animation.h
│ ├── buffers.h
│ ├── ...
│ ├── vertex.h
│ └── world.h
└── src
├── animation.cpp
├── buffers.cpp
├── ...
├── vertex.cpp
└── world.cpp
所以我想做的只是将源代码编译成共享库,然后用头文件安装它。
So what I am trying to do is just to compile the source into a shared library and then install it with the header files.
大多数例子,我发现编译可执行文件一些共享库,但从不只是一个简单的共享库。
如果有人能告诉我一个使用cmake的非常简单的库,我可以用这个例子。
Most examples that I have found compile executables with some shared libraries but never just a plain shared library. It would also be helpful if someone could just tell me a very simple library that uses cmake, so I can use this as an example.
推荐答案
这个最小的CMakeLists.txt文件编译一个简单的共享库:
This minimal CMakeLists.txt file compiles a simple shared library:
cmake_minimum_required(VERSION 2.8)
project (test)
set(CMAKE_BUILD_TYPE Release)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
add_library(test SHARED src/test.cpp)
但是,我没有经验使用CMake将文件复制到不同的目的地。带有COPY / INSTALL签名的文件命令看起来可能很有用。
However, I have no experience copying files to a different destination with CMake. The file command with the COPY/INSTALL signature looks like it might be useful.
这篇关于使用cmake创建共享库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!