Created
March 13, 2018 16:31
-
-
Save M-Mueller/57cbd5d41e31b597297706b078562e23 to your computer and use it in GitHub Desktop.
Example of CMake export target
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmake_minimum_required(VERSION 3.0) | |
project(MyProject) | |
set(Sources | |
... | |
) | |
set(Headers | |
... | |
) | |
add_library(MyProject ${Sources}) | |
target_include_directories(MyProject INTERFACE $<INSTALL_INTERFACE:include>) # or whatever the include directory is | |
# install header | |
install(FILES ${Headers} DESTINATION include) | |
# install the library | |
install(TARGETS MyProject | |
EXPORT MyProject-targets | |
LIBRARY DESTINATION lib | |
ARCHIVE DESTINATION lib | |
) | |
# install export target and config for find_package | |
install(EXPORT MyProject-targets DESTINATION lib/cmake/MyProject) | |
include(CMakePackageConfigHelpers) | |
configure_package_config_file( | |
"MyProjectConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/MyProjectConfig.cmake" | |
INSTALL_DESTINATION "lib/cmake/MyProject" | |
) | |
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/MyProjectConfig.cmake" DESTINATION "lib/cmake/MyProject") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@PACKAGE_INIT@ | |
include("${CMAKE_CURRENT_LIST_DIR}/MyProject-targets.cmake") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment