1 cmake_minimum_required( VERSION 3.3 )
4 project( rlottie VERSION 0.2 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 2)
22 set(player_version ${player_version_major}.${player_version_minor})
23 set_target_properties(rlottie PROPERTIES
24 VERSION ${player_version}
25 SOVERSION ${player_version_major}
28 #declare alias so that library can be used inside the build tree, e.g. when testing
29 add_library(rlottie::rlottie ALIAS rlottie)
31 option(LOTTIE_MODULE "Enable LOTTIE MODULE SUPPORT" ON)
32 option(LOTTIE_THREAD "Enable LOTTIE THREAD SUPPORT" ON)
33 option(LOTTIE_CACHE "Enable LOTTIE CACHE SUPPORT" ON)
34 option(LOTTIE_TEST "Build LOTTIE AUTOTESTS" OFF)
35 option(LOTTIE_CCACHE "Enable LOTTIE ccache SUPPORT" OFF)
36 option(LOTTIE_ASAN "Compile with asan" OFF)
38 set(LOTTIE_MODULE_PATH "${CMAKE_SHARED_LIBRARY_PREFIX}rlottie-image-loader${CMAKE_SHARED_LIBRARY_SUFFIX}"
39 CACHE STRING "Absolute or relative path to dynamic loader plugin.")
41 configure_file(${CMAKE_CURRENT_LIST_DIR}/cmake/config.h.in config.h)
43 target_include_directories(rlottie
45 "${CMAKE_CURRENT_BINARY_DIR}"
48 #declare common target compilation options
49 target_compile_options(rlottie
55 -fno-asynchronous-unwind-tables
61 #MSVC does not recognize these parameters
63 target_compile_options(rlottie
72 if (WIN32 AND NOT BUILD_SHARED_LIBS)
73 target_compile_definitions(rlottie PUBLIC -DRLOTTIE_BUILD=0)
77 set( CMAKE_THREAD_PREFER_PTHREAD TRUE )
78 find_package( Threads )
80 target_link_libraries(rlottie
82 "${CMAKE_THREAD_LIBS_INIT}"
85 if (NOT APPLE AND NOT WIN32)
86 target_link_libraries(rlottie
88 "-Wl,--version-script=${CMAKE_SOURCE_DIR}/rlottie.expmap"
93 # for dlopen, dlsym and dlclose dependancy
94 target_link_libraries(rlottie PRIVATE ${CMAKE_DL_LIBS})
99 target_link_libraries(rlottie
101 "-Wl, -undefined error"
104 target_link_libraries(rlottie
112 find_program(CCACHE_FOUND ccache)
114 message(STATUS "Found ccache")
115 set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
116 set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
118 message(STATUS "Could NOT find ccache (this is NOT an error)")
123 target_compile_options(rlottie PUBLIC -fsanitize=address)
124 target_link_options(rlottie PUBLIC -fsanitize=address)
127 if (NOT LIB_INSTALL_DIR)
128 set (LIB_INSTALL_DIR "/usr/lib")
129 endif (NOT LIB_INSTALL_DIR)
131 #declare source and include files
132 add_subdirectory(inc)
133 add_subdirectory(src)
134 add_subdirectory(example)
138 add_subdirectory(test)
141 SET(PREFIX ${CMAKE_INSTALL_PREFIX})
142 SET(EXEC_DIR ${PREFIX})
143 SET(LIBDIR ${LIB_INSTALL_DIR})
144 SET(INCDIR ${PREFIX}/include)
146 CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc)
147 INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
158 install( TARGETS rlottie EXPORT rlottie-targets
159 LIBRARY DESTINATION ${LIB_INSTALL_DIR}
160 ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
161 INCLUDES DESTINATION include
164 #install config file.
166 install( EXPORT rlottie-targets
167 FILE rlottieTargets.cmake
169 DESTINATION ${LIB_INSTALL_DIR}/cmake/rlottie
173 #Create a ConfigVersion.cmake file
174 include(CMakePackageConfigHelpers)
175 write_basic_package_version_file(
176 ${CMAKE_CURRENT_BINARY_DIR}/rlottieConfigVersion.cmake
177 VERSION ${PROJECT_VERSION}
178 COMPATIBILITY AnyNewerVersion
181 configure_package_config_file(${CMAKE_CURRENT_LIST_DIR}/cmake/rlottieConfig.cmake.in
182 ${CMAKE_CURRENT_BINARY_DIR}/rlottieConfig.cmake
183 INSTALL_DESTINATION ${LIB_INSTALL_DIR}/cmake/rlottie
186 #Install the config, configversion and custom find modules
188 ${CMAKE_CURRENT_BINARY_DIR}/rlottieConfig.cmake
189 ${CMAKE_CURRENT_BINARY_DIR}/rlottieConfigVersion.cmake
190 DESTINATION ${LIB_INSTALL_DIR}/cmake/rlottie
194 export(EXPORT rlottie-targets FILE ${CMAKE_CURRENT_BINARY_DIR}/rlottieTargets.cmake NAMESPACE rlottie::)
196 #Register package in user's package registry
197 export(PACKAGE rlottie)