-
Notifications
You must be signed in to change notification settings - Fork 4
/
CMakeLists.txt
137 lines (121 loc) · 5.01 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
cmake_minimum_required(VERSION 3.18 FATAL_ERROR)
project(lottieconverter)
include(ExternalProject)
include(FindPackageMessage)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_C_STANDARD 99)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_C_STANDARD_REQUIRED True)
set(ZLIB_MINIMUM 1.2.3)
set(PNG_MINIMUM 1.6.0)
set(COMPILE_PARAMS -Wall)
set(SOURCE_FILES lottie_export.cpp)
set(LIBS z)
set(INCLUDES)
add_executable(${PROJECT_NAME})
option(SYSTEM_PNG "Use system dynamic libpng" 1)
option(SYSTEM_RL "Use system dynamic rlottie" 0)
option(SYSTEM_GL "Use system shared giflib" 0)
enable_testing()
find_package(ZLIB ${ZLIB_MINIMUM} REQUIRED)
if (SYSTEM_PNG)
find_package(PNG ${PNG_MINIMUM} REQUIRED)
set(LIBS ${LIBS} png)
else ()
message(NOTICE "-- Building static libpng")
ExternalProject_Add(
png
URL "${CMAKE_SOURCE_DIR}/lib/libpng"
${ARGN}
PREFIX "${CMAKE_BINARY_DIR}/lib/libpng"
CMAKE_ARGS
-Wno-dev
"-DCMAKE_TOOLCHAIN_FILE:PATH=${CMAKE_TOOLCHAIN_FILE}"
"-DCMAKE_USER_MAKE_RULES_OVERRIDE=${CMAKE_USER_MAKE_RULES_OVERRIDE}"
"-DCMAKE_C_FLAGS:STRING=${CMAKE_C_FLAGS}"
"-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}"
"-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>"
"-DBUILD_SHARED_LIBS=OFF"
"-DPNG_SHARED=OFF"
"-DPNG_TESTS=OFF"
"-DCMAKE_INSTALL_LIBDIR=${CMAKE_BINARY_DIR}/lib/libpng"
BUILD_BYPRODUCTS "${CMAKE_BINARY_DIR}/lib/libpng/libpng.a"
)
set(INCLUDES ${INCLUDES} "${CMAKE_BINARY_DIR}/lib/libpng/include")
set(LIBS ${LIBS} pthread "${CMAKE_BINARY_DIR}/lib/libpng/libpng.a")
add_dependencies(${PROJECT_NAME} png)
endif ()
if (SYSTEM_RL)
find_path(RL_INCLUDEDIR NAMES rlottie.h HINTS ${_RL_INCLUDEDIR} REQUIRED)
find_library(RL_LIBDIR NAMES rlottie HINTS ${_RL_LIBDIR} REQUIRED)
find_package_message(rlottie "Found RLOTTIE: ${RL_LIBDIR}" "Include path: ${RL_INCLUDEDIR}")
set(LIBS ${LIBS} "${RL_LIBDIR}")
set(INCLUDES ${INCLUDES} "${RL_INCLUDEDIR}")
else ()
message(NOTICE "-- Building static rlottie")
ExternalProject_Add(
rlottie
URL "${CMAKE_SOURCE_DIR}/lib/rlottie"
${ARGN}
PREFIX "${CMAKE_BINARY_DIR}/lib/rlottie"
CMAKE_ARGS
-Wno-dev
"-DCMAKE_TOOLCHAIN_FILE:PATH=${CMAKE_TOOLCHAIN_FILE}"
"-DCMAKE_USER_MAKE_RULES_OVERRIDE=${CMAKE_USER_MAKE_RULES_OVERRIDE}"
"-DCMAKE_C_FLAGS:STRING=${CMAKE_C_FLAGS}"
"-DCMAKE_CXX_FLAGS:STRING=${CMAKE_CXX_FLAGS}"
"-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}"
"-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>"
"-DLOTTIE_MODULE=OFF"
"-DBUILD_SHARED_LIBS=OFF"
"-DLIB_INSTALL_DIR=${CMAKE_BINARY_DIR}/lib/rlottie"
BUILD_BYPRODUCTS "${CMAKE_BINARY_DIR}/lib/rlottie/librlottie.a"
)
set(INCLUDES ${INCLUDES} "${CMAKE_BINARY_DIR}/lib/rlottie/include")
set(LIBS ${LIBS} pthread "${CMAKE_BINARY_DIR}/lib/rlottie/librlottie.a")
add_dependencies(${PROJECT_NAME} rlottie)
endif ()
if (SYSTEM_GL)
find_path(GL_INCLUDEDIR NAMES gif_lib.h HINTS ${_GL_INCLUDEDIR} REQUIRED)
find_library(GL_LIBDIR NAMES gif HINTS ${_GL_LIBDIR} REQUIRED)
find_package_message(gif "Found GIF: ${GL_LIBDIR}" "Include path: ${GL_INCLUDEDIR}")
set(INCLUDES ${INCLUDES} "${GL_INCLUDEDIR}")
set(LIBS ${LIBS} "${GL_LIBDIR}")
set(SOURCE_FILES ${SOURCE_FILES} gif_quantize.c)
else ()
message(NOTICE "-- Building static giflib")
file(COPY ${CMAKE_SOURCE_DIR}/lib/giflib DESTINATION ${CMAKE_BINARY_DIR}/lib)
add_custom_target(
giflibProject
COMMAND make libgif.a libutil.a
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/lib/giflib"
BYPRODUCTS "${CMAKE_BINARY_DIR}/lib/giflib/libgif.a" "${CMAKE_BINARY_DIR}/lib/giflib/libutil.a"
)
add_library(giflibUtil STATIC IMPORTED)
add_dependencies(giflibUtil giflibProject)
set_target_properties(giflibUtil
PROPERTIES IMPORTED_LOCATION "${CMAKE_BINARY_DIR}/lib/giflib/libutil.a"
)
add_library(giflibMain STATIC IMPORTED)
add_dependencies(giflibMain giflibProject)
set_target_properties(giflibMain
PROPERTIES IMPORTED_LOCATION "${CMAKE_BINARY_DIR}/lib/giflib/libgif.a"
)
add_library(giflib INTERFACE IMPORTED)
set_property(TARGET giflib PROPERTY
INTERFACE_LINK_LIBRARIES giflibUtil giflibMain)
#add_dependencies(giflib giflibMain giflibUtil)
set(LIBS ${LIBS} giflib)
add_dependencies(${PROJECT_NAME} giflib)
set(INCLUDES ${INCLUDES} "${CMAKE_BINARY_DIR}/lib/giflib")
endif ()
if (INCLUDES)
include_directories(${INCLUDES})
endif ()
target_sources(${PROJECT_NAME} PRIVATE ${SOURCE_FILES})
target_compile_options(${PROJECT_NAME} PUBLIC PRIVATE ${COMPILE_PARAMS})
target_link_libraries(${PROJECT_NAME} PUBLIC ${LIBS})
add_test(NAME convert
COMMAND run.sh $<TARGET_FILE:lottieconverter>
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/test"
)