From c21ee77d5c97418d04ae237d5de11861edb2928f Mon Sep 17 00:00:00 2001 From: Sasha Rahlin Date: Fri, 16 Aug 2024 19:44:49 -0500 Subject: [PATCH] CMake option to build dependencies locally This makes it easier to install the library from source with pip using a single command: CMAKE_ARGS="-DBUILD_DEPS=yes" pip install tuberd --- CMakeLists.txt | 12 ++++++++++++ README.rst | 21 +++++++++++---------- wheels/install_deps.sh | 22 ++++++++++++++++++++-- 3 files changed, 43 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index af2368b..d75b9e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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") diff --git a/README.rst b/README.rst index bbb54fa..9c14a6f 100644 --- a/README.rst +++ b/README.rst @@ -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 diff --git a/wheels/install_deps.sh b/wheels/install_deps.sh index 1591d42..afa2ef5 100755 --- a/wheels/install_deps.sh +++ b/wheels/install_deps.sh @@ -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) @@ -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 @@ -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