Create cmake package using imported targets.

Create and install the necessary files so that cmake can find FreeGLUT
in config mode ("find_package(FreeGLUT CONFIG)").

This pushes cmake_minimum_required to 3.0.0.
This commit is contained in:
Johannes Zarl 2015-07-10 20:25:48 +02:00
parent 85b23a7130
commit ba7326ce8d
2 changed files with 43 additions and 7 deletions

View File

@ -1,4 +1,4 @@
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.8 FATAL_ERROR) CMAKE_MINIMUM_REQUIRED(VERSION 3.0.0 FATAL_ERROR)
PROJECT(freeglut) PROJECT(freeglut)
# for multiarch LIBDIR support (requires cmake>=2.8.8) # for multiarch LIBDIR support (requires cmake>=2.8.8)
@ -20,6 +20,7 @@ SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
set(VERSION_MAJOR 3) set(VERSION_MAJOR 3)
set(VERSION_MINOR 0) set(VERSION_MINOR 0)
set(VERSION_PATCH 0) set(VERSION_PATCH 0)
set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
# Update fg_version.h to match the versions number here in cmake # Update fg_version.h to match the versions number here in cmake
CONFIGURE_FILE(src/fg_version.h.in src/fg_version.h) CONFIGURE_FILE(src/fg_version.h.in src/fg_version.h)
@ -454,30 +455,34 @@ IF(FREEGLUT_BUILD_STATIC_LIBS)
ENDIF() ENDIF()
IF(FREEGLUT_BUILD_SHARED_LIBS) IF(FREEGLUT_BUILD_SHARED_LIBS)
INSTALL(TARGETS freeglut INSTALL(TARGETS freeglut EXPORT FreeGLUTTargets
RUNTIME DESTINATION bin RUNTIME DESTINATION bin
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
INCLUDES DESTINATION include
) )
IF(INSTALL_PDB) IF(INSTALL_PDB)
INSTALL(FILES ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Debug/freeglut${CMAKE_DEBUG_POSTFIX}.pdb INSTALL(FILES ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Debug/freeglut${CMAKE_DEBUG_POSTFIX}.pdb
DESTINATION bin DESTINATION bin
CONFIGURATIONS Debug) CONFIGURATIONS Debug
COMPONENT Devel)
ENDIF() ENDIF()
ENDIF() ENDIF()
IF(FREEGLUT_BUILD_STATIC_LIBS) IF(FREEGLUT_BUILD_STATIC_LIBS)
INSTALL(TARGETS freeglut_static INSTALL(TARGETS freeglut_static EXPORT FreeGLUTTargets
RUNTIME DESTINATION bin RUNTIME DESTINATION bin
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
INCLUDES DESTINATION include
) )
IF(INSTALL_PDB) IF(INSTALL_PDB)
INSTALL(FILES ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/Debug/freeglut_static${CMAKE_DEBUG_POSTFIX}.pdb INSTALL(FILES ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/Debug/freeglut_static${CMAKE_DEBUG_POSTFIX}.pdb
DESTINATION lib DESTINATION lib
CONFIGURATIONS Debug) CONFIGURATIONS Debug
COMPONENT Devel)
ENDIF() ENDIF()
ENDIF() ENDIF()
INSTALL(FILES ${FREEGLUT_HEADERS} DESTINATION include/GL) INSTALL(FILES ${FREEGLUT_HEADERS} DESTINATION include/GL COMPONENT Devel)
@ -571,6 +576,36 @@ IF(FREEGLUT_GLES)
SET(PC_FILENAME "freeglut-gles.pc") SET(PC_FILENAME "freeglut-gles.pc")
ENDIF() ENDIF()
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/freeglut.pc.in ${CMAKE_BINARY_DIR}/freeglut.pc @ONLY) CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/freeglut.pc.in ${CMAKE_BINARY_DIR}/freeglut.pc @ONLY)
INSTALL(FILES ${CMAKE_BINARY_DIR}/freeglut.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig/ RENAME ${PC_FILENAME}) INSTALL(FILES ${CMAKE_BINARY_DIR}/freeglut.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig/ RENAME ${PC_FILENAME} COMPONENT Devel)
# TODO: change the library and .pc name when building for GLES, # TODO: change the library and .pc name when building for GLES,
# e.g. -lglut-GLES # e.g. -lglut-GLES
INCLUDE(CMakePackageConfigHelpers)
WRITE_BASIC_PACKAGE_VERSION_FILE(
"${CMAKE_CURRENT_BINARY_DIR}/FreeGLUT/FreeGLUTConfigVersion.cmake"
VERSION ${VERSION}
COMPATIBILITY AnyNewerVersion
)
# needs cmake 3.0 (as does the "INCLUDES DIRECTORY" argument to install(TARGETS)):
EXPORT(EXPORT FreeGLUTTargets
FILE "${CMAKE_CURRENT_BINARY_DIR}/FreeGLUT/FreeGLUTTargets.cmake"
NAMESPACE FreeGLUT::
)
CONFIGURE_FILE(FreeGLUTConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/FreeGLUT/FreeGLUTConfig.cmake"
@ONLY
)
SET(ConfigPackageLocation lib/cmake/FreeGLUT)
INSTALL(EXPORT FreeGLUTTargets
FILE FreeGLUTTargets.cmake
NAMESPACE FreeGLUT::
DESTINATION ${ConfigPackageLocation}
)
INSTALL(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/FreeGLUT/FreeGLUTConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/FreeGLUT/FreeGLUTConfigVersion.cmake"
DESTINATION ${ConfigPackageLocation}
COMPONENT Devel
)

View File

@ -0,0 +1 @@
include("${CMAKE_CURRENT_LIST_DIR}/FreeGLUTTargets.cmake")