Skip to content

Commit

Permalink
CMake option to build dependencies locally
Browse files Browse the repository at this point in the history
This makes it easier to install the library from source with pip using a single
command:

    CMAKE_ARGS="-DBUILD_DEPS=yes" pip install tuberd
  • Loading branch information
arahlin committed Aug 17, 2024
1 parent 7d85d49 commit c21ee77
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 12 deletions.
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")

# build dependencies if requested
option(BUILD_DEPS "Build library dependencies")

if(BUILD_DEPS)
message(STATUS "Building dependencies: ${CMAKE_SOURCE_DIR}/deps")
execute_process(COMMAND ${CMAKE_SOURCE_DIR}/wheels/install_deps.sh
RESULT_VARIABLE STATUS)
if(STATUS AND NOT STATUS EQUAL 0)
message(FATAL_ERROR "Failed to install dependencies: ${STATUS}")
endif()
endif()

# link against deps dir
if(EXISTS ${CMAKE_SOURCE_DIR}/deps)
message(STATUS "Found deps: ${CMAKE_SOURCE_DIR}/deps")
Expand Down
21 changes: 11 additions & 10 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -140,20 +140,21 @@ CPython 3.8+:
pip install tuberd
Building from source requires the ``libfmt`` and ``libmicrohttpd`` dependencies,
along with ``libhttpserver``. To ensure that ``cmake`` can find the
``libhttpserver`` library, you may need to add the path where the
``FindLibHttpServer.cmake`` file is installed to the ``CMAKE_MODULE_PATH``
option, for example:
along with ``libhttpserver``. To simplify the build process, the
``wheels/install_deps.sh`` script can be used to build all the dependencies
locally and compile against them. In this instance, ``cmake`` should be able to
discover the appropriate paths for all dependencies. Use the ``BUILD_DEPS``
``cmake`` argument to trigger this build with pip:

.. code:: bash
CMAKE_ARGS="-DCMAKE_MODULE_PATH=/usr/local/share/cmake/Modules" pip install .
CMAKE_ARGS="-DBUILD_DEPS=yes" pip install tuberd
To simplify the build process, the ``wheels/install_deps.sh`` script can be used to
build all the dependencies locally and compile against them. In this instance,
``cmake`` should be able to discover the appropriate paths for all dependencies:
If you prefer to build the dependencies manually, to ensure that ``cmake`` can
find the ``libhttpserver`` library, you may need to add the path where the
``FindLibHttpServer.cmake`` file is installed to the ``CMAKE_MODULE_PATH``
option, for example:

.. code:: bash
./wheels/install_deps.sh
pip install .
CMAKE_ARGS="-DCMAKE_MODULE_PATH=/usr/local/share/cmake/Modules" pip install tuberd
22 changes: 20 additions & 2 deletions wheels/install_deps.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
#!/bin/sh

# Figure out how to download things
if wget -q -O /dev/null http://www.google.com; then
FETCH () {
test -f `basename $1` || wget --no-check-certificate $1
}
elif curl -Ls -o /dev/null http://www.google.com; then
FETCH () {
test -f `basename $1` || curl -kLO $1
}
elif fetch -o /dev/null http://www.google.com; then
FETCH () {
test -f `basename $1` || fetch $1
}
else
echo "Cannot figure out how to download things!"
exit 1
fi

set -e

scriptdir=$(cd `dirname $0`; pwd -P)
Expand All @@ -10,7 +28,7 @@ cd $scriptdir/..
prefix=$PWD/deps
cd $prefix

[ -e fmt-10.2.1.zip ] || wget https://github.com/fmtlib/fmt/releases/download/10.2.1/fmt-10.2.1.zip
[ -e fmt-10.2.1.zip ] || FETCH https://github.com/fmtlib/fmt/releases/download/10.2.1/fmt-10.2.1.zip
[ -e fmt-10.2.1 ] || unzip fmt-10.2.1.zip
[ -e fmt-10.2.1/build ] || mkdir fmt-10.2.1/build
cd fmt-10.2.1/build
Expand All @@ -19,7 +37,7 @@ make
make install
cd $prefix

[ -e libmicrohttpd-1.0.1.tar.gz ] || wget https://github.com/Karlson2k/libmicrohttpd/releases/download/v1.0.1/libmicrohttpd-1.0.1.tar.gz
[ -e libmicrohttpd-1.0.1.tar.gz ] || FETCH https://github.com/Karlson2k/libmicrohttpd/releases/download/v1.0.1/libmicrohttpd-1.0.1.tar.gz
[ -e libmicrohttpd-1.0.1 ] || tar xzf libmicrohttpd-1.0.1.tar.gz
cd libmicrohttpd-1.0.1
./configure --without-gnutls --enable-https=no --enable-shared=no --disable-doc --disable-examples --disable-tools --prefix=$prefix
Expand Down

0 comments on commit c21ee77

Please sign in to comment.