CMakeLists.txt | 5 ++++- cmake/ExportTargets.cmake | 21 +++++++++++++++++++++ cppunitConfig.cmake.in | 27 +++++++++++++++++++++++++++ cppunitConfigVersion.cmake.in | 10 ++++++++++ src/cppunit/CMakeLists.txt | 1 + 5 files changed, 63 insertions(+), 1 deletion(-)
New commits: commit 0c417c4a933ec390da1f315079abbfacd2be3806 Author: Bernhard Sessler <bernhard.sess...@corscience.de> Date: Wed Dec 4 12:45:19 2013 +0100 cmake: Use target export feature This eliminates the need for a "Findcppunit.cmake" script in projects needing the cppunit library. The project configuration files are installed along with the library itself and provide information about where to find the library and how to use it. A prominent example of this method are the Qt5 libraries, which are shipping CMake project configuration files by default. Change-Id: I9db4f07d4a56361215eb68d9080955fede8eb205 Signed-off-by: Bernhard Sessler <bernhard.sess...@corscience.de> Reviewed-on: https://gerrit.libreoffice.org/7112 Reviewed-by: Markus Mohrhard <markus.mohrh...@googlemail.com> Tested-by: Markus Mohrhard <markus.mohrh...@googlemail.com> diff --git a/CMakeLists.txt b/CMakeLists.txt index 7b386ce..a43fe1b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,7 @@ include(Versioning) # Build options option(BUILD_SHARED_LIBS "Build cppunit as shared or static library" ON) -if(BUILD_SHARED_LIBS) +if(BUILD_SHARED_LIBS AND WIN32) add_definitions(-DCPPUNIT_BUILD_DLL) endif() @@ -25,3 +25,6 @@ include_directories("${CMAKE_CURRENT_BINARY_DIR}/include") # Subdirectories add_subdirectory(include) add_subdirectory(src) + +# Export targets +include(ExportTargets) diff --git a/cmake/ExportTargets.cmake b/cmake/ExportTargets.cmake new file mode 100644 index 0000000..4affeb4 --- /dev/null +++ b/cmake/ExportTargets.cmake @@ -0,0 +1,21 @@ +# Export targets +if(WIN32 AND NOT CYGWIN) + set(INSTALL_CMAKE_DIR CMake) +else() + set(INSTALL_CMAKE_DIR lib/cmake/cppunit) +endif() + +file(RELATIVE_PATH CONF_REL_INCLUDE_DIR + "${CMAKE_INSTALL_PREFIX}/${INSTALL_CMAKE_DIR}" + "${CMAKE_INSTALL_PREFIX}/include") +configure_file(cppunitConfig.cmake.in + "${PROJECT_BINARY_DIR}/cppunitConfig.cmake" @ONLY) +configure_file(cppunitConfigVersion.cmake.in + "${PROJECT_BINARY_DIR}/cppunitConfigVersion.cmake" @ONLY) + +install(FILES + "${PROJECT_BINARY_DIR}/cppunitConfig.cmake" + "${PROJECT_BINARY_DIR}/cppunitConfigVersion.cmake" + DESTINATION "${INSTALL_CMAKE_DIR}" COMPONENT dev) + +install(EXPORT cppunitLibraryDepends DESTINATION "${INSTALL_CMAKE_DIR}") diff --git a/cppunitConfig.cmake.in b/cppunitConfig.cmake.in new file mode 100644 index 0000000..a83550a --- /dev/null +++ b/cppunitConfig.cmake.in @@ -0,0 +1,27 @@ +# - CMake config file for cppunit +# It defines the following variables +# CPPUNIT_INCLUDE_DIRS - include directories for cppunit +# CPPUNIT_LIBRARY - the cppunit base library +# CPPUNIT_LIBRARIES - all of the cppunit libraries to link against +# CPPUNIT_FOUND - the cppunit library has been found + +if(NOT TARGET cppunit AND NOT cppunit_BINARY_DIR) + # Compute paths + get_filename_component(CPPUNIT_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) + get_filename_component(CPPUNIT_INCLUDE_DIR + "${CPPUNIT_CMAKE_DIR}/@CONF_REL_INCLUDE_DIR@" + ABSOLUTE) + + # Add the targets and dependencies + include("${CPPUNIT_CMAKE_DIR}/cppunitLibraryDepends.cmake") + + get_target_property(_cppunit_lib_type cppunit TYPE) + if(${_cppunit_lib_type} EQUAL SHARED_LIBRARY AND WIN32) + add_definitions(-DCPPUNIT_DLL) + endif() + + set(CPPUNIT_FOUND TRUE) + set(CPPUNIT_LIBRARY cppunit) + set(CPPUNIT_LIBRARIES ${CPPUNIT_LIBRARY}) + message(STATUS "Found cppunit - version: @CPPUNIT_VERSION@") +endif() diff --git a/cppunitConfigVersion.cmake.in b/cppunitConfigVersion.cmake.in new file mode 100644 index 0000000..eb9fb87 --- /dev/null +++ b/cppunitConfigVersion.cmake.in @@ -0,0 +1,10 @@ +set(PACKAGE_VERSION "@CPPUNIT_VERSION@") + +if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}") + set(PACKAGE_VERSION_COMPATIBLE FALSE) +else() + set(PACKAGE_VERSION_COMPATIBLE TRUE) + if("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}") + set(PACKAGE_VERSION_EXACT TRUE) + endif() +endif() diff --git a/src/cppunit/CMakeLists.txt b/src/cppunit/CMakeLists.txt index 27a1e18..6dbb6dd 100644 --- a/src/cppunit/CMakeLists.txt +++ b/src/cppunit/CMakeLists.txt @@ -81,6 +81,7 @@ endif() # Create install target install(TARGETS cppunit + EXPORT cppunitLibraryDepends LIBRARY DESTINATION lib ARCHIVE DESTINATION lib RUNTIME DESTINATION bin) _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits