Skip to content

Commit

Permalink
[cmake] Fix minor issues (#270)
Browse files Browse the repository at this point in the history
* Fail when trying to static link libgc on windows

The current cmake configuration doesn't actually support it, but it
wasn't clear that this is the case.

* Warn about APRutil on macOS

Same way we give error about statically linking BoehmGC on windows.

APRutil was merged with APR in the version we build with on macOS, so we
don't allow adding it to STATIC_DEPS

See:
http://svn.apache.org/viewvc/apr/apr/trunk/CHANGES?revision=1902371&view=markup#l252

* Rename download_static_deps to download_deps

It also downloads boehmgc on windows when linking dynamically, so it's
not just for static dependencies

* Clean up download target dependencies

* Fix minor libatomic_ops install issue

* Fix grammar in cmake option descriptions

* Fix whitespace

* Fix APR configure step
  • Loading branch information
tobil4sk authored Jan 31, 2023
1 parent e97453d commit adc9215
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 60 deletions.
79 changes: 43 additions & 36 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ set(NEKO_VERSION ${NEKO_VERSION_MAJOR}.${NEKO_VERSION_MINOR}.${NEKO_VERSION_PATC
# Determine target endianness
TEST_BIG_ENDIAN(NEKO_BIG_ENDIAN)

option(WITH_REGEXP "Build Perl-compatible regex support." ON)
option(WITH_UI "Build GTK-2 UI support." ON)
option(WITH_SSL "Build SSL support." ON)
option(WITH_MYSQL "Build MySQL support." ON)
option(WITH_SQLITE "Build Sqlite support." ON)
option(WITH_APACHE "Build Apache modules." ON)
option(WITH_REGEXP "Build with Perl-compatible regex support." ON)
option(WITH_UI "Build with GTK-2 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_APACHE "Build with Apache modules." ON)
option(WITH_NEKOML "Build NekoML." ON)

# Process common headers in libraries
Expand Down Expand Up @@ -112,13 +112,10 @@ set(external_deps
pcre2
Sqlite3
APR
APRutil
Apache
MbedTLS
)
# Mac build uses a newer version of APR which already contains APRutil
if (NOT APPLE)
list(APPEND external_deps APRutil)
endif()

if (WIN32)
set(STATIC_DEPS_DEFAULT "all")
Expand All @@ -137,19 +134,30 @@ set(STATIC_DEPS ${STATIC_DEPS_DEFAULT} CACHE STRING "${STATIC_DEPS_DOC}")

# Validate STATIC_DEPS
if (STATIC_DEPS STREQUAL "all")
set(STATIC_DEPS ${external_deps} CACHE STRING "${STATIC_DEPS_DOC}" FORCE)
set(STATIC_DEPS_ALL ${external_deps})
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")
set(STATIC_DEPS CACHE STRING "${STATIC_DEPS_DOC}" FORCE)
else()
foreach(dep ${STATIC_DEPS})
list(FIND external_deps ${dep} idx)
if(idx EQUAL -1)
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()

foreach(dep ${STATIC_DEPS})
list(FIND external_deps ${dep} idx)
if(idx EQUAL -1)
message(FATAL_ERROR "Invalid STATIC_DEPS. There is no ${dep} in the list of ${external_deps}")
endif()
endforeach()

# Set STATIC_* variables according to STATIC_DEPS.
foreach(dep ${external_deps})
string(TOUPPER ${dep} var)
Expand Down Expand Up @@ -270,7 +278,8 @@ add_executable(nekovm
vm/main.c
)

if (STATIC_BOEHMGC)
# We need to build from source on Windows regardless
if (STATIC_BOEHMGC OR WIN32)
ExternalProject_Add(libatomic_ops
${EP_CONFIGS}
URL https://github.com/ivmai/libatomic_ops/releases/download/v7.6.0/libatomic_ops-7.6.0.tar.gz
Expand All @@ -279,6 +288,7 @@ if (STATIC_BOEHMGC)
BUILD_COMMAND echo skip build
INSTALL_COMMAND echo skip install
)
set_target_properties(libatomic_ops PROPERTIES ${EP_PROPS})

set (
BoehmGC_CONFIGS
Expand All @@ -289,7 +299,12 @@ if (STATIC_BOEHMGC)
URL_MD5 bf46ccbdaccfa3186c2ab87191c8855a
)

set(GC_INCLUDE_DIR ${CMAKE_BINARY_DIR}/libs/src/BoehmGC-build/include)

if (WIN32)
set(GC_LIBRARIES
${CMAKE_BINARY_DIR}/libs/src/BoehmGC-build/${CMAKE_CFG_INTDIR}/gcmt-dll.lib
)
ExternalProject_Add(BoehmGC
${EP_CONFIGS}
${BoehmGC_CONFIGS}
Expand All @@ -298,16 +313,13 @@ if (STATIC_BOEHMGC)
-Denable_threads=ON
-Denable_parallel_mark=ON
-DCMAKE_USE_WIN32_THREADS_INIT=ON
-DCMAKE_CXX_STANDARD=14
PATCH_COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_BINARY_DIR}/libs/src/libatomic_ops ${CMAKE_BINARY_DIR}/libs/src/BoehmGC/libatomic_ops
INSTALL_COMMAND
${CMAKE_COMMAND} -E copy_directory
${CMAKE_BINARY_DIR}/libs/src/BoehmGC/include
${CMAKE_BINARY_DIR}/libs/src/BoehmGC-build/include/gc
)
set(GC_INCLUDE_DIR ${CMAKE_BINARY_DIR}/libs/src/BoehmGC-build/include)
set(GC_LIBRARIES
${CMAKE_BINARY_DIR}/libs/src/BoehmGC-build/${CMAKE_CFG_INTDIR}/gcmt-dll.lib
)
add_custom_command(OUTPUT ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/gcmt-dll.dll
DEPENDS BoehmGC
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/libs/src/BoehmGC-build/${CMAKE_CFG_INTDIR}/gcmt-dll.dll ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
Expand All @@ -323,7 +335,6 @@ if (STATIC_BOEHMGC)
set(GC_CFLAGS "-w")
endif()

set(GC_INCLUDE_DIR ${CMAKE_BINARY_DIR}/libs/src/BoehmGC-build/include)
set(GC_LIBRARIES
${CMAKE_BINARY_DIR}/libs/src/BoehmGC-build/lib/libgc.a
)
Expand All @@ -348,17 +359,20 @@ if (STATIC_BOEHMGC)
BYPRODUCTS
${GC_LIBRARIES}
)

# don't want to add libatomic_ops to external_deps,
# but want download_static_deps depends on it
add_dependencies(BoehmGC-download libatomic_ops-download)
endif()

set_target_properties(BoehmGC PROPERTIES ${EP_PROPS})
add_dependencies(libneko BoehmGC)
else()
find_package(BoehmGC REQUIRED)
endif()

add_custom_target(download_deps)
if (STATIC_BOEHMGC OR WIN32)
add_dependencies(download_deps libatomic_ops-download)
add_dependencies(download_deps BoehmGC-download)
endif()

target_include_directories(libneko PRIVATE ${GC_INCLUDE_DIR})

target_link_libraries(libneko ${GC_LIBRARIES})
Expand Down Expand Up @@ -522,13 +536,6 @@ endif()

#######################

add_custom_target(download_static_deps)
if (STATIC_BOEHMGC)
add_dependencies(download_static_deps BoehmGC-download)
endif()

#######################

# source_archive
# We create our own source package target instead of using CPack's package_source.
# One reason is that the CPack VS generator doesn't generate package_source target.
Expand Down Expand Up @@ -569,7 +576,7 @@ add_custom_command(OUTPUT ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${source_archive_fat
-Dsrc_dir=${CMAKE_SOURCE_DIR}
-Dlib_src_dir=libs/src
-P ${CMAKE_SOURCE_DIR}/cmake/source_archive_fat.cmake
DEPENDS source_archive download_static_deps
DEPENDS source_archive download_deps
VERBATIM
)

Expand Down
2 changes: 1 addition & 1 deletion Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ build:
dynamic) cmake .. -DSTATIC_DEPS=none -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo;; \
*) exit 1;; \
esac
RUN if [ "$LINK_TYPE" = "static" ]; then ninja download_static_deps; fi
RUN if [ "$LINK_TYPE" = "static" ]; then ninja download_deps; fi
RUN ninja
RUN ninja test
SAVE ARTIFACT bin/*
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`). NOTE: On MacOS, APRutil cannot be added here as it has become part of the APR version used on MacOS builds.
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+2 (Linux), can be linked statically. We do not support statically linking GTK+2 due to the difficulty of building it and its own dependencies.
All third-party libraries, except GTK+2 (Linux) and BoehmGC on Windows, can be linked statically. We do not support statically linking GTK+2 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.

#### `RELOCATABLE`

Expand Down
2 changes: 1 addition & 1 deletion extra/azure-pipelines/build-mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- script: cmake . -DSTATIC_DEPS=$(STATIC_DEPS) -G Ninja -DCMAKE_BUILD_TYPE=${{ parameters.config }}
displayName: CMake
- ${{ if eq(parameters.staticDeps, 'true') }}:
- script: ninja download_static_deps || ninja download_static_deps || ninja download_static_deps
- script: ninja download_deps || ninja download_deps || ninja download_deps
displayName: Download static deps
- script: ninja
displayName: Build
Expand Down
6 changes: 3 additions & 3 deletions extra/azure-pipelines/build-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ jobs:
- script: cmake . -G "${{ parameters.cmakeGenerator }}" -A ${{ parameters.arch }}
displayName: CMake
- script: |
cmake --build . --config ${{ parameters.config }} --target download_static_deps || \
cmake --build . --config ${{ parameters.config }} --target download_static_deps || \
cmake --build . --config ${{ parameters.config }} --target download_static_deps
cmake --build . --config ${{ parameters.config }} --target download_deps || \
cmake --build . --config ${{ parameters.config }} --target download_deps || \
cmake --build . --config ${{ parameters.config }} --target download_deps
displayName: Download static deps
- script: cmake --build . --config ${{ parameters.config }}
displayName: Build
Expand Down
17 changes: 9 additions & 8 deletions libs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,16 @@ if (WITH_APACHE)

set_target_properties(PCRE PROPERTIES ${EP_PROPS})
# don't want to add PCRE 1 to external_deps,
# but want download_static_deps depends on it
add_dependencies(download_static_deps PCRE-download)
# but want download_deps to depend on it
add_dependencies(download_deps PCRE-download)

## End of PCRE download info

if (APPLE) # We need to use the most up to date version on MacOS
set(APR_SOURCE
SVN_REPOSITORY https://svn.apache.org/repos/asf/apr/apr/trunk/
UPDATE_COMMAND ./buildconf
CONFIGURE_COMMAND cd ${CMAKE_BINARY_DIR}/libs/src/APR &&
./buildconf
)
else()
set(APR_SOURCE
Expand Down Expand Up @@ -272,10 +273,10 @@ if (WITH_APACHE)
)
set_target_properties(Apache PROPERTIES ${EP_PROPS})
# Download sources for fat source archive
add_dependencies(download_static_deps Apache-download)
add_dependencies(download_static_deps APR-download)
add_dependencies(download_deps Apache-download)
add_dependencies(download_deps APR-download)
if (NOT APPLE)
add_dependencies(download_static_deps APRutil-download)
add_dependencies(download_deps APRutil-download)
endif()
else()
find_package(APACHE REQUIRED)
Expand All @@ -287,6 +288,6 @@ if (WITH_APACHE)
set(APACHE_INCLUDE_DIRS ${APACHE_INCLUDE_DIR} ${APR_INCLUDE_DIR} ${APRUTIL_INCLUDE_DIR})
endif()

add_subdirectory(mod_neko)
add_subdirectory(mod_tora)
add_subdirectory(mod_neko)
add_subdirectory(mod_tora)
endif()
4 changes: 2 additions & 2 deletions libs/mod_tora/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ add_library(mod_tora2.ndll MODULE
add_dependencies(mod_tora2.ndll
mod_neko2.ndll
socket
)
)

target_include_directories(mod_tora2.ndll
PRIVATE
Expand All @@ -20,7 +20,7 @@ target_include_directories(mod_tora2.ndll
target_link_libraries(mod_tora2.ndll
socket
${APACHE_LIBRARIES}
)
)

if (WIN32)
target_link_libraries(mod_tora2.ndll ws2_32)
Expand Down
6 changes: 3 additions & 3 deletions libs/mysql/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ if (STATIC_OPENSSL)
)
endif()
# Download project for fat source archive
add_dependencies(download_static_deps OpenSSL-download)
add_dependencies(download_deps OpenSSL-download)
else()
find_package(OpenSSL)
endif()
Expand Down Expand Up @@ -109,7 +109,7 @@ if (STATIC_MARIADBCONNECTOR)
)
add_dependencies(mysql.ndll MariaDBConnector)
# Download project for fat source archive
add_dependencies(download_static_deps MariaDBConnector-download)
add_dependencies(download_deps MariaDBConnector-download)
else()
find_package(MariaDBConnector REQUIRED)
endif()
Expand Down Expand Up @@ -157,7 +157,7 @@ target_link_libraries(mysql5.ndll
socket
sha1
libneko
)
)

if (WIN32)
target_link_libraries(mysql5.ndll ws2_32)
Expand Down
2 changes: 1 addition & 1 deletion libs/regexp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ if (STATIC_PCRE2)
set(PCRE2_INCLUDE_DIRS ${CMAKE_BINARY_DIR}/libs/src/install-prefix/include)
add_dependencies(regexp.ndll pcre2)
# Download project for fat source archive
add_dependencies(download_static_deps pcre2-download)
add_dependencies(download_deps pcre2-download)
else()
find_package(PCRE2 REQUIRED)
endif()
Expand Down
2 changes: 1 addition & 1 deletion libs/sqlite/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ if (STATIC_SQLITE3)
target_link_libraries(sqlite.ndll libneko)
target_compile_definitions(sqlite.ndll PRIVATE SQLITE_MAX_VARIABLE_NUMBER=250000 SQLITE_ENABLE_RTREE=1)
# Download project for fat source archive
add_dependencies(download_static_deps Sqlite3-download)
add_dependencies(download_deps Sqlite3-download)
else()
add_library(sqlite.ndll MODULE sqlite.c)
pkg_check_modules(SQLITE3 REQUIRED sqlite3)
Expand Down
2 changes: 1 addition & 1 deletion libs/ssl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ if (STATIC_MBEDTLS)

add_dependencies(ssl.ndll MbedTLS)
# Download project for fat source archive
add_dependencies(download_static_deps MbedTLS-download)
add_dependencies(download_deps MbedTLS-download)
else()
find_package(MbedTLS REQUIRED)
endif()
Expand Down
2 changes: 1 addition & 1 deletion libs/zlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ if (STATIC_ZLIB)
add_dependencies(zlib.ndll Zlib)
target_include_directories(zlib.ndll PRIVATE ${ZLIB_INCLUDE_DIRS})
# Download project for fat source archive
add_dependencies(download_static_deps Zlib-download)
add_dependencies(download_deps Zlib-download)
else()
pkg_check_modules(ZLIB REQUIRED zlib)
target_include_directories(zlib.ndll PRIVATE ${ZLIB_INCLUDEDIR} ${ZLIB_INCLUDE_DIRS})
Expand Down

0 comments on commit adc9215

Please sign in to comment.