improve README
[platform/core/uifw/lottie-player.git] / CMakeLists.txt
1 cmake_minimum_required( VERSION 3.3 )
2
3 #declare project
4 project( rlottie VERSION 0.1 LANGUAGES C CXX ASM)
5
6 if (NOT CMAKE_BUILD_TYPE)
7     set(CMAKE_BUILD_TYPE MinSizeRel)
8 endif()
9
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)
13 endif()
14
15 #declare target
16 add_library( rlottie )
17 set_target_properties( rlottie PROPERTIES DEFINE_SYMBOL LOT_BUILD )
18
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}
27                       )
28
29 #declare alias so that library can be used inside the build tree, e.g. when testing
30 add_library(rlottie::rlottie ALIAS rlottie)
31
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)
38
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.")
41
42 configure_file(${CMAKE_CURRENT_LIST_DIR}/cmake/config.h.in config.h)
43
44 target_include_directories(rlottie
45     PRIVATE
46         "${CMAKE_CURRENT_BINARY_DIR}"
47     )
48
49 #declare common target compilation options
50 target_compile_options(rlottie
51                     PUBLIC
52                     PRIVATE
53                         -std=c++14
54                         -fno-exceptions
55                         -fno-unwind-tables
56                         -fno-asynchronous-unwind-tables
57                         -fno-rtti
58                         -Wall
59                         -fvisibility=hidden
60                     )
61
62 #MSVC does not recognize these parameters
63 if (NOT WIN32)
64     target_compile_options(rlottie
65                         PUBLIC
66                         PRIVATE
67                             -Werror
68                             -Wextra
69                             -Wnon-virtual-dtor
70                             -Woverloaded-virtual
71                             -Wno-unused-parameter
72                         )
73 endif()
74
75 if (WIN32 AND NOT BUILD_SHARED_LIBS)
76     target_compile_definitions(rlottie PUBLIC -DLOT_BUILD=0)
77 endif()
78
79 #declare dependancy
80 set( CMAKE_THREAD_PREFER_PTHREAD TRUE )
81 find_package( Threads )
82
83 target_link_libraries(rlottie
84                     PUBLIC
85                         "${CMAKE_THREAD_LIBS_INIT}"
86                      )
87
88 if (NOT APPLE AND NOT WIN32)
89     target_link_libraries(rlottie
90                         PRIVATE
91                             "-Wl,--version-script=${CMAKE_SOURCE_DIR}/rlottie.expmap"
92                           )
93 endif()
94
95 if (LOTTIE_MODULE)
96     # for dlopen, dlsym and dlclose dependancy
97     target_link_libraries(rlottie PRIVATE ${CMAKE_DL_LIBS})
98 endif()
99
100 if (NOT LOTTIE_ASAN)
101     if(APPLE)
102         target_link_libraries(rlottie
103                             PUBLIC
104                                  "-Wl, -undefined error"
105                               )
106     else()
107         target_link_libraries(rlottie
108                             PUBLIC
109                                  "-Wl,--no-undefined"
110                               )
111     endif()
112 endif()
113
114 if (LOTTIE_CCACHE)
115     find_program(CCACHE_FOUND ccache)
116     if (CCACHE_FOUND)
117         message(STATUS "Found ccache")
118         set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
119         set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
120     else()
121         message(STATUS "Could NOT find ccache (this is NOT an error)")
122     endif()
123 endif()
124
125 if (LOTTIE_ASAN)
126     target_compile_options(rlottie PUBLIC -fsanitize=address)
127     target_link_options(rlottie PUBLIC  -fsanitize=address)
128 endif()
129
130 if (NOT LIB_INSTALL_DIR)
131     set (LIB_INSTALL_DIR "/usr/lib")
132 endif (NOT LIB_INSTALL_DIR)
133
134 #declare source and include files
135 add_subdirectory(inc)
136 add_subdirectory(src)
137 add_subdirectory(example)
138
139 if (LOTTIE_TEST)
140     enable_testing()
141     add_subdirectory(test)
142 endif()
143
144 SET(PREFIX ${CMAKE_INSTALL_PREFIX})
145 SET(EXEC_DIR ${PREFIX})
146 SET(LIBDIR ${LIB_INSTALL_DIR})
147 SET(INCDIR ${PREFIX}/include)
148
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)
151
152
153 #install header
154 install(FILES
155         inc/rlottie.h
156         inc/rlottie_capi.h
157         inc/rlottiecommon.h
158         DESTINATION include)
159
160 #install lib
161 install( TARGETS rlottie EXPORT rlottie-targets
162          LIBRARY     DESTINATION    ${LIB_INSTALL_DIR}
163          ARCHIVE     DESTINATION    ${LIB_INSTALL_DIR}
164          INCLUDES    DESTINATION    include
165        )
166
167 #install config file.
168
169 install( EXPORT rlottie-targets
170          FILE          rlottieTargets.cmake
171          NAMESPACE     rlottie::
172          DESTINATION   ${LIB_INSTALL_DIR}/cmake/rlottie
173        )
174
175
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
182 )
183
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
187 )
188
189 #Install the config, configversion and custom find modules
190 install(FILES
191     ${CMAKE_CURRENT_BINARY_DIR}/rlottieConfig.cmake
192     ${CMAKE_CURRENT_BINARY_DIR}/rlottieConfigVersion.cmake
193     DESTINATION ${LIB_INSTALL_DIR}/cmake/rlottie
194 )
195
196
197 export(EXPORT rlottie-targets FILE ${CMAKE_CURRENT_BINARY_DIR}/rlottieTargets.cmake NAMESPACE rlottie::)
198
199 #Register package in user's package registry
200 export(PACKAGE rlottie)
201