-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
72 lines (58 loc) · 3.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
# ====================================================================
#
# This file is part of Resvg4JUCE.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# ====================================================================
cmake_minimum_required (VERSION 3.16)
project (RESVG4JUCE VERSION 0.2.0)
# Some CMake exporters (e.g. ninja) need a dummy library file to be present before the
# build target referencing this file and triggering the prior build has been executed.
# Therefore we create a dummy library output file here first
set (RESVG_LIB_OUTPUT_DIR ${CMAKE_CURRENT_LIST_DIR}/Ext/resvg/target/release)
if (WIN32)
set (RESVG_LIB_OUTPUT ${RESVG_LIB_OUTPUT_DIR}/resvg.lib)
else()
set (RESVG_LIB_OUTPUT ${RESVG_LIB_OUTPUT_DIR}/libresvg.a)
endif()
file (MAKE_DIRECTORY ${RESVG_LIB_OUTPUT_DIR})
file (TOUCH ${RESVG_LIB_OUTPUT})
# The target to trigger the rust cargo based compilation of the resvg library used.
# For macOS we need to ensure the C-Parts of it being built for the right deployment
# target by setting an environment variable first
if (APPLE)
add_custom_target (resvg_cargo_build_arm64
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/Ext/resvg/c-api
COMMAND ${CMAKE_COMMAND} -E env MACOSX_DEPLOYMENT_TARGET=10.7 cargo build --release --target aarch64-apple-darwin)
add_custom_target (resvg_cargo_build_x86_64
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/Ext/resvg/c-api
COMMAND ${CMAKE_COMMAND} -E env MACOSX_DEPLOYMENT_TARGET=10.7 cargo build --release --target x86_64-apple-darwin)
add_custom_target (resvg_cargo_build
WORKING_DIRECTORY ${RESVG_LIB_OUTPUT_DIR}
COMMAND lipo -create -output libresvg.a ../aarch64-apple-darwin/release/libresvg.a ../x86_64-apple-darwin/release/libresvg.a)
add_dependencies (resvg_cargo_build resvg_cargo_build_arm64 resvg_cargo_build_x86_64)
else()
add_custom_target (resvg_cargo_build
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/Ext/resvg/c-api
COMMAND cargo build --release)
endif()
# Make an imported targe that references the library just built
add_library (resvg STATIC IMPORTED)
add_dependencies (resvg resvg_cargo_build)
set_target_properties (resvg PROPERTIES IMPORTED_LOCATION ${RESVG_LIB_OUTPUT})
target_include_directories (resvg INTERFACE ${CMAKE_CURRENT_LIST_DIR}/Ext/resvg/c-api)
# Seems like bcrypt is a dependency on Windows
if (WIN32)
target_link_libraries (resvg INTERFACE bcrypt)
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options (resvg INTERFACE -mssse3)
endif()
# Create the Resvg4JUCE juce module target. This depends on the resvg library created above and on the juce_gui_basics module
juce_add_module (Modules/Resvg4JUCE)
target_link_libraries (Resvg4JUCE INTERFACE resvg)
# Export an alias target
add_library (jb::Resvg4JUCE ALIAS Resvg4JUCE)