babelouest / rhonabwy

Javascript Object Signing and Encryption (JOSE) library - JWK, JWKS, JWS, JWE and JWT
https://babelouest.github.io/rhonabwy/
GNU Lesser General Public License v2.1
45 stars 21 forks source link

Building with dependencies with non-standard PREFIX does not work #12

Closed wbangna closed 3 years ago

wbangna commented 3 years ago

Compiling rhonabwy with dependencies installed in non-standard directories does not work. The following script makes it possible to do so:

#!/bin/bash

SCRIPT_DIR=$(cd $(dirname $0); pwd)
BUILD_DIR=${SCRIPT_DIR}/build
INST_DIR=${SCRIPT_DIR}/inst
RHONABWY_SRC_DIR=${SCRIPT_DIR}/rhonabwy-0.9.9999

rm -rf "${BUILD_DIR}" "${INST_DIR}"
mkdir "${BUILD_DIR}" "${INST_DIR}"

cd "${BUILD_DIR}"
cmake \
    -DCMAKE_INSTALL_PREFIX="${INST_DIR}" \
    -DCMAKE_BUILD_TYPE=Release \
    -DDOWNLOAD_DEPENDENCIES=OFF \
    -DBUILD_RNBYC=ON\
    -DWITH_ULFIUS=OFF \
    -DPC_ORCANIA_INCLUDEDIR="${SCRIPT_DIR}/orcania-inst/include" \
    -DPC_ORCANIA_LIBDIR="${SCRIPT_DIR}/orcania-inst/lib64" \
    \
    -DPC_YDER_INCLUDEDIR="${SCRIPT_DIR}/yder-inst/include" \
    -DPC_YDER_LIBDIR="${SCRIPT_DIR}/yder-inst/lib64" \
    \
    -DPC_JANSSON_INCLUDEDIR="${SCRIPT_DIR}/jansson-inst/include" \
    -DPC_JANSSON_LIBDIR="${SCRIPT_DIR}/jansson-inst/lib" \
    \
    -DPC_GNUTLS_INCLUDEDIR="${SCRIPT_DIR}/gnutls-inst/include" \
    -DPC_GNUTLS_LIBDIR="${SCRIPT_DIR}/gnutls-inst/lib" \
    \
    -DZLIB_LIBRARY="${SCRIPT_DIR}/zlib-inst/lib/libz.so.1" \
    -DZLIB_INCLUDE_DIR="${SCRIPT_DIR}/zlib-inst/include" \
    \
    "${RHONABWY_SRC_DIR}"

# This makes building the library work
cat >> CMakeFiles/rhonabwy.dir/flags.make <<EOF
C_INCLUDES += -I${SCRIPT_DIR}/orcania-inst/include
C_INCLUDES += -I${SCRIPT_DIR}/yder-inst/include
C_INCLUDES += -I${SCRIPT_DIR}/nettle-inst/include
C_INCLUDES += -I${SCRIPT_DIR}/gmp-inst/include
EOF

# This makes building the binary work
cat >> CMakeFiles/rnbyc.dir/flags.make <<EOF
C_INCLUDES += -I${SCRIPT_DIR}/orcania-inst/include
C_INCLUDES += -I${SCRIPT_DIR}/yder-inst/include
C_INCLUDES += -I${SCRIPT_DIR}/nettle-inst/include
C_INCLUDES += -I${SCRIPT_DIR}/gmp-inst/include
EOF

make
make install

All dependencies are compiled and installed in the same directory as the script.

babelouest commented 3 years ago

Hello @wbangna ,

I'm not sure if you want to discuss improvements for rhonabwy related to your description.

I don't usually use libraries outside of standard directories, but I can point out 2 other solutions that may work:

1 - Use pkg-config and set PKG_CONFIG_PATH accordingly to where your pkg-config config files are installed

Something like that:

$ export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:${SCRIPT_DIR}/orcania-inst/lib64/pkgconfig:${SCRIPT_DIR}/yder-inst/lib64/pkgconfig:${SCRIPT_DIR}/jansson-inst/lib/pkgconfig:${SCRIPT_DIR}/gnutls-inst/lib/pkgconfig:${SCRIPT_DIR}/zlib-inst/lib/pkgconfig
$ cd "${BUILD_DIR}"
$ cmake \
    -DCMAKE_INSTALL_PREFIX="${INST_DIR}" \
    -DCMAKE_BUILD_TYPE=Release \
    -DDOWNLOAD_DEPENDENCIES=OFF \
    -DBUILD_RNBYC=ON\
    -DWITH_ULFIUS=OFF \
    "${RHONABWY_SRC_DIR}"

2 - Use CMAKE_FIND_ROOT_PATH_MODE_INCLUDE and CMAKE_FIND_ROOT_PATH_MODE_LIBRARY (not tested)

Maybe something like that:

$ cd "${BUILD_DIR}"
$ cmake \
    -DCMAKE_INSTALL_PREFIX="${INST_DIR}" \
    -DCMAKE_BUILD_TYPE=Release \
    -DDOWNLOAD_DEPENDENCIES=OFF \
    -DBUILD_RNBYC=ON\
    -DWITH_ULFIUS=OFF \
    -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE="${SCRIPT_DIR}/orcania-inst/include:${SCRIPT_DIR}/yder-inst/include:${SCRIPT_DIR}/jansson-inst/include:${SCRIPT_DIR}/gnutls-inst/include:${SCRIPT_DIR}/zlib-inst/include" \
    -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY="${SCRIPT_DIR}/orcania-inst/lib64:${SCRIPT_DIR}/yder-inst/lib64:${SCRIPT_DIR}/jansson-inst/lib:${SCRIPT_DIR}/gnutls-inst/lib:${SCRIPT_DIR}/zlib-inst/lib" \
    "${RHONABWY_SRC_DIR}"

If you have suggestion on rhonabwy cmake script improvements though, I'm all ears.

wbangna commented 3 years ago

Hello @babelouest

I just want to be able to build your library the way I described but I also am not very familiar with cmake. Therefore I reported the issue hoping it was just a minor bug in the CMakeLists.txt file. I expected that when getting cmake to find all libraries with the options PC_INCLUDEDIR and PC_LIBDIR, make would also be able to compile the library accordingly.

Getting familiar with cmake is on my todo list so perhaps in the near future I will be able to find a solution. By now the workaround described in my first message is ok for me.

babelouest commented 3 years ago

Thanks for the precisions, although your method involves changing files generated by cmake, so I'm not at ease with it...

If you find a way to achieve your goal using environnement variables or cmake options but need some changes in rhonabwy to do so, let me know, so I can make the change.