diff --git a/.github/workflows/base/action.yml b/.github/workflows/base/action.yml index 82e76ef..173fc25 100644 --- a/.github/workflows/base/action.yml +++ b/.github/workflows/base/action.yml @@ -7,6 +7,9 @@ inputs: ARCH: description: 'matrix.arch' required: true + PY_VERSION: + description: 'matrix.py_version' + required: true description: '' @@ -14,6 +17,9 @@ outputs: BOOST_ROOT: description: '' value: ${{ steps.install_boost.outputs.BOOST_ROOT }} + BOOST_VERSION: + description: '' + value: 1.74.0 runs: using: "composite" @@ -22,12 +28,16 @@ runs: uses: aminya/setup-cpp@v1 with: compiler: gcc - vcvarsall: ${{ contains(inputs.OS, 'windows') }} + vcvarsall: ${{ contains(inputs.OS, 'windows') }} # evaluate to the string 'true' msvc: ${{ contains(inputs.OS, 'windows') }} choco: ${{ contains(inputs.OS, 'windows') }} cmake: true ninja: true + - uses: actions/setup-python@v4 + with: + python-version: ${{ inputs.PY_VERSION }} + - uses: makslevental/mlir-wheels/actions/setup_ccache@d77bf5dc69c46a8c2738b44528749768888eb361 id: setup_ccache with: @@ -36,8 +46,40 @@ runs: WORKSPACE_ROOT: ${{ github.workspace }} - name: Install boost for XRT - if: contains(inputs.OS, 'windows') || contains(inputs.OS, 'ubuntu') uses: MarkusJx/install-boost@v2.4.5 id: install_boost with: - boost_version: 1.73.0 \ No newline at end of file + boost_version: 1.74.0 + + - name: Build and install system deps + shell: bash + run: | + + if [ ${{ inputs.OS }} == 'windows-2019' ]; then + choco install -y pkgconfiglite protoc + else + sudo apt install -y libdrm-dev ocl-icd-opencl-dev rapidjson-dev libprotobuf-dev systemtap-sdt-dev uuid-dev python3-dev + fi + + - name: Full checkout + shell: bash + run: | + git sparse-checkout disable + git submodule update --init --recursive + + - name: Remove path limit and export VCTOOLSVERSION + if: contains(inputs.OS, 'windows') + shell: pwsh + run: | + + pwsh.exe .\util\remove_path_limit.ps1 + + VCTOOLSVERSION=${VCTOOLSVERSION:0:4} + echo "VCTOOLSVERSION=$VCTOOLSVERSION" >> $GITHUB_ENV + + - name: Install python deps + shell: bash + run: | + + ls -lah + pip install -r requirements-dev.txt diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index acfa67b..3ee8ed4 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -28,45 +28,30 @@ jobs: shell: bash steps: + - name: Checkout actions uses: actions/checkout@v3 with: - submodules: true - - - name: Get recursive submodules - run: | - - git submodule update --init --recursive + sparse-checkout: .github/workflows/base/action.yml + sparse-checkout-cone-mode: false - uses: ./.github/workflows/base id: base with: OS: ${{ matrix.OS }} ARCH: ${{ matrix.ARCH }} - - - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.PY_VERSION }} - - - name: Build and install protoc - if: contains(matrix.OS, 'windows') || contains(matrix.OS, 'ubuntu') - run: | - - if [ ${{ matrix.OS }} == 'windows-2019' ]; then - choco install -y pkgconfiglite protoc - else - sudo apt install -y libdrm-dev ocl-icd-opencl-dev rapidjson-dev libprotobuf-dev systemtap-sdt-dev uuid-dev python3-dev - fi + PY_VERSION: ${{ matrix.PY_VERSION }} - name: build wheel env: BOOST_ROOT: ${{ steps.base.outputs.BOOST_ROOT }} - BOOST_VERSION: 1.73.0 + BOOST_VERSION: ${{ steps.base.outputs.BOOST_VERSION }} run: | - REPO_SRC_DIR=$PWD bash patches/apply_patches.sh - pip install -r requirements-dev.txt - pip wheel . -v -w wheelhouse --no-build-isolation + CIBW_BUILD=${{ matrix.PY_VERSION }} + CIBW_BUILD="cp${CIBW_BUILD//./}-*" + echo "CIBW_BUILD=$CIBW_BUILD" | tee -a $GITHUB_OUTPUT + cibuildwheel --output-dir wheelhouse - name: test run: | @@ -99,52 +84,35 @@ jobs: PY_VERSION: [ "3.8", "3.9", "3.10", "3.11", "3.12" ] steps: + - name: Checkout actions uses: actions/checkout@v3 with: - submodules: true - - - name: Get recursive submodules - run: | - - git submodule update --init --recursive - - - name: Setup Cpp - uses: aminya/setup-cpp@v1 - with: - compiler: gcc - cmake: true - ninja: true + sparse-checkout: .github/workflows/base/action.yml + sparse-checkout-cone-mode: false - name: Set up QEMU uses: docker/setup-qemu-action@v2 with: platforms: aarch64 - - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.PY_VERSION }} - - uses: ./.github/workflows/base id: base with: OS: ${{ matrix.OS }} ARCH: ${{ matrix.ARCH }} - - - name: Install XRT deps - run: | - - sudo apt install -y libdrm-dev ocl-icd-opencl-dev rapidjson-dev libprotobuf-dev systemtap-sdt-dev uuid-dev python3-dev + PY_VERSION: ${{ matrix.PY_VERSION }} - name: build wheel env: BOOST_ROOT: ${{ steps.base.outputs.BOOST_ROOT }} - BOOST_VERSION: 1.73.0 + BOOST_VERSION: ${{ steps.base.outputs.BOOST_VERSION }} run: | - REPO_SRC_DIR=$PWD bash patches/apply_patches.sh - pip install -r requirements-dev.txt - pip wheel . -v -w wheelhouse --no-build-isolation + CIBW_BUILD=${{ matrix.PY_VERSION }} + CIBW_BUILD="cp${CIBW_BUILD//./}-*" + echo "CIBW_BUILD=$CIBW_BUILD" | tee -a $GITHUB_OUTPUT + cibuildwheel --output-dir wheelhouse - name: test run: | diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index 13586e9..65d55a7 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -38,35 +38,24 @@ jobs: - name: Checkout actions uses: actions/checkout@v3 with: - submodules: true - - - name: Get recursive submodules - run: | - - git submodule update --init --recursive + sparse-checkout: .github/workflows/base/action.yml + sparse-checkout-cone-mode: false - uses: ./.github/workflows/base - if: contains(matrix.OS, 'windows') id: base with: OS: ${{ matrix.OS }} ARCH: ${{ matrix.ARCH }} - - - name: Build and install protoc - if: contains(matrix.OS, 'windows') - run: | - - choco install -y pkgconfiglite protoc + PY_VERSION: '3.10' # build - name: cibuildwheel python bindings env: BOOST_ROOT: ${{ steps.base.outputs.BOOST_ROOT }} - BOOST_VERSION: 1.73.0 + BOOST_VERSION: ${{ steps.base.outputs.BOOST_VERSION }} run: | - pip install cibuildwheel cibuildwheel --output-dir wheelhouse # done @@ -85,30 +74,32 @@ jobs: steps: + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + with: + platforms: aarch64 + - name: Checkout actions uses: actions/checkout@v3 with: - submodules: true + sparse-checkout: .github/workflows/base/action.yml + sparse-checkout-cone-mode: false - - name: Get recursive submodules - run: | - - git submodule update --init --recursive - - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 + - uses: ./.github/workflows/base + id: base with: - platforms: aarch64 + OS: ubuntu-20.04 + ARCH: aarch64 + PY_VERSION: '3.10' # build - name: cibuildwheel python bindings aarch64 env: BOOST_ROOT: ${{ steps.base.outputs.BOOST_ROOT }} - BOOST_VERSION: 1.73.0 + BOOST_VERSION: ${{ steps.base.outputs.BOOST_VERSION }} run: | - pip install cibuildwheel cibuildwheel --output-dir wheelhouse # done diff --git a/.gitignore b/.gitignore index a598cb3..02ff0d1 100644 --- a/.gitignore +++ b/.gitignore @@ -159,6 +159,18 @@ cython_debug/ # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. .idea/ -cmake-build-debug -cmake-build-release -.envrc \ No newline at end of file +cmake-build-* +.envrc +*.whl +*.zip +*.ilk +*.pyd +*.lib +*.exp +*.pdb +*.dll +*.json +*.pdi +*.bif +*.bin +*.xclbin diff --git a/CMakeLists.txt b/CMakeLists.txt index 4cc93a1..16cbaf6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,14 +12,43 @@ if(POLICY CMP0148) cmake_policy(SET CMP0148 NEW) endif() -option(OUTPUT_DIR "Output directory" ${CMAKE_CURRENT_BINARY_DIR}) +if(WIN32) + # see util/remove_path_limit.ps1 + set(CMAKE_OBJECT_PATH_MAX 4096) +endif() -include(util/helpers.cmake) +set(OUTPUT_DIR + ${CMAKE_CURRENT_BINARY_DIR} + CACHE STRING "Output directory") + +if(NOT ${CMAKE_SIZEOF_VOID_P} EQUAL 8) + # if you open up the wrong developer shell in windows... + message( + FATAL_ERROR + "Something has gone terribly wrong: CMAKE_SIZEOF_VOID_P=${CMAKE_SIZEOF_VOID_P}" + ) +endif() +# can delete after this is all worked out +# https://gitlab.kitware.com/cmake/cmake/-/issues/25702 +find_package(OpenSSL) +if(NOT DEFINED OPENSSL_FOUND OR NOT ${OPENSSL_FOUND}) + list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/util") + find_package(OpenSSL) + if(NOT DEFINED USE_OUR_FIND_OPENSSL OR NOT ${USE_OUR_FIND_OPENSSL}) + message(FATAL_ERROR "Didn't pickup our FindOpenSSL.cmake") + endif() + if(NOT DEFINED OPENSSL_FOUND OR NOT ${OPENSSL_FOUND}) + message(FATAL_ERROR "OpenSSL not found") + endif() +endif() +message(STATUS "OpenSSL include directories:" ${OPENSSL_INCLUDE_DIR}) +include(util/helpers.cmake) configure_python_dev_packages() -find_package(OpenSSL REQUIRED) + find_package(Threads REQUIRED) find_package(Boost REQUIRED COMPONENTS system program_options filesystem) +message(STATUS "Boost include directories:" ${Boost_INCLUDE_DIRS}) # ############################################################################## # bootgen @@ -69,7 +98,6 @@ if(uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG") set(XAIE_DEBUG "XAIE_DEBUG") endif() -target_compile_options(aienginev2 PRIVATE -Wall -Wextra -D__AIECDO__) target_compile_definitions(aienginev2 PUBLIC ${XAIE_DEBUG}) get_target_property(AIERT_SRCS aienginev2 SOURCES) list(TRANSFORM AIERT_SRCS PREPEND ${AIERT_SRC_DIR}/) @@ -135,17 +163,22 @@ if(NOT WIN32) target_compile_definitions(xclbinutil-lib PUBLIC ENABLE_JSON_SCHEMA_VALIDATION) target_link_libraries(xclbinutil-lib PUBLIC transformcdo) +else() + target_compile_options(xclbinutil-lib PUBLIC "/EHsc") + # LINK : fatal error LNK1104: cannot open file + # 'libboost_filesystem-vc142-mt-gd-x64-1_74.lib' + target_compile_definitions(xclbinutil-lib PUBLIC BOOST_ALL_DYN_LINK) endif() set(THREADS_PREFER_PTHREAD_FLAG ON) target_link_libraries(xclbinutil-lib PUBLIC ${Boost_LIBRARIES} Threads::Threads) -target_include_directories(xclbinutil-lib PUBLIC ${XRT_BINARY_DIR}/gen) +target_include_directories(xclbinutil-lib PUBLIC ${XRT_BINARY_DIR}/gen + ${Boost_INCLUDE_DIRS}) set_target_properties( xclbinutil-lib PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${OUTPUT_DIR} ARCHIVE_OUTPUT_DIRECTORY ${OUTPUT_DIR} - RUNTIME_OUTPUT_DIRECTORY ${OUTPUT_DIR} - MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>DLL") + RUNTIME_OUTPUT_DIRECTORY ${OUTPUT_DIR}) pybind11_add_module(_xclbinutil xaiepy/xclbinutil.cpp) target_include_directories(_xclbinutil PRIVATE ${XCLBINUTIL_SOURCE_DIR}) diff --git a/README.md b/README.md index df041f5..0ebd697 100644 --- a/README.md +++ b/README.md @@ -19,4 +19,19 @@ opcode='XAIE_IO_WRITE' reg_off=000000000021d040 val=0 mask=000000000fffc000 -``` \ No newline at end of file +``` + +# Gotchas + +If **ON WINDOWS** you're having trouble with + +```shell +CMake Error at C:/Users/maksim/miniconda3/envs/xaiepy/Lib/site-packages/cmake/data/share/cmake-3.29/Modules/FindPackageHandleStandardArgs.cmake:230 (message): + Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the + system variable OPENSSL_ROOT_DIR (missing: OPENSSL_CRYPTO_LIBRARY) (found + version "3.3.0") +``` + +you probably have the win32 developer shell open; open the `x64 Native Tools Command Prompt for VS` instead ([or copy the settings from the win32 powershell to a new link](https://developercommunity.visualstudio.com/t/the-developer-powershell-for-vs-2022-should-use-x6/1568773#T-N10609425)) 🤦. + +**Note**: `setup.py` expects OpenSSL to be installed @ `C:\Program Files\OpenSSL`. \ No newline at end of file diff --git a/examples/.gitignore b/examples/.gitignore deleted file mode 100644 index cf3a371..0000000 --- a/examples/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -*.json -*.pdi -*.bif -*.bin -*.xclbin \ No newline at end of file diff --git a/patches/aie-rt.diff b/patches/aie-rt.diff index bd8a6fa..c05bbb5 100644 --- a/patches/aie-rt.diff +++ b/patches/aie-rt.diff @@ -1,6 +1,6 @@ Submodule third_party/aie-rt contains modified content diff --git a/third_party/aie-rt/driver/src/CMakeLists.txt b/third_party/aie-rt/driver/src/CMakeLists.txt -index beacb4a..4dae7b6 100644 +index beacb4a..d279531 100644 --- a/third_party/aie-rt/driver/src/CMakeLists.txt +++ b/third_party/aie-rt/driver/src/CMakeLists.txt @@ -3,7 +3,7 @@ @@ -12,3 +12,12 @@ index beacb4a..4dae7b6 100644 collector_create (PROJECT_LIB_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}") collector_create (PROJECT_LIB_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}") include_directories(${CMAKE_BINARY_DIR}/include/xaiengine) +@@ -170,4 +170,7 @@ file(COPY ${_headers} DESTINATION ${CMAKE_BINARY_DIR}/include/xaiengine) + add_library(aienginev2 STATIC ${_sources}) + + set_target_properties(aienginev2 PROPERTIES LINKER_LANGUAGE C) +-target_compile_options(aienginev2 PRIVATE -Wall -Wextra -D__AIEBAREMETAL__) ++target_compile_options(aienginev2 PRIVATE -D__AIECDO__) ++if(CMAKE_COMPILER_IS_GNUCXX) ++ target_compile_options(aienginev2 PRIVATE -Wall -Wextra) ++endif(CMAKE_COMPILER_IS_GNUCXX) diff --git a/pyproject.toml b/pyproject.toml index e7bfd2f..46b8808 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,5 +35,5 @@ before-build = [ "pip install -r requirements-dev.txt", ] repair-wheel-command = [ -# "delvewheel repair -v --add-path xaiepy -w {dest_dir} {wheel} --no-dll xrt_coreutil.dll" + "delvewheel repair -v -w {dest_dir} {wheel} --ignore-in-wheel --add-path ${BOOST_ROOT}/lib64-msvc-${VCTOOLSVERSION} --no-dll xrt_coreutil.dll" ] diff --git a/requirements-dev.txt b/requirements-dev.txt index 9761adb..be5e64c 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -3,9 +3,13 @@ setuptools>=64 wheel ninja -cmake>=3.28 +# https://gitlab.kitware.com/cmake/cmake/-/issues/25702#note_1485760 +cmake>=3.29 ctypesgen cmake-format black pytest -pybind11[global] \ No newline at end of file +pybind11[global] +delvewheel; sys_platform == 'win32' +auditwheel; sys_platform == 'linux' +cibuildwheel \ No newline at end of file diff --git a/setup.py b/setup.py index f0f6053..e1d4331 100644 --- a/setup.py +++ b/setup.py @@ -6,6 +6,7 @@ from pathlib import Path from pprint import pprint +from cmake import cmake_executable_path from pip._internal.network.session import PipSession from pip._internal.req import parse_requirements from setuptools import Extension, setup @@ -69,12 +70,14 @@ def build_extension(self, ext: CMakeExtension) -> None: cmake_args += [ "-DCMAKE_C_COMPILER=cl", "-DCMAKE_CXX_COMPILER=cl", - "-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded", - "-DCMAKE_C_FLAGS=/MT", - "-DCMAKE_CXX_FLAGS=/MT /EHsc", "-DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=ON", "-DCMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS=ON", ] + if check_env("OPENSSL_ROOT_DIR"): + OPENSSL_ROOT_DIR = os.getenv( + "OPENSSL_ROOT_DIR", "C:\\Program Files\\OpenSSL" + ) + cmake_args += [f"-DOPENSSL_ROOT_DIR={OPENSSL_ROOT_DIR}"] if "CMAKE_ARGS" in os.environ: cmake_args += [item for item in os.environ["CMAKE_ARGS"].split(" ") if item] @@ -111,12 +114,17 @@ def build_extension(self, ext: CMakeExtension) -> None: env = os.environ.copy() print("ENV", pprint(os.environ), file=sys.stderr) print("CMAKE_ARGS", cmake_args, file=sys.stderr) + print(f"{cmake_executable_path=}", file=sys.stderr) + CMAKE_EXE_PATH = cmake_executable_path / "bin" / "cmake" subprocess.run( - ["cmake", ext.sourcedir, *cmake_args], cwd=build_temp, check=True, env=env + [str(CMAKE_EXE_PATH), ext.sourcedir, *cmake_args], + cwd=build_temp, + check=True, + env=env, ) subprocess.run( - ["cmake", "--build", ".", "--target", "xaie", *build_args], + [CMAKE_EXE_PATH, "--build", ".", "--target", "xaie", *build_args], cwd=build_temp, check=True, env=env, diff --git a/util/FindOpenSSL.cmake b/util/FindOpenSSL.cmake new file mode 100644 index 0000000..df078eb --- /dev/null +++ b/util/FindOpenSSL.cmake @@ -0,0 +1,804 @@ +################################################################################################### +# THIS IS A PATCHED VERSION FROM https://gitlab.kitware.com/cmake/cmake/-/issues/25702#note_1485779 +# SEE https://gitlab.kitware.com/cmake/cmake/-/issues/25702#note_1485760 +################################################################################################### + +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +#[=======================================================================[.rst: +FindOpenSSL +----------- + +Find the OpenSSL encryption library. + +This module finds an installed OpenSSL library and determines its version. + +.. versionadded:: 3.19 + When a version is requested, it can be specified as a simple value or as a + range. For a detailed description of version range usage and capabilities, + refer to the :command:`find_package` command. + +.. versionadded:: 3.18 + Support for OpenSSL 3.0. + +Optional COMPONENTS +^^^^^^^^^^^^^^^^^^^ + +.. versionadded:: 3.12 + +This module supports two optional COMPONENTS: ``Crypto`` and ``SSL``. Both +components have associated imported targets, as described below. + +Imported Targets +^^^^^^^^^^^^^^^^ + +.. versionadded:: 3.4 + +This module defines the following :prop_tgt:`IMPORTED` targets: + +``OpenSSL::SSL`` + The OpenSSL ``ssl`` library, if found. +``OpenSSL::Crypto`` + The OpenSSL ``crypto`` library, if found. +``OpenSSL::applink`` + .. versionadded:: 3.18 + + The OpenSSL ``applink`` components that might be need to be compiled into + projects under MSVC. This target is available only if found OpenSSL version + is not less than 0.9.8. By linking this target the above OpenSSL targets can + be linked even if the project has different MSVC runtime configurations with + the above OpenSSL targets. This target has no effect on platforms other than + MSVC. + +NOTE: Due to how ``INTERFACE_SOURCES`` are consumed by the consuming target, +unless you certainly know what you are doing, it is always preferred to link +``OpenSSL::applink`` target as ``PRIVATE`` and to make sure that this target is +linked at most once for the whole dependency graph of any library or +executable: + +.. code-block:: cmake + + target_link_libraries(myTarget PRIVATE OpenSSL::applink) + +Otherwise you would probably encounter unexpected random problems when building +and linking, as both the ISO C and the ISO C++ standard claims almost nothing +about what a link process should be. + +Result Variables +^^^^^^^^^^^^^^^^ + +This module will set the following variables in your project: + +``OPENSSL_FOUND`` + System has the OpenSSL library. If no components are requested it only + requires the crypto library. +``OPENSSL_INCLUDE_DIR`` + The OpenSSL include directory. +``OPENSSL_CRYPTO_LIBRARY`` + The OpenSSL crypto library. +``OPENSSL_CRYPTO_LIBRARIES`` + The OpenSSL crypto library and its dependencies. +``OPENSSL_SSL_LIBRARY`` + The OpenSSL SSL library. +``OPENSSL_SSL_LIBRARIES`` + The OpenSSL SSL library and its dependencies. +``OPENSSL_LIBRARIES`` + All OpenSSL libraries and their dependencies. +``OPENSSL_VERSION`` + This is set to ``$major.$minor.$revision$patch`` (e.g. ``0.9.8s``). +``OPENSSL_APPLINK_SOURCE`` + The sources in the target ``OpenSSL::applink`` that is mentioned above. This + variable shall always be undefined if found openssl version is less than + 0.9.8 or if platform is not MSVC. + +Hints +^^^^^ + +The following variables may be set to control search behavior: + +``OPENSSL_ROOT_DIR`` + Set to the root directory of an OpenSSL installation. + +``OPENSSL_USE_STATIC_LIBS`` + .. versionadded:: 3.4 + + Set to ``TRUE`` to look for static libraries. + +``OPENSSL_MSVC_STATIC_RT`` + .. versionadded:: 3.5 + + Set to ``TRUE`` to choose the MT version of the lib. + +``ENV{PKG_CONFIG_PATH}`` + On UNIX-like systems, ``pkg-config`` is used to locate the system OpenSSL. + Set the ``PKG_CONFIG_PATH`` environment variable to look in alternate + locations. Useful on multi-lib systems. +#]=======================================================================] + +set(USE_OUR_FIND_OPENSSL TRUE) + +macro(_OpenSSL_test_and_find_dependencies ssl_library crypto_library) + unset(_OpenSSL_extra_static_deps) + if(UNIX AND + (("${ssl_library}" MATCHES "\\${CMAKE_STATIC_LIBRARY_SUFFIX}$") OR + ("${crypto_library}" MATCHES "\\${CMAKE_STATIC_LIBRARY_SUFFIX}$"))) + set(_OpenSSL_has_dependencies TRUE) + unset(_OpenSSL_has_dependency_zlib) + if(OPENSSL_USE_STATIC_LIBS) + set(_OpenSSL_libs "${_OPENSSL_STATIC_LIBRARIES}") + set(_OpenSSL_ldflags_other "${_OPENSSL_STATIC_LDFLAGS_OTHER}") + else() + set(_OpenSSL_libs "${_OPENSSL_LIBRARIES}") + set(_OpenSSL_ldflags_other "${_OPENSSL_LDFLAGS_OTHER}") + endif() + if(_OpenSSL_libs) + unset(_OpenSSL_has_dependency_dl) + foreach(_OPENSSL_DEP_LIB IN LISTS _OpenSSL_libs) + if (_OPENSSL_DEP_LIB STREQUAL "ssl" OR _OPENSSL_DEP_LIB STREQUAL "crypto") + # ignoring: these are the targets + elseif(_OPENSSL_DEP_LIB STREQUAL CMAKE_DL_LIBS) + set(_OpenSSL_has_dependency_dl TRUE) + elseif(_OPENSSL_DEP_LIB STREQUAL "z") + find_package(ZLIB) + set(_OpenSSL_has_dependency_zlib TRUE) + else() + list(APPEND _OpenSSL_extra_static_deps "${_OPENSSL_DEP_LIB}") + endif() + endforeach() + unset(_OPENSSL_DEP_LIB) + elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") + set(_OpenSSL_has_dependency_dl TRUE) + endif() + if(_OpenSSL_ldflags_other) + unset(_OpenSSL_has_dependency_threads) + foreach(_OPENSSL_DEP_LDFLAG IN LISTS _OpenSSL_ldflags_other) + if (_OPENSSL_DEP_LDFLAG STREQUAL "-pthread") + set(_OpenSSL_has_dependency_threads TRUE) + find_package(Threads) + endif() + endforeach() + unset(_OPENSSL_DEP_LDFLAG) + elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") + set(_OpenSSL_has_dependency_threads TRUE) + find_package(Threads) + endif() + unset(_OpenSSL_libs) + unset(_OpenSSL_ldflags_other) + else() + set(_OpenSSL_has_dependencies FALSE) + endif() +endmacro() + +function(_OpenSSL_add_dependencies libraries_var) + if(_OpenSSL_has_dependency_zlib) + list(APPEND ${libraries_var} ${ZLIB_LIBRARY}) + endif() + if(_OpenSSL_has_dependency_threads) + list(APPEND ${libraries_var} ${CMAKE_THREAD_LIBS_INIT}) + endif() + if(_OpenSSL_has_dependency_dl) + list(APPEND ${libraries_var} ${CMAKE_DL_LIBS}) + endif() + list(APPEND ${libraries_var} ${_OpenSSL_extra_static_deps}) + set(${libraries_var} ${${libraries_var}} PARENT_SCOPE) +endfunction() + +function(_OpenSSL_target_add_dependencies target) + if(_OpenSSL_has_dependencies) + if(_OpenSSL_has_dependency_zlib) + set_property( TARGET ${target} APPEND PROPERTY INTERFACE_LINK_LIBRARIES ZLIB::ZLIB ) + endif() + if(_OpenSSL_has_dependency_threads) + set_property( TARGET ${target} APPEND PROPERTY INTERFACE_LINK_LIBRARIES Threads::Threads) + endif() + if(_OpenSSL_has_dependency_dl) + set_property( TARGET ${target} APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${CMAKE_DL_LIBS} ) + endif() + if(_OpenSSL_extra_static_deps) + set_property( TARGET ${target} APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${_OpenSSL_extra_static_deps}) + endif() + endif() + if(WIN32 AND OPENSSL_USE_STATIC_LIBS) + if(WINCE) + set_property( TARGET ${target} APPEND PROPERTY INTERFACE_LINK_LIBRARIES ws2 ) + else() + set_property( TARGET ${target} APPEND PROPERTY INTERFACE_LINK_LIBRARIES ws2_32 ) + endif() + set_property( TARGET ${target} APPEND PROPERTY INTERFACE_LINK_LIBRARIES crypt32 ) + endif() +endfunction() + +if (UNIX) + find_package(PkgConfig QUIET) + pkg_check_modules(_OPENSSL QUIET openssl) +endif () + +# Support preference of static libs by adjusting CMAKE_FIND_LIBRARY_SUFFIXES +if(OPENSSL_USE_STATIC_LIBS) + set(_openssl_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) + if(MSVC) + set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES}) + else() + set(CMAKE_FIND_LIBRARY_SUFFIXES .a ) + endif() +endif() + +if(CMAKE_SYSTEM_NAME STREQUAL "QNX" AND + CMAKE_SYSTEM_VERSION VERSION_GREATER_EQUAL "7.0" AND CMAKE_SYSTEM_VERSION VERSION_LESS "7.1" AND + OpenSSL_FIND_VERSION VERSION_GREATER_EQUAL "1.1" AND OpenSSL_FIND_VERSION VERSION_LESS "1.2") + # QNX 7.0.x provides openssl 1.0.2 and 1.1.1 in parallel: + # * openssl 1.0.2: libcrypto.so.2 and libssl.so.2, headers under usr/include/openssl + # * openssl 1.1.1: libcrypto1_1.so.2.1 and libssl1_1.so.2.1, header under usr/include/openssl1_1 + # See http://www.qnx.com/developers/articles/rel_6726_0.html + set(_OPENSSL_FIND_PATH_SUFFIX "openssl1_1") + set(_OPENSSL_NAME_POSTFIX "1_1") +else() + set(_OPENSSL_FIND_PATH_SUFFIX "include") +endif() + +if (OPENSSL_ROOT_DIR OR NOT "$ENV{OPENSSL_ROOT_DIR}" STREQUAL "") + set(_OPENSSL_ROOT_HINTS HINTS ${OPENSSL_ROOT_DIR} ENV OPENSSL_ROOT_DIR) + set(_OPENSSL_ROOT_PATHS NO_DEFAULT_PATH) +elseif (MSVC) + # http://www.slproweb.com/products/Win32OpenSSL.html + set(_OPENSSL_ROOT_HINTS + HINTS + "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\OpenSSL (32-bit)_is1;Inno Setup: App Path]" + "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\OpenSSL (64-bit)_is1;Inno Setup: App Path]" + ) + + if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8") + set(_arch "Win64") + file(TO_CMAKE_PATH "$ENV{PROGRAMFILES}" _programfiles) + else() + set(_arch "Win32") + set(_progfiles_x86 "ProgramFiles(x86)") + if(NOT "$ENV{${_progfiles_x86}}" STREQUAL "") + # under windows 64 bit machine + file(TO_CMAKE_PATH "$ENV{${_progfiles_x86}}" _programfiles) + else() + # under windows 32 bit machine + file(TO_CMAKE_PATH "$ENV{ProgramFiles}" _programfiles) + endif() + endif() + + set(_OPENSSL_ROOT_PATHS + PATHS + "${_programfiles}/OpenSSL" + "${_programfiles}/OpenSSL-${_arch}" + "C:/OpenSSL/" + "C:/OpenSSL-${_arch}/" + ) + unset(_programfiles) + unset(_arch) +endif () + +set(_OPENSSL_ROOT_HINTS_AND_PATHS + ${_OPENSSL_ROOT_HINTS} + ${_OPENSSL_ROOT_PATHS} + ) + +find_path(OPENSSL_INCLUDE_DIR + NAMES + openssl/ssl.h + ${_OPENSSL_ROOT_HINTS_AND_PATHS} + HINTS + ${_OPENSSL_INCLUDEDIR} + ${_OPENSSL_INCLUDE_DIRS} + PATH_SUFFIXES + ${_OPENSSL_FIND_PATH_SUFFIX} +) + +if(WIN32 AND NOT CYGWIN) + if(MSVC) + # /MD and /MDd are the standard values - if someone wants to use + # others, the libnames have to change here too + # use also ssl and ssleay32 in debug as fallback for openssl < 0.9.8b + # enable OPENSSL_MSVC_STATIC_RT to get the libs build /MT (Multithreaded no-DLL) + # In Visual C++ naming convention each of these four kinds of Windows libraries has it's standard suffix: + # * MD for dynamic-release + # * MDd for dynamic-debug + # * MT for static-release + # * MTd for static-debug + + # Implementation details: + # We are using the libraries located in the VC subdir instead of the parent directory even though : + # libeay32MD.lib is identical to ../libeay32.lib, and + # ssleay32MD.lib is identical to ../ssleay32.lib + # enable OPENSSL_USE_STATIC_LIBS to use the static libs located in lib/VC/static + + if (OPENSSL_MSVC_STATIC_RT) + set(_OPENSSL_MSVC_RT_MODE "MT") + else () + set(_OPENSSL_MSVC_RT_MODE "MD") + endif () + + # Since OpenSSL 1.1, lib names are like libcrypto32MTd.lib and libssl32MTd.lib + if( "${CMAKE_SIZEOF_VOID_P}" STREQUAL "8" ) + set(_OPENSSL_MSVC_ARCH_SUFFIX "64") + else() + set(_OPENSSL_MSVC_ARCH_SUFFIX "32") + endif() + + if(OPENSSL_USE_STATIC_LIBS) + set(_OPENSSL_STATIC_SUFFIX + "_static" + ) + set(_OPENSSL_PATH_SUFFIXES_DEBUG + "lib/VC/x${_OPENSSL_MSVC_ARCH_SUFFIX}/${_OPENSSL_MSVC_RT_MODE}d" + "lib/VC/static" + "VC/static" + "lib" + ) + set(_OPENSSL_PATH_SUFFIXES_RELEASE + "lib/VC/x${_OPENSSL_MSVC_ARCH_SUFFIX}/${_OPENSSL_MSVC_RT_MODE}" + "lib/VC/static" + "VC/static" + "lib" + ) + else() + set(_OPENSSL_STATIC_SUFFIX + "" + ) + set(_OPENSSL_PATH_SUFFIXES_DEBUG + "lib/VC/x${_OPENSSL_MSVC_ARCH_SUFFIX}/${_OPENSSL_MSVC_RT_MODE}d" + "lib/VC" + "VC" + "lib" + ) + set(_OPENSSL_PATH_SUFFIXES_RELEASE + "lib/VC/x${_OPENSSL_MSVC_ARCH_SUFFIX}/${_OPENSSL_MSVC_RT_MODE}" + "lib/VC" + "VC" + "lib" + ) + endif () + message(STATUS "searching for MSVC libs in ${_OPENSSL_PATH_SUFFIXES_DEBUG}") + message(STATUS "searching for MSVC libs in ${_OPENSSL_PATH_SUFFIXES_RELEASE}") + message(FATAL_ERROR) + + find_library(LIB_EAY_DEBUG + NAMES + # When OpenSSL is built with default options, the static library name is suffixed with "_static". + # Looking the "libcrypto_static.lib" with a higher priority than "libcrypto.lib" which is the + # import library of "libcrypto.dll". + libcrypto${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_ARCH_SUFFIX}${_OPENSSL_MSVC_RT_MODE}d + libcrypto${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_RT_MODE}d + libcrypto${_OPENSSL_STATIC_SUFFIX}d + libeay32${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_RT_MODE}d + libeay32${_OPENSSL_STATIC_SUFFIX}d + crypto${_OPENSSL_STATIC_SUFFIX}d + # When OpenSSL is built with the "-static" option, only the static build is produced, + # and it is not suffixed with "_static". + libcrypto${_OPENSSL_MSVC_ARCH_SUFFIX}${_OPENSSL_MSVC_RT_MODE}d + libcrypto${_OPENSSL_MSVC_RT_MODE}d + libcryptod + libeay32${_OPENSSL_MSVC_RT_MODE}d + libeay32d + cryptod + NAMES_PER_DIR + ${_OPENSSL_ROOT_HINTS_AND_PATHS} + PATH_SUFFIXES + ${_OPENSSL_PATH_SUFFIXES_DEBUG} + ) + + find_library(LIB_EAY_RELEASE + NAMES + # When OpenSSL is built with default options, the static library name is suffixed with "_static". + # Looking the "libcrypto_static.lib" with a higher priority than "libcrypto.lib" which is the + # import library of "libcrypto.dll". + libcrypto${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_ARCH_SUFFIX}${_OPENSSL_MSVC_RT_MODE} + libcrypto${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_RT_MODE} + libcrypto${_OPENSSL_STATIC_SUFFIX} + libeay32${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_RT_MODE} + libeay32${_OPENSSL_STATIC_SUFFIX} + crypto${_OPENSSL_STATIC_SUFFIX} + # When OpenSSL is built with the "-static" option, only the static build is produced, + # and it is not suffixed with "_static". + libcrypto${_OPENSSL_MSVC_ARCH_SUFFIX}${_OPENSSL_MSVC_RT_MODE} + libcrypto${_OPENSSL_MSVC_RT_MODE} + libcrypto + libeay32${_OPENSSL_MSVC_RT_MODE} + libeay32 + crypto + NAMES_PER_DIR + ${_OPENSSL_ROOT_HINTS_AND_PATHS} + PATH_SUFFIXES + ${_OPENSSL_PATH_SUFFIXES_RELEASE} + ) + + find_library(SSL_EAY_DEBUG + NAMES + # When OpenSSL is built with default options, the static library name is suffixed with "_static". + # Looking the "libssl_static.lib" with a higher priority than "libssl.lib" which is the + # import library of "libssl.dll". + libssl${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_ARCH_SUFFIX}${_OPENSSL_MSVC_RT_MODE}d + libssl${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_RT_MODE}d + libssl${_OPENSSL_STATIC_SUFFIX}d + ssleay32${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_RT_MODE}d + ssleay32${_OPENSSL_STATIC_SUFFIX}d + ssl${_OPENSSL_STATIC_SUFFIX}d + # When OpenSSL is built with the "-static" option, only the static build is produced, + # and it is not suffixed with "_static". + libssl${_OPENSSL_MSVC_ARCH_SUFFIX}${_OPENSSL_MSVC_RT_MODE}d + libssl${_OPENSSL_MSVC_RT_MODE}d + libssld + ssleay32${_OPENSSL_MSVC_RT_MODE}d + ssleay32d + ssld + NAMES_PER_DIR + ${_OPENSSL_ROOT_HINTS_AND_PATHS} + PATH_SUFFIXES + ${_OPENSSL_PATH_SUFFIXES_DEBUG} + ) + + find_library(SSL_EAY_RELEASE + NAMES + # When OpenSSL is built with default options, the static library name is suffixed with "_static". + # Looking the "libssl_static.lib" with a higher priority than "libssl.lib" which is the + # import library of "libssl.dll". + libssl${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_ARCH_SUFFIX}${_OPENSSL_MSVC_RT_MODE} + libssl${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_RT_MODE} + libssl${_OPENSSL_STATIC_SUFFIX} + ssleay32${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_RT_MODE} + ssleay32${_OPENSSL_STATIC_SUFFIX} + ssl${_OPENSSL_STATIC_SUFFIX} + # When OpenSSL is built with the "-static" option, only the static build is produced, + # and it is not suffixed with "_static". + libssl${_OPENSSL_MSVC_ARCH_SUFFIX}${_OPENSSL_MSVC_RT_MODE} + libssl${_OPENSSL_MSVC_RT_MODE} + libssl + ssleay32${_OPENSSL_MSVC_RT_MODE} + ssleay32 + ssl + NAMES_PER_DIR + ${_OPENSSL_ROOT_HINTS_AND_PATHS} + PATH_SUFFIXES + ${_OPENSSL_PATH_SUFFIXES_RELEASE} + ) + + set(LIB_EAY_LIBRARY_DEBUG "${LIB_EAY_DEBUG}") + set(LIB_EAY_LIBRARY_RELEASE "${LIB_EAY_RELEASE}") + set(SSL_EAY_LIBRARY_DEBUG "${SSL_EAY_DEBUG}") + set(SSL_EAY_LIBRARY_RELEASE "${SSL_EAY_RELEASE}") + + include(SelectLibraryConfigurations) + select_library_configurations(LIB_EAY) + select_library_configurations(SSL_EAY) + + mark_as_advanced(LIB_EAY_LIBRARY_DEBUG LIB_EAY_LIBRARY_RELEASE + SSL_EAY_LIBRARY_DEBUG SSL_EAY_LIBRARY_RELEASE) + set(OPENSSL_SSL_LIBRARY ${SSL_EAY_LIBRARY} ) + set(OPENSSL_CRYPTO_LIBRARY ${LIB_EAY_LIBRARY} ) + elseif(MINGW) + # same player, for MinGW + set(LIB_EAY_NAMES crypto libeay32) + set(SSL_EAY_NAMES ssl ssleay32) + find_library(LIB_EAY + NAMES + ${LIB_EAY_NAMES} + NAMES_PER_DIR + ${_OPENSSL_ROOT_HINTS_AND_PATHS} + PATH_SUFFIXES + "lib/MinGW" + "lib" + "lib64" + ) + + find_library(SSL_EAY + NAMES + ${SSL_EAY_NAMES} + NAMES_PER_DIR + ${_OPENSSL_ROOT_HINTS_AND_PATHS} + PATH_SUFFIXES + "lib/MinGW" + "lib" + "lib64" + ) + + mark_as_advanced(SSL_EAY LIB_EAY) + set(OPENSSL_SSL_LIBRARY ${SSL_EAY} ) + set(OPENSSL_CRYPTO_LIBRARY ${LIB_EAY} ) + unset(LIB_EAY_NAMES) + unset(SSL_EAY_NAMES) + else() + # Not sure what to pick for -say- intel, let's use the toplevel ones and hope someone report issues: + find_library(LIB_EAY + NAMES + libcrypto + libeay32 + NAMES_PER_DIR + ${_OPENSSL_ROOT_HINTS_AND_PATHS} + HINTS + ${_OPENSSL_LIBDIR} + PATH_SUFFIXES + lib + ) + + find_library(SSL_EAY + NAMES + libssl + ssleay32 + NAMES_PER_DIR + ${_OPENSSL_ROOT_HINTS_AND_PATHS} + HINTS + ${_OPENSSL_LIBDIR} + PATH_SUFFIXES + lib + ) + + mark_as_advanced(SSL_EAY LIB_EAY) + set(OPENSSL_SSL_LIBRARY ${SSL_EAY} ) + set(OPENSSL_CRYPTO_LIBRARY ${LIB_EAY} ) + endif() +else() + + find_library(OPENSSL_SSL_LIBRARY + NAMES + ssl${_OPENSSL_NAME_POSTFIX} + ssleay32 + ssleay32MD + NAMES_PER_DIR + ${_OPENSSL_ROOT_HINTS_AND_PATHS} + HINTS + ${_OPENSSL_LIBDIR} + ${_OPENSSL_LIBRARY_DIRS} + PATH_SUFFIXES + lib lib64 + ) + + find_library(OPENSSL_CRYPTO_LIBRARY + NAMES + crypto${_OPENSSL_NAME_POSTFIX} + NAMES_PER_DIR + ${_OPENSSL_ROOT_HINTS_AND_PATHS} + HINTS + ${_OPENSSL_LIBDIR} + ${_OPENSSL_LIBRARY_DIRS} + PATH_SUFFIXES + lib lib64 + ) + + mark_as_advanced(OPENSSL_CRYPTO_LIBRARY OPENSSL_SSL_LIBRARY) + +endif() + +set(OPENSSL_SSL_LIBRARIES ${OPENSSL_SSL_LIBRARY}) +set(OPENSSL_CRYPTO_LIBRARIES ${OPENSSL_CRYPTO_LIBRARY}) +set(OPENSSL_LIBRARIES ${OPENSSL_SSL_LIBRARIES} ${OPENSSL_CRYPTO_LIBRARIES} ) +_OpenSSL_test_and_find_dependencies("${OPENSSL_SSL_LIBRARY}" "${OPENSSL_CRYPTO_LIBRARY}") +if(_OpenSSL_has_dependencies) + _OpenSSL_add_dependencies( OPENSSL_SSL_LIBRARIES ) + _OpenSSL_add_dependencies( OPENSSL_CRYPTO_LIBRARIES ) + _OpenSSL_add_dependencies( OPENSSL_LIBRARIES ) +endif() + +function(from_hex HEX DEC) + string(TOUPPER "${HEX}" HEX) + set(_res 0) + string(LENGTH "${HEX}" _strlen) + + while (_strlen GREATER 0) + math(EXPR _res "${_res} * 16") + string(SUBSTRING "${HEX}" 0 1 NIBBLE) + string(SUBSTRING "${HEX}" 1 -1 HEX) + if (NIBBLE STREQUAL "A") + math(EXPR _res "${_res} + 10") + elseif (NIBBLE STREQUAL "B") + math(EXPR _res "${_res} + 11") + elseif (NIBBLE STREQUAL "C") + math(EXPR _res "${_res} + 12") + elseif (NIBBLE STREQUAL "D") + math(EXPR _res "${_res} + 13") + elseif (NIBBLE STREQUAL "E") + math(EXPR _res "${_res} + 14") + elseif (NIBBLE STREQUAL "F") + math(EXPR _res "${_res} + 15") + else() + math(EXPR _res "${_res} + ${NIBBLE}") + endif() + + string(LENGTH "${HEX}" _strlen) + endwhile() + + set(${DEC} ${_res} PARENT_SCOPE) +endfunction() + +if(OPENSSL_INCLUDE_DIR AND EXISTS "${OPENSSL_INCLUDE_DIR}/openssl/opensslv.h") + file(STRINGS "${OPENSSL_INCLUDE_DIR}/openssl/opensslv.h" openssl_version_str + REGEX "^#[\t ]*define[\t ]+OPENSSL_VERSION_NUMBER[\t ]+0x([0-9a-fA-F])+.*") + + if(openssl_version_str) + # The version number is encoded as 0xMNNFFPPS: major minor fix patch status + # The status gives if this is a developer or prerelease and is ignored here. + # Major, minor, and fix directly translate into the version numbers shown in + # the string. The patch field translates to the single character suffix that + # indicates the bug fix state, which 00 -> nothing, 01 -> a, 02 -> b and so + # on. + + string(REGEX REPLACE "^.*OPENSSL_VERSION_NUMBER[\t ]+0x([0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F]).*$" + "\\1;\\2;\\3;\\4;\\5" OPENSSL_VERSION_LIST "${openssl_version_str}") + list(GET OPENSSL_VERSION_LIST 0 OPENSSL_VERSION_MAJOR) + list(GET OPENSSL_VERSION_LIST 1 OPENSSL_VERSION_MINOR) + from_hex("${OPENSSL_VERSION_MINOR}" OPENSSL_VERSION_MINOR) + list(GET OPENSSL_VERSION_LIST 2 OPENSSL_VERSION_FIX) + from_hex("${OPENSSL_VERSION_FIX}" OPENSSL_VERSION_FIX) + list(GET OPENSSL_VERSION_LIST 3 OPENSSL_VERSION_PATCH) + + if (NOT OPENSSL_VERSION_PATCH STREQUAL "00") + from_hex("${OPENSSL_VERSION_PATCH}" _tmp) + # 96 is the ASCII code of 'a' minus 1 + math(EXPR OPENSSL_VERSION_PATCH_ASCII "${_tmp} + 96") + unset(_tmp) + # Once anyone knows how OpenSSL would call the patch versions beyond 'z' + # this should be updated to handle that, too. This has not happened yet + # so it is simply ignored here for now. + string(ASCII "${OPENSSL_VERSION_PATCH_ASCII}" OPENSSL_VERSION_PATCH_STRING) + endif () + + set(OPENSSL_VERSION "${OPENSSL_VERSION_MAJOR}.${OPENSSL_VERSION_MINOR}.${OPENSSL_VERSION_FIX}${OPENSSL_VERSION_PATCH_STRING}") + else () + # Since OpenSSL 3.0.0, the new version format is MAJOR.MINOR.PATCH and + # a new OPENSSL_VERSION_STR macro contains exactly that + file(STRINGS "${OPENSSL_INCLUDE_DIR}/openssl/opensslv.h" OPENSSL_VERSION_STR + REGEX "^#[\t ]*define[\t ]+OPENSSL_VERSION_STR[\t ]+\"([0-9])+\\.([0-9])+\\.([0-9])+\".*") + string(REGEX REPLACE "^.*OPENSSL_VERSION_STR[\t ]+\"([0-9]+\\.[0-9]+\\.[0-9]+)\".*$" + "\\1" OPENSSL_VERSION_STR "${OPENSSL_VERSION_STR}") + + set(OPENSSL_VERSION "${OPENSSL_VERSION_STR}") + + # Setting OPENSSL_VERSION_MAJOR OPENSSL_VERSION_MINOR and OPENSSL_VERSION_FIX + string(REGEX MATCHALL "([0-9])+" OPENSSL_VERSION_NUMBER "${OPENSSL_VERSION}") + list(POP_FRONT OPENSSL_VERSION_NUMBER + OPENSSL_VERSION_MAJOR + OPENSSL_VERSION_MINOR + OPENSSL_VERSION_FIX) + + unset(OPENSSL_VERSION_NUMBER) + unset(OPENSSL_VERSION_STR) + endif () +endif () + +foreach(_comp IN LISTS OpenSSL_FIND_COMPONENTS) + if(_comp STREQUAL "Crypto") + if(EXISTS "${OPENSSL_INCLUDE_DIR}" AND + (EXISTS "${OPENSSL_CRYPTO_LIBRARY}" OR + EXISTS "${LIB_EAY_LIBRARY_DEBUG}" OR + EXISTS "${LIB_EAY_LIBRARY_RELEASE}") + ) + set(OpenSSL_${_comp}_FOUND TRUE) + else() + set(OpenSSL_${_comp}_FOUND FALSE) + endif() + elseif(_comp STREQUAL "SSL") + if(EXISTS "${OPENSSL_INCLUDE_DIR}" AND + (EXISTS "${OPENSSL_SSL_LIBRARY}" OR + EXISTS "${SSL_EAY_LIBRARY_DEBUG}" OR + EXISTS "${SSL_EAY_LIBRARY_RELEASE}") + ) + set(OpenSSL_${_comp}_FOUND TRUE) + else() + set(OpenSSL_${_comp}_FOUND FALSE) + endif() + else() + message(WARNING "${_comp} is not a valid OpenSSL component") + set(OpenSSL_${_comp}_FOUND FALSE) + endif() +endforeach() +unset(_comp) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(OpenSSL + REQUIRED_VARS + OPENSSL_CRYPTO_LIBRARY + OPENSSL_INCLUDE_DIR + VERSION_VAR + OPENSSL_VERSION + HANDLE_VERSION_RANGE + HANDLE_COMPONENTS + FAIL_MESSAGE + "Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the system variable OPENSSL_ROOT_DIR" +) + +mark_as_advanced(OPENSSL_INCLUDE_DIR) + +if(OPENSSL_FOUND) + if(NOT TARGET OpenSSL::Crypto AND + (EXISTS "${OPENSSL_CRYPTO_LIBRARY}" OR + EXISTS "${LIB_EAY_LIBRARY_DEBUG}" OR + EXISTS "${LIB_EAY_LIBRARY_RELEASE}") + ) + add_library(OpenSSL::Crypto UNKNOWN IMPORTED) + set_target_properties(OpenSSL::Crypto PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${OPENSSL_INCLUDE_DIR}") + if(EXISTS "${OPENSSL_CRYPTO_LIBRARY}") + set_target_properties(OpenSSL::Crypto PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES "C" + IMPORTED_LOCATION "${OPENSSL_CRYPTO_LIBRARY}") + endif() + if(EXISTS "${LIB_EAY_LIBRARY_RELEASE}") + set_property(TARGET OpenSSL::Crypto APPEND PROPERTY + IMPORTED_CONFIGURATIONS RELEASE) + set_target_properties(OpenSSL::Crypto PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "C" + IMPORTED_LOCATION_RELEASE "${LIB_EAY_LIBRARY_RELEASE}") + endif() + if(EXISTS "${LIB_EAY_LIBRARY_DEBUG}") + set_property(TARGET OpenSSL::Crypto APPEND PROPERTY + IMPORTED_CONFIGURATIONS DEBUG) + set_target_properties(OpenSSL::Crypto PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "C" + IMPORTED_LOCATION_DEBUG "${LIB_EAY_LIBRARY_DEBUG}") + endif() + _OpenSSL_target_add_dependencies(OpenSSL::Crypto) + endif() + + if(NOT TARGET OpenSSL::SSL AND + (EXISTS "${OPENSSL_SSL_LIBRARY}" OR + EXISTS "${SSL_EAY_LIBRARY_DEBUG}" OR + EXISTS "${SSL_EAY_LIBRARY_RELEASE}") + ) + add_library(OpenSSL::SSL UNKNOWN IMPORTED) + set_target_properties(OpenSSL::SSL PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${OPENSSL_INCLUDE_DIR}") + if(EXISTS "${OPENSSL_SSL_LIBRARY}") + set_target_properties(OpenSSL::SSL PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES "C" + IMPORTED_LOCATION "${OPENSSL_SSL_LIBRARY}") + endif() + if(EXISTS "${SSL_EAY_LIBRARY_RELEASE}") + set_property(TARGET OpenSSL::SSL APPEND PROPERTY + IMPORTED_CONFIGURATIONS RELEASE) + set_target_properties(OpenSSL::SSL PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "C" + IMPORTED_LOCATION_RELEASE "${SSL_EAY_LIBRARY_RELEASE}") + endif() + if(EXISTS "${SSL_EAY_LIBRARY_DEBUG}") + set_property(TARGET OpenSSL::SSL APPEND PROPERTY + IMPORTED_CONFIGURATIONS DEBUG) + set_target_properties(OpenSSL::SSL PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "C" + IMPORTED_LOCATION_DEBUG "${SSL_EAY_LIBRARY_DEBUG}") + endif() + if(TARGET OpenSSL::Crypto) + set_target_properties(OpenSSL::SSL PROPERTIES + INTERFACE_LINK_LIBRARIES OpenSSL::Crypto) + endif() + _OpenSSL_target_add_dependencies(OpenSSL::SSL) + endif() + + if("${OPENSSL_VERSION_MAJOR}.${OPENSSL_VERSION_MINOR}.${OPENSSL_VERSION_FIX}" VERSION_GREATER_EQUAL "0.9.8") + if(MSVC) + if(EXISTS "${OPENSSL_INCLUDE_DIR}") + set(_OPENSSL_applink_paths PATHS ${OPENSSL_INCLUDE_DIR}) + endif() + find_file(OPENSSL_APPLINK_SOURCE + NAMES + openssl/applink.c + ${_OPENSSL_applink_paths} + NO_DEFAULT_PATH) + if(OPENSSL_APPLINK_SOURCE) + set(_OPENSSL_applink_interface_srcs ${OPENSSL_APPLINK_SOURCE}) + endif() + endif() + if(NOT TARGET OpenSSL::applink) + add_library(OpenSSL::applink INTERFACE IMPORTED) + set_property(TARGET OpenSSL::applink APPEND + PROPERTY INTERFACE_SOURCES + ${_OPENSSL_applink_interface_srcs}) + endif() + endif() +endif() + +# Restore the original find library ordering +if(OPENSSL_USE_STATIC_LIBS) + set(CMAKE_FIND_LIBRARY_SUFFIXES ${_openssl_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES}) +endif() + +unset(_OPENSSL_FIND_PATH_SUFFIX) +unset(_OPENSSL_NAME_POSTFIX) +unset(_OpenSSL_extra_static_deps) +unset(_OpenSSL_has_dependency_dl) +unset(_OpenSSL_has_dependency_threads) +unset(_OpenSSL_has_dependency_zlib) diff --git a/util/remove_path_limit.ps1 b/util/remove_path_limit.ps1 new file mode 100644 index 0000000..e1eff97 --- /dev/null +++ b/util/remove_path_limit.ps1 @@ -0,0 +1,2 @@ +# https://stackoverflow.com/a/68353105 +New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" -Name "LongPathsEnabled" -Value 1 -PropertyType DWORD -Force \ No newline at end of file diff --git a/xaiepy/.gitignore b/xaiepy/.gitignore index a099821..93f5256 100644 --- a/xaiepy/.gitignore +++ b/xaiepy/.gitignore @@ -1,3 +1 @@ -libxaie.so -__init__.py -xclbinutil \ No newline at end of file +__init__.py \ No newline at end of file