1 cmake_minimum_required( VERSION 3.3 )
4 project( rlottie VERSION 0.1 LANGUAGES C CXX ASM)
6 if (NOT CMAKE_BUILD_TYPE)
7 set(CMAKE_BUILD_TYPE MinSizeRel)
10 if (NOT DEFINED BUILD_SHARED_LIBS)
11 # Keep the previous behavior of the build system, consistent with Meson.
12 set(BUILD_SHARED_LIBS ON)
16 add_library( rlottie )
17 set_target_properties( rlottie PROPERTIES DEFINE_SYMBOL RLOTTIE_BUILD )
19 #declare version of the target
20 set(player_version_major 0)
21 set(player_version_minor 0)
22 set(player_version_patch 1)
23 set(player_version ${player_version_major}.${player_version_minor}.${player_version_patch} )
24 set_target_properties(rlottie PROPERTIES
25 VERSION ${player_version}
26 SOVERSION ${player_version_major}
29 #declare alias so that library can be used inside the build tree, e.g. when testing
30 add_library(rlottie::rlottie ALIAS rlottie)
32 option(LOTTIE_MODULE "Enable LOTTIE MODULE SUPPORT" ON)
33 option(LOTTIE_THREAD "Enable LOTTIE THREAD SUPPORT" ON)
34 option(LOTTIE_CACHE "Enable LOTTIE CACHE SUPPORT" ON)
35 option(LOTTIE_TEST "Build LOTTIE AUTOTESTS" OFF)
36 option(LOTTIE_CCACHE "Enable LOTTIE ccache SUPPORT" OFF)
37 option(LOTTIE_ASAN "Compile with asan" OFF)
39 set(LOTTIE_MODULE_PATH "${CMAKE_SHARED_LIBRARY_PREFIX}rlottie-image-loader${CMAKE_SHARED_LIBRARY_SUFFIX}"
40 CACHE STRING "Absolute or relative path to dynamic loader plugin.")
42 configure_file(${CMAKE_CURRENT_LIST_DIR}/cmake/config.h.in config.h)
44 target_include_directories(rlottie
46 "${CMAKE_CURRENT_BINARY_DIR}"
49 #declare common target compilation options
50 target_compile_options(rlottie
56 -fno-asynchronous-unwind-tables
62 #MSVC does not recognize these parameters
64 target_compile_options(rlottie
75 if (WIN32 AND NOT BUILD_SHARED_LIBS)
76 target_compile_definitions(rlottie PUBLIC -DRLOTTIE_BUILD=0)
80 set( CMAKE_THREAD_PREFER_PTHREAD TRUE )
81 find_package( Threads )
83 target_link_libraries(rlottie
85 "${CMAKE_THREAD_LIBS_INIT}"
88 if (NOT APPLE AND NOT WIN32)
89 target_link_libraries(rlottie
91 "-Wl,--version-script=${CMAKE_SOURCE_DIR}/rlottie.expmap"
96 # for dlopen, dlsym and dlclose dependancy
97 target_link_libraries(rlottie PRIVATE ${CMAKE_DL_LIBS})
102 target_link_libraries(rlottie
104 "-Wl, -undefined error"
107 target_link_libraries(rlottie
115 find_program(CCACHE_FOUND ccache)
117 message(STATUS "Found ccache")
118 set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
119 set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
121 message(STATUS "Could NOT find ccache (this is NOT an error)")
126 target_compile_options(rlottie PUBLIC -fsanitize=address)
127 target_link_options(rlottie PUBLIC -fsanitize=address)
130 if (NOT LIB_INSTALL_DIR)
131 set (LIB_INSTALL_DIR "/usr/lib")
132 endif (NOT LIB_INSTALL_DIR)
134 #declare source and include files
135 add_subdirectory(inc)
136 add_subdirectory(src)
137 add_subdirectory(example)
141 add_subdirectory(test)
144 SET(PREFIX ${CMAKE_INSTALL_PREFIX})
145 SET(EXEC_DIR ${PREFIX})
146 SET(LIBDIR ${LIB_INSTALL_DIR})
147 SET(INCDIR ${PREFIX}/include)
149 CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc)
150 INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
161 install( TARGETS rlottie EXPORT rlottie-targets
162 LIBRARY DESTINATION ${LIB_INSTALL_DIR}
163 ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
164 INCLUDES DESTINATION include
167 #install config file.
169 install( EXPORT rlottie-targets
170 FILE rlottieTargets.cmake
172 DESTINATION ${LIB_INSTALL_DIR}/cmake/rlottie
176 #Create a ConfigVersion.cmake file
177 include(CMakePackageConfigHelpers)
178 write_basic_package_version_file(
179 ${CMAKE_CURRENT_BINARY_DIR}/rlottieConfigVersion.cmake
180 VERSION ${PROJECT_VERSION}
181 COMPATIBILITY AnyNewerVersion
184 configure_package_config_file(${CMAKE_CURRENT_LIST_DIR}/cmake/rlottieConfig.cmake.in
185 ${CMAKE_CURRENT_BINARY_DIR}/rlottieConfig.cmake
186 INSTALL_DESTINATION ${LIB_INSTALL_DIR}/cmake/rlottie
189 #Install the config, configversion and custom find modules
191 ${CMAKE_CURRENT_BINARY_DIR}/rlottieConfig.cmake
192 ${CMAKE_CURRENT_BINARY_DIR}/rlottieConfigVersion.cmake
193 DESTINATION ${LIB_INSTALL_DIR}/cmake/rlottie
197 export(EXPORT rlottie-targets FILE ${CMAKE_CURRENT_BINARY_DIR}/rlottieTargets.cmake NAMESPACE rlottie::)
199 #Register package in user's package registry
200 export(PACKAGE rlottie)