# Example of setting up CMake config files when developing a library # 2009-2010 Ryan Pavlik # http://academic.cleardefinition.com/ # Iowa State University HCI Graduate Program/VRAC cmake_minimum_required(VERSION 2.6.2) # Set package properties project(MyPackage) set(BIN_DIR bin) set(INCLUDE_DIR include) set(ARCH_DIR lib) if(WIN32) set(LIB_DIR bin) else() set(LIB_DIR lib) endif() # Create a library set(SOURCES MyLib1.cpp) set(API MyLib1.h) add_library(MyLib1 ${SOURCES} ${API}) set_target_properties(MyLib1 PROPERTIES PUBLIC_HEADER "${API}") # target_link_libraries(MyLib1 ${WHATEVER_LIBRARIES}) # if needed install(TARGETS MyLib1 EXPORT mypackage-sdk RUNTIME DESTINATION ${BIN_DIR} COMPONENT runtime # In case this becomes a shared library LIBRARY DESTINATION ${LIB_DIR} COMPONENT runtime # In case this becomes a shared library ARCHIVE DESTINATION ${ARCH_DIR} COMPONENT sdk PUBLIC_HEADER DESTINATION include/MyPackage) ### # Pretend this directory creates and installs another library, like above add_subdirectory(mylib2) ### # Set up use from build tree set(BUILD_TREE_TARGETS MyLib1 MyLib2) configure_file(mypackage-config-build-tree.cmake.in MyPackageConfig.cmake @ONLY) export(TARGETS ${BUILD_TREE_TARGETS} NAMESPACE mypackage_buildtree_ FILE mypackage-targets.cmake) export(PACKAGE MyPackage) ### # Set up use from install tree if(WIN32) set(EXPORT_DIR cmake) else() set(EXPORT_DIR ${LIB_DIR}/MyPackage) endif() install(EXPORT mypackage-sdk DESTINATION ${EXPORT_DIR} NAMESPACE mypackage_exported_ FILE mypackage-targets.cmake) configure_file(mypackage-config.cmake.in mypackage-config-for-install.cmake @ONLY) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/mypackage-config-for-install.cmake RENAME mypackage-config.cmake DESTINATION ${EXPORT_DIR}) ### # Include the packaging system now that we have it all set up include(CPack)