-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathCMakeLists.txt
168 lines (148 loc) · 5.39 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
cmake_minimum_required(VERSION 3.8 FATAL_ERROR)
project(ect VERSION 0.9.5 LANGUAGES CXX C)
cmake_policy(SET CMP0048 NEW)
include(GNUInstallDirs)
#Note that C++11 is still supported, but using it will cause the directory support to be disabled.
set (CMAKE_CXX_STANDARD 17)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
# Check that submodules are present only if source was downloaded with git
if(EXISTS "${CMAKE_SOURCE_DIR}/../.git" AND NOT EXISTS "${CMAKE_SOURCE_DIR}/../src/libpng/README")
message (FATAL_ERROR "Submodules are not initialized. Run \n\tgit submodule update --init --recursive\n within the repository")
endif()
add_executable(ect
main.cpp
gztools.cpp
jpegtran.cpp
LzFind.c
support.cpp
zopflipng.cpp
# Add headers so they get added to things like Xcode projects
gztools.h
LzFind.h
main.h
pngusr.h
support.h
mozjpeg/transupp.c)
add_executable(ect::ect ALIAS ect)
if(MINGW)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-mno-ms-bitfields>)
add_compile_options($<$<COMPILE_LANGUAGE:C>:-mno-ms-bitfields>)
endif()
if(NOT MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-sign-compare -Wno-unused -Wno-unused-parameter")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wno-sign-compare -Wno-unused -Wno-unused-parameter")
endif()
# Use -Ofast in release builds
foreach(var CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_RELWITHDEBINFO CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_RELWITHDEBINFO)
if(${var} MATCHES "-O(2|3)")
string(REGEX REPLACE "-O(2|3)" "-Ofast" ${var} "${${var}}")
endif()
endforeach()
# Detect CPU type and whether we're building 64-bit or 32-bit code, courtesy of mozjpeg
math(EXPR BITS "${CMAKE_SIZEOF_VOID_P} * 8")
string(TOLOWER ${CMAKE_SYSTEM_PROCESSOR} CMAKE_SYSTEM_PROCESSOR_LC)
set(COUNT 1)
foreach(ARCH ${CMAKE_OSX_ARCHITECTURES})
if(COUNT GREATER 1)
message(FATAL_ERROR "The libjpeg-turbo build system does not support multiple values in CMAKE_OSX_ARCHITECTURES.")
endif()
math(EXPR COUNT "${COUNT}+1")
endforeach()
if(CMAKE_SYSTEM_PROCESSOR_LC MATCHES "x86_64" OR
CMAKE_SYSTEM_PROCESSOR_LC MATCHES "amd64" OR
CMAKE_SYSTEM_PROCESSOR_LC MATCHES "i[0-9]86" OR
CMAKE_SYSTEM_PROCESSOR_LC MATCHES "x86" OR
CMAKE_SYSTEM_PROCESSOR_LC MATCHES "ia32")
if(BITS EQUAL 64 OR CMAKE_C_COMPILER_ABI MATCHES "ELF X32")
set(CPU_TYPE x86_64)
else()
set(CPU_TYPE i386)
endif()
if(NOT CMAKE_SYSTEM_PROCESSOR STREQUAL ${CPU_TYPE})
set(CMAKE_SYSTEM_PROCESSOR ${CPU_TYPE})
endif()
elseif(CMAKE_SYSTEM_PROCESSOR_LC STREQUAL "aarch64" OR
CMAKE_SYSTEM_PROCESSOR_LC MATCHES "^arm")
if(BITS EQUAL 64)
set(CPU_TYPE arm64)
else()
set(CPU_TYPE arm)
endif()
else()
set(CPU_TYPE ${CMAKE_SYSTEM_PROCESSOR_LC})
endif()
if(CMAKE_OSX_ARCHITECTURES MATCHES "x86_64" OR
CMAKE_OSX_ARCHITECTURES MATCHES "arm64" OR
CMAKE_OSX_ARCHITECTURES MATCHES "i386")
set(CPU_TYPE ${CMAKE_OSX_ARCHITECTURES})
endif()
if(MSVC_IDE AND CMAKE_GENERATOR_PLATFORM MATCHES "arm64")
set(CPU_TYPE arm64)
endif()
#Enable vector extensions. May also add these for ARM if needed.
#32-bit x86 is no longer officially supported and might not work, but do enable the compile flags for it.
if(CPU_TYPE STREQUAL "x86_64" OR CPU_TYPE STREQUAL "i386")
add_definitions(-DADLER32_SIMD_SSSE3)
add_definitions(-DINFLATE_CHUNK_SIMD_SSE2)
add_definitions(-DINFLATE_CHUNK_READ_64LE)
add_definitions(-DHAS_PCLMUL)
elseif(CPU_TYPE STREQUAL arm64)
add_definitions(-DADLER32_SIMD_NEON)
add_definitions(-DINFLATE_CHUNK_SIMD_NEON)
add_definitions(-DINFLATE_CHUNK_READ_64LE)
add_definitions(-DPNG_ALIGNED_MEMORY_SUPPORTED)
set(PNG_ARM_NEON "on")
endif()
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang"
OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" OR CMAKE_CXX_COMPILER_ID STREQUAL "ARMClang")
if(CPU_TYPE STREQUAL "x86_64" OR CPU_TYPE STREQUAL "i386")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mpclmul -msse4.2")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mpclmul -msse4.2")
elseif(CPU_TYPE STREQUAL arm64)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=armv8-a+crc")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv8-a+crc")
endif()
endif()
# Enable ZLIB_CONST for everything
add_definitions(-DZLIB_CONST)
option(ECT_MULTITHREADING "Enable multithreaded processing support" ON)
option(ECT_MP3_SUPPORT "Enable MP3 support (not currently working)" OFF)
add_subdirectory(leanify EXCLUDE_FROM_ALL)
add_subdirectory(lodepng EXCLUDE_FROM_ALL)
add_subdirectory(miniz EXCLUDE_FROM_ALL)
add_subdirectory(zlib EXCLUDE_FROM_ALL)
add_subdirectory(zopfli EXCLUDE_FROM_ALL)
file(COPY ${CMAKE_SOURCE_DIR}/pngusr.h DESTINATION ${CMAKE_SOURCE_DIR}/libpng/)
add_subdirectory(optipng EXCLUDE_FROM_ALL)
# Mozjpeg changes the install prefix if it thinks the current is defaulted
set(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT FALSE)
add_subdirectory(mozjpeg EXCLUDE_FROM_ALL)
target_link_libraries(ect
leanify::leanify
lodepng::lodepng
miniz::miniz
optipng::optipng
zopfli::zopfli
zlib::zlib
jpeg-static)
# mozjpeg generates some header files that we need to be able to include
target_include_directories(ect
PRIVATE
${CMAKE_CURRENT_BINARY_DIR}/mozjpeg)
if(NOT ECT_MULTITHREADING)
target_compile_definitions(ect
PRIVATE
NOMULTI=1)
else()
find_package(Threads REQUIRED)
target_link_libraries(ect
Threads::Threads)
endif()
if(ECT_MP3_SUPPORT)
target_compile_definitions(ect
PRIVATE
MP3_SUPPORTED=1)
endif()
install(TARGETS ect RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})