Skip to content
Browse files

Build system now creates STPConfig.cmake file in build and in install

directory which allows external projects that use CMake to easily
import STP as a target.
  • Loading branch information...
1 parent 1eb83ac commit 971889f7612f795a25db5782fb16ac9aa487ccaf @delcypher delcypher committed Oct 17, 2013
Showing with 75 additions and 0 deletions.
  1. +57 −0 CMakeLists.txt
  2. +16 −0 STPConfig.cmake.in
  3. +1 −0 src/libstp/CMakeLists.txt
  4. +1 −0 src/main/CMakeLists.txt
View
57 CMakeLists.txt
@@ -218,6 +218,11 @@ endmacro()
# -----------------------------------------------------------------------------
+# Provide an export name to be used by targets that wish to export themselves.
+# -----------------------------------------------------------------------------
+set(STP_EXPORT_NAME "STPTargets")
+
+# -----------------------------------------------------------------------------
# Compile all subdirs
# -----------------------------------------------------------------------------
@@ -246,3 +251,55 @@ add_test(NAME regresscvc
)
#regresscvc: REGRESS_LOG=`date +%Y-%m-%d`"-regress-cvc.log"
#regresscvc: baseTest
+
+# -----------------------------------------------------------------------------
+# Export our targets so that other CMake based projects can interface with
+# the build of STP in the build-tree
+# -----------------------------------------------------------------------------
+set(STP_TARGETS_FILENAME "STPTargets.cmake")
+set(STP_CONFIG_FILENAME "STPConfig.cmake")
+
+# Export targets
+export(TARGETS libstp stp FILE "${PROJECT_BINARY_DIR}/${STP_TARGETS_FILENAME}")
+
+# Create STPConfig file
+set(EXPORT_TYPE "Build-tree")
+set(CONF_INCLUDE_DIRS "${CMAKE_BINARY_DIR}/include")
+configure_file(STPConfig.cmake.in
+ "${CMAKE_BINARY_DIR}/${STP_CONFIG_FILENAME}" @ONLY
+ )
+
+# Export this package to the CMake user package registry
+# Now the user can just use find_package(STP) on their system
+export(PACKAGE STP)
+
+
+# -----------------------------------------------------------------------------
+# Export our targets so that other CMake based projects can interface with
+# the build of STP that is installed.
+# -----------------------------------------------------------------------------
+if(WIN32 AND NOT CYGWIN)
+ set(DEF_INSTALL_CMAKE_DIR CMake)
+else()
+ set(DEF_INSTALL_CMAKE_DIR lib/cmake/STP)
+endif()
+set(STP_INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH
+ "Installation directory for STP CMake files")
+
+# Create STPConfig file
+set(EXPORT_TYPE "installed")
+set(CONF_INCLUDE_DIRS "${CMAKE_INSTALL_PREFIX}/include")
+configure_file(STPConfig.cmake.in
+ "${CMAKE_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/${STP_CONFIG_FILENAME}" @ONLY
+ )
+
+install(FILES
+ "${CMAKE_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/${STP_CONFIG_FILENAME}"
+ DESTINATION "${STP_INSTALL_CMAKE_DIR}"
+ )
+
+# Install the export set for use with the install-tree
+install(EXPORT ${STP_EXPORT_NAME} DESTINATION
+ "${STP_INSTALL_CMAKE_DIR}"
+ )
+
View
16 STPConfig.cmake.in
@@ -0,0 +1,16 @@
+# Config file for the @EXPORT_TYPE@ STP Package
+# It defines the following variables
+# STP_INCLUDE_DIRS - include directories for STP
+# STP_LIBRARIES - libraries to link against
+# STP_EXECUTABLE - the stp executable
+
+# Compute paths
+get_filename_component(STP_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
+set(STP_INCLUDE_DIRS "@CONF_INCLUDE_DIRS@")
+
+# Our library dependencies (contains definitions for IMPORTED targets)
+include("${STP_CMAKE_DIR}/@STP_TARGETS_FILENAME@")
+
+# These are IMPORTED targets created by @STP_TARGETS_FILENAME@
+set(STP_LIBRARIES libstp)
+set(STP_EXECUTABLE stp)
View
1 src/libstp/CMakeLists.txt
@@ -78,6 +78,7 @@ foreach(public_header ${stp_public_headers})
endforeach()
install(TARGETS libstp
+ EXPORT ${STP_EXPORT_NAME}
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_PREFIX}/include/stp"
View
1 src/main/CMakeLists.txt
@@ -19,5 +19,6 @@ set_target_properties(stp PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_D
target_link_libraries(stp libstp)
install(TARGETS stp
+ EXPORT ${STP_EXPORT_NAME}
RUNTIME DESTINATION bin
)

0 comments on commit 971889f

Please sign in to comment.
Something went wrong with that request. Please try again.