summaryrefslogtreecommitdiff
path: root/Depends.cmake
blob: b7a6cd25c887cce0f3378ce01e7b3c1b2d84888e (plain)
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
find_package (PkgConfig)

if (IOS)
    include (Depends-iOS.cmake)
    return ()
endif ()

if (ANDROID)
    include (Depends-Android.cmake)
    return ()
endif ()

find_package (PkgConfig)
find_program (MESON_EXECUTABLE meson DOC "Meson build system")
find_program (NINJA_EXECUTABLE ninja DOC "Ninja build tool")
include (ExternalProject)
set (_dependsToBuild)

if (NOT EXISTS ${CMAKE_SOURCE_DIR}/lib/the_Foundation/CMakeLists.txt)
    set (INSTALL_THE_FOUNDATION YES)
    find_package (the_Foundation 1.1.0 REQUIRED)
else ()
    if (EXISTS ${CMAKE_SOURCE_DIR}/lib/the_Foundation/.git)
        # the_Foundation is checked out as a submodule, make sure it's up to date.
        find_package (Git)
        if (GIT_FOUND)
            execute_process (
                COMMAND ${GIT_EXECUTABLE} submodule update
                WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
                OUTPUT_VARIABLE subout
                OUTPUT_STRIP_TRAILING_WHITESPACE
            )
            if (subout)
                message (FATAL_ERROR "'lib/the_Foundation' Git submodule has been updated, please re-run CMake.\n")
            endif ()
        endif ()
    endif ()
    set (INSTALL_THE_FOUNDATION OFF)
    set (TFDN_STATIC_LIBRARY    ON  CACHE BOOL "")
    set (TFDN_ENABLE_INSTALL    OFF CACHE BOOL "")
    set (TFDN_ENABLE_TESTS      OFF CACHE BOOL "")
    set (TFDN_ENABLE_WEBREQUEST OFF CACHE BOOL "")
    add_subdirectory (lib/the_Foundation)
    add_library (the_Foundation::the_Foundation ALIAS the_Foundation)
    if (NOT OPENSSL_FOUND)
        message (FATAL_ERROR "Lagrange requires OpenSSL for TLS. Please check if pkg-config can find 'openssl'.")
    endif ()
    if (NOT ZLIB_FOUND)
        message (FATAL_ERROR "Lagrange requires zlib for reading compressed archives. Please check if pkg-config can find 'zlib'.")
    endif ()
endif ()

if (APPLE AND CMAKE_OSX_DEPLOYMENT_TARGET)
    set (_dependMacOpts
        -Dc_args=-mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}
        -Dc_link_args=-mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}
        -Dcpp_args=-mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}
        -Dcpp_link_args=-mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}
    )
endif ()

if (ENABLE_HARFBUZZ)
    # Find HarfBuzz with pkg-config.
    if (NOT ENABLE_HARFBUZZ_MINIMAL AND PKG_CONFIG_FOUND)
        pkg_check_modules (HARFBUZZ IMPORTED_TARGET harfbuzz)
    endif ()
    if (EXISTS ${CMAKE_SOURCE_DIR}/lib/harfbuzz/CMakeLists.txt AND
            (ENABLE_HARFBUZZ_MINIMAL OR NOT HARFBUZZ_FOUND))
        # Build HarfBuzz with minimal dependencies.
        if (MESON_EXECUTABLE AND NINJA_EXECUTABLE)
            set (_dst ${CMAKE_BINARY_DIR}/lib/harfbuzz)
            ExternalProject_Add (harfbuzz-ext
                PREFIX              ${CMAKE_BINARY_DIR}/harfbuzz-ext
                SOURCE_DIR          ${CMAKE_SOURCE_DIR}/lib/harfbuzz
                CONFIGURE_COMMAND   NINJA=${NINJA_EXECUTABLE} ${MESON_EXECUTABLE}
                                        ${CMAKE_SOURCE_DIR}/lib/harfbuzz
                                        -Dbuildtype=release
                                        -Ddefault_library=both
                                        -Dlibdir=lib
                                        -Dtests=disabled -Dglib=disabled -Dgobject=disabled
                                        -Dcairo=disabled -Dicu=disabled -Dfreetype=disabled
                                        -Ddocs=disabled
                                        ${_dependMacOpts}
                                        --prefix ${_dst}
                BUILD_COMMAND       ${NINJA_EXECUTABLE} install
                INSTALL_COMMAND     ""
            )
            list (APPEND _dependsToBuild harfbuzz-ext)
            add_library (harfbuzz-lib INTERFACE)
            target_include_directories (harfbuzz-lib INTERFACE ${_dst}/include/harfbuzz)
            if (MSYS)
                # Link dynamically.
                target_link_libraries (harfbuzz-lib INTERFACE -L${_dst}/lib harfbuzz)
                install (PROGRAMS ${_dst}/bin/msys-harfbuzz-0.dll DESTINATION .)
            else ()
                if (APPLE)
                    target_link_libraries (harfbuzz-lib INTERFACE ${_dst}/lib/libharfbuzz.0.dylib)
                    target_link_libraries (harfbuzz-lib INTERFACE c++)
                else ()
                    target_link_libraries (harfbuzz-lib INTERFACE ${_dst}/lib/libharfbuzz.a)
                    target_link_libraries (harfbuzz-lib INTERFACE stdc++)
                endif ()
            endif ()
            set (HARFBUZZ_FOUND YES)
        else ()
            # Try the CMake instead.
            set (HB_BUILD_SUBSET  OFF CACHE BOOL "" FORCE)
            set (HB_HAVE_CORETEXT OFF CACHE BOOL "" FORCE)
            set (HB_HAVE_FREETYPE OFF CACHE BOOL "" FORCE)
            set (HB_HAVE_GLIB     OFF CACHE BOOL "" FORCE)
            set (HB_HAVE_GOBJECT  OFF CACHE BOOL "" FORCE)
            set (HB_HAVE_ICU      OFF CACHE BOOL "" FORCE)
            set (SKIP_INSTALL_ALL YES CACHE BOOL "" FORCE)
            set (CMAKE_CXX_FLAGS)
            add_subdirectory (${CMAKE_SOURCE_DIR}/lib/harfbuzz)
            set (HARFBUZZ_LIBRARIES harfbuzz)
            # HarfBuzz is C++ so must link with the standard library.
            if (APPLE)
                list (APPEND HARFBUZZ_LIBRARIES c++)
            else ()
                list (APPEND HARFBUZZ_LIBRARIES stdc++)
            endif ()
            set (HARFBUZZ_FOUND YES)
            set (SKIP_INSTALL_ALL NO CACHE BOOL "" FORCE)
        endif ()
    endif ()
