CMake Package: Difference between revisions
From KitwarePublic
Jump to navigationJump to search
(New page: The example shown below will work for INSTALLED projects only. I just hacked it out in a couple minutes, and it is not well tested. It should get you started, though. After installation...) |
No edit summary |
||
Line 1: | Line 1: | ||
== Using CMake Package == | |||
FIND_PACKAGE(CME) | FIND_PACKAGE(CME) | ||
IF(CME_FOUND) | IF(CME_FOUND) | ||
INCLUDE(${CME_USE_FILE}) | |||
# ... Use library ... | |||
ENDIF(CME_FOUND) | ENDIF(CME_FOUND) | ||
== Setup CMake Package == | |||
<pre> | |||
#----------------------------------------------------------------------------- | #----------------------------------------------------------------------------- | ||
# CMEConfig.cmake - CME CMake configuration file for external projects. | # CMEConfig.cmake - CME CMake configuration file for external projects. | ||
Line 42: | Line 40: | ||
# Additional project-specific configuration settings can be set here. | # Additional project-specific configuration settings can be set here. | ||
</pre> | |||
<pre> | |||
#----------------------------------------------------------------------------- | #----------------------------------------------------------------------------- | ||
# CMakeLists.txt | # CMakeLists.txt | ||
Line 80: | Line 78: | ||
INSTALL_FILES(/lib/cme .cmake CMEBuildSettings CMELibraryDepends | INSTALL_FILES(/lib/cme .cmake CMEBuildSettings CMELibraryDepends | ||
UseCME CMEConfig) | UseCME CMEConfig) | ||
</pre> | |||
<pre> | |||
#----------------------------------------------------------------------------- | #----------------------------------------------------------------------------- | ||
# UseCME.cmake | # UseCME.cmake | ||
Line 102: | Line 100: | ||
# Add link directories needed to use CME. | # Add link directories needed to use CME. | ||
LINK_DIRECTORIES(${CME_LIBRARY_DIRS}) | LINK_DIRECTORIES(${CME_LIBRARY_DIRS}) | ||
</pre> | |||
<pre> | |||
/*--------------------------------------------------------------------------*/ | /*--------------------------------------------------------------------------*/ | ||
/* cme.cxx */ | /* cme.cxx */ | ||
Line 112: | Line 111: | ||
return sqrt(2); | return sqrt(2); | ||
} | } | ||
</pre> | |||
<pre> | |||
/*--------------------------------------------------------------------------*/ | /*--------------------------------------------------------------------------*/ | ||
/* cme.h */ | /* cme.h */ | ||
Line 123: | Line 123: | ||
#endif | #endif | ||
</pre> | |||
== Reference == | == Reference == | ||
* http://public.kitware.com/pipermail/cmake/2003-March/003554.html | * http://public.kitware.com/pipermail/cmake/2003-March/003554.html |
Revision as of 10:27, 19 June 2007
Using CMake Package
FIND_PACKAGE(CME) IF(CME_FOUND) INCLUDE(${CME_USE_FILE}) # ... Use library ... ENDIF(CME_FOUND)
Setup CMake Package
#----------------------------------------------------------------------------- # CMEConfig.cmake - CME CMake configuration file for external projects. # # This file is configured by CME and used by the UseCME.cmake module # to load CME's settings for an external project. # The CME include file directories. SET(CME_INCLUDE_DIRS "@CMAKE_INSTALL_PREFIX@/include") # The CME library directories. SET(CME_LIBRARY_DIRS "@CMAKE_INSTALL_PREFIX@/lib") # The CME version number. SET(CME_VERSION_MAJOR "@CME_VERSION_MAJOR@") SET(CME_VERSION_MINOR "@CME_VERSION_MINOR@") # The location of the UseCME.cmake file. SET(CME_USE_FILE "@CMAKE_INSTALL_PREFIX@/lib/cme/UseCME.cmake") # The build settings file. SET(CME_BUILD_SETTINGS_FILE "@CMAKE_INSTALL_PREFIX@/lib/cme/CMEBuildSettings.cmake") # The CME library dependencies. These can be blocked by projects # not interested in linking to CME's library. IF(NOT CME_NO_LIBRARY_DEPENDS) INCLUDE("@CMAKE_INSTALL_PREFIX@/lib/cme/CMELibraryDepends.cmake") ENDIF(NOT CME_NO_LIBRARY_DEPENDS) # Additional project-specific configuration settings can be set here.
#----------------------------------------------------------------------------- # CMakeLists.txt # Example project "CMake Export". PROJECT(CME) # Every project should have a version number. SET(CME_VERSION_MAJOR 1) SET(CME_VERSION_MINOR 0) # Example library. ADD_LIBRARY(cme cme.cxx) # Link to libm on unix for sqrt(). This is to demonstrate library # dependency chaining. IF(UNIX) TARGET_LINK_LIBRARIES(cme m) ENDIF(UNIX) # Create the CMEConfig.cmake file for installation. CONFIGURE_FILE(${CME_SOURCE_DIR}/CMEConfig.cmake.in ${CME_BINARY_DIR}/CMEConfig.cmake @ONLY IMMEIDATE) # Save the compiler settings and library dependencies so another # project can import them. INCLUDE(${CMAKE_ROOT}/Modules/CMakeExportBuildSettings.cmake) CMAKE_EXPORT_BUILD_SETTINGS(${CME_BINARY_DIR}/CMEBuildSettings.cmake) EXPORT_LIBRARY_DEPENDENCIES(${CME_BINARY_DIR}/CMELibraryDepends.cmake) # Install targets. Make sure the paths configured into # CMEConfig.cmake match. INSTALL_TARGETS(/lib cme) INSTALL_FILES(/include .h cme) INSTALL_FILES(/lib/cme .cmake CMEBuildSettings CMELibraryDepends UseCME CMEConfig)
#----------------------------------------------------------------------------- # UseCME.cmake # # This module is provided as CME_USE_FILE by CMEConfig.cmake. It can # be INCLUDEd in a project to load the needed compiler and linker # settings to use CME. # # Load the compiler settings used for CME. IF(CME_BUILD_SETTINGS_FILE) INCLUDE(${CMAKE_ROOT}/Modules/CMakeImportBuildSettings.cmake) CMAKE_IMPORT_BUILD_SETTINGS(${CME_BUILD_SETTINGS_FILE}) ENDIF(CME_BUILD_SETTINGS_FILE) # Add include directories needed to use CME. INCLUDE_DIRECTORIES(${CME_INCLUDE_DIRS}) # Add link directories needed to use CME. LINK_DIRECTORIES(${CME_LIBRARY_DIRS})
/*--------------------------------------------------------------------------*/ /* cme.cxx */ #include <math.h> double cme() { return sqrt(2); }
/*--------------------------------------------------------------------------*/ /* cme.h */ #ifndef _cme_h #define _cme_h extern double cme(); #endif