lottie: add cmake config file so that library can be found with find_package() 52/185452/2
authorsubhransu mohanty <sub.mohanty@samsung.com>
Tue, 31 Jul 2018 01:14:46 +0000 (10:14 +0900)
committersubhransu mohanty <sub.mohanty@samsung.com>
Tue, 31 Jul 2018 01:20:46 +0000 (10:20 +0900)
Change-Id: I4e1c29f79a1a24636808079762cc88501fe2389b

CMakeLists.txt
cmake/lottie-playerConfig.cmake.in [new file with mode: 0644]

index 8e8f161..6a04e59 100644 (file)
@@ -1,7 +1,7 @@
 cmake_minimum_required( VERSION 3.2 )
 
 #declare project
-project( lottie-player LANGUAGES C CXX )
+project( lottie-player VERSION 0.0.1 LANGUAGES C CXX )
 
 #declare target
 add_library( lottie-player SHARED  "" )
@@ -53,12 +53,37 @@ install( TARGETS lottie-player EXPORT lottie-player-targets
        )
 
 #install config file.
+
 install( EXPORT lottie-player-targets
-         FILE          lottie-player.cmake
+         FILE          lottie-playerTargets.cmake
          NAMESPACE     lottie-player::
          DESTINATION   lib/cmake/lottie-player
        )
 
 
+#Create a ConfigVersion.cmake file
+include(CMakePackageConfigHelpers)
+write_basic_package_version_file(
+    ${CMAKE_CURRENT_BINARY_DIR}/lottie-playerConfigVersion.cmake
+    VERSION ${PROJECT_VERSION}
+    COMPATIBILITY AnyNewerVersion
+)
+
+configure_package_config_file(${CMAKE_CURRENT_LIST_DIR}/cmake/lottie-playerConfig.cmake.in
+    ${CMAKE_CURRENT_BINARY_DIR}/lottie-playerConfig.cmake
+    INSTALL_DESTINATION lib/cmake/lottie-player
+)
+
+#Install the config, configversion and custom find modules
+install(FILES
+    ${CMAKE_CURRENT_BINARY_DIR}/lottie-playerConfig.cmake
+    ${CMAKE_CURRENT_BINARY_DIR}/lottie-playerConfigVersion.cmake
+    DESTINATION lib/cmake/lottie-player
+)
+
+
+export(EXPORT lottie-player-targets FILE ${CMAKE_CURRENT_BINARY_DIR}/lottie-playerTargets.cmake NAMESPACE lottie-player::)
+
 #Register package in user's package registry
 export(PACKAGE lottie-player)
+
diff --git a/cmake/lottie-playerConfig.cmake.in b/cmake/lottie-playerConfig.cmake.in
new file mode 100644 (file)
index 0000000..8367242
--- /dev/null
@@ -0,0 +1,16 @@
+get_filename_component(lottie-player_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
+include(CMakeFindDependencyMacro)
+
+list(APPEND CMAKE_MODULE_PATH ${lottie-player_CMAKE_DIR})
+
+# NOTE Had to use find_package because find_dependency does not support COMPONENTS or MODULE until 3.8.0
+
+#find_dependency(RapidJSON 1.0 REQUIRED MODULE)
+#find_package(Boost 1.55 REQUIRED COMPONENTS regex)
+list(REMOVE_AT CMAKE_MODULE_PATH -1)
+
+if(NOT TARGET lottie-player::lottie-player)
+    include("${lottie-player_CMAKE_DIR}/lottie-playerTargets.cmake")
+endif()
+
+set(lottie-player_LIBRARIES lottie-player::lottie-player)