作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
假设我有以下库:
add_library(myLib_static STATIC ${SRC_FILES})
add_library(myLib SHARED ${SRC_FILES})
# installing header files
install(FILES ${H_FILES} DESTINATION ${INSTDIRHEADER})
# installing binaries
install(TARGETS myLib_static
DESTINATION ${INSTDIRBIN})
install(TARGETS myLib
DESTINATION ${INSTDIRBIN})
make install
make install-static
make install-shared
install(FILES ${H_FILES} DESTINATION ${INSTDIRHEADER})
最佳答案
将它们分别放在不同的组件中,并为安装设置自定义目标。
add_library(foo_static STATIC foo.cpp)
add_library(foo SHARED foo.cpp)
install(TARGETS foo_static
DESTINATION bin
COMPONENT static)
install(TARGETS foo
DESTINATION bin
COMPONENT shared)
add_custom_target(foo-install
DEPENDS foo
COMMAND
"${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=shared
-P "${CMAKE_BINARY_DIR}/cmake_install.cmake"
)
add_custom_target(foo_static-install
DEPENDS foo_static
COMMAND
"${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=static
-P "${CMAKE_BINARY_DIR}/cmake_install.cmake"
)
install(FILES foo.h DESTINATION include COMPONENT static)
install(FILES foo.h DESTINATION include COMPONENT shared)
stephen@hal:~/dev/src/playground/cmake/build{master}$ cmake .. -DCMAKE_INSTALL_PREFIX=prefix
-- The C compiler identification is GNU 4.8.1
-- The CXX compiler identification is GNU 4.8.1
-- Check for working C compiler: /usr/lib/icecc/bin/cc
-- Check for working C compiler: /usr/lib/icecc/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/lib/icecc/bin/c++
-- Check for working CXX compiler: /usr/lib/icecc/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/stephen/dev/src/playground/cmake/build
stephen@hal:~/dev/src/playground/cmake/build{master}$ make foo_static-install
makeobj[0]: Entering directory `/home/stephen/dev/src/playground/cmake/build'
Scanning dependencies of target foo_static
[100%] Building CXX object CMakeFiles/foo_static.dir/foo.cpp.o
Linking CXX static library libfoo_static.a
[100%] Built target foo_static
Scanning dependencies of target foo_static-install
-- Install configuration: ""
-- Installing: /home/stephen/dev/src/playground/cmake/build/prefix/bin/libfoo_static.a
-- Installing: /home/stephen/dev/src/playground/cmake/build/prefix/include/foo.h
[100%] Built target foo_static-install
makeobj[0]: Leaving directory `/home/stephen/dev/src/playground/cmake/build'
stephen@hal:~/dev/src/playground/cmake/build{master}$ make foo-install
makeobj[0]: Entering directory `/home/stephen/dev/src/playground/cmake/build'
Scanning dependencies of target foo
[100%] Building CXX object CMakeFiles/foo.dir/foo.cpp.o
Linking CXX shared library libfoo.so
[100%] Built target foo
Scanning dependencies of target foo-install
-- Install configuration: ""
-- Installing: /home/stephen/dev/src/playground/cmake/build/prefix/bin/libfoo.so
-- Up-to-date: /home/stephen/dev/src/playground/cmake/build/prefix/include/foo_p.h
[100%] Built target foo-install
makeobj[0]: Leaving directory `/home/stephen/dev/src/playground/cmake/build'
关于CMake:如何为安装不同的目标创建别名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21852817/
我是一名优秀的程序员,十分优秀!