Skip to content

Commit

Permalink
[cmake] Update static dependencies to fix build issues (#272)
Browse files Browse the repository at this point in the history
* Update mariadb-connector-c to 3.3.4

Fixes #216

* Update apache, apr, and aprutil

This means we no longer need to use the trunk version for mac, since the
new releases have the desired patches for:
https://bz.apache.org/bugzilla/show_bug.cgi?id=64753

Also means we no longer need pcre1, since now apache can use pcre2.

Apache 2.4.55, apr 1.7.2, and aprutil 1.6.3.

* Update remaining dependencies

OpenSSL 1.1.1t, pcre2 10.42, SQLite 3.40.1, and MbedTLS 2.28.2

* Remove unneeded cmake scripts

* Use sha256 for zlib instead of md5

* Reuse zlib build for mariadbconnector

This allows mariadbconnector to reuse the static zlib build created for
zlib.ndll, or to use the system version otherwise on unix systems.

* Fix pcre linking

* Fix make cflags for pcre2 build on mac

* Fix and update cmake patches

Remove obsolete patches

Avoid patch error with semicolons
https://stackoverflow.com/questions/72098319/cmake-string-replace-removes-semi-colon

* Fix openssl linking for mariadbconnector

Should ensure static linking on all platforms if STATIC_OPENSSL is set.

* Cleanup openssl config

* Remove openssl config from aprutil build

These flags are not enough to build aprutil with openssl support,
so they have had no effect even for aprutil 1.5.4.

* Update cmake version to 3.14

This gives access to FindSQLite3.

* Fix new aprutil build on windows

We now have to download and build the expat library separately, as it is
no longer bundled with aprutil.

This requires patching the aprutil cmakelists file, as cmake's findexpat
script is currently quite limited. See:
https://gitlab.kitware.com/cmake/cmake/-/issues/24422
It also requires setting the CMP0074 policy (available from cmake 3.12)
when building aprutil, so that EXPAT_ROOT is not ignored.

* Fix apache static linking to pcre on windows

* Update changelog

* Fix azure pipeline step name

* Use add_compile_definitions

We can use this now with cmake 3.12+

* Avoid error when only Apache is set in STATIC_DEPS

If Apache was set in STATIC_DEPS, but not APR or APRutil, this would
cause a build error previously.

* Fix GNUInstallDirs warning

project() call should come first

* Clean up minor issues

* Remove call to find openssl

If we are not doing a static build, then there is no reason to know
anything about the openssl library. That will be handled by the
mariadbconnector build scripts.

* Fix "WARNING: OpenSSL version is too old"

* Fix openssl static linking

* Add version check for expat locating code

* Clean up cmake version checks

* Fix "no known rule" error for libssl.a

* Update CHANGES

* Fix changelog

* Restore cmake 3.10.2 support

* Add warning about CMake 3.12 on Windows

When building APRutil, we rely on EXPAT_ROOT for finding expat, which is
only available with CMP0074 on CMake 3.12+. This means building APRutil
on Windows will fail if CMake is older than 3.12.

* Remove redundant policy setting

This policy is from CMake 3.9, so it gets set automatically with:
cmake_minimum_required(VERSION 3.10.2)

* Update mbedtls to 2.28.3

---------

Co-authored-by: Simon Krajewski <[email protected]>
  • Loading branch information
tobil4sk and Simn authored Apr 13, 2023
1 parent 66ec5e9 commit c852db0
Show file tree
Hide file tree
Showing 22 changed files with 395 additions and 410 deletions.
4 changes: 2 additions & 2 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
std : fixed put_env when null is passed in (#229 https://github.com/HaxeFoundation/haxe/issues/10395)
std : added sys_cpu_arch (#275)
std : fix sys_is64 returning false on 64 bit Windows (#276)
cmake : updated apr version for Mac
all : fixed various build issues on macOS Catalina
all : fixed various build issues on macOS Catalina and Big Sur
cmake : update all dependencies

2019-10-19 : 2.3.0
std : added socket_set_broadcast function (#190)
Expand Down
17 changes: 6 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
cmake_minimum_required(VERSION 3.10.2)

if (NOT ${CMAKE_VERSION} VERSION_LESS 3.24)
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.24)
cmake_policy(VERSION 3.24)
elseif (NOT ${CMAKE_VERSION} VERSION_LESS 3.19)
elseif (${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.19)
cmake_policy(VERSION 3.19)
endif()
cmake_policy(SET CMP0068 NEW)

project(Neko C)

include(GNUInstallDirs)
include(CheckCCompilerFlag)
include(CheckIncludeFile)
include(TestBigEndian)
project(Neko C)

set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})

Expand Down Expand Up @@ -57,7 +57,7 @@ option(WITH_REGEXP "Build with Perl-compatible regex support." ON)
option(WITH_UI "Build with GTK-3 UI support." ON)
option(WITH_SSL "Build with SSL support." ON)
option(WITH_MYSQL "Build with MySQL support." ON)
option(WITH_SQLITE "Build with Sqlite support." ON)
option(WITH_SQLITE "Build with SQLite support." ON)
option(WITH_APACHE "Build with Apache modules." ON)
option(WITH_NEKOML "Build NekoML." ON)

Expand Down Expand Up @@ -102,7 +102,7 @@ set(external_deps
OpenSSL
MariaDBConnector
pcre2
Sqlite3
SQLite3
APR
APRutil
Apache
Expand Down Expand Up @@ -130,9 +130,6 @@ if (STATIC_DEPS STREQUAL "all")
if (WIN32)
list(REMOVE_ITEM STATIC_DEPS_ALL BoehmGC)
endif()
if (APPLE)
list(REMOVE_ITEM STATIC_DEPS_ALL APRutil)
endif()
set(STATIC_DEPS ${STATIC_DEPS_ALL} CACHE STRING "${STATIC_DEPS_DOC}" FORCE)
elseif (STATIC_DEPS STREQUAL "none")
message(STATUS "set STATIC_DEPS to nothing")
Expand All @@ -144,8 +141,6 @@ else()
message(FATAL_ERROR "Invalid STATIC_DEPS. There is no ${dep} in the list of ${external_deps}")
elseif(WIN32 AND dep STREQUAL "BoehmGC")
message(FATAL_ERROR "Cannot link ${dep} statically on Windows")
elseif(APPLE AND dep STREQUAL "APRutil")
message(WARNING "${dep} is redundant as it was merged into APR in version 2.0, which is the version we build with on macOS.")
endif()
endforeach()
endif()
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ Settings that allow to exclude libraries and their dependencies from the build;

Default value: `all` for Windows, `none` otherwise

It defines the dependencies that should be linked statically. Can be `all`, `none`, or a list of library names (e.g. `BoehmGC;Zlib;OpenSSL;MariaDBConnector;pcre2;Sqlite3;APR;APRutil;Apache;MbedTLS`).
It defines the dependencies that should be linked statically. Can be `all`, `none`, or a list of library names (e.g. `BoehmGC;Zlib;OpenSSL;MariaDBConnector;pcre2;SQLite3;APR;APRutil;Apache;MbedTLS`).

CMake will automatically download and build the specified dependencies into the build folder. If a library is not present in this list, it should be installed manually, and it will be linked dynamically.

All third-party libraries, except GTK+3 (Linux) and BoehmGC on Windows, can be linked statically. We do not support statically linking GTK+3 due to the difficulty of building it and its own dependencies. Additionally, we do not support statically linking the BoehmGC library on Windows systems. Finally, on MacOS, APRutil cannot be linked statically as it has been merged with APR 2.0, which is used on MacOS builds.
All third-party libraries, except GTK+3 (Linux) and BoehmGC on Windows, can be linked statically. We do not support statically linking GTK+3 due to the difficulty of building it and its own dependencies. Additionally, we do not support statically linking the BoehmGC library on Windows systems.

#### `RELOCATABLE`

Expand Down
104 changes: 104 additions & 0 deletions cmake/FindSQLite3.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# https://gitlab.kitware.com/cmake/cmake/-/blob/master/Modules/FindSQLite3.cmake

#[==[
CMake - Cross Platform Makefile Generator
Copyright 2000-2023 Kitware, Inc. and Contributors
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

* Neither the name of Kitware, Inc. nor the names of Contributors
may be used to endorse or promote products derived from this
software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
]==]

# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.

#[=======================================================================[.rst:
FindSQLite3
-----------

.. versionadded:: 3.14

Find the SQLite libraries, v3

IMPORTED targets
^^^^^^^^^^^^^^^^

This module defines the following :prop_tgt:`IMPORTED` target:

``SQLite::SQLite3``

Result variables
^^^^^^^^^^^^^^^^

This module will set the following variables if found:

``SQLite3_INCLUDE_DIRS``
where to find sqlite3.h, etc.
``SQLite3_LIBRARIES``
the libraries to link against to use SQLite3.
``SQLite3_VERSION``
version of the SQLite3 library found
``SQLite3_FOUND``
TRUE if found

#]=======================================================================]


# Look for the necessary header
find_path(SQLite3_INCLUDE_DIR NAMES sqlite3.h)
mark_as_advanced(SQLite3_INCLUDE_DIR)

# Look for the necessary library
find_library(SQLite3_LIBRARY NAMES sqlite3 sqlite)
mark_as_advanced(SQLite3_LIBRARY)

# Extract version information from the header file
if(SQLite3_INCLUDE_DIR)
file(STRINGS ${SQLite3_INCLUDE_DIR}/sqlite3.h _ver_line
REGEX "^#define SQLITE_VERSION *\"[0-9]+\\.[0-9]+\\.[0-9]+\""
LIMIT_COUNT 1)
string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+"
SQLite3_VERSION "${_ver_line}")
unset(_ver_line)
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(SQLite3
REQUIRED_VARS SQLite3_INCLUDE_DIR SQLite3_LIBRARY
VERSION_VAR SQLite3_VERSION)

# Create the imported target
if(SQLite3_FOUND)
set(SQLite3_INCLUDE_DIRS ${SQLite3_INCLUDE_DIR})
set(SQLite3_LIBRARIES ${SQLite3_LIBRARY})
if(NOT TARGET SQLite::SQLite3)
add_library(SQLite::SQLite3 UNKNOWN IMPORTED)
set_target_properties(SQLite::SQLite3 PROPERTIES
IMPORTED_LOCATION "${SQLite3_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${SQLite3_INCLUDE_DIR}")
endif()
endif()
48 changes: 0 additions & 48 deletions cmake/FindSqlite3.cmake

This file was deleted.

33 changes: 0 additions & 33 deletions cmake/FindZlib.cmake

This file was deleted.

26 changes: 26 additions & 0 deletions cmake/patch_apache.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# https://github.com/apache/httpd/commit/dd4561dd17a669a8c1757ada0ca875dfa840d0e7
# https://github.com/apache/httpd/pull/343

set(cmakelists ${apache_source}/CMakeLists.txt)

file(READ ${cmakelists} content)

string(REPLACE
"pcre2-8d.lib"
"pcre2-8-staticd.lib"
content "${content}"
)

string(REPLACE
"pcre2-8.lib"
"pcre2-8-static.lib"
content "${content}"
)

string(REPLACE
"\"-DHAVE_PCRE2\""
"\"-DHAVE_PCRE2 -DPCRE2_STATIC\""
content "${content}"
)

file(WRITE ${cmakelists} "${content}")
28 changes: 28 additions & 0 deletions cmake/patch_apr-util.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# This is necessary so that the CMAKE_FIND_LIBRARY_SUFFIXES is preserved when
# locating expat, since it gets reset when PROJECT is called

set(cmakelists "${apr-util_source}/CMakeLists.txt")

file(READ ${cmakelists} content)

string(REPLACE
"PROJECT(APR-Util C)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
FIND_PACKAGE(OpenSSL)
FIND_PACKAGE(EXPAT)"

"CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
FIND_PACKAGE(OpenSSL)
FIND_PACKAGE(EXPAT)
PROJECT(APR-Util C)"

content "${content}"
)

file(WRITE ${cmakelists} "${content}")
19 changes: 3 additions & 16 deletions cmake/patch_mariadb.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,10 @@ set(cmakelists ${mariadb_source}/CMakeLists.txt)
file(READ ${cmakelists} content)

# do not use replace /MD with /MT
string(REPLACE
string(REPLACE
"STRING(REPLACE \"/MD\" \"/MT\" COMPILER_FLAGS \${COMPILER_FLAGS})"
"# STRING(REPLACE \"/MD\" \"/MT\" COMPILER_FLAGS \${COMPILER_FLAGS})"
content ${content}
)

file(WRITE ${cmakelists} ${content})

set(cmakelists ${mariadb_source}/cmake/ConnectorName.cmake)

file(READ ${cmakelists} content)

# Fix broken syntax on newer CMake
string(REPLACE
" END()"
" ENDIF()"
content ${content}
content "${content}"
)

file(WRITE ${cmakelists} ${content})
file(WRITE ${cmakelists} "${content}")
Loading

0 comments on commit c852db0

Please sign in to comment.