CMake:ExportInterface: Difference between revisions
From KitwarePublic
Jump to navigationJump to search
(New page: =Export Interface for CMake Projects= This page documents a prototype design Alex and Brad created for exporting project information from a CMake project for use by outside projects. Her...) |
|||
Line 8: | Line 8: | ||
EXPORT( # anonymous export must be fully specified here | EXPORT( # anonymous export must be fully specified here | ||
FILE myproj-build.cmake | FILE myproj-build.cmake | ||
PREFIX myproj-1.2 | PREFIX myproj-1.2- | ||
TARGETS mylibA mylibB mygen | TARGETS mylibA mylibB mygen | ||
) | ) | ||
Line 22: | Line 22: | ||
DESTINATION lib/myproj-1.2 | DESTINATION lib/myproj-1.2 | ||
FILE myproj-install.cmake | FILE myproj-install.cmake | ||
PREFIX myproj-1.2 | PREFIX myproj-1.2- | ||
) | ) | ||
</pre> | </pre> | ||
Line 32: | Line 32: | ||
EXPORT(myproj-build # named export allows more rules later | EXPORT(myproj-build # named export allows more rules later | ||
FILE myproj-build.cmake | FILE myproj-build.cmake | ||
PREFIX myproj-1.2 | PREFIX myproj-1.2- | ||
) | ) | ||
INSTALL( | INSTALL( | ||
Line 38: | Line 38: | ||
DESTINATION lib/myproj-1.2 | DESTINATION lib/myproj-1.2 | ||
FILE myproj-install.cmake | FILE myproj-install.cmake | ||
PREFIX myproj-1.2 | PREFIX myproj-1.2- | ||
) | ) | ||
Line 60: | Line 60: | ||
DESTINATION bin | DESTINATION bin | ||
) | ) | ||
</pre> | |||
The generated export .cmake files will have content such as | |||
<pre> | |||
add_library(myproj-1.2-mylibA IMPORT) | |||
set_target_properties(mylibA PROPERTIES | |||
LOCATION /path/to/libmylibA.a) | |||
add_library(myproj-1.2-mylibB IMPORT) | |||
set_target_properties(mylibB PROPERTIES | |||
LOCATION /path/to/libmylibB.a | |||
INTERFACE_LIBRARIES myproj-1.2-mylibA | |||
) | |||
add_executable(myproj-1.2-mygen IMPORT) | |||
set_target_properties(mylibB PROPERTIES | |||
LOCATION /path/to/mygen) | |||
</pre> | </pre> |
Revision as of 18:51, 6 June 2007
Export Interface for CMake Projects
This page documents a prototype design Alex and Brad created for exporting project information from a CMake project for use by outside projects.
Here is an example for exporing a simple project from the build tree and install tree:
EXPORT( # anonymous export must be fully specified here FILE myproj-build.cmake PREFIX myproj-1.2- TARGETS mylibA mylibB mygen ) INSTALL( TARGETS mylibA mylibB mygen EXPORT myproj-install RUNTIME DESTINATION bin ARCHIVE DESTINATION lib LIBRARY DESTINATION lib ) INSTALL( EXPORT myproj-install DESTINATION lib/myproj-1.2 FILE myproj-install.cmake PREFIX myproj-1.2- )
A more complicated project may be organized this way:
# CMakeLists.txt EXPORT(myproj-build # named export allows more rules later FILE myproj-build.cmake PREFIX myproj-1.2- ) INSTALL( EXPORT myproj-install DESTINATION lib/myproj-1.2 FILE myproj-install.cmake PREFIX myproj-1.2- ) # lib/CMakeLists.txt EXPORT(myproj-build TARGETS mylibA mylibB ) INSTALL(TARGETS mylibA mylibB EXPORT myproj-install RUNTIME DESTINATION bin ARCHIVE DESTINATION lib LIBRARY DESTINATION lib ) # exe/CMakeLists.txt EXPORT(myproj-build TARGETS mygen ) INSTALL(TARGETS mygen EXPORT myproj-install DESTINATION bin )
The generated export .cmake files will have content such as
add_library(myproj-1.2-mylibA IMPORT) set_target_properties(mylibA PROPERTIES LOCATION /path/to/libmylibA.a) add_library(myproj-1.2-mylibB IMPORT) set_target_properties(mylibB PROPERTIES LOCATION /path/to/libmylibB.a INTERFACE_LIBRARIES myproj-1.2-mylibA ) add_executable(myproj-1.2-mygen IMPORT) set_target_properties(mylibB PROPERTIES LOCATION /path/to/mygen)