endif ()

if (ENABLE_FRIBIDI)
    # Find FriBidi with pkg-config.
    if (NOT ENABLE_FRIBIDI_BUILD AND PKG_CONFIG_FOUND)
        pkg_check_modules (FRIBIDI IMPORTED_TARGET fribidi)
    endif ()
    if (EXISTS ${CMAKE_SOURCE_DIR}/lib/fribidi AND (ENABLE_FRIBIDI_BUILD OR NOT FRIBIDI_FOUND))
        # Build FriBidi with Meson.
        set (_dst ${CMAKE_BINARY_DIR}/lib/fribidi)
        if (MESON_EXECUTABLE AND NINJA_EXECUTABLE)
            ExternalProject_Add (fribidi-ext
                PREFIX              ${CMAKE_BINARY_DIR}/fribidi-ext
                SOURCE_DIR          ${CMAKE_SOURCE_DIR}/lib/fribidi
                CONFIGURE_COMMAND   NINJA=${NINJA_EXECUTABLE} ${MESON_EXECUTABLE}
                                        ${CMAKE_SOURCE_DIR}/lib/fribidi
                                        -Dbuildtype=release
                                        -Ddefault_library=static
                                        -Dtests=false -Ddocs=false -Dbin=false
                                        -Dc_flags=-Wno-macro-redefined
                                        -Dlibdir=lib
                                        ${_dependMacOpts}
                                        --prefix ${_dst}
                BUILD_COMMAND       ${NINJA_EXECUTABLE} install
                INSTALL_COMMAND     ""
                BUILD_BYPRODUCTS    ${_dst}/lib/libfribidi.a
            )
            list (APPEND _dependsToBuild fribidi-ext)
        else ()
            message (FATAL_ERROR
                "GNU FriBidi must be built with Meson. Please install Meson and Ninja and try again, or provide FriBidi via pkg-config.")
        endif ()
        add_library (fribidi-lib INTERFACE)
        target_include_directories (fribidi-lib INTERFACE ${_dst}/include)
        target_link_libraries (fribidi-lib INTERFACE ${_dst}/lib/libfribidi.a)
        set (FRIBIDI_FOUND YES)
    endif ()
endif ()

add_custom_target (ext-deps DEPENDS ${_dependsToBuild})

if (ENABLE_SPARKLE)
    # macOS only.
    add_library (sparkle INTERFACE)
    set (SPARKLE_FRAMEWORK ${SPARKLE_DIR}/Sparkle.framework)
    target_link_libraries (sparkle INTERFACE ${SPARKLE_FRAMEWORK})
    target_compile_definitions (sparkle INTERFACE LAGRANGE_ENABLE_SPARKLE=1)
    message (STATUS "Using Sparkle: ${SPARKLE_FRAMEWORK}")
    if (NOT SPARKLE_ARCH)
        message (FATAL_ERROR "Set SPARKLE_ARCH to a CPU architecture ID (e.g., arm64)")
    endif ()
endif ()

if (ENABLE_WINSPARKLE)
    # Windows only.
    add_library (winsparkle INTERFACE)
    target_include_directories (winsparkle INTERFACE ${WINSPARKLE_DIR}/include)
    set (WINSPARKLE_DLL ${WINSPARKLE_DIR}/x64/Release/WinSparkle.dll)
    target_link_libraries (winsparkle INTERFACE ${WINSPARKLE_DLL})
    target_compile_definitions (winsparkle INTERFACE LAGRANGE_ENABLE_WINSPARKLE=1)
    install (
        PROGRAMS ${WINSPARKLE_DLL}
        DESTINATION .
    )
    message (STATUS "Using WinSparkle: ${WINSPARKLE_DLL}")
endif ()

find_package (PkgConfig REQUIRED)
pkg_check_modules (SDL2 REQUIRED sdl2)
pkg_check_modules (MPG123 IMPORTED_TARGET libmpg123)
pkg_check_modules (WEBP IMPORTED_TARGET libwebp)