-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
71 lines (57 loc) · 2.54 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
# Copyright (c) 2023 - 2024 sincos2854
# Licensed under the MIT License
cmake_minimum_required(VERSION 3.22...3.30)
project(ifswp2cm LANGUAGES CXX VERSION 0.2.1)
set(CMAKE_CXX_STANDARD 20)
# Write ifswp2cm version number in version.h
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/version.h.in ${CMAKE_CURRENT_SOURCE_DIR}/version.h)
set(CMAKE_SHARED_LIBRARY_PREFIX "") # Don't prefix file names with "lib"
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>" CACHE STRING "Use /MT option instead of /MD option.")
set(BUILD_SHARED_LIBS OFF CACHE BOOL "Make libwebp2 a static build.")
set(WP2_BUILD_TESTS OFF CACHE BOOL "")
set(WP2_ENABLE_TESTS OFF CACHE BOOL "")
set(WP2_BUILD_EXAMPLES OFF CACHE BOOL "")
set(WP2_BUILD_EXTRAS OFF CACHE BOOL "")
set(LIBWEBP2_NAME "libwebp2")
set(LIBWEBP2_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ext/${LIBWEBP2_NAME})
message(STATUS "CMAKE_HOST_SYSTEM_NAME = ${CMAKE_HOST_SYSTEM_NAME}")
message(STATUS "CMAKE_CXX_COMPILER_ID = ${CMAKE_CXX_COMPILER_ID}")
message(STATUS "${LIBWEBP2_NAME} SOURCE DIR = ${LIBWEBP2_SRC_DIR}")
# Since Linux can't read "Windows.h", replace it with "windows.h".
if(NOT CMAKE_HOST_SYSTEM_NAME MATCHES "Windows")
message(STATUS "Replacing Windows.h with windows.h")
execute_process(
COMMAND find ${LIBWEBP2_SRC_DIR} -name "*.h" -type f -exec sed -i "s/Windows\.h/windows.h/g" {} +
)
endif()
# Add libwebp2 directory
add_subdirectory(${LIBWEBP2_SRC_DIR})
set(DLL_NAME "ifswp2cm")
# Creating ifswp2cm
add_library(${DLL_NAME} SHARED spi00in.cpp ifswp2cm.cpp spi00in.def)
target_include_directories(${DLL_NAME} PRIVATE ${LIBWEBP2_SRC_DIR}/src)
target_link_libraries(${DLL_NAME} webp2)
# .spi extension for 32bit version, .sph extension for 64bit version
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
message(STATUS "Build target is 32-bit.")
set_target_properties(${DLL_NAME} PROPERTIES SUFFIX ".spi")
else()
message(STATUS "Build target is 64-bit.")
set_target_properties(${DLL_NAME} PROPERTIES SUFFIX ".sph")
endif()
target_compile_definitions(${DLL_NAME} PRIVATE _USRDLL UNICODE _UNICODE)
if(MSVC)
target_compile_options(${DLL_NAME} PRIVATE /W3)
else()
target_compile_options(${DLL_NAME} PRIVATE -Wall -Wextra)
if(CMAKE_BUILD_TYPE STREQUAL "Release")
target_link_options(${DLL_NAME} PRIVATE -s)
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
target_link_options(${DLL_NAME} PRIVATE -static)
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
target_link_options(${DLL_NAME} PRIVATE -static-libstdc++)
endif()
endif()
install(TARGETS ${DLL_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX})