diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index f60defb9..1a163753 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -68,7 +68,7 @@ jobs: else version="$(date '+%Y.%-m.%-d').dev${GITHUB_RUN_NUMBER}" fi - echo "${version}" > src/git-tag.txt + echo "${version}" > VERSION if [ "${{ matrix.docker_image }}" != "" ]; then export OCL_DOCKER_IMAGE="${{ matrix.docker_image }}" @@ -81,13 +81,13 @@ jobs: fi ./install.sh \ - --build-library cxx \ --build-type release \ --install-ci-deps \ --install-boost \ --boost-prefix $(pwd) \ --install \ - --install-prefix $(pwd)/dist + --install-prefix $(pwd)/dist \ + cxx - uses: actions/upload-artifact@v3 with: name: ${{ matrix.os_short }}-cxx-${{ matrix.architecture }} @@ -156,7 +156,7 @@ jobs: else version="$(date '+%Y.%-m.%-d')-dev.${GITHUB_RUN_NUMBER}" fi - echo "${version}" > src/git-tag.txt + echo "${version}" > VERSION if [ "${{ matrix.docker_image }}" != "" ]; then export OCL_DOCKER_IMAGE="${{ matrix.docker_image }}" @@ -169,14 +169,14 @@ jobs: fi ./install.sh \ - --build-library nodejs \ --build-type release \ --install-ci-deps \ --install-boost \ --boost-prefix $(pwd) \ --node-architecture ${{ matrix.node_architecture }} \ --install \ - --install-prefix $(pwd)/dist + --install-prefix $(pwd)/dist \ + nodejs - uses: actions/upload-artifact@v3 with: name: ${{ matrix.os_short }}-nodejs-${{ matrix.node_architecture }} @@ -272,7 +272,7 @@ jobs: version="$(date '+%Y.%-m.%-d').dev${GITHUB_RUN_NUMBER}" fi sed -i.bak "s/^version = .*/version = \"${version}\"/g" pyproject.toml && rm pyproject.toml.bak - echo "${version}" > src/git-tag.txt + echo "${version}" > VERSION - name: Set up QEMU uses: docker/setup-qemu-action@v2 if: matrix.architecture == 'aarch64' @@ -330,13 +330,13 @@ jobs: shell: bash run: | ./install.sh \ - --build-library emscripten \ --build-type release \ --install-ci-deps \ --install-boost \ --boost-prefix $(pwd) \ --install \ - --install-prefix $(pwd)/dist + --install-prefix $(pwd)/dist \ + emscripten - uses: actions/upload-artifact@v3 with: name: emscripten diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 93836501..76a2a8b9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -40,12 +40,12 @@ jobs: fi ./install.sh \ --install-ci-deps \ - --build-library cxx \ --build-type release \ --install-boost \ --boost-prefix $(pwd) \ --install \ - --test + --test \ + cxx nodejs: name: ${{ matrix.os_short }} node.js runs-on: ${{ matrix.os }} @@ -76,14 +76,14 @@ jobs: fi ./install.sh \ --install-ci-deps \ - --build-library nodejs \ --build-type release \ --node-architecture x64 \ --install-boost \ --boost-prefix $(pwd) \ --install \ --install-prefix $(pwd)/src/npmpackage/build/Release/${{ matrix.libdir }} \ - --test + --test \ + nodejs python: name: ${{ matrix.os_short }} python runs-on: ${{ matrix.os }} @@ -113,19 +113,11 @@ jobs: - name: Install shell: bash run: | - if [ "${{ matrix.os_short }}" == "linux" ]; then - export OCL_INSTALL_BOOST="1" - export OCL_BOOST_WITH_PYTHON="1" - export OCL_BOOST_PREFIX="$(pwd)" - else - export OCL_INSTALL_BOOST_FROM_REPO="1" - fi ./install.sh \ - --build-library python \ --build-type release \ --install-system-deps \ --python-executable python \ - --python-pip-install \ - --test + --test \ + python || (pip install delvewheel && cd /c/hostedtoolcache/windows/Python/3.10.11/x64/lib/site-packages/opencamlib && ls -lah && delvewheel show opencamlib || delvewheel show ocl.pyd) env: CMAKE_GENERATOR: ${{ matrix.cmake_generator }} diff --git a/README.rst b/README.rst index 689f3a9f..0648bd8e 100644 --- a/README.rst +++ b/README.rst @@ -183,6 +183,7 @@ Install - Visual Studio Build Tools (https://visualstudio.microsoft.com/visual-cpp-build-tools/) - Git (https://git-scm.com/download/win) - CMake (https://git-scm.com/download/win) +- Boost (https://www.boost.org/users/download/) By downloading the installers from the internet, or by using your package manager. @@ -228,7 +229,7 @@ Now you can compile OpenCAMLib like this (make sure to replace the ``path/to/`` mkdir build cd build emcmake cmake \ - -D CMAKE_BUILD_TYPE="Release" \ + -D CMAKE_BUILD_TYPE="RelWithDebInfo" \ -D BUILD_EMSCRIPTEN_LIB="ON" \ -D USE_OPENMP="OFF" \ -D CMAKE_INSTALL_PREFIX="/path/to/opencamlib/src/npmpackage/build" \ @@ -262,10 +263,10 @@ Next, use cmake-js to compile the library: --directory ".." \ --out "." \ --parallel 4 \ - --CD BUILD_NODEJS_LIB="ON" \ - --CD USE_OPENMP="ON" \ - --CD CMAKE_INSTALL_PREFIX="/path/to/opencamlib/build/Release/$(node --print 'process.platform')-nodejs-$(node --print 'process.arch')" \ - --CD BOOST_ROOT="/path/to/boost" \ + --CDBUILD_NODEJS_LIB="ON" \ + --CDUSE_OPENMP="ON" \ + --CDCMAKE_INSTALL_PREFIX="/path/to/opencamlib/build/Release/$(node --print 'process.platform')-nodejs-$(node --print 'process.arch')" \ + --CDBOOST_ROOT="/path/to/boost" \ --config "Release" =================== diff --git a/VERSION b/VERSION new file mode 100644 index 00000000..c9df6993 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +2023.09.6 \ No newline at end of file diff --git a/install.sh b/install.sh index 3d7f51b0..241019bf 100755 --- a/install.sh +++ b/install.sh @@ -8,17 +8,17 @@ project_dir=$(pwd) print_help() { cat << EOF -Usage: ./install.sh [OPTIONS] +Usage: ./install.sh [OPTIONS] [LIBRARY] -Options: - --clean Clean the build folder before compiling a library (only valid with --build-library) - --build-library Compile a library with CMake (one of: cxx, nodejs, python, emscripten) - --build-type Choose the build type (one of: debug, release) (only valid with --build-library) - --disable-openmp Disable OpenMP in the build. (only valid with --build-library) +LIBRARY: one of: cxx, nodejs, python, emscripten + +OPTIONS: + --clean Clean the build folder before compiling a library + --build-type Choose the build type (one of: debug, release) + --disable-openmp Disable OpenMP in the build. --install-system-deps Install dependencies for compiling libraries (only aware of apt, brew and choco at the moment) --install-ci-deps Install curl and, when the platform is macos, installs OpenMP for the given architecture (see: --macos-architecture) --install-boost Install Boost from source - --install-boost-from-repo Install Boost (pre-compiled) from platform specific package repositories --install Install the CMake install targets to the prefix (see: --install-prefix) --sudo-install Install the CMake install targets to the prefix with root privileges (see: --install-prefix) @@ -30,10 +30,9 @@ Options: --boost-architecture Set the architecture for Boost (one of: x86, ia64, sparc, power, loongarch, mips, mips1, mips2, mips3, mips4, mips32, mips32r2, mips64, parisc, arm, riscv, s390x, arm+x86) (only valid when using --install-boost and --boost-with-python) --boost-python-version Set the python version to look for when compiling Boost (only valid when using --install-boost and --boost-with-python) - --python-executable Set a custom path (or name of) the Python executable (only valid when using --build-library python) - --python-prefix Set the python prefix, this will be passed to CMake as Python3_ROOT_DIR, to make sure CMake is using the correct Python installation. (only valid when using --build-library python) - --python-pip-install Uses "pip install ." to compile and install the Python library (only valid when using --build-library python) - + --python-executable Set a custom path (or name of) the Python executable + --python-prefix Set the python prefix, this will be passed to CMake as Python3_ROOT_DIR, to make sure CMake is using the correct Python installation. + --platform Set the platform, for when auto-detection doesn't work (one of: windows, macos, linux) --macos-architecture Set the macOS architecture to compile for (one of: arm64, x86_64), useful for cross compiling. @@ -43,18 +42,47 @@ Options: --cmake-generator-platform Set the CMake Generator Platform option, useful for cross compiling on Windows with the Visual Studio generator. --node-architecture Set the node.js architecture to compile for, useful for cross compiling. - --test Run a test script after compiling the library (only valid with --build-library) + --test Run a test script after compiling the library --help Shows this help page EOF exit 1 } +primary='\033[1;34m' +secondary='\033[1;35m' +nc='\033[0m' +prettyprint() { + printf "${primary}${1}${nc}${secondary}${2}${nc}\n" +} + +get_os() { + if [ "${OCL_PLATFORM}" ]; then + echo "${OCL_PLATFORM}" + else + if [[ "${OSTYPE}" =~ ^darwin.* ]]; then + echo "macos" + elif [[ "${OSTYPE}" =~ ^linux.* ]]; then + echo "linux" + else + echo "windows" + fi + fi +} +determined_os=$(get_os) +prettyprint "Determined OS: " "${determined_os}" + +# defaults +OCL_CLEAN="1" +OCL_BUILD_TYPE="release" +OCL_PLATFORM="${determined_os}" +OCL_INSTALL="1" + original_args="$*" +positional_args=() while [[ "$#" -gt 0 ]]; do case $1 in --clean) OCL_CLEAN="1"; ;; - --build-library) OCL_BUILD_LIBRARY="$2"; shift ;; --build-type) OCL_BUILD_TYPE="$2"; shift ;; --platform) OCL_PLATFORM="$2"; shift ;; --install-system-deps) OCL_INSTALL_SYSTEM_DEPS="1"; ;; @@ -64,7 +92,6 @@ while [[ "$#" -gt 0 ]]; do --sudo-install) OCL_SUDO_INSTALL="1"; ;; --install-prefix) OCL_INSTALL_PREFIX="$2"; shift ;; --install-boost) OCL_INSTALL_BOOST="1"; ;; - --install-boost-from-repo) OCL_INSTALL_BOOST_FROM_REPO="1"; ;; --boost-prefix) OCL_BOOST_PREFIX="$2"; shift ;; --boost-address-model) OCL_BOOST_ADDRESS_MODEL="$2"; shift ;; --boost-architecture) OCL_BOOST_ARCHITECTURE="$2"; shift ;; @@ -77,31 +104,27 @@ while [[ "$#" -gt 0 ]]; do --cmake-generator-platform) OCL_GENERATOR_PLATFORM="$2"; shift ;; --python-executable) OCL_PYTHON_EXECUTABLE="$2"; shift ;; --python-prefix) OCL_PYTHON_PREFIX="$2"; shift ;; - --python-pip-install) OCL_PYTHON_PIP_INSTALL="1"; ;; --node-architecture) OCL_NODE_ARCH="$2"; shift ;; --test) OCL_TEST="1"; ;; --help|--*) echo $1 print_help ;; *) + # Append unmatched arguments to the positional_args array + positional_args+=("$1") esac shift done +if [[ ${#positional_args[@]} != 1 ]]; then + print_help + exit 0 +fi + +OCL_BUILD_LIBRARY="${positional_args[0]}" + verify_args() { - if [ -n "${OCL_CLEAN}" ] && [ -z "${OCL_BUILD_LIBRARY}" ]; then - echo "Cannot set --clean without building a library. add the --build-library [lib] option or remove the --clean option" - exit 1 - elif [ -n "${OCL_BUILD_TYPE}" ] && [ -z "${OCL_BUILD_LIBRARY}" ]; then - echo "Cannot set --build-type without building a library. add the --build-library [lib] option or remove the --build-type option" - exit 1 - elif [ -n "${OCL_TEST}" ] && [ -z "${OCL_BUILD_LIBRARY}" ]; then - echo "Cannot set --test without building a library. add the --build-library [lib] option or remove the --test option" - exit 1 - elif [ -n "${OCL_DISABLE_OPENMP}" ] && [ -z "${OCL_BUILD_LIBRARY}" ]; then - echo "Cannot set --disable-openmp without building a library. add the --build-library [lib] option or remove the --disable-openmp option" - exit 1 - elif [ -n "${OCL_INSTALL_PREFIX}" ] && [ -z "${OCL_INSTALL}" ] && [ -z "${OCL_SUDO_INSTALL}" ]; then + if [ -n "${OCL_INSTALL_PREFIX}" ] && [ -z "${OCL_INSTALL}" ] && [ -z "${OCL_SUDO_INSTALL}" ]; then echo "WARN: Settings --install-prefix without setting --install or --sudo-install. add --install or --sudo-install option or remove the --install-prefix option" elif [ -n "${OCL_BOOST_WITH_PYTHON}" ] && [ -z "${OCL_INSTALL_BOOST}" ]; then echo "WARN: Setting --boost-with-python without setting --install-boost. add --install-boost or remove the --boost-with-python option" @@ -125,31 +148,9 @@ else build_type_lower="release" fi build_dir="${project_dir}/build/${OCL_BUILD_LIBRARY}/${build_type_lower}" -primary='\033[1;34m' -secondary='\033[1;35m' -nc='\033[0m' -prettyprint() { - printf "${primary}${1}${nc}${secondary}${2}${nc}\n" -} prettyprint "./install.sh " "$original_args" -get_os() { - if [ "${OCL_PLATFORM}" ]; then - echo "${OCL_PLATFORM}" - else - if [[ "${OSTYPE}" =~ ^darwin.* ]]; then - echo "macos" - elif [[ "${OSTYPE}" =~ ^linux.* ]]; then - echo "linux" - else - echo "windows" - fi - fi -} -determined_os=$(get_os) -prettyprint "Determined OS: " "${determined_os}" - num_procs() { if [ "${determined_os}" = "macos" ]; then sysctl -n hw.logicalcpu @@ -170,46 +171,14 @@ fi install_system_dependencies() { if [ "${determined_os}" = "linux" ]; then sudo apt update - sudo apt install -y --no-install-recommends git cmake curl build-essential - if [ -n "${OCL_INSTALL_BOOST_FROM_REPO}" ]; then - sudo apt install -y --no-install-recommends libboost-dev - fi - if [ "${OCL_BUILD_LIBRARY}" = "python" ]; then - if [ -z "${OCL_PYTHON_EXECUTABLE}" ]; then - sudo apt install -y --no-install-recommends python3 - fi - if [ -n "${OCL_INSTALL_BOOST_FROM_REPO}" ]; then - sudo apt install -y --no-install-recommends libboost-python-dev - fi - fi - if [ "${OCL_BUILD_LIBRARY}" = "nodejs" ]; then - sudo apt install -y --no-install-recommends nodejs npm - fi + sudo apt install -y --no-install-recommends git cmake curl build-essential libboost-dev python3 libboost-python-dev nodejs npm elif [ "${determined_os}" = "macos" ]; then - brew install libomp - if [ -n "${OCL_INSTALL_BOOST_FROM_REPO}" ]; then - brew install boost - fi - if [ "${OCL_BUILD_LIBRARY}" = "python" ]; then - if [ -z "${OCL_PYTHON_EXECUTABLE}" ]; then - brew install python@3.11 - fi - if [ -n "${OCL_INSTALL_BOOST_FROM_REPO}" ]; then - brew install boost-python3 - fi - fi - if [ "${OCL_BUILD_LIBRARY}" = "nodejs" ]; then - brew install node - fi + brew install libomp boost python boost-python3 node else # @todo installing git and cmake fails in github's CI choco install curl --no-progress - if [ -n "${OCL_INSTALL_BOOST_FROM_REPO}" ]; then - choco install boost-msvc-14.3 --no-progress - fi - if [ "${OCL_BUILD_LIBRARY}" = "nodejs" ]; then - choco install nodejs - fi + choco install boost-msvc-14.3 --no-progress + choco install nodejs --no-progress fi } @@ -372,8 +341,7 @@ if [ -n "${OCL_MACOS_ARCHITECTURE}" ]; then fi dependencies_nodejslib () { - cd "${project_dir}/src/nodejslib" - npm install --silent + (cd "${project_dir}/src/nodejslib" && npm install --silent) } dependencies_emscriptenlib () { @@ -387,6 +355,7 @@ dependencies_emscriptenlib () { cd ../emsdk ./emsdk install latest ./emsdk activate latest + cd "${project_dir}" } build_clean() { @@ -395,48 +364,54 @@ build_clean() { cmake_build() { if [ "${determined_os}" = "windows" ]; then - ${OCL_SUDO_INSTALL:+"sudo"} cmake \ + cmake \ --build . \ --config "${build_type}" \ -j "${num_procs}" else - ${OCL_SUDO_INSTALL:+"sudo"} cmake \ + cmake \ --build . \ -j "${num_procs}" fi } cmake_install() { - prettyprint "Installing" - if [ "${determined_os}" = "windows" ]; then - ${OCL_SUDO_INSTALL:+"sudo"} cmake \ - --install . \ - --config "${build_type}" - else - ${OCL_SUDO_INSTALL:+"sudo"} cmake \ - --install . + if [ -n "${OCL_INSTALL}" ] || [ -n "${OCL_SUDO_INSTALL}" ]; then + prettyprint "Installing" + if [ "${determined_os}" = "windows" ]; then + ${OCL_SUDO_INSTALL:+"sudo"} cmake \ + --install . \ + --config "${build_type}" + else + ${OCL_SUDO_INSTALL:+"sudo"} cmake \ + --install . + fi fi } +get_cmake_args() { + echo "-S . \ + -B "${build_dir}" \ + ${OCL_GENERATOR:+"-G ${OCL_GENERATOR}"} \ + ${OCL_GENERATOR_PLATFORM:+"-A ${OCL_GENERATOR_PLATFORM}"} \ + -D CMAKE_BUILD_TYPE="${build_type}" \ + -D USE_STATIC_BOOST="ON" \ + -D Boost_ADDITIONAL_VERSIONS="${boost_additional_versions}" \ + -D VERSION_STRING="2023.09.6" + ${OCL_DISABLE_OPENMP:+"-D USE_OPENMP=OFF"} \ + ${OCL_INSTALL_PREFIX:+"-D CMAKE_INSTALL_PREFIX=${OCL_INSTALL_PREFIX}"} \ + ${OCL_BOOST_PREFIX:+"-D BOOST_ROOT=${OCL_BOOST_PREFIX}"}" +} + +get_cmakejs_args() { + echo "$(get_cmake_args)" | sed -e 's/-D /--CD/g' -e 's/-S/--directory/g' -e 's/-B/--out/g' +} + build_cxxlib() { - mkdir -p "${build_dir}" - cd "${build_dir}" set -x - cmake \ - ${OCL_GENERATOR:+"-G ${OCL_GENERATOR}"} \ - ${OCL_GENERATOR_PLATFORM:+"-A ${OCL_GENERATOR_PLATFORM}"} \ - -D CMAKE_BUILD_TYPE="${build_type}" \ - -D BUILD_CXX_LIB="ON" \ - -D Boost_ADDITIONAL_VERSIONS="${boost_additional_versions}" \ - ${OCL_DISABLE_OPENMP:+"-DUSE_OPENMP=OFF"} \ - ${OCL_INSTALL_PREFIX:+"-DCMAKE_INSTALL_PREFIX=${OCL_INSTALL_PREFIX}"} \ - ${OCL_BOOST_PREFIX:+"-DBOOST_ROOT=${OCL_BOOST_PREFIX}"} \ - ../../.. + cmake $(get_cmake_args) -D BUILD_CXX_LIB="ON" set +x - cmake_build - if [ -n "${OCL_INSTALL}" ] || [ -n "${OCL_SUDO_INSTALL}" ]; then - cmake_install - fi + (cd "${build_dir}" && cmake_build && cmake_install) } test_cxxlib() { @@ -445,16 +420,16 @@ test_cxxlib() { prettyprint "Cleaning build directory..." rm -rf build || true fi - mkdir build || true - cd build set -x cmake \ + -S . \ + -B build \ ${OCL_GENERATOR:+"-G ${OCL_GENERATOR}"} \ ${OCL_GENERATOR_PLATFORM:+"-A ${OCL_GENERATOR_PLATFORM}"} \ -D Boost_ADDITIONAL_VERSIONS="${boost_additional_versions}" \ - ${OCL_BOOST_PREFIX:+"-DBOOST_ROOT=${OCL_BOOST_PREFIX}"} \ - .. + ${OCL_BOOST_PREFIX:+"-DBOOST_ROOT=${OCL_BOOST_PREFIX}"} set +x + cd build cmake_build if [ "${determined_os}" = "windows" ]; then ./test_example.exe @@ -464,29 +439,19 @@ test_cxxlib() { } build_nodejslib() { - mkdir -p "${build_dir}" - cd "${build_dir}" set -x determined_arch=$(node -p 'process.arch') install_prefix_fallback="${project_dir}/src/npmpackage/build/Release/${determined_os}-nodejs-${determined_arch}" - ../../../src/nodejslib/node_modules/.bin/cmake-js \ + OCL_INSTALL_PREFIX="${OCL_INSTALL_PREFIX:-"${install_prefix_fallback}"}" + src/nodejslib/node_modules/.bin/cmake-js \ build \ - --directory "../../.." \ - --out "." \ + $(get_cmakejs_args) \ --parallel "${num_procs}" \ ${OCL_NODE_ARCH:+"--arch=${OCL_NODE_ARCH}"} \ - ${OCL_GENERATOR:+"--generator=${OCL_GENERATOR}"} \ - ${OCL_GENERATOR_PLATFORM:+"--platform=${OCL_GENERATOR_PLATFORM}"} \ --CDBUILD_NODEJS_LIB="ON" \ - --CDBoost_ADDITIONAL_VERSIONS="${boost_additional_versions}" \ - --CDCMAKE_INSTALL_PREFIX="${OCL_INSTALL_PREFIX:-"${install_prefix_fallback}"}" \ - ${OCL_DISABLE_OPENMP:+"--CDUSE_OPENMP=OFF"} \ - ${OCL_BOOST_PREFIX:+"--CDBOOST_ROOT=${OCL_BOOST_PREFIX}"} \ --config "${build_type}" set +x - if [ -n "${OCL_INSTALL}" ] || [ -n "${OCL_SUDO_INSTALL}" ]; then - cmake_install - fi + (cd "${build_dir}" && cmake_install) } test_nodejslib() { @@ -512,44 +477,12 @@ get_python_executable() { build_pythonlib() { python_executable=$(get_python_executable) - if [ -n "${OCL_PYTHON_PIP_INSTALL}" ]; then - ${python_executable} -m pip install scikit-build-core distlib pyproject_metadata - # ${python_executable} -m venv env - # if [ "${determined_os}" = "windows" ]; then - # source env/Scripts/activate - # else - # source env/bin/activate - # fi - # forward cmake args - export CMAKE_ARGS="${OCL_GENERATOR:+"-G ${OCL_GENERATOR} "}\ + export CMAKE_ARGS="${OCL_GENERATOR:+"-G ${OCL_GENERATOR} "}\ ${OCL_GENERATOR_PLATFORM:+"-A ${OCL_GENERATOR_PLATFORM} "}\ -D CMAKE_BUILD_TYPE=${build_type} \ --D Boost_ADDITIONAL_VERSIONS=${boost_additional_versions} \ ${OCL_BOOST_PREFIX:+"-D BOOST_ROOT=${OCL_BOOST_PREFIX} "}" - cd "${project_dir}" - ${python_executable} -m pip install --verbose . - else - mkdir -p "${build_dir}" - cd "${build_dir}" - set -x - install_prefix_fallback=$(${python_executable} -c 'import sysconfig; print(sysconfig.get_paths()["purelib"])') - cmake \ - ${OCL_GENERATOR:+"-G ${OCL_GENERATOR}"} \ - ${OCL_GENERATOR_PLATFORM:+"-A ${OCL_GENERATOR_PLATFORM}"} \ - -D CMAKE_BUILD_TYPE="${build_type}" \ - -D BUILD_PY_LIB="ON" \ - -D Boost_ADDITIONAL_VERSIONS="${boost_additional_versions}" \ - -D CMAKE_INSTALL_PREFIX="${OCL_INSTALL_PREFIX:-"${install_prefix_fallback}"}" \ - ${OCL_DISABLE_OPENMP:+"-DUSE_OPENMP=OFF"} \ - ${OCL_PYTHON_PREFIX:+"-DPython3_ROOT_DIR=${OCL_PYTHON_PREFIX}"} \ - ${OCL_BOOST_PREFIX:+"-DBOOST_ROOT=${OCL_BOOST_PREFIX}"} \ - ../../.. - set +x - cmake_build - if [ -n "${OCL_INSTALL}" ] || [ -n "${OCL_SUDO_INSTALL}" ]; then - cmake_install - fi - fi + cd "${project_dir}" + ${python_executable} -m pip install --verbose . } test_pythonlib() { @@ -559,20 +492,15 @@ test_pythonlib() { } build_emscriptenlib() { - mkdir -p "${build_dir}" - cd "${build_dir}" source "${project_dir}/../emsdk/emsdk_env.sh" set -x install_prefix_fallback="${project_dir}/src/npmpackage/build" - emcmake cmake \ - -G "Unix Makefiles" \ - -D CMAKE_BUILD_TYPE="${build_type}" \ + OCL_INSTALL_PREFIX="${OCL_INSTALL_PREFIX:-"${install_prefix_fallback}"}" + emcmake cmake $(get_cmake_args) \ -D BUILD_EMSCRIPTEN_LIB="ON" \ -D USE_OPENMP="OFF" \ - -D Boost_ADDITIONAL_VERSIONS="${boost_additional_versions}" \ - -D CMAKE_INSTALL_PREFIX="${OCL_INSTALL_PREFIX:-"${install_prefix_fallback}"}" \ - ${OCL_BOOST_PREFIX:+"-DBOOST_ROOT=${OCL_BOOST_PREFIX}"} \ - ../../.. + -D USE_STATIC_BOOST="ON" + cd "${build_dir}" if [ "${determined_os}" = "windows" ]; then emmake make \ --config "${build_type}" \ @@ -621,7 +549,7 @@ if [ -n "${OCL_CLEAN}" ]; then build_clean fi -if [ "${OCL_BUILD_LIBRARY}" = "cxx" ]; then +if [[ "${OCL_BUILD_LIBRARY}" == "cxx" ]]; then prettyprint "Building C++ library" build_cxxlib if [ -n "${OCL_TEST}" ]; then @@ -630,18 +558,7 @@ if [ "${OCL_BUILD_LIBRARY}" = "cxx" ]; then fi fi -if [ "${OCL_BUILD_LIBRARY}" = "nodejs" ]; then - prettyprint "Installing node.js dependencies" - dependencies_nodejslib - prettyprint "Building node.js library" - build_nodejslib - if [ -n "${OCL_TEST}" ]; then - prettyprint "Testing node.js library" - test_nodejslib - fi -fi - -if [ "${OCL_BUILD_LIBRARY}" = "python" ]; then +if [[ "${OCL_BUILD_LIBRARY}" == "python" ]]; then prettyprint "Building Python library " "${OCL_BOOST_PYTHON_VERSION}" build_pythonlib if [ -n "${OCL_TEST}" ]; then @@ -650,7 +567,7 @@ if [ "${OCL_BUILD_LIBRARY}" = "python" ]; then fi fi -if [ "${OCL_BUILD_LIBRARY}" = "emscripten" ]; then +if [[ "${OCL_BUILD_LIBRARY}" == "emscripten" ]]; then prettyprint "Installing emscripten dependencies" dependencies_emscriptenlib prettyprint "Building emscripten library" @@ -660,3 +577,14 @@ if [ "${OCL_BUILD_LIBRARY}" = "emscripten" ]; then test_emscriptenlib fi fi + +if [[ "${OCL_BUILD_LIBRARY}" == "nodejs" ]]; then + prettyprint "Installing node.js dependencies" + dependencies_nodejslib + prettyprint "Building node.js library" + build_nodejslib + if [ -n "${OCL_TEST}" ]; then + prettyprint "Testing node.js library" + test_nodejslib + fi +fi diff --git a/pyproject.toml b/pyproject.toml index 20be73f3..572c4256 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "opencamlib" -version = "2022.12.18" +version = "2023.09.6" description = "open source computer aided manufacturing algorithms library" readme = "README.rst" authors = [ @@ -44,6 +44,7 @@ wheel.packages = ["src/pythonlib/opencamlib"] BUILD_PY_LIB = "ON" Boost_ADDITIONAL_VERSIONS = "1.80.0;1.79.0;1.78.0;1.77.0;1.76.0;1.75.0;1.74.0;1.73.0;1.72.0;1.71.0;1.70.0" BUILD_DOC = "OFF" +VERSION_STRING="2022.12.18" [tool.cibuildwheel] build = ["cp37*", "cp38*", "cp39*", "cp310*", "cp311*"] diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e475933a..89780051 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -9,6 +9,8 @@ if(COMMAND cmake_policy) cmake_policy(SET CMP0094 NEW) # for Python*_FIND_STRATEGY=LOCATION cmake_policy(SET CMP0042 NEW) cmake_policy(SET CMP0054 NEW) + cmake_policy(SET CMP0144 NEW) + cmake_policy(SET CMP0167 OLD) endif(COMMAND cmake_policy) # install targets in root of the build dir, using $<0:> generator expression to force it from not being overwritten @@ -45,11 +47,14 @@ option(USE_OPENMP "Use OpenMP for parallel computation" ON) option(VERSION_STRING - "Set version string") + "Set version string" OFF) option(USE_PY_3 "Use Python V3" ON) +option(USE_STATIC_BOOST + "Use static boost" OFF) + if(NOT BUILD_CXX_LIB) message(STATUS " Note: will NOT build pure c++ library") endif() @@ -70,6 +75,10 @@ if(NOT BUILD_DOC) message(STATUS " Note: will NOT build ocl documentation") endif() +if (NOT VERSION_STRING) + set(VERSION_STRING "unknown-version") +endif() + # figure out the gcc version include(gcc_version.cmake) @@ -99,7 +108,9 @@ endif() include_directories(${CMAKE_CURRENT_BINARY_DIR}) set(Boost_DEBUG ON CACHE BOOL "boost-debug") -set(Boost_USE_STATIC_LIBS ON CACHE BOOL "boost-use-static-libs") +if(USE_STATIC_BOOST) + set(Boost_USE_STATIC_LIBS ON CACHE BOOL "boost-use-static-libs") +endif() if(DEFINED ENV{BOOST_ROOT} OR DEFINED BOOST_ROOT) set(Boost_NO_SYSTEM_PATHS ON) endif() @@ -152,6 +163,10 @@ if(USE_OPENMP) list(APPEND CMAKE_PREFIX_PATH "/opt/homebrew/opt/libomp") endif() endif() + if(MSVC) + set(CMAKE_INSTALL_OPENMP_LIBRARIES ON) + include(InstallRequiredSystemLibraries) + endif() find_package(OpenMP REQUIRED) if(OPENMP_FOUND) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") @@ -160,40 +175,6 @@ if(USE_OPENMP) endif() endif() -if(EXISTS ${PROJECT_SOURCE_DIR}/version_string.hpp) - file(STRINGS "${PROJECT_SOURCE_DIR}/version_string.hpp" PROJECT_BUILD_SPECIFICATION REGEX "^[ \t]*#define[ \t]+VERSION_STRING[ \t]+.*$") - if(PROJECT_BUILD_SPECIFICATION) - string(REGEX REPLACE ".*#define[ \t]+VERSION_STRING[ \t]+\"(.*)\".*" "\\1" MY_VERSION ${PROJECT_BUILD_SPECIFICATION}) - else() - message(FATAL_ERROR "Data were not found for the required build specification.") - endif() - set(version_string ${PROJECT_SOURCE_DIR}/version_string.hpp) -else() - ################ create version_string.hpp, http://stackoverflow.com/questions/3780667 - # include the output directory, where the version_string.hpp file is generated - include_directories(${CMAKE_CURRENT_BINARY_DIR}) - if(VERSION_STRING) - set( vstring "//version_string.hpp - written by cmake. changes will be lost!\n" - "#ifndef VERSION_STRING\n" - "#define VERSION_STRING \"${VERSION_STRING}\"\n" - "#endif\n" - ) - file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/version_string.hpp ${vstring} ) - set(MY_VERSION ${VERSION_STRING}) - set(version_string ${VERSION_STRING}) - else() - include(version_string.cmake) - # now parse the git commit id: - string(REGEX REPLACE "([0-9]+).*" "\\1" GIT_MAJOR_VERSION "${GIT_COMMIT_ID}" ) - string(REGEX REPLACE "[0-9]+.([0-9]+)-.*" "\\1" GIT_MINOR_VERSION "${GIT_COMMIT_ID}" ) - string(REGEX REPLACE "[0-9]+.[0-9]+-(.*)-.*" "\\1" GIT_PATCH_VERSION "${GIT_COMMIT_ID}" ) - set(MY_VERSION "${GIT_MAJOR_VERSION}.${GIT_MINOR_VERSION}.${GIT_PATCH_VERSION}" CACHE STRING "name") - set(version_string ${CMAKE_CURRENT_BINARY_DIR}/version_string.hpp) - endif() -endif() - -message(STATUS "OpenCAMLib version: ${MY_VERSION}") - # this defines the source-files set(OCL_SRC ${PROJECT_SOURCE_DIR}/ocl.cpp @@ -347,7 +328,7 @@ if(BUILD_DOC) OUTPUT doc/latex/index.tex doc/html/index.html - COMMAND ${DOXYGEN_EXECUTABLE} ${DOXY_CONFIG} + COMMAND Doxygen::doxygen ${DOXY_CONFIG} COMMENT building LaTex & HTML docs ) diff --git a/src/cxxlib/cxxlib.cmake b/src/cxxlib/cxxlib.cmake index 7c97e5d3..0e1d50fd 100644 --- a/src/cxxlib/cxxlib.cmake +++ b/src/cxxlib/cxxlib.cmake @@ -8,6 +8,8 @@ add_library(ocl ${OCL_COMMON_SRC} ) +target_compile_definitions(ocl PUBLIC VERSION_STRING="${VERSION_STRING}") + if(WIN32) # on windows, prefix the library with lib, and make sure the .lib file is installed as well set_target_properties(ocl PROPERTIES @@ -62,12 +64,9 @@ install( ) if(APPLE) - target_compile_options(ocl PRIVATE -g) - # if(CMAKE_CXX_FLAGS MATCHES "-flto") - set(lto_object ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/ocl-lto.o) - set_property(TARGET ocl APPEND_STRING PROPERTY - LINK_FLAGS " -Wl,-object_path_lto -Wl,${lto_object}") - # endif() + # target_compile_options(ocl PRIVATE -g) # commented out because I think Debug and RelWithDebInfo should already use the -g flag + set_property(TARGET ocl APPEND_STRING PROPERTY + LINK_FLAGS "-Wl,-object_path_lto,ocl-lto.o -Wl,-cache_path_lto,${CMAKE_BINARY_DIR}/LTOCache") add_custom_command(TARGET ocl POST_BUILD COMMAND xcrun dsymutil $ COMMAND xcrun strip -Sl $) diff --git a/src/emscriptenlib/emscriptenlib.cmake b/src/emscriptenlib/emscriptenlib.cmake index d857a877..a19c495d 100644 --- a/src/emscriptenlib/emscriptenlib.cmake +++ b/src/emscriptenlib/emscriptenlib.cmake @@ -25,6 +25,8 @@ add_executable(ocl ${PROJECT_SOURCE_DIR}/emscriptenlib/emscriptenlib.cpp ) +target_compile_definitions(ocl PUBLIC VERSION_STRING="${VERSION_STRING}") + target_link_libraries( ocl ${Boost_LIBRARIES} diff --git a/src/nodejslib/nodejslib.cmake b/src/nodejslib/nodejslib.cmake index a39be700..d163baac 100644 --- a/src/nodejslib/nodejslib.cmake +++ b/src/nodejslib/nodejslib.cmake @@ -45,6 +45,9 @@ target_link_libraries( Boost::boost ${CMAKE_JS_LIB} ) + +target_compile_definitions(ocl PUBLIC VERSION_STRING="${VERSION_STRING}") + if(USE_OPENMP) target_link_libraries(ocl PRIVATE OpenMP::OpenMP_CXX) endif() diff --git a/src/ocl.cpp b/src/ocl.cpp index 31e4f8e5..580aa956 100644 --- a/src/ocl.cpp +++ b/src/ocl.cpp @@ -23,7 +23,6 @@ #ifdef _OPENMP #include #endif -#include "version_string.hpp" namespace ocl { diff --git a/src/ocl.hpp b/src/ocl.hpp index 5cd6149b..583db842 100644 --- a/src/ocl.hpp +++ b/src/ocl.hpp @@ -23,6 +23,10 @@ #include +#ifndef VERSION_STRING +#define VERSION_STRING "unknown-version" +#endif + namespace ocl { int max_threads(); diff --git a/src/pythonlib/ocl.cpp b/src/pythonlib/ocl.cpp index 72f0efc8..b652a190 100644 --- a/src/pythonlib/ocl.cpp +++ b/src/pythonlib/ocl.cpp @@ -27,8 +27,6 @@ #include #include -#include "version_string.hpp" // autogenerated by version_string.cmake - std::string ocl_docstring() { return "OpenCAMLib docstring"; } diff --git a/src/pythonlib/pythonlib.cmake b/src/pythonlib/pythonlib.cmake index 87b47e89..e567c332 100644 --- a/src/pythonlib/pythonlib.cmake +++ b/src/pythonlib/pythonlib.cmake @@ -4,7 +4,7 @@ if(Python3_FOUND) message(STATUS "Python libraries: " ${Python3_LIBRARIES}) message(STATUS "Python executable: " ${Python3_EXECUTABLE}) endif() -find_package(Boost COMPONENTS python${Python3_VERSION_MAJOR}${Python3_VERSION_MINOR} REQUIRED) +find_package(Boost CONFIG COMPONENTS python${Python3_VERSION_MAJOR}${Python3_VERSION_MINOR} REQUIRED) # include dirs include_directories(${PROJECT_SOURCE_DIR}/cutters) @@ -25,6 +25,8 @@ MODULE pythonlib/ocl.cpp ) +target_compile_definitions(ocl PUBLIC VERSION_STRING="${VERSION_STRING}") + target_link_libraries( ocl PRIVATE diff --git a/src/version_string.cmake b/src/version_string.cmake deleted file mode 100644 index 88ffc645..00000000 --- a/src/version_string.cmake +++ /dev/null @@ -1,73 +0,0 @@ -#use git for a pretty commit id -#uses 'git describe --tags', so tags are required in the repo -#create a tag with 'git tag ' and 'git push --tags' - -#version_string.hpp will define VERSION_STRING to something like "test-1-g5e1fb47" -# where test is the name of the last tagged git revision, 1 is the number of commits since that tag, -# 'g' is ???, and 5e1fb47 is the first 7 chars of the git sha1 commit id. - - -find_package(Git) - -if(NOT GIT_FOUND) - # cmake 2.8.1 (in Lucid) does not have a git Cmake interface - # cmake 2.8.5 (in Oneiric) does have it - message(STATUS "couldn't find Cmake interface to git, old version of Cmake? looking by hand...") - execute_process( - COMMAND git --version - RESULT_VARIABLE RC - ) - if (${RC} EQUAL 0) - set(GIT_FOUND 1) - set(GIT_EXECUTABLE "git") - else() - message(ERROR "couldn't run git executable!") - endif() -endif() - -if(GIT_FOUND) - execute_process( - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - COMMAND ${GIT_EXECUTABLE} describe --tags - RESULT_VARIABLE res_var - OUTPUT_VARIABLE GIT_COM_ID - OUTPUT_STRIP_TRAILING_WHITESPACE - ERROR_QUIET - ) - if( NOT ${res_var} EQUAL 0 ) - message( WARNING "Git failed (not a repo, or no tags)." ) - file(READ "git-tag.txt" GIT_COM_ID) - string( REPLACE "\n" "" GIT_COMMIT_ID ${GIT_COM_ID} ) - message( STATUS "version_string.cmake read from file GIT_COMMIT_ID: " ${GIT_COMMIT_ID}) - else() - string( REPLACE "\n" "" GIT_COMMIT_ID ${GIT_COM_ID} ) - message( STATUS "version_string.cmake git set GIT_COMMIT_ID: " ${GIT_COMMIT_ID}) - endif() - -else() - # if we don't have git, try to read git-tag from file instead - file(READ "git-tag.txt" GIT_COMMIT_ID) - - #set( GIT_COMMIT_ID "unknown (git not found!)") - message( STATUS "version_string.cmake read from file git-tag.txt: " ${GIT_COMMIT_ID}) - #message( WARNING "Git not found. Reading tag from git-tag.txt instead: " ${GIT_COMMIT_ID}) -endif() - -set( vstring "//version_string.hpp - written by cmake. changes will be lost!\n" - "#ifndef VERSION_STRING\n" - "#define VERSION_STRING \"${GIT_COMMIT_ID}\"\n" - "#endif\n" -) - -file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/version_string.hpp ${vstring} ) -set_source_files_properties( - ${CMAKE_CURRENT_BINARY_DIR}/version_string.hpp - PROPERTIES GENERATED TRUE - HEADER_FILE_ONLY TRUE -) - -# copy the file to the final header only if the version changes -# reduces needless rebuilds -#execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different -# version_string.hpp.txt /version_string.hpp) -