Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • asapo/asapo
  • joao.alvim/asapo
  • philipp.middendorf/asapo
  • stefan.dietrich/asapo
4 results
Show changes
Showing
with 745 additions and 2122 deletions
......@@ -32,10 +32,6 @@ ELSEIF(UNIX)
ENDIF(WIN32)
SET_PROPERTY(GLOBAL PROPERTY ASAPO_COMMON_IO_LIBRARIES ${ASAPO_COMMON_IO_LIBRARIES})
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
add_definitions(-DUNIT_TESTS)
endif (CMAKE_BUILD_TYPE STREQUAL "Debug")
if (APPLE)
link_directories("/usr/local/lib")
endif()
\ No newline at end of file
endif()
......@@ -22,4 +22,4 @@ endif()
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libcurl4-openssl-dev")
set(CPACK_RPM_PACKAGE_REQUIRES "libcurl-devel")
include(CPack)
\ No newline at end of file
include(CPack)
string(TIMESTAMP TIMESTAMP "%H:%M:%S %d.%m.%Y UTC" UTC)
configure_file( ${PROJECT_SOURCE_DIR}/common/cpp/include/asapo/common/internal/version.h.in ../common/cpp/include/asapo/common/internal/version.h @ONLY)
configure_file( ${PROJECT_SOURCE_DIR}/common/go/src/asapo_common/version/version_lib.go.in ../common/go/src/asapo_common/version/version_lib.go @ONLY)
configure_file(
${PROJECT_SOURCE_DIR}/common/cpp/include/asapo/common/internal/version.h.in
${PROJECT_SOURCE_DIR}/common/cpp/include/asapo/common/internal/version.h @ONLY
)
configure_file(
${PROJECT_SOURCE_DIR}/common/go/src/asapo_common/version/version_lib.go.in
${PROJECT_SOURCE_DIR}/common/go/src/asapo_common/version/version_lib.go @ONLY
)
function(cleanup varname)
string (REPLACE "-" "_" out ${${varname}})
SET( ${varname} ${out} PARENT_SCOPE)
string(REPLACE "-" "_" out ${${varname}})
SET(${varname} ${out} PARENT_SCOPE)
endfunction()
execute_process(COMMAND git describe --tags --abbrev=0
OUTPUT_VARIABLE ASAPO_TAG
WORKING_DIRECTORY ..)
if (DEFINED ENV{CI_COMMIT_REF_NAME})
# this is gitlab CI
if (DEFINED ENV{CI_COMMIT_TAG})
# both refname and tag are defined - this is a tagged build
SET(ASAPO_VERSION $ENV{CI_COMMIT_TAG})
SET(PYTHON_ASAPO_VERSION ${ASAPO_VERSION})
SET(ASAPO_VERSION_COMMIT "")
SET(ASAPO_VERSION_DOCKER_TAG $ENV{CI_COMMIT_TAG})
SET(ASAPO_VERSION_DOCKER_SUFFIX "")
else ()
# tag is not defined, this is the developer build
SET(ASAPO_VERSION $ENV{CI_COMMIT_REF_NAME})
string(REPLACE "_" "-" ASAPO_VERSION ${ASAPO_VERSION})
SET(ASAPO_VERSION 100.0.${ASAPO_VERSION})
SET(PYTHON_ASAPO_VERSION 100.0.dev2)
SET(ASAPO_VERSION_COMMIT ", build $ENV{CI_COMMIT_SHORT_SHA}")
SET(ASAPO_VERSION_DOCKER_TAG $ENV{CI_COMMIT_SHORT_SHA})
SET(ASAPO_VERSION_DOCKER_SUFFIX "-dev")
endif ()
SET(ASAPO_VERSION_DOCKER_REPOSITORY $ENV{CI_REGISTRY_IMAGE})
SET(ASAPO_VERSION_DOCKER_REPOSITORY_USERNAME $ENV{CI_REGISTRY_IMAGE_USERNAME})
SET(ASAPO_VERSION_DOCKER_REPOSITORY_PASSWORD $ENV{CI_REGISTRY_IMAGE_PASSWORD})
message("Asapo Version: " ${ASAPO_VERSION})
message("Python Asapo Version: " ${PYTHON_ASAPO_VERSION})
message("Asapo commit: " ${ASAPO_VERSION_COMMIT})
return ()
endif ()
# Enable running CMake from a directory which is not a subdirectory of
# ${CMAKE_SOURCE_DIR}. See https://git-scm.com/docs/git#Documentation/git.txt--Cltpathgt
# for more information on `git -C <path>`.
set(GIT_CMD git -C "${CMAKE_SOURCE_DIR}")
execute_process(COMMAND ${GIT_CMD} describe --tags --abbrev=0
OUTPUT_VARIABLE ASAPO_TAG
WORKING_DIRECTORY ..)
string(STRIP ${ASAPO_TAG} ASAPO_TAG)
execute_process(COMMAND git rev-parse --abbrev-ref HEAD
OUTPUT_VARIABLE BRANCH
WORKING_DIRECTORY ..)
execute_process(COMMAND ${GIT_CMD} rev-parse --abbrev-ref HEAD
OUTPUT_VARIABLE BRANCH
WORKING_DIRECTORY ..)
string(STRIP ${BRANCH} BRANCH)
cleanup(BRANCH)
execute_process(COMMAND git rev-parse --short=10 HEAD
execute_process(COMMAND ${GIT_CMD} rev-parse --short=10 HEAD
OUTPUT_VARIABLE ASAPO_VERSION_COMMIT
WORKING_DIRECTORY ..)
string(STRIP ${ASAPO_VERSION_COMMIT} ASAPO_VERSION_COMMIT)
if (${BRANCH} STREQUAL "master")
SET (ASAPO_VERSION_IN_DOCS ${ASAPO_TAG})
SET (ASAPO_VERSION ${ASAPO_TAG})
SET (ASAPO_VERSION_COMMIT "")
SET (ASAPO_VERSION_DOCKER_SUFFIX "")
SET (PYTHON_ASAPO_VERSION ${ASAPO_VERSION})
SET(ASAPO_VERSION ${ASAPO_TAG})
SET(ASAPO_VERSION_COMMIT "")
SET(ASAPO_VERSION_DOCKER_SUFFIX "")
SET(PYTHON_ASAPO_VERSION ${ASAPO_VERSION})
string(REGEX REPLACE "\\.0([0-9]+)\\."
".\\1." ASAPO_WHEEL_VERSION
${ASAPO_VERSION})
else()
SET (ASAPO_VERSION ${BRANCH})
SET (ASAPO_VERSION_COMMIT ", build ${ASAPO_VERSION_COMMIT}")
SET (ASAPO_VERSION_DOCKER_SUFFIX "-dev")
else ()
SET(ASAPO_VERSION ${BRANCH})
SET(ASAPO_VERSION_COMMIT ", build ${ASAPO_VERSION_COMMIT}")
SET(ASAPO_VERSION_DOCKER_SUFFIX "-dev")
string(REPLACE "_" "-" ASAPO_VERSION ${ASAPO_VERSION})
SET (ASAPO_VERSION 100.0.${ASAPO_VERSION})
SET (PYTHON_ASAPO_VERSION ${ASAPO_VERSION})
SET (ASAPO_WHEEL_VERSION ${ASAPO_VERSION})
endif()
string(REGEX REPLACE "\\.0([0-9]+)\\."
".\\1." ASAPO_WHEEL_VERSION_IN_DOCS
${ASAPO_VERSION_IN_DOCS})
SET(ASAPO_VERSION 100.0.${ASAPO_VERSION})
if (${BRANCH} STREQUAL "develop")
SET(PYTHON_ASAPO_VERSION 100.0.dev0)
else ()
string(FIND ${BRANCH} feature_ASAPO pos)
if( ${pos} EQUAL 0)
string(SUBSTRING ${ASAPO_VERSION} 20 -1 TMP)
string(REGEX MATCH "^([0-9]+)|.+$" ISSUE_NUM "${TMP}")
if (ISSUE_NUM STREQUAL "")
SET(PYTHON_ASAPO_VERSION 100.0.dev2)
else ()
SET(PYTHON_ASAPO_VERSION 100.0.dev${ISSUE_NUM})
endif ()
else ()
SET(PYTHON_ASAPO_VERSION 100.0.dev2)
endif ()
endif ()
SET(ASAPO_WHEEL_VERSION ${ASAPO_VERSION})
endif ()
SET(ASAPO_VERSION_DOCKER_REPOSITORY yakser)
SET(ASAPO_VERSION_DOCKER_REPOSITORY_USERNAME "")
SET(ASAPO_VERSION_DOCKER_REPOSITORY_PASSWORD "")
SET(ASAPO_VERSION_DOCKER_TAG ${ASAPO_VERSION})
message("Asapo Version: " ${ASAPO_VERSION})
message("Python Asapo Version: " ${PYTHON_ASAPO_VERSION})
......
......@@ -3,20 +3,16 @@ project(ASAPO)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMakeModules/ ${PROJECT_SOURCE_DIR}/CMakeIncludes/)
set (ASAPO_VERSION_IN_DOCS 21.06.0) # is overwritten in master branch
set (ASAPO_EXAMPLES_DIR .)
#set (ASAPO_EXAMPLES_DIR ./frozen_versions/${ASAPO_VERSION_IN_DOCS})
#protocol version changes if one of the microservice API's change
set (ASAPO_CONSUMER_PROTOCOL "v0.4")
set (ASAPO_PRODUCER_PROTOCOL "v0.4")
set (ASAPO_CONSUMER_PROTOCOL "v0.7")
set (ASAPO_PRODUCER_PROTOCOL "v0.7")
set (ASAPO_DISCOVERY_API_VER "v0.1")
set (ASAPO_AUTHORIZER_API_VER "v0.2")
set (ASAPO_BROKER_API_VER "v0.4")
set (ASAPO_BROKER_API_VER "v0.7")
set (ASAPO_FILE_TRANSFER_SERVICE_API_VER "v0.2")
set (ASAPO_RECEIVER_API_VER "v0.4")
set (ASAPO_RECEIVER_API_VER "v0.7")
set (ASAPO_RDS_API_VER "v0.1")
set (DB_SCHEMA_VER "v0.1")
set (DB_SCHEMA_VER "v0.1") # TODO: Remove later.
#global settings
......@@ -26,6 +22,7 @@ set(ConfigPackageLocation lib/cmake/Asapo)
# options
option(BUILD_PYTHON "Build python libs" ON)
option(BUILD_CLIENTS_ONLY "Build clients only" OFF)
option(BUILD_CONSUMER_TOOLS "Build consumer tools" OFF)
......@@ -46,6 +43,8 @@ option(BUILD_ASAPO_SITE "Build the asapo web site" OFF)
option(ENABLE_LIBFABRIC "Enables LibFabric support for RDMA transfers" OFF)
option(ENABLE_LIBFABRIC_LOCALHOST "Emulates LibFabric stack over TCP. Only for localhost and testing purposes." OFF)
option(ENABLE_NEW_RECEIVER_MONITORING "Enables the new monitoring for the receiver, but requires gRPC" OFF)
option(BUILD_SHARED_CLIENT_LIBS "Build shared consumer and producer libs" ON)
option(BUILD_STATIC_CLIENT_LIBS "Build static consumer and producer libs" ON)
......@@ -68,12 +67,16 @@ add_subdirectory(common/cpp)
add_subdirectory(producer)
add_subdirectory(consumer)
if (NOT BUILD_CLIENTS_ONLY)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
list(APPEND GO_OPTS -gcflags "all=-N -l")
endif()
add_subdirectory(broker)
add_subdirectory(receiver)
add_subdirectory(discovery)
add_subdirectory(authorizer)
add_subdirectory(asapo_tools)
add_subdirectory(file_transfer)
add_subdirectory(monitoring)
endif()
add_subdirectory(deploy)
......@@ -89,4 +92,3 @@ endif()
add_subdirectory(docs)
add_subdirectory(install)
# Copyright (c) 2012 - 2017, Lars Bilke
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors
# may be used to endorse or promote products processed from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# CHANGES:
#
# 2012-01-31, Lars Bilke
# - Enable Code Coverage
#
# 2013-09-17, Joakim Söderberg
# - Added support for Clang.
# - Some additional usage instructions.
#
# 2016-02-03, Lars Bilke
# - Refactored functions to use named parameters
#
# 2017-06-02, Lars Bilke
# - Merged with modified version from github.com/ufz/ogs
#
#
# USAGE:
#
# 1. Copy this file into your cmake modules path.
#
# 2. Add the following line to your CMakeLists.txt:
# include(CodeCoverage)
#
# 3. Append necessary compiler flags:
# APPEND_COVERAGE_COMPILER_FLAGS()
#
# 4. If you need to exclude additional directories from the report, specify them
# using the COVERAGE_EXCLUDES variable before calling SETUP_TARGET_FOR_COVERAGE.
# Example:
# set(COVERAGE_EXCLUDES 'dir1/*' 'dir2/*')
#
# 5. Use the functions described below to create a custom make target which
# runs your test executable and produces a code coverage report.
#
# 6. Build a Debug build:
# cmake -DCMAKE_BUILD_TYPE=Debug ..
# make
# make my_coverage_target
#
include(CMakeParseArguments)
# Check prereqs
find_program( GCOV_PATH gcov )
find_program( LCOV_PATH lcov )
find_program( GENHTML_PATH genhtml )
find_program( GCOVR_PATH gcovr PATHS ${CMAKE_SOURCE_DIR}/scripts/test)
if(NOT GCOV_PATH)
message(FATAL_ERROR "gcov not found! Aborting...")
endif() # NOT GCOV_PATH
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "(Apple)?[Cc]lang")
if("${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS 3)
message(FATAL_ERROR "Clang version must be 3.0.0 or greater! Aborting...")
endif()
elseif(NOT CMAKE_COMPILER_IS_GNUCXX)
message(FATAL_ERROR "Compiler is not GNU gcc! Aborting...")
endif()
set(COVERAGE_COMPILER_FLAGS "-g -O0 --coverage -fprofile-arcs -ftest-coverage"
CACHE INTERNAL "")
set(CMAKE_CXX_FLAGS_COVERAGE
${COVERAGE_COMPILER_FLAGS}
CACHE STRING "Flags used by the C++ compiler during coverage builds."
FORCE )
set(CMAKE_C_FLAGS_COVERAGE
${COVERAGE_COMPILER_FLAGS}
CACHE STRING "Flags used by the C compiler during coverage builds."
FORCE )
set(CMAKE_EXE_LINKER_FLAGS_COVERAGE
""
CACHE STRING "Flags used for linking binaries during coverage builds."
FORCE )
set(CMAKE_SHARED_LINKER_FLAGS_COVERAGE
""
CACHE STRING "Flags used by the shared libraries linker during coverage builds."
FORCE )
mark_as_advanced(
CMAKE_CXX_FLAGS_COVERAGE
CMAKE_C_FLAGS_COVERAGE
CMAKE_EXE_LINKER_FLAGS_COVERAGE
CMAKE_SHARED_LINKER_FLAGS_COVERAGE )
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
message(ERROR "Code coverage results with an optimised (non-Debug) build may be misleading")
endif() # NOT CMAKE_BUILD_TYPE STREQUAL "Debug"
if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
link_libraries(gcov)
else()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
endif()
# Defines a target for running and collection code coverage information
# Builds dependencies, runs the given executable and outputs reports.
# NOTE! The executable should always have a ZERO as exit code otherwise
# the coverage generation will not complete.
#
# SETUP_TARGET_FOR_COVERAGE(
# NAME testrunner_coverage # New target name
# EXECUTABLE testrunner -j ${PROCESSOR_COUNT} # Executable in PROJECT_BINARY_DIR
# DEPENDENCIES testrunner # Dependencies to build first
# )
function(SETUP_TARGET_FOR_COVERAGE)
set(options NONE)
set(oneValueArgs NAME)
set(multiValueArgs EXECUTABLE EXECUTABLE_ARGS DEPENDENCIES)
cmake_parse_arguments(Coverage "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if(NOT LCOV_PATH)
message(FATAL_ERROR "lcov not found! Aborting...")
endif() # NOT LCOV_PATH
if(NOT GENHTML_PATH)
message(FATAL_ERROR "genhtml not found! Aborting...")
endif() # NOT GENHTML_PATH
# Setup target
add_custom_target(${Coverage_NAME}
# Cleanup lcov
COMMAND ${LCOV_PATH} --directory . --zerocounters
COMMAND rm -f ${PROJECT_BINARY_DIR}/${Coverage_NAME}.txt
# Create baseline to make sure untouched files show up in the report
COMMAND ${LCOV_PATH} -b ${CMAKE_CURRENT_SOURCE_DIR} -no-external -c -i -d ${CMAKE_CURRENT_BINARY_DIR} -o ${Coverage_NAME}.base
# Run tests
COMMAND ${Coverage_EXECUTABLE}
# Capturing lcov counters and generating report
COMMAND ${LCOV_PATH} -b ${CMAKE_CURRENT_SOURCE_DIR} -no-external --directory . --capture --output-file ${Coverage_NAME}.info
# add baseline counters
COMMAND ${LCOV_PATH} -b ${CMAKE_CURRENT_SOURCE_DIR} -no-external -a ${Coverage_NAME}.base -a ${Coverage_NAME}.info --output-file ${Coverage_NAME}.total
COMMAND ${LCOV_PATH} --remove ${Coverage_NAME}.total ${COVERAGE_EXCLUDES} --output-file ${PROJECT_BINARY_DIR}/${Coverage_NAME}.info.cleaned
COMMAND ${GENHTML_PATH} -o ${Coverage_NAME} ${PROJECT_BINARY_DIR}/${Coverage_NAME}.info.cleaned
| grep -A 3 "Overall coverage rate" | grep lines | cut -d ":" -f 2 | cut -d "." -f 1
> ${PROJECT_BINARY_DIR}/${Coverage_NAME}.txt
COMMAND ${CMAKE_COMMAND} -E remove ${Coverage_NAME}.base ${Coverage_NAME}.info ${Coverage_NAME}.total ${PROJECT_BINARY_DIR}/${Coverage_NAME}.info.cleaned
# COMMAND echo bar OUTPUT_VARIABLE FOO)
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
DEPENDS ${Coverage_DEPENDENCIES}
COMMENT "Resetting code coverage counters to zero.\nProcessing code coverage counters and generating report."
)
# Show info where to find the report
add_custom_command(TARGET ${Coverage_NAME} POST_BUILD
COMMAND ;
COMMENT "Open ./${Coverage_NAME}/index.html in your browser to view the coverage report."
)
endfunction() # SETUP_TARGET_FOR_COVERAGE
# Defines a target for running and collection code coverage information
# Builds dependencies, runs the given executable and outputs reports.
# NOTE! The executable should always have a ZERO as exit code otherwise
# the coverage generation will not complete.
#
# SETUP_TARGET_FOR_COVERAGE_COBERTURA(
# NAME ctest_coverage # New target name
# EXECUTABLE ctest -j ${PROCESSOR_COUNT} # Executable in PROJECT_BINARY_DIR
# DEPENDENCIES executable_target # Dependencies to build first
# )
function(SETUP_TARGET_FOR_COVERAGE_COBERTURA)
set(options NONE)
set(oneValueArgs NAME)
set(multiValueArgs EXECUTABLE EXECUTABLE_ARGS DEPENDENCIES)
cmake_parse_arguments(Coverage "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if(NOT GCOVR_PATH)
message(FATAL_ERROR "gcovr not found! Aborting...")
endif() # NOT GCOVR_PATH
# Combine excludes to several -e arguments
set(COBERTURA_EXCLUDES "")
foreach(EXCLUDE ${COVERAGE_EXCLUDES})
set(COBERTURA_EXCLUDES "-e ${EXCLUDE} ${COBERTURA_EXCLUDES}")
endforeach()
add_custom_target(${Coverage_NAME}
# Run tests
${Coverage_EXECUTABLE}
# Running gcovr
COMMAND ${GCOVR_PATH} -x -r ${CMAKE_SOURCE_DIR} ${COBERTURA_EXCLUDES}
-o ${Coverage_NAME}.xml
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
DEPENDS ${Coverage_DEPENDENCIES}
COMMENT "Running gcovr to produce Cobertura code coverage report."
)
# Show info where to find the report
add_custom_command(TARGET ${Coverage_NAME} POST_BUILD
COMMAND ;
COMMENT "Cobertura code coverage report saved in ${Coverage_NAME}.xml."
)
endfunction() # SETUP_TARGET_FOR_COVERAGE_COBERTURA
function(APPEND_COVERAGE_COMPILER_FLAGS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COVERAGE_COMPILER_FLAGS}" PARENT_SCOPE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COVERAGE_COMPILER_FLAGS}" PARENT_SCOPE)
message(STATUS "Appending code coverage compiler flags: ${COVERAGE_COMPILER_FLAGS}")
endfunction() # APPEND_COVERAGE_COMPILER_FLAGS
......@@ -7,10 +7,10 @@
# LIBFABRIC_LIBRARY - Path to the library
# LIBFABRIC_INCLUDE_DIR - Path to the include dir
cmake_minimum_required(VERSION 2.6)
find_path(LIBFABRIC_INCLUDE_DIR fabric.h HINT ENV LIBFABRIC_INCLUDE_DIR)
get_filename_component(LIBFABRIC_INCLUDE_DIR ${LIBFABRIC_INCLUDE_DIR} DIRECTORY)
find_path(LIBFABRIC_INCLUDE_DIR "rdma/fabric.h" HINT ENV LIBFABRIC_INCLUDE_DIR)
if(NOT LIBFABRIC_INCLUDE_DIR)
message(FATAL_ERROR "Could not find libfabric include directory that contains 'rdma/fabric.h'")
endif()
find_library(LIBFABRIC_LIBRARY fabric)
......
# Find the Python NumPy package
# PYTHON_NUMPY_INCLUDE_DIR
# PYTHON_NUMPY_FOUND
# will be set by this script
cmake_minimum_required(VERSION 2.6)
if(NOT Python3_EXECUTABLE)
if(NumPy_FIND_QUIETLY)
find_package(Python3 QUIET)
else()
find_package(Python3)
set(__numpy_out 1)
endif()
endif()
if (Python3_EXECUTABLE)
# Find out the include path
execute_process(
COMMAND "${Python3_EXECUTABLE}" -c
"from __future__ import print_function\ntry: import numpy; print(numpy.get_include(), end='')\nexcept:pass\n"
OUTPUT_VARIABLE __numpy_path)
# And the version
execute_process(
COMMAND "${Python3_EXECUTABLE}" -c
"from __future__ import print_function\ntry: import numpy; print(numpy.__version__, end='')\nexcept:pass\n"
OUTPUT_VARIABLE __numpy_version)
elseif(__numpy_out)
message(STATUS "Python executable not found.")
endif(Python3_EXECUTABLE)
find_path(PYTHON_NUMPY_INCLUDE_DIR numpy/arrayobject.h
HINTS "${__numpy_path}" "${PYTHON_INCLUDE_PATH}" NO_DEFAULT_PATH)
if(PYTHON_NUMPY_INCLUDE_DIR)
set(PYTHON_NUMPY_FOUND 1 CACHE INTERNAL "Python numpy found")
endif(PYTHON_NUMPY_INCLUDE_DIR)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(NumPy REQUIRED_VARS PYTHON_NUMPY_INCLUDE_DIR
VERSION_VAR __numpy_version)
\ No newline at end of file
# ~~~
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ~~~
#[=======================================================================[.rst:
FindProtobufWithTargets
-------------------
A module to use ``Protobuf`` with less complications.
Using ``find_package(Protobuf)`` should be simple, but it is not.
CMake provides a ``FindProtobuf`` module. Unfortunately it does not generate
``protobuf::*`` targets until CMake-3.9, and ``protobuf::protoc`` does not
appear until CMake-3.10.
The CMake-config files generated by ``protobuf`` always create these targets,
but on some Linux distributions (e.g. Fedora>=29, and openSUSE-Tumbleweed) there
are system packages for protobuf, but these packages are installed without the
CMake-config files. One must either use the ``FindProtobuf`` module, find the
libraries via ``pkg-config``, or find the libraries manually.
When the CMake-config files are installed they produce the same targets as
recent versions of ``FindProtobuf``. However, they do not produce the
``Protobuf_LIBRARY``, ``Protobuf_INCLUDE_DIR``, etc. that are generated by the
module. Furthermore, the ``protobuf::protoc`` library is not usable when loaded
from the CMake-config files: its ``IMPORTED_LOCATION`` variable is not defined.
This module is designed to provide a single, uniform, ``find_package()``
module that always produces the same outputs:
- It always generates the ``protobuf::*`` targets.
- It always defines ``ProtobufWithTargets_FOUND`` and
``ProtobufWithTargets_VERSION``.
- It *prefers* using the CMake config files if they are available.
- It fallsback on the ``FindProtobuf`` module if the config files are not found.
- It populates any missing targets and their properties.
The following ``IMPORTED`` targets are defined:
``protobuf::libprotobuf``
The protobuf library.
``protobuf::libprotobuf-lite``
The protobuf lite library.
``protobuf::libprotoc``
The protoc library.
``protobuf::protoc``
The protoc compiler.
Example:
.. code-block:: cmake
find_package(ProtobufWithTargets REQUIRED)
add_executable(bar bar.cc)
target_link_libraries(bar PRIVATE protobuf::libprotobuf)
#]=======================================================================]
if (protobuf_DEBUG)
message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
"protobuf_USE_STATIC_LIBS = ${protobuf_USE_STATIC_LIBS}"
" ProtobufWithTargets = ${ProtobufWithTargets_FOUND}")
endif ()
# Always load thread support, even on Windows.
find_package(Threads REQUIRED)
# First try to use the ``protobufConfig.cmake`` or ``protobuf-config.cmake``
# file if it was installed. This is common on systems (or package managers)
# where protobuf was compiled and installed with `CMake`. Note that on Linux
# this *must* be all lowercase ``protobuf``, while on Windows it does not
# matter.
find_package(Protobuf CONFIG QUIET)
if (protobuf_DEBUG)
message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
"Protobuf_FOUND = ${Protobuf_FOUND}"
" Protobuf_VERSION = ${Protobuf_VERSION}")
endif ()
if (NOT Protobuf_FOUND)
find_package(Protobuf QUIET)
endif ()
if (Protobuf_FOUND)
set(ProtobufWithTargets_FOUND 1)
set(ProtobufWithTargets_VERSION ${Protobuf_VERSION})
if (NOT TARGET protobuf::libprotobuf)
add_library(protobuf::libprotobuf INTERFACE IMPORTED)
set_property(
TARGET protobuf::libprotobuf PROPERTY INTERFACE_INCLUDE_DIRECTORIES
${Protobuf_INCLUDE_DIR})
set_property(
TARGET protobuf::libprotobuf
APPEND
PROPERTY INTERFACE_LINK_LIBRARIES ${Protobuf_LIBRARY}
Threads::Threads)
endif ()
if (NOT TARGET protobuf::libprotobuf-lite)
add_library(protobuf::libprotobuf-lite INTERFACE IMPORTED)
set_property(
TARGET protobuf::libprotobuf-lite
PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${Protobuf_INCLUDE_DIR})
set_property(
TARGET protobuf::libprotobuf-lite
APPEND
PROPERTY INTERFACE_LINK_LIBRARIES ${Protobuf_LITE_LIBRARY}
Threads::Threads)
endif ()
if (NOT TARGET protobuf::libprotoc)
add_library(protobuf::libprotoc INTERFACE IMPORTED)
set_property(
TARGET protobuf::libprotoc PROPERTY INTERFACE_INCLUDE_DIRECTORIES
${Protobuf_INCLUDE_DIR})
set_property(
TARGET protobuf::libprotoc
APPEND
PROPERTY INTERFACE_LINK_LIBRARIES ${Protobuf_PROTOC_LIBRARY}
Threads::Threads)
endif ()
if (NOT TARGET protobuf::protoc)
add_executable(protobuf::protoc IMPORTED)
# Discover the protoc compiler location.
find_program(
_protobuf_PROTOC_EXECUTABLE
NAMES protoc
DOC "The Google Protocol Buffers Compiler")
if (protobuf_DEBUG)
message(
STATUS
"[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
"ProtobufWithTargets_FOUND = ${ProtobufWithTargets_FOUND}"
" ProtobufWithTargets_VERSION = ${ProtobufWithTargets_VERSION}"
" EXE = ${_protobuf_PROTOC_EXECUTABLE}")
endif ()
set_property(TARGET protobuf::protoc
PROPERTY IMPORTED_LOCATION ${_protobuf_PROTOC_EXECUTABLE})
set_property(
TARGET protobuf::protoc PROPERTY IMPORTED_LOCATION_DEBUG
${_protobuf_PROTOC_EXECUTABLE})
set_property(
TARGET protobuf::protoc PROPERTY IMPORTED_LOCATION_RELEASE
${_protobuf_PROTOC_EXECUTABLE})
unset(_protobuf_PROTOC_EXECUTABLE)
if (protobuf_DEBUG)
get_target_property(_protobuf_PROTOC_EXECUTABLE protobuf::protoc
IMPORTED_LOCATION)
message(
STATUS
"[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
"LOCATION=${_protobuf_PROTOC_EXECUTABLE}")
endif ()
endif ()
endif ()
if (protobuf_DEBUG)
message(
STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
"ProtobufWithTargets_FOUND = ${ProtobufWithTargets_FOUND}"
" ProtobufWithTargets_VERSION = ${ProtobufWithTargets_VERSION}")
endif ()
if (protobuf_DEBUG)
message(
STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
"ProtobufWithTargets_FOUND = ${ProtobufWithTargets_FOUND}"
" ProtobufWithTargets_VERSION = ${ProtobufWithTargets_VERSION}")
if (ProtobufWithTargets_FOUND)
foreach (_target protobuf::libprotobuf protobuf::libprotobuf-lite
protobuf::libprotoc)
if (NOT TARGET ${_target})
message(
STATUS
"[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
"target=${_target} is NOT a target")
endif ()
endforeach ()
unset(_target)
endif ()
endif ()
find_package_handle_standard_args(
ProtobufWithTargets REQUIRED_VARS ProtobufWithTargets_FOUND
ProtobufWithTargets_VERSION)
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
#[=======================================================================[.rst:
FindPython
----------
Find Python interpreter, compiler and development environment (include
directories and libraries).
Three components are supported:
* ``Interpreter``: search for Python interpreter.
* ``Compiler``: search for Python compiler. Only offered by IronPython.
* ``Development``: search for development artifacts (include directories and
libraries).
* ``NumPy``: search for NumPy include directories.
If no ``COMPONENTS`` is specified, ``Interpreter`` is assumed.
To ensure consistent versions between components ``Interpreter``, ``Compiler``,
``Development`` and ``NumPy``, specify all components at the same time::
find_package (Python COMPONENTS Interpreter Development)
This module looks preferably for version 3 of Python. If not found, version 2
is searched.
To manage concurrent versions 3 and 2 of Python, use :module:`FindPython3` and
:module:`FindPython2` modules rather than this one.
.. note::
If components ``Interpreter`` and ``Development`` are both specified, this
module search only for interpreter with same platform architecture as the one
defined by ``CMake`` configuration. This contraint does not apply if only
``Interpreter`` component is specified.
Imported Targets
^^^^^^^^^^^^^^^^
This module defines the following :ref:`Imported Targets <Imported Targets>`
(when :prop_gbl:`CMAKE_ROLE` is ``PROJECT``):
``Python::Interpreter``
Python interpreter. Target defined if component ``Interpreter`` is found.
``Python::Compiler``
Python compiler. Target defined if component ``Compiler`` is found.
``Python::Python``
Python library. Target defined if component ``Development`` is found.
``Python::NumPy``
NumPy Python library. Target defined if component ``NumPy`` is found.
Result Variables
^^^^^^^^^^^^^^^^
This module will set the following variables in your project
(see :ref:`Standard Variable Names <CMake Developer Standard Variable Names>`):
``Python_FOUND``
System has the Python requested components.
``Python_Interpreter_FOUND``
System has the Python interpreter.
``Python_EXECUTABLE``
Path to the Python interpreter.
``Python_INTERPRETER_ID``
A short string unique to the interpreter. Possible values include:
* Python
* ActivePython
* Anaconda
* Canopy
* IronPython
``Python_STDLIB``
Standard platform independent installation directory.
Information returned by
``distutils.sysconfig.get_python_lib(plat_specific=False,standard_lib=True)``.
``Python_STDARCH``
Standard platform dependent installation directory.
Information returned by
``distutils.sysconfig.get_python_lib(plat_specific=True,standard_lib=True)``.
``Python_SITELIB``
Third-party platform independent installation directory.
Information returned by
``distutils.sysconfig.get_python_lib(plat_specific=False,standard_lib=False)``.
``Python_SITEARCH``
Third-party platform dependent installation directory.
Information returned by
``distutils.sysconfig.get_python_lib(plat_specific=True,standard_lib=False)``.
``Python_Compiler_FOUND``
System has the Python compiler.
``Python_COMPILER``
Path to the Python compiler. Only offered by IronPython.
``Python_COMPILER_ID``
A short string unique to the compiler. Possible values include:
* IronPython
``Python_Development_FOUND``
System has the Python development artifacts.
``Python_INCLUDE_DIRS``
The Python include directories.
``Python_LIBRARIES``
The Python libraries.
``Python_LIBRARY_DIRS``
The Python library directories.
``Python_RUNTIME_LIBRARY_DIRS``
The Python runtime library directories.
``Python_VERSION``
Python version.
``Python_VERSION_MAJOR``
Python major version.
``Python_VERSION_MINOR``
Python minor version.
``Python_VERSION_PATCH``
Python patch version.
``Python_NumPy_FOUND``
System has the NumPy.
``Python_NumPy_INCLUDE_DIRS``
The NumPy include directries.
``Python_NumPy_VERSION``
The NumPy version.
Hints
^^^^^
``Python_ROOT_DIR``
Define the root directory of a Python installation.
``Python_USE_STATIC_LIBS``
* If not defined, search for shared libraries and static libraries in that
order.
* If set to TRUE, search **only** for static libraries.
* If set to FALSE, search **only** for shared libraries.
``Python_FIND_REGISTRY``
On Windows the ``Python_FIND_REGISTRY`` variable determine the order
of preference between registry and environment variables.
the ``Python_FIND_REGISTRY`` variable can be set to empty or one of the
following:
* ``FIRST``: Try to use registry before environment variables.
This is the default.
* ``LAST``: Try to use registry after environment variables.
* ``NEVER``: Never try to use registry.
``CMAKE_FIND_FRAMEWORK``
On OS X the :variable:`CMAKE_FIND_FRAMEWORK` variable determine the order of
preference between Apple-style and unix-style package components.
.. note::
Value ``ONLY`` is not supported so ``FIRST`` will be used instead.
.. note::
If a Python virtual environment is configured, set variable
``Python_FIND_REGISTRY`` (Windows) or ``CMAKE_FIND_FRAMEWORK`` (macOS) with
value ``LAST`` or ``NEVER`` to select it preferably.
Commands
^^^^^^^^
This module defines the command ``Python_add_library`` (when
:prop_gbl:`CMAKE_ROLE` is ``PROJECT``), which has the same semantics as
:command:`add_library`, but takes care of Python module naming rules
(only applied if library is of type ``MODULE``), and adds a dependency to target
``Python::Python``::
Python_add_library (my_module MODULE src1.cpp)
If library type is not specified, ``MODULE`` is assumed.
#]=======================================================================]
set (_PYTHON_PREFIX Python)
if (DEFINED Python_FIND_VERSION)
set (_Python_REQUIRED_VERSION_MAJOR ${Python_FIND_VERSION_MAJOR})
include (${CMAKE_CURRENT_LIST_DIR}/FindPython/Support.cmake)
else()
# iterate over versions in quiet and NOT required modes to avoid multiple
# "Found" messages and prematurally failure.
set (_Python_QUIETLY ${Python_FIND_QUIETLY})
set (_Python_REQUIRED ${Python_FIND_REQUIRED})
set (Python_FIND_QUIETLY TRUE)
set (Python_FIND_REQUIRED FALSE)
set (_Python_REQUIRED_VERSIONS 3 2)
set (_Python_REQUIRED_VERSION_LAST 2)
foreach (_Python_REQUIRED_VERSION_MAJOR IN LISTS _Python_REQUIRED_VERSIONS)
set (Python_FIND_VERSION ${_Python_REQUIRED_VERSION_MAJOR})
include (${CMAKE_CURRENT_LIST_DIR}/FindPython/Support.cmake)
if (Python_FOUND OR
_Python_REQUIRED_VERSION_MAJOR EQUAL _Python_REQUIRED_VERSION_LAST)
break()
endif()
# clean-up some CACHE variables to ensure look-up restart from scratch
foreach (_Python_ITEM IN LISTS _Python_CACHED_VARS)
unset (${_Python_ITEM} CACHE)
endforeach()
endforeach()
unset (Python_FIND_VERSION)
set (Python_FIND_QUIETLY ${_Python_QUIETLY})
set (Python_FIND_REQUIRED ${_Python_REQUIRED})
if (Python_FIND_REQUIRED OR NOT Python_FIND_QUIETLY)
# call again validation command to get "Found" or error message
find_package_handle_standard_args (Python HANDLE_COMPONENTS
REQUIRED_VARS ${_Python_REQUIRED_VARS}
VERSION_VAR Python_VERSION)
endif()
endif()
if (COMMAND __Python_add_library)
macro (Python_add_library)
__Python_add_library (Python ${ARGV})
endmacro()
endif()
unset (_PYTHON_PREFIX)
\ No newline at end of file
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
#
# This file is a "template" file used by various FindPython modules.
#
cmake_policy (VERSION 3.7)
#
# Initial configuration
#
if (NOT DEFINED _PYTHON_PREFIX)
message (FATAL_ERROR "FindPython: INTERNAL ERROR")
endif()
if (NOT DEFINED _${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR)
message (FATAL_ERROR "FindPython: INTERNAL ERROR")
endif()
if (_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR EQUAL 3)
set(_${_PYTHON_PREFIX}_VERSIONS 3.8 3.7 3.6 3.5 3.4 3.3 3.2 3.1 3.0)
elseif (_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR EQUAL 2)
set(_${_PYTHON_PREFIX}_VERSIONS 2.7 2.6 2.5 2.4 2.3 2.2 2.1 2.0)
else()
message (FATAL_ERROR "FindPython: INTERNAL ERROR")
endif()
get_property(_${_PYTHON_PREFIX}_CMAKE_ROLE GLOBAL PROPERTY CMAKE_ROLE)
#
# helper commands
#
macro (_PYTHON_DISPLAY_FAILURE _PYTHON_MSG)
if (${_PYTHON_PREFIX}_FIND_REQUIRED)
message (FATAL_ERROR "${_PYTHON_MSG}")
else()
if (NOT ${_PYTHON_PREFIX}_FIND_QUIETLY)
message(STATUS "${_PYTHON_MSG}")
endif ()
endif()
set (${_PYTHON_PREFIX}_FOUND FALSE)
string (TOUPPER "${_PYTHON_PREFIX}" _${_PYTHON_PREFIX}_UPPER_PREFIX)
set (${_PYTHON_UPPER_PREFIX}_FOUND FALSE)
return()
endmacro()
macro (_PYTHON_FIND_FRAMEWORKS)
set (${_PYTHON_PREFIX}_FRAMEWORKS)
if (APPLE)
set (_pff_frameworks ${CMAKE_FRAMEWORK_PATH}
$ENV{CMAKE_FRAMEWORK_PATH}
~/Library/Frameworks
/usr/local/Frameworks
${CMAKE_SYSTEM_FRAMEWORK_PATH})
list (REMOVE_DUPLICATES _pff_frameworks)
foreach (_pff_framework IN LISTS _pff_frameworks)
if (EXISTS ${_pff_framework}/Python.framework)
list (APPEND ${_PYTHON_PREFIX}_FRAMEWORKS ${_pff_framework}/Python.framework)
endif()
endforeach()
unset (_pff_frameworks)
unset (_pff_framework)
endif()
endmacro()
function (_PYTHON_GET_FRAMEWORKS _PYTHON_PGF_FRAMEWORK_PATHS _PYTHON_VERSION)
set (_PYTHON_FRAMEWORK_PATHS)
foreach (_PYTHON_FRAMEWORK IN LISTS ${_PYTHON_PREFIX}_FRAMEWORKS)
list (APPEND _PYTHON_FRAMEWORK_PATHS
"${_PYTHON_FRAMEWORK}/Versions/${_PYTHON_VERSION}")
endforeach()
set (${_PYTHON_PGF_FRAMEWORK_PATHS} ${_PYTHON_FRAMEWORK_PATHS} PARENT_SCOPE)
endfunction()
function (_PYTHON_VALIDATE_INTERPRETER)
if (NOT ${_PYTHON_PREFIX}_EXECUTABLE)
return()
endif()
if (ARGC EQUAL 1)
set (expected_version ${ARGV0})
else()
unset (expected_version)
endif()
get_filename_component (python_name "${${_PYTHON_PREFIX}_EXECUTABLE}" NAME)
if (expected_version AND NOT python_name STREQUAL "python${expected_version}${CMAKE_EXECUTABLE_SUFFIX}")
# executable found must have a specific version
execute_process (COMMAND "${${_PYTHON_PREFIX}_EXECUTABLE}" -c
"import sys; sys.stdout.write('.'.join([str(x) for x in sys.version_info[:2]]))"
RESULT_VARIABLE result
OUTPUT_VARIABLE version
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
if (result OR NOT version EQUAL expected_version)
# interpreter not usable or has wrong major version
set (${_PYTHON_PREFIX}_EXECUTABLE ${_PYTHON_PREFIX}_EXECUTABLE-NOTFOUND CACHE INTERNAL "" FORCE)
return()
endif()
else()
if (NOT python_name STREQUAL "python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR}${CMAKE_EXECUTABLE_SUFFIX}")
# executable found do not have version in name
# ensure major version is OK
execute_process (COMMAND "${${_PYTHON_PREFIX}_EXECUTABLE}" -c
"import sys; sys.stdout.write(str(sys.version_info[0]))"
RESULT_VARIABLE result
OUTPUT_VARIABLE version
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
if (result OR NOT version EQUAL _${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR)
# interpreter not usable or has wrong major version
set (${_PYTHON_PREFIX}_EXECUTABLE ${_PYTHON_PREFIX}_EXECUTABLE-NOTFOUND CACHE INTERNAL "" FORCE)
return()
endif()
endif()
endif()
if (CMAKE_SIZEOF_VOID_P AND "Development" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS
AND NOT CMAKE_CROSSCOMPILING)
# In this case, interpreter must have same architecture as environment
execute_process (COMMAND "${${_PYTHON_PREFIX}_EXECUTABLE}" -c
"import sys, struct; sys.stdout.write(str(struct.calcsize(\"P\")))"
RESULT_VARIABLE result
OUTPUT_VARIABLE size
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
if (result OR NOT size EQUAL CMAKE_SIZEOF_VOID_P)
# interpreter not usable or has wrong architecture
set (${_PYTHON_PREFIX}_EXECUTABLE ${_PYTHON_PREFIX}_EXECUTABLE-NOTFOUND CACHE INTERNAL "" FORCE)
return()
endif()
endif()
endfunction()
function (_PYTHON_VALIDATE_COMPILER expected_version)
if (NOT ${_PYTHON_PREFIX}_COMPILER)
return()
endif()
# retrieve python environment version from compiler
set (working_dir "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/PythonCompilerVersion.dir")
file (WRITE "${working_dir}/version.py" "import sys; sys.stdout.write('.'.join([str(x) for x in sys.version_info[:2]]))\n")
execute_process (COMMAND "${${_PYTHON_PREFIX}_COMPILER}" /target:exe /embed "${working_dir}/version.py"
WORKING_DIRECTORY "${working_dir}"
OUTPUT_QUIET
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process (COMMAND "${working_dir}/version"
WORKING_DIRECTORY "${working_dir}"
RESULT_VARIABLE result
OUTPUT_VARIABLE version
ERROR_QUIET)
file (REMOVE_RECURSE "${_${_PYTHON_PREFIX}_VERSION_DIR}")
if (result OR NOT version EQUAL expected_version)
# Compiler not usable or has wrong major version
set (${_PYTHON_PREFIX}_COMPILER ${_PYTHON_PREFIX}_COMPILER-NOTFOUND CACHE INTERNAL "" FORCE)
endif()
endfunction()
function (_PYTHON_FIND_RUNTIME_LIBRARY _PYTHON_LIB)
string (REPLACE "_RUNTIME" "" _PYTHON_LIB "${_PYTHON_LIB}")
# look at runtime part on systems supporting it
if (CMAKE_SYSTEM_NAME STREQUAL "Windows" OR
(CMAKE_SYSTEM_NAME MATCHES "MSYS|CYGWIN"
AND ${_PYTHON_LIB} MATCHES "${CMAKE_IMPORT_LIBRARY_SUFFIX}$"))
set (CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_SHARED_LIBRARY_SUFFIX})
# MSYS has a special syntax for runtime libraries
if (CMAKE_SYSTEM_NAME MATCHES "MSYS")
list (APPEND CMAKE_FIND_LIBRARY_PREFIXES "msys-")
endif()
find_library (${ARGV})
endif()
endfunction()
function (_PYTHON_SET_LIBRARY_DIRS _PYTHON_SLD_RESULT)
unset (_PYTHON_DIRS)
set (_PYTHON_LIBS ${ARGV})
list (REMOVE_AT _PYTHON_LIBS 0)
foreach (_PYTHON_LIB IN LISTS _PYTHON_LIBS)
if (${_PYTHON_LIB})
get_filename_component (_PYTHON_DIR "${${_PYTHON_LIB}}" DIRECTORY)
list (APPEND _PYTHON_DIRS "${_PYTHON_DIR}")
endif()
endforeach()
if (_PYTHON_DIRS)
list (REMOVE_DUPLICATES _PYTHON_DIRS)
endif()
set (${_PYTHON_SLD_RESULT} ${_PYTHON_DIRS} PARENT_SCOPE)
endfunction()
# If major version is specified, it must be the same as internal major version
if (DEFINED ${_PYTHON_PREFIX}_FIND_VERSION_MAJOR
AND NOT ${_PYTHON_PREFIX}_FIND_VERSION_MAJOR VERSION_EQUAL _${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR)
_python_display_failure ("Could NOT find ${_PYTHON_PREFIX}: Wrong major version specified is \"${${_PYTHON_PREFIX}_FIND_VERSION_MAJOR}\", but expected major version is \"${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR}\"")
endif()
# handle components
if (NOT ${_PYTHON_PREFIX}_FIND_COMPONENTS)
set (${_PYTHON_PREFIX}_FIND_COMPONENTS Interpreter)
set (${_PYTHON_PREFIX}_FIND_REQUIRED_Interpreter TRUE)
endif()
if ("NumPy" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS)
list (APPEND ${_PYTHON_PREFIX}_FIND_COMPONENTS "Interpreter" "Development")
list (REMOVE_DUPLICATES ${_PYTHON_PREFIX}_FIND_COMPONENTS)
endif()
foreach (_${_PYTHON_PREFIX}_COMPONENT IN LISTS ${_PYTHON_PREFIX}_FIND_COMPONENTS)
set (${_PYTHON_PREFIX}_${_${_PYTHON_PREFIX}_COMPONENT}_FOUND FALSE)
endforeach()
unset (_${_PYTHON_PREFIX}_FIND_VERSIONS)
# Set versions to search
## default: search any version
set (_${_PYTHON_PREFIX}_FIND_VERSIONS ${_${_PYTHON_PREFIX}_VERSIONS})
if (${_PYTHON_PREFIX}_FIND_VERSION_COUNT GREATER 1)
if (${_PYTHON_PREFIX}_FIND_VERSION_EXACT)
set (_${_PYTHON_PREFIX}_FIND_VERSIONS ${${_PYTHON_PREFIX}_FIND_VERSION_MAJOR}.${${_PYTHON_PREFIX}_FIND_VERSION_MINOR})
else()
unset (_${_PYTHON_PREFIX}_FIND_VERSIONS)
# add all compatible versions
foreach (_${_PYTHON_PREFIX}_VERSION IN LISTS _${_PYTHON_PREFIX}_VERSIONS)
if (_${_PYTHON_PREFIX}_VERSION VERSION_GREATER_EQUAL ${_PYTHON_PREFIX}_FIND_VERSION)
list (APPEND _${_PYTHON_PREFIX}_FIND_VERSIONS ${_${_PYTHON_PREFIX}_VERSION})
endif()
endforeach()
endif()
endif()
# Python and Anaconda distributions: define which architectures can be used
if (CMAKE_SIZEOF_VOID_P)
# In this case, search only for 64bit or 32bit
math (EXPR _${_PYTHON_PREFIX}_ARCH "${CMAKE_SIZEOF_VOID_P} * 8")
set (_${_PYTHON_PREFIX}_ARCH2 ${_${_PYTHON_PREFIX}_ARCH})
else()
# architecture unknown, search for both 64bit and 32bit
set (_${_PYTHON_PREFIX}_ARCH 64)
set (_${_PYTHON_PREFIX}_ARCH2 32)
endif()
# IronPython support
if (CMAKE_SIZEOF_VOID_P)
# In this case, search only for 64bit or 32bit
math (EXPR _${_PYTHON_PREFIX}_ARCH "${CMAKE_SIZEOF_VOID_P} * 8")
set (_${_PYTHON_PREFIX}_IRON_PYTHON_NAMES ipy${_${_PYTHON_PREFIX}_ARCH} ipy)
else()
# architecture unknown, search for natural interpreter
set (_${_PYTHON_PREFIX}_IRON_PYTHON_NAMES ipy)
endif()
set (_${_PYTHON_PREFIX}_IRON_PYTHON_PATH_SUFFIXES net45 net40)
# Apple frameworks handling
_python_find_frameworks ()
# Save CMAKE_FIND_APPBUNDLE
if (DEFINED CMAKE_FIND_APPBUNDLE)
set (_${_PYTHON_PREFIX}_CMAKE_FIND_APPBUNDLE ${CMAKE_FIND_APPBUNDLE})
else()
unset (_${_PYTHON_PREFIX}_CMAKE_FIND_APPBUNDLE)
endif()
# To avoid app bundle lookup
set (CMAKE_FIND_APPBUNDLE "NEVER")
# Save CMAKE_FIND_FRAMEWORK
if (DEFINED CMAKE_FIND_FRAMEWORK)
set (_${_PYTHON_PREFIX}_CMAKE_FIND_FRAMEWORK ${CMAKE_FIND_FRAMEWORK})
if (CMAKE_FIND_FRAMEWORK STREQUAL "ONLY")
message (AUTHOR_WARNING "Find${_PYTHON_PREFIX}: CMAKE_FIND_FRAMEWORK: 'ONLY' value is not supported. 'FIRST' will be used instead.")
set (_${_PYTHON_PREFIX}_FIND_FRAMEWORK "FIRST")
else()
set (_${_PYTHON_PREFIX}_FIND_FRAMEWORK ${CMAKE_FIND_FRAMEWORK})
endif()
else()
unset (_${_PYTHON_PREFIX}_CMAKE_FIND_FRAMEWORK)
set (_${_PYTHON_PREFIX}_FIND_FRAMEWORK "FIRST")
endif()
# To avoid framework lookup
set (CMAKE_FIND_FRAMEWORK "NEVER")
# Windows Registry handling
if (DEFINED ${_PYTHON_PREFIX}_FIND_REGISTRY)
if (NOT ${_PYTHON_PREFIX}_FIND_REGISTRY MATCHES "^(FIRST|LAST|NEVER)$")
message (AUTHOR_WARNING "Find${_PYTHON_PREFIX}: ${${_PYTHON_PREFIX}_FIND_REGISTRY}: invalid value for '${_PYTHON_PREFIX}_FIND_REGISTRY'. 'FIRST', 'LAST' or 'NEVER' expected.")
set (_${_PYTHON_PREFIX}_FIND_REGISTRY "FIRST")
else()
set (_${_PYTHON_PREFIX}_FIND_REGISTRY ${${_PYTHON_PREFIX}_FIND_REGISTRY})
endif()
else()
set (_${_PYTHON_PREFIX}_FIND_REGISTRY "FIRST")
endif()
unset (_${_PYTHON_PREFIX}_REQUIRED_VARS)
unset (_${_PYTHON_PREFIX}_CACHED_VARS)
# first step, search for the interpreter
if ("Interpreter" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS)
if (${_PYTHON_PREFIX}_FIND_REQUIRED_Interpreter)
list (APPEND _${_PYTHON_PREFIX}_REQUIRED_VARS ${_PYTHON_PREFIX}_EXECUTABLE)
list (APPEND _${_PYTHON_PREFIX}_CACHED_VARS ${_PYTHON_PREFIX}_EXECUTABLE)
endif()
set (_${_PYTHON_PREFIX}_HINTS "${${_PYTHON_PREFIX}_ROOT_DIR}" ENV ${_PYTHON_PREFIX}_ROOT_DIR)
# look-up for various versions and locations
foreach (_${_PYTHON_PREFIX}_VERSION IN LISTS _${_PYTHON_PREFIX}_FIND_VERSIONS)
string (REPLACE "." "" _${_PYTHON_PREFIX}_VERSION_NO_DOTS ${_${_PYTHON_PREFIX}_VERSION})
_python_get_frameworks (_${_PYTHON_PREFIX}_FRAMEWORK_PATHS ${_${_PYTHON_PREFIX}_VERSION})
# Apple frameworks handling
if (APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "FIRST")
find_program (${_PYTHON_PREFIX}_EXECUTABLE
NAMES python${_${_PYTHON_PREFIX}_VERSION}
python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR}
NAMES_PER_DIR
PATHS ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS}
PATH_SUFFIXES bin
NO_CMAKE_PATH
NO_CMAKE_ENVIRONMENT_PATH
NO_SYSTEM_ENVIRONMENT_PATH
NO_CMAKE_SYSTEM_PATH)
endif()
# Windows registry
if (WIN32 AND _${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "FIRST")
find_program (${_PYTHON_PREFIX}_EXECUTABLE
NAMES python${_${_PYTHON_PREFIX}_VERSION}
python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR}
python
${_${_PYTHON_PREFIX}_IRON_PYTHON_NAMES}
NAMES_PER_DIR
HINTS ${_${_PYTHON_PREFIX}_HINTS}
PATHS [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_${_PYTHON_PREFIX}_VERSION}-${_${_PYTHON_PREFIX}_ARCH}\\InstallPath]
[HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_${_PYTHON_PREFIX}_VERSION}-${_${_PYTHON_PREFIX}_ARCH2}\\InstallPath]
[HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_${_PYTHON_PREFIX}_VERSION}\\InstallPath]
[HKEY_CURRENT_USER\\SOFTWARE\\Python\\ContinuumAnalytics\\Anaconda${_${_PYTHON_PREFIX}_VERSION_NO_DOTS}-${_${_PYTHON_PREFIX}_ARCH}\\InstallPath]
[HKEY_CURRENT_USER\\SOFTWARE\\Python\\ContinuumAnalytics\\Anaconda${_${_PYTHON_PREFIX}_VERSION_NO_DOTS}-${_${_PYTHON_PREFIX}_ARCH2}\\InstallPath]
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_${_PYTHON_PREFIX}_VERSION}-${_${_PYTHON_PREFIX}_ARCH}\\InstallPath]
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_${_PYTHON_PREFIX}_VERSION}-${_${_PYTHON_PREFIX}_ARCH2}\\InstallPath]
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_${_PYTHON_PREFIX}_VERSION}\\InstallPath]
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\ContinuumAnalytics\\Anaconda${_${_PYTHON_PREFIX}_VERSION_NO_DOTS}-${_${_PYTHON_PREFIX}_ARCH}\\InstallPath]
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\ContinuumAnalytics\\Anaconda${_${_PYTHON_PREFIX}_VERSION_NO_DOTS}-${_${_PYTHON_PREFIX}_ARCH2}\\InstallPath]
[HKEY_LOCAL_MACHINE\\SOFTWARE\\IronPython\\${_${_PYTHON_PREFIX}_VERSION}\\InstallPath]
PATH_SUFFIXES bin ${_${_PYTHON_PREFIX}_IRON_PYTHON_PATH_SUFFIXES}
NO_SYSTEM_ENVIRONMENT_PATH
NO_CMAKE_SYSTEM_PATH)
endif()
# try using HINTS
find_program (${_PYTHON_PREFIX}_EXECUTABLE
NAMES python${_${_PYTHON_PREFIX}_VERSION}
python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR}
python
${_${_PYTHON_PREFIX}_IRON_PYTHON_NAMES}
NAMES_PER_DIR
HINTS ${_${_PYTHON_PREFIX}_HINTS}
PATH_SUFFIXES bin ${_${_PYTHON_PREFIX}_IRON_PYTHON_PATH_SUFFIXES}
NO_SYSTEM_ENVIRONMENT_PATH
NO_CMAKE_SYSTEM_PATH)
# try using standard paths.
if (WIN32)
find_program (${_PYTHON_PREFIX}_EXECUTABLE
NAMES python${_${_PYTHON_PREFIX}_VERSION}
python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR}
python
${_${_PYTHON_PREFIX}_IRON_PYTHON_NAMES}
NAMES_PER_DIR)
else()
find_program (${_PYTHON_PREFIX}_EXECUTABLE
NAMES python${_${_PYTHON_PREFIX}_VERSION}
python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR}
NAMES_PER_DIR)
endif()
# Apple frameworks handling
if (APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "LAST")
find_program (${_PYTHON_PREFIX}_EXECUTABLE
NAMES python${_${_PYTHON_PREFIX}_VERSION}
python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR}
NAMES_PER_DIR
PATHS ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS}
PATH_SUFFIXES bin
NO_DEFAULT_PATH)
endif()
# Windows registry
if (WIN32 AND _${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "LAST")
find_program (${_PYTHON_PREFIX}_EXECUTABLE
NAMES python${_${_PYTHON_PREFIX}_VERSION}
python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR}
python
${_${_PYTHON_PREFIX}_IRON_PYTHON_NAMES}
NAMES_PER_DIR
PATHS [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_${_PYTHON_PREFIX}_VERSION}-${_${_PYTHON_PREFIX}_ARCH}\\InstallPath]
[HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_${_PYTHON_PREFIX}_VERSION}-${_${_PYTHON_PREFIX}_ARCH2}\\InstallPath]
[HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_${_PYTHON_PREFIX}_VERSION}\\InstallPath]
[HKEY_CURRENT_USER\\SOFTWARE\\Python\\ContinuumAnalytics\\Anaconda${_${_PYTHON_PREFIX}_VERSION_NO_DOTS}-${_${_PYTHON_PREFIX}_ARCH}\\InstallPath]
[HKEY_CURRENT_USER\\SOFTWARE\\Python\\ContinuumAnalytics\\Anaconda${_${_PYTHON_PREFIX}_VERSION_NO_DOTS}-${_${_PYTHON_PREFIX}_ARCH2}\\InstallPath]
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_${_PYTHON_PREFIX}_VERSION}-${_${_PYTHON_PREFIX}_ARCH}\\InstallPath]
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_${_PYTHON_PREFIX}_VERSION}-${_${_PYTHON_PREFIX}_ARCH2}\\InstallPath]
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_${_PYTHON_PREFIX}_VERSION}\\InstallPath]
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\ContinuumAnalytics\\Anaconda${_${_PYTHON_PREFIX}_VERSION_NO_DOTS}-${_${_PYTHON_PREFIX}_ARCH}\\InstallPath]
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\ContinuumAnalytics\\Anaconda${_${_PYTHON_PREFIX}_VERSION_NO_DOTS}-${_${_PYTHON_PREFIX}_ARCH2}\\InstallPath]
[HKEY_LOCAL_MACHINE\\SOFTWARE\\IronPython\\${_${_PYTHON_PREFIX}_VERSION}\\InstallPath]
PATH_SUFFIXES bin ${_${_PYTHON_PREFIX}_IRON_PYTHON_PATH_SUFFIXES}
NO_DEFAULT_PATH)
endif()
_python_validate_interpreter (${_${_PYTHON_PREFIX}_VERSION})
if (${_PYTHON_PREFIX}_EXECUTABLE)
break()
endif()
endforeach()
if (NOT ${_PYTHON_PREFIX}_EXECUTABLE)
# No specific version found. Retry with generic names
# try using HINTS
find_program (${_PYTHON_PREFIX}_EXECUTABLE
NAMES python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR}
python
${_${_PYTHON_PREFIX}_IRON_PYTHON_NAMES}
NAMES_PER_DIR
HINTS ${_${_PYTHON_PREFIX}_HINTS}
PATH_SUFFIXES bin ${_${_PYTHON_PREFIX}_IRON_PYTHON_PATH_SUFFIXES}
NO_SYSTEM_ENVIRONMENT_PATH
NO_CMAKE_SYSTEM_PATH)
# try using standard paths.
# NAMES_PER_DIR is not defined on purpose to have a chance to find
# expected version.
# For example, typical systems have 'python' for version 2.* and 'python3'
# for version 3.*. So looking for names per dir will find, potentially,
# systematically 'python' (i.e. version 2) even if version 3 is searched.
find_program (${_PYTHON_PREFIX}_EXECUTABLE
NAMES python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR}
python
${_${_PYTHON_PREFIX}_IRON_PYTHON_NAMES})
_python_validate_interpreter ()
endif()
# retrieve exact version of executable found
if (${_PYTHON_PREFIX}_EXECUTABLE)
execute_process (COMMAND "${${_PYTHON_PREFIX}_EXECUTABLE}" -c
"import sys; sys.stdout.write('.'.join([str(x) for x in sys.version_info[:3]]))"
RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT
OUTPUT_VARIABLE ${_PYTHON_PREFIX}_VERSION
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
if (NOT _${_PYTHON_PREFIX}_RESULT)
string (REGEX MATCHALL "[0-9]+" _${_PYTHON_PREFIX}_VERSIONS "${${_PYTHON_PREFIX}_VERSION}")
list (GET _${_PYTHON_PREFIX}_VERSIONS 0 ${_PYTHON_PREFIX}_VERSION_MAJOR)
list (GET _${_PYTHON_PREFIX}_VERSIONS 1 ${_PYTHON_PREFIX}_VERSION_MINOR)
list (GET _${_PYTHON_PREFIX}_VERSIONS 2 ${_PYTHON_PREFIX}_VERSION_PATCH)
else()
# Interpreter is not usable
set (${_PYTHON_PREFIX}_EXECUTABLE ${_PYTHON_PREFIX}_EXECUTABLE-NOTFOUND CACHE INTERNAL "" FORCE)
unset (${_PYTHON_PREFIX}_VERSION)
endif()
endif()
if (${_PYTHON_PREFIX}_EXECUTABLE
AND ${_PYTHON_PREFIX}_VERSION_MAJOR VERSION_EQUAL _${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR)
set (${_PYTHON_PREFIX}_Interpreter_FOUND TRUE)
# Use interpreter version for future searches to ensure consistency
set (_${_PYTHON_PREFIX}_FIND_VERSIONS ${${_PYTHON_PREFIX}_VERSION_MAJOR}.${${_PYTHON_PREFIX}_VERSION_MINOR})
endif()
if (${_PYTHON_PREFIX}_Interpreter_FOUND)
if (NOT CMAKE_SIZEOF_VOID_P)
# determine interpreter architecture
execute_process (COMMAND "${${_PYTHON_PREFIX}_EXECUTABLE}" -c "import sys; print(sys.maxsize > 2**32)"
RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT
OUTPUT_VARIABLE ${_PYTHON_PREFIX}_IS64BIT
ERROR_VARIABLE ${_PYTHON_PREFIX}_IS64BIT)
if (NOT _${_PYTHON_PREFIX}_RESULT)
if (${_PYTHON_PREFIX}_IS64BIT)
set (_${_PYTHON_PREFIX}_ARCH 64)
set (_${_PYTHON_PREFIX}_ARCH2 64)
else()
set (_${_PYTHON_PREFIX}_ARCH 32)
set (_${_PYTHON_PREFIX}_ARCH2 32)
endif()
endif()
endif()
# retrieve interpreter identity
execute_process (COMMAND "${${_PYTHON_PREFIX}_EXECUTABLE}" -V
RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT
OUTPUT_VARIABLE ${_PYTHON_PREFIX}_INTERPRETER_ID
ERROR_VARIABLE ${_PYTHON_PREFIX}_INTERPRETER_ID)
if (NOT _${_PYTHON_PREFIX}_RESULT)
if (${_PYTHON_PREFIX}_INTERPRETER_ID MATCHES "Anaconda")
set (${_PYTHON_PREFIX}_INTERPRETER_ID "Anaconda")
elseif (${_PYTHON_PREFIX}_INTERPRETER_ID MATCHES "Enthought")
set (${_PYTHON_PREFIX}_INTERPRETER_ID "Canopy")
else()
string (REGEX REPLACE "^([^ ]+).*" "\\1" ${_PYTHON_PREFIX}_INTERPRETER_ID "${${_PYTHON_PREFIX}_INTERPRETER_ID}")
if (${_PYTHON_PREFIX}_INTERPRETER_ID STREQUAL "Python")
# try to get a more precise ID
execute_process (COMMAND "${${_PYTHON_PREFIX}_EXECUTABLE}" -c "import sys; print(sys.copyright)"
RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT
OUTPUT_VARIABLE ${_PYTHON_PREFIX}_COPYRIGHT
ERROR_QUIET)
if (${_PYTHON_PREFIX}_COPYRIGHT MATCHES "ActiveState")
set (${_PYTHON_PREFIX}_INTERPRETER_ID "ActivePython")
endif()
endif()
endif()
else()
set (${_PYTHON_PREFIX}_INTERPRETER_ID Python)
endif()
else()
unset (${_PYTHON_PREFIX}_INTERPRETER_ID)
endif()
# retrieve various package installation directories
execute_process (COMMAND "${${_PYTHON_PREFIX}_EXECUTABLE}" -c "import sys; from distutils import sysconfig;sys.stdout.write(';'.join([sysconfig.get_python_lib(plat_specific=False,standard_lib=True),sysconfig.get_python_lib(plat_specific=True,standard_lib=True),sysconfig.get_python_lib(plat_specific=False,standard_lib=False),sysconfig.get_python_lib(plat_specific=True,standard_lib=False)]))"
RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT
OUTPUT_VARIABLE _${_PYTHON_PREFIX}_LIBPATHS
ERROR_QUIET)
if (NOT _${_PYTHON_PREFIX}_RESULT)
list (GET _${_PYTHON_PREFIX}_LIBPATHS 0 ${_PYTHON_PREFIX}_STDLIB)
list (GET _${_PYTHON_PREFIX}_LIBPATHS 1 ${_PYTHON_PREFIX}_STDARCH)
list (GET _${_PYTHON_PREFIX}_LIBPATHS 2 ${_PYTHON_PREFIX}_SITELIB)
list (GET _${_PYTHON_PREFIX}_LIBPATHS 3 ${_PYTHON_PREFIX}_SITEARCH)
else()
unset (${_PYTHON_PREFIX}_STDLIB)
unset (${_PYTHON_PREFIX}_STDARCH)
unset (${_PYTHON_PREFIX}_SITELIB)
unset (${_PYTHON_PREFIX}_SITEARCH)
endif()
mark_as_advanced (${_PYTHON_PREFIX}_EXECUTABLE)
endif()
# second step, search for compiler (IronPython)
if ("Compiler" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS)
if (${_PYTHON_PREFIX}_FIND_REQUIRED_Compiler)
list (APPEND _${_PYTHON_PREFIX}_REQUIRED_VARS ${_PYTHON_PREFIX}_COMPILER)
list (APPEND _${_PYTHON_PREFIX}_CACHED_VARS ${_PYTHON_PREFIX}_COMPILER)
endif()
# IronPython specific artifacts
# If IronPython interpreter is found, use its path
unset (_${_PYTHON_PREFIX}_IRON_ROOT)
if (${_PYTHON_PREFIX}_Interpreter_FOUND AND ${_PYTHON_PREFIX}_INTERPRETER_ID STREQUAL "IronPython")
get_filename_component (_${_PYTHON_PREFIX}_IRON_ROOT "${${_PYTHON_PREFIX}_EXECUTABLE}" DIRECTORY)
endif()
# try using root dir and registry
foreach (_${_PYTHON_PREFIX}_VERSION IN LISTS _${_PYTHON_PREFIX}_FIND_VERSIONS)
if (_${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "FIRST")
find_program (${_PYTHON_PREFIX}_COMPILER
NAMES ipyc
HINTS ${_${_PYTHON_PREFIX}_IRON_ROOT} ${_${_PYTHON_PREFIX}_HINTS}
PATHS [HKEY_LOCAL_MACHINE\\SOFTWARE\\IronPython\\${_${_PYTHON_PREFIX}_VERSION}\\InstallPath]
PATH_SUFFIXES ${_${_PYTHON_PREFIX}_IRON_PYTHON_PATH_SUFFIXES}
NO_SYSTEM_ENVIRONMENT_PATH
NO_CMAKE_SYSTEM_PATH)
endif()
find_program (${_PYTHON_PREFIX}_COMPILER
NAMES ipyc
HINTS ${_${_PYTHON_PREFIX}_IRON_ROOT} ${_${_PYTHON_PREFIX}_HINTS}
PATH_SUFFIXES ${_${_PYTHON_PREFIX}_IRON_PYTHON_PATH_SUFFIXES}
NO_SYSTEM_ENVIRONMENT_PATH
NO_CMAKE_SYSTEM_PATH)
if (_${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "LAST")
find_program (${_PYTHON_PREFIX}_COMPILER
NAMES ipyc
PATHS [HKEY_LOCAL_MACHINE\\SOFTWARE\\IronPython\\${_${_PYTHON_PREFIX}_VERSION}\\InstallPath]
PATH_SUFFIXES ${_${_PYTHON_PREFIX}_IRON_PYTHON_PATH_SUFFIXES}
NO_DEFAULT_PATH)
endif()
_python_validate_compiler (${_${_PYTHON_PREFIX}_VERSION})
if (${_PYTHON_PREFIX}_COMPILER)
break()
endif()
endforeach()
# no specific version found, re-try in standard paths
find_program (${_PYTHON_PREFIX}_COMPILER
NAMES ipyc
HINTS ${_${_PYTHON_PREFIX}_IRON_ROOT} ${_${_PYTHON_PREFIX}_HINTS}
PATH_SUFFIXES ${_${_PYTHON_PREFIX}_IRON_PYTHON_PATH_SUFFIXES})
if (${_PYTHON_PREFIX}_COMPILER)
# retrieve python environment version from compiler
set (_${_PYTHON_PREFIX}_VERSION_DIR "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/PythonCompilerVersion.dir")
file (WRITE "${_${_PYTHON_PREFIX}_VERSION_DIR}/version.py" "import sys; sys.stdout.write('.'.join([str(x) for x in sys.version_info[:3]]))\n")
execute_process (COMMAND "${${_PYTHON_PREFIX}_COMPILER}" /target:exe /embed "${_${_PYTHON_PREFIX}_VERSION_DIR}/version.py"
WORKING_DIRECTORY "${_${_PYTHON_PREFIX}_VERSION_DIR}"
OUTPUT_QUIET
ERROR_QUIET)
execute_process (COMMAND "${_${_PYTHON_PREFIX}_VERSION_DIR}/version"
WORKING_DIRECTORY "${_${_PYTHON_PREFIX}_VERSION_DIR}"
RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT
OUTPUT_VARIABLE _${_PYTHON_PREFIX}_VERSION
ERROR_QUIET)
if (NOT _${_PYTHON_PREFIX}_RESULT)
string (REGEX MATCHALL "[0-9]+" _${_PYTHON_PREFIX}_VERSIONS "${_${_PYTHON_PREFIX}_VERSION}")
list (GET _${_PYTHON_PREFIX}_VERSIONS 0 _${_PYTHON_PREFIX}_VERSION_MAJOR)
list (GET _${_PYTHON_PREFIX}_VERSIONS 1 _${_PYTHON_PREFIX}_VERSION_MINOR)
list (GET _${_PYTHON_PREFIX}_VERSIONS 2 _${_PYTHON_PREFIX}_VERSION_PATCH)
if (NOT ${_PYTHON_PREFIX}_Interpreter_FOUND)
# set public version information
set (${_PYTHON_PREFIX}_VERSION ${_${_PYTHON_PREFIX}_VERSION})
set (${_PYTHON_PREFIX}_VERSION_MAJOR ${_${_PYTHON_PREFIX}_VERSION_MAJOR})
set (${_PYTHON_PREFIX}_VERSION_MINOR ${_${_PYTHON_PREFIX}_VERSION_MINOR})
set (${_PYTHON_PREFIX}_VERSION_PATCH ${_${_PYTHON_PREFIX}_VERSION_PATCH})
endif()
else()
# compiler not usable
set (${_PYTHON_PREFIX}_COMPILER ${_PYTHON_PREFIX}_COMPILER-NOTFOUND CACHE INTERNAL "" FORCE)
endif()
file (REMOVE_RECURSE "${_${_PYTHON_PREFIX}_VERSION_DIR}")
endif()
if (${_PYTHON_PREFIX}_COMPILER)
if (${_PYTHON_PREFIX}_Interpreter_FOUND)
# Compiler must be compatible with interpreter
if (${_${_PYTHON_PREFIX}_VERSION_MAJOR}.${_${_PYTHON_PREFIX}_VERSION_MINOR} VERSION_EQUAL ${${_PYTHON_PREFIX}_VERSION_MAJOR}.${${_PYTHON_PREFIX}_VERSION_MINOR})
set (${_PYTHON_PREFIX}_Compiler_FOUND TRUE)
endif()
elseif (${_PYTHON_PREFIX}_VERSION_MAJOR VERSION_EQUAL _${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR)
set (${_PYTHON_PREFIX}_Compiler_FOUND TRUE)
# Use compiler version for future searches to ensure consistency
set (_${_PYTHON_PREFIX}_FIND_VERSIONS ${${_PYTHON_PREFIX}_VERSION_MAJOR}.${${_PYTHON_PREFIX}_VERSION_MINOR})
endif()
endif()
if (${_PYTHON_PREFIX}_Compiler_FOUND)
set (${_PYTHON_PREFIX}_COMPILER_ID IronPython)
else()
unset (${_PYTHON_PREFIX}_COMPILER_ID)
endif()
mark_as_advanced (${_PYTHON_PREFIX}_COMPILER)
endif()
# third step, search for the development artifacts
## Development environment is not compatible with IronPython interpreter
if ("Development" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS
AND NOT ${_PYTHON_PREFIX}_INTERPRETER_ID STREQUAL "IronPython")
if (${_PYTHON_PREFIX}_FIND_REQUIRED_Development)
list (APPEND _${_PYTHON_PREFIX}_REQUIRED_VARS ${_PYTHON_PREFIX}_LIBRARY
${_PYTHON_PREFIX}_INCLUDE_DIR)
list (APPEND _${_PYTHON_PREFIX}_CACHED_VARS ${_PYTHON_PREFIX}_LIBRARY
${_PYTHON_PREFIX}_LIBRARY_RELEASE
${_PYTHON_PREFIX}_RUNTIME_LIBRARY_RELEASE
${_PYTHON_PREFIX}_LIBRARY_DEBUG
${_PYTHON_PREFIX}_RUNTIME_LIBRARY_DEBUG
${_PYTHON_PREFIX}_INCLUDE_DIR)
endif()
# Support preference of static libs by adjusting CMAKE_FIND_LIBRARY_SUFFIXES
unset (_${_PYTHON_PREFIX}_CMAKE_FIND_LIBRARY_SUFFIXES)
if (DEFINED ${_PYTHON_PREFIX}_USE_STATIC_LIBS AND NOT WIN32)
set(_${_PYTHON_PREFIX}_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
if(${_PYTHON_PREFIX}_USE_STATIC_LIBS)
set (CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_STATIC_LIBRARY_SUFFIX})
else()
list (REMOVE_ITEM CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_STATIC_LIBRARY_SUFFIX})
endif()
else()
endif()
# if python interpreter is found, use its location and version to ensure consistency
# between interpreter and development environment
unset (_${_PYTHON_PREFIX}_PREFIX)
if (${_PYTHON_PREFIX}_Interpreter_FOUND)
execute_process (COMMAND "${${_PYTHON_PREFIX}_EXECUTABLE}" -c
"import sys; from distutils import sysconfig; sys.stdout.write(sysconfig.PREFIX)"
RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT
OUTPUT_VARIABLE _${_PYTHON_PREFIX}_PREFIX
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
if (_${_PYTHON_PREFIX}_RESULT)
unset (_${_PYTHON_PREFIX}_PREFIX)
endif()
endif()
set (_${_PYTHON_PREFIX}_HINTS "${_${_PYTHON_PREFIX}_PREFIX}" "${${_PYTHON_PREFIX}_ROOT_DIR}" ENV ${_PYTHON_PREFIX}_ROOT_DIR)
foreach (_${_PYTHON_PREFIX}_VERSION IN LISTS _${_PYTHON_PREFIX}_FIND_VERSIONS)
string (REPLACE "." "" _${_PYTHON_PREFIX}_VERSION_NO_DOTS ${_${_PYTHON_PREFIX}_VERSION})
# try to use pythonX.Y-config tool
set (_${_PYTHON_PREFIX}_CONFIG_NAMES)
if (DEFINED CMAKE_LIBRARY_ARCHITECTURE)
set (_${_PYTHON_PREFIX}_CONFIG_NAMES "${CMAKE_LIBRARY_ARCHITECTURE}-python${_${_PYTHON_PREFIX}_VERSION}-config")
endif()
list (APPEND _${_PYTHON_PREFIX}_CONFIG_NAMES "python${_${_PYTHON_PREFIX}_VERSION}-config")
find_program (_${_PYTHON_PREFIX}_CONFIG
NAMES ${_${_PYTHON_PREFIX}_CONFIG_NAMES}
NAMES_PER_DIR
HINTS ${_${_PYTHON_PREFIX}_HINTS}
PATH_SUFFIXES bin)
unset (_${_PYTHON_PREFIX}_CONFIG_NAMES)
if (NOT _${_PYTHON_PREFIX}_CONFIG)
continue()
endif()
if (DEFINED CMAKE_LIBRARY_ARCHITECTURE)
# check that config tool match library architecture
execute_process (COMMAND "${_${_PYTHON_PREFIX}_CONFIG}" --configdir
RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT
OUTPUT_VARIABLE _${_PYTHON_PREFIX}_CONFIGDIR
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
if (_${_PYTHON_PREFIX}_RESULT)
unset (_${_PYTHON_PREFIX}_CONFIG CACHE)
continue()
endif()
string(FIND "${_${_PYTHON_PREFIX}_CONFIGDIR}" "${CMAKE_LIBRARY_ARCHITECTURE}" _${_PYTHON_PREFIX}_RESULT)
if (_${_PYTHON_PREFIX}_RESULT EQUAL -1)
unset (_${_PYTHON_PREFIX}_CONFIG CACHE)
continue()
endif()
endif()
# retrieve root install directory
execute_process (COMMAND "${_${_PYTHON_PREFIX}_CONFIG}" --prefix
RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT
OUTPUT_VARIABLE _${_PYTHON_PREFIX}_PREFIX
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
if (_${_PYTHON_PREFIX}_RESULT)
# python-config is not usable
unset (_${_PYTHON_PREFIX}_CONFIG CACHE)
continue()
endif()
set (_${_PYTHON_PREFIX}_HINTS "${_${_PYTHON_PREFIX}_PREFIX}" "${${_PYTHON_PREFIX}_ROOT_DIR}" ENV ${_PYTHON_PREFIX}_ROOT_DIR)
# retrieve library
execute_process (COMMAND "${_${_PYTHON_PREFIX}_CONFIG}" --ldflags
RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT
OUTPUT_VARIABLE _${_PYTHON_PREFIX}_FLAGS
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
if (NOT _${_PYTHON_PREFIX}_RESULT)
# retrieve library directory
string (REGEX MATCHALL "-L[^ ]+" _${_PYTHON_PREFIX}_LIB_DIRS "${_${_PYTHON_PREFIX}_FLAGS}")
string (REPLACE "-L" "" _${_PYTHON_PREFIX}_LIB_DIRS "${_${_PYTHON_PREFIX}_LIB_DIRS}")
list (REMOVE_DUPLICATES _${_PYTHON_PREFIX}_LIB_DIRS)
# retrieve library name
string (REGEX MATCHALL "-lpython[^ ]+" _${_PYTHON_PREFIX}_LIB_NAMES "${_${_PYTHON_PREFIX}_FLAGS}")
string (REPLACE "-l" "" _${_PYTHON_PREFIX}_LIB_NAMES "${_${_PYTHON_PREFIX}_LIB_NAMES}")
list (REMOVE_DUPLICATES _${_PYTHON_PREFIX}_LIB_NAMES)
find_library (${_PYTHON_PREFIX}_LIBRARY_RELEASE
NAMES ${_${_PYTHON_PREFIX}_LIB_NAMES}
NAMES_PER_DIR
HINTS ${_${_PYTHON_PREFIX}_HINTS} ${_${_PYTHON_PREFIX}_LIB_DIRS}
PATH_SUFFIXES lib
NO_SYSTEM_ENVIRONMENT_PATH
NO_CMAKE_SYSTEM_PATH)
# retrieve runtime library
if (${_PYTHON_PREFIX}_LIBRARY_RELEASE)
get_filename_component (_${_PYTHON_PREFIX}_PATH "${${_PYTHON_PREFIX}_LIBRARY_RELEASE}" DIRECTORY)
_python_find_runtime_library (${_PYTHON_PREFIX}_RUNTIME_LIBRARY_RELEASE
NAMES ${_${_PYTHON_PREFIX}_LIB_NAMES}
NAMES_PER_DIR
HINTS ${_${_PYTHON_PREFIX}_PATH} ${_${_PYTHON_PREFIX}_HINTS}
PATH_SUFFIXES bin
NO_SYSTEM_ENVIRONMENT_PATH
NO_CMAKE_SYSTEM_PATH)
endif()
endif()
# retrieve include directory
execute_process (COMMAND "${_${_PYTHON_PREFIX}_CONFIG}" --includes
RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT
OUTPUT_VARIABLE _${_PYTHON_PREFIX}_FLAGS
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
if (NOT _${_PYTHON_PREFIX}_RESULT)
# retrieve include directory
string (REGEX MATCHALL "-I[^ ]+" _${_PYTHON_PREFIX}_INCLUDE_DIRS "${_${_PYTHON_PREFIX}_FLAGS}")
string (REPLACE "-I" "" _${_PYTHON_PREFIX}_INCLUDE_DIRS "${_${_PYTHON_PREFIX}_INCLUDE_DIRS}")
list (REMOVE_DUPLICATES _${_PYTHON_PREFIX}_INCLUDE_DIRS)
find_path (${_PYTHON_PREFIX}_INCLUDE_DIR
NAMES Python.h
HINTS ${_${_PYTHON_PREFIX}_INCLUDE_DIRS}
NO_SYSTEM_ENVIRONMENT_PATH
NO_CMAKE_SYSTEM_PATH)
endif()
if (${_PYTHON_PREFIX}_LIBRARY_RELEASE AND ${_PYTHON_PREFIX}_INCLUDE_DIR)
break()
endif()
endforeach()
# Rely on HINTS and standard paths if config tool failed to locate artifacts
if (NOT (${_PYTHON_PREFIX}_LIBRARY_RELEASE OR ${_PYTHON_PREFIX}_LIBRARY_DEBUG) OR NOT ${_PYTHON_PREFIX}_INCLUDE_DIR)
foreach (_${_PYTHON_PREFIX}_VERSION IN LISTS _${_PYTHON_PREFIX}_FIND_VERSIONS)
string (REPLACE "." "" _${_PYTHON_PREFIX}_VERSION_NO_DOTS ${_${_PYTHON_PREFIX}_VERSION})
_python_get_frameworks (_${_PYTHON_PREFIX}_FRAMEWORK_PATHS ${_${_PYTHON_PREFIX}_VERSION})
set (_${_PYTHON_PREFIX}_REGISTRY_PATHS
[HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_${_PYTHON_PREFIX}_VERSION}-${_${_PYTHON_PREFIX}_ARCH}\\InstallPath]
[HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_${_PYTHON_PREFIX}_VERSION}-${_${_PYTHON_PREFIX}_ARCH2}\\InstallPath]
[HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_${_PYTHON_PREFIX}_VERSION}\\InstallPath]
[HKEY_CURRENT_USER\\SOFTWARE\\Python\\ContinuumAnalytics\\Anaconda${_${_PYTHON_PREFIX}_VERSION_NO_DOTS}-${_${_PYTHON_PREFIX}_ARCH}\\InstallPath]
[HKEY_CURRENT_USER\\SOFTWARE\\Python\\ContinuumAnalytics\\Anaconda${_${_PYTHON_PREFIX}_VERSION_NO_DOTS}-${_${_PYTHON_PREFIX}_ARCH2}\\InstallPath]
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_${_PYTHON_PREFIX}_VERSION}-${_${_PYTHON_PREFIX}_ARCH}\\InstallPath]
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_${_PYTHON_PREFIX}_VERSION}-${_${_PYTHON_PREFIX}_ARCH2}\\InstallPath]
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_${_PYTHON_PREFIX}_VERSION}\\InstallPath]
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\ContinuumAnalytics\\Anaconda${_${_PYTHON_PREFIX}_VERSION_NO_DOTS}-${_${_PYTHON_PREFIX}_ARCH}\\InstallPath]
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\ContinuumAnalytics\\Anaconda${_${_PYTHON_PREFIX}_VERSION_NO_DOTS}-${_${_PYTHON_PREFIX}_ARCH2}\\InstallPath])
if (APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "FIRST")
find_library (${_PYTHON_PREFIX}_LIBRARY_RELEASE
NAMES python${_${_PYTHON_PREFIX}_VERSION_NO_DOTS}
python${_${_PYTHON_PREFIX}_VERSION}mu
python${_${_PYTHON_PREFIX}_VERSION}m
python${_${_PYTHON_PREFIX}_VERSION}u
python${_${_PYTHON_PREFIX}_VERSION}
NAMES_PER_DIR
PATHS ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS}
PATH_SUFFIXES lib/${CMAKE_LIBRARY_ARCHITECTURE} lib libs
lib/python${_${_PYTHON_PREFIX}_VERSION}/config-${_${_PYTHON_PREFIX}_VERSION}mu
lib/python${_${_PYTHON_PREFIX}_VERSION}/config-${_${_PYTHON_PREFIX}_VERSION}m
lib/python${_${_PYTHON_PREFIX}_VERSION}/config-${_${_PYTHON_PREFIX}_VERSION}u
lib/python${_${_PYTHON_PREFIX}_VERSION}/config-${_${_PYTHON_PREFIX}_VERSION}
lib/python${_${_PYTHON_PREFIX}_VERSION}/config
NO_CMAKE_PATH
NO_CMAKE_ENVIRONMENT_PATH
NO_SYSTEM_ENVIRONMENT_PATH
NO_CMAKE_SYSTEM_PATH)
endif()
if (WIN32 AND _${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "FIRST")
find_library (${_PYTHON_PREFIX}_LIBRARY_RELEASE
NAMES python${_${_PYTHON_PREFIX}_VERSION_NO_DOTS}
python${_${_PYTHON_PREFIX}_VERSION}mu
python${_${_PYTHON_PREFIX}_VERSION}m
python${_${_PYTHON_PREFIX}_VERSION}u
python${_${_PYTHON_PREFIX}_VERSION}
NAMES_PER_DIR
HINTS ${_${_PYTHON_PREFIX}_HINTS}
PATHS ${_${_PYTHON_PREFIX}_REGISTRY_PATHS}
PATH_SUFFIXES lib/${CMAKE_LIBRARY_ARCHITECTURE} lib libs
lib/python${_${_PYTHON_PREFIX}_VERSION}/config-${_${_PYTHON_PREFIX}_VERSION}mu
lib/python${_${_PYTHON_PREFIX}_VERSION}/config-${_${_PYTHON_PREFIX}_VERSION}m
lib/python${_${_PYTHON_PREFIX}_VERSION}/config-${_${_PYTHON_PREFIX}_VERSION}u
lib/python${_${_PYTHON_PREFIX}_VERSION}/config-${_${_PYTHON_PREFIX}_VERSION}
lib/python${_${_PYTHON_PREFIX}_VERSION}/config
NO_SYSTEM_ENVIRONMENT_PATH
NO_CMAKE_SYSTEM_PATH)
endif()
# search in HINTS locations
find_library (${_PYTHON_PREFIX}_LIBRARY_RELEASE
NAMES python${_${_PYTHON_PREFIX}_VERSION_NO_DOTS}
python${_${_PYTHON_PREFIX}_VERSION}mu
python${_${_PYTHON_PREFIX}_VERSION}m
python${_${_PYTHON_PREFIX}_VERSION}u
python${_${_PYTHON_PREFIX}_VERSION}
NAMES_PER_DIR
HINTS ${_${_PYTHON_PREFIX}_HINTS}
PATH_SUFFIXES lib/${CMAKE_LIBRARY_ARCHITECTURE} lib libs
lib/python${_${_PYTHON_PREFIX}_VERSION}/config-${_${_PYTHON_PREFIX}_VERSION}mu
lib/python${_${_PYTHON_PREFIX}_VERSION}/config-${_${_PYTHON_PREFIX}_VERSION}m
lib/python${_${_PYTHON_PREFIX}_VERSION}/config-${_${_PYTHON_PREFIX}_VERSION}u
lib/python${_${_PYTHON_PREFIX}_VERSION}/config-${_${_PYTHON_PREFIX}_VERSION}
lib/python${_${_PYTHON_PREFIX}_VERSION}/config
NO_SYSTEM_ENVIRONMENT_PATH
NO_CMAKE_SYSTEM_PATH)
if (APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "LAST")
set (__${_PYTHON_PREFIX}_FRAMEWORK_PATHS ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS})
else()
unset (__${_PYTHON_PREFIX}_FRAMEWORK_PATHS)
endif()
if (WIN32 AND _${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "LAST")
set (__${_PYTHON_PREFIX}_REGISTRY_PATHS ${_${_PYTHON_PREFIX}_REGISTRY_PATHS})
else()
unset (__${_PYTHON_PREFIX}_REGISTRY_PATHS)
endif()
# search in all default paths
find_library (${_PYTHON_PREFIX}_LIBRARY_RELEASE
NAMES python${_${_PYTHON_PREFIX}_VERSION_NO_DOTS}
python${_${_PYTHON_PREFIX}_VERSION}mu
python${_${_PYTHON_PREFIX}_VERSION}m
python${_${_PYTHON_PREFIX}_VERSION}u
python${_${_PYTHON_PREFIX}_VERSION}
NAMES_PER_DIR
PATHS ${__${_PYTHON_PREFIX}_FRAMEWORK_PATHS}
${__${_PYTHON_PREFIX}_REGISTRY_PATHS}
PATH_SUFFIXES lib/${CMAKE_LIBRARY_ARCHITECTURE} lib libs
lib/python${_${_PYTHON_PREFIX}_VERSION}/config-${_${_PYTHON_PREFIX}_VERSION}mu
lib/python${_${_PYTHON_PREFIX}_VERSION}/config-${_${_PYTHON_PREFIX}_VERSION}m
lib/python${_${_PYTHON_PREFIX}_VERSION}/config-${_${_PYTHON_PREFIX}_VERSION}u
lib/python${_${_PYTHON_PREFIX}_VERSION}/config-${_${_PYTHON_PREFIX}_VERSION}
lib/python${_${_PYTHON_PREFIX}_VERSION}/config)
# retrieve runtime library
if (${_PYTHON_PREFIX}_LIBRARY_RELEASE)
get_filename_component (_${_PYTHON_PREFIX}_PATH "${${_PYTHON_PREFIX}_LIBRARY_RELEASE}" DIRECTORY)
_python_find_runtime_library (${_PYTHON_PREFIX}_RUNTIME_LIBRARY_RELEASE
NAMES python${_${_PYTHON_PREFIX}_VERSION_NO_DOTS}
python${_${_PYTHON_PREFIX}_VERSION}mu
python${_${_PYTHON_PREFIX}_VERSION}m
python${_${_PYTHON_PREFIX}_VERSION}u
python${_${_PYTHON_PREFIX}_VERSION}
NAMES_PER_DIR
HINTS "${_${_PYTHON_PREFIX}_PATH}" ${_${_PYTHON_PREFIX}_HINTS}
PATH_SUFFIXES bin)
endif()
if (WIN32)
# search for debug library
if (${_PYTHON_PREFIX}_LIBRARY_RELEASE)
# use library location as a hint
get_filename_component (_${_PYTHON_PREFIX}_PATH "${${_PYTHON_PREFIX}_LIBRARY_RELEASE}" DIRECTORY)
find_library (${_PYTHON_PREFIX}_LIBRARY_DEBUG
NAMES python${_${_PYTHON_PREFIX}_VERSION_NO_DOTS}_d
NAMES_PER_DIR
HINTS "${_${_PYTHON_PREFIX}_PATH}" ${_${_PYTHON_PREFIX}_HINTS}
NO_DEFAULT_PATH)
else()
# search first in known locations
if (_${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "FIRST")
find_library (${_PYTHON_PREFIX}_LIBRARY_DEBUG
NAMES python${_${_PYTHON_PREFIX}_VERSION_NO_DOTS}_d
NAMES_PER_DIR
HINTS ${_${_PYTHON_PREFIX}_HINTS}
PATHS ${_${_PYTHON_PREFIX}_REGISTRY_PATHS}
PATH_SUFFIXES lib libs
NO_SYSTEM_ENVIRONMENT_PATH
NO_CMAKE_SYSTEM_PATH)
endif()
# search in all default paths
find_library (${_PYTHON_PREFIX}_LIBRARY_DEBUG
NAMES python${_${_PYTHON_PREFIX}_VERSION_NO_DOTS}_d
NAMES_PER_DIR
HINTS ${_${_PYTHON_PREFIX}_HINTS}
PATHS ${__${_PYTHON_PREFIX}_REGISTRY_PATHS}
PATH_SUFFIXES lib libs)
endif()
if (${_PYTHON_PREFIX}_LIBRARY_DEBUG)
get_filename_component (_${_PYTHON_PREFIX}_PATH "${${_PYTHON_PREFIX}_LIBRARY_DEBUG}" DIRECTORY)
_python_find_runtime_library (${_PYTHON_PREFIX}_RUNTIME_LIBRARY_DEBUG
NAMES python${_${_PYTHON_PREFIX}_VERSION_NO_DOTS}_d
NAMES_PER_DIR
HINTS "${_${_PYTHON_PREFIX}_PATH}" ${_${_PYTHON_PREFIX}_HINTS}
PATH_SUFFIXES bin)
endif()
endif()
# Don't search for include dir until library location is known
if (${_PYTHON_PREFIX}_LIBRARY_RELEASE OR ${_PYTHON_PREFIX}_LIBRARY_DEBUG)
unset (_${_PYTHON_PREFIX}_INCLUDE_HINTS)
if (${_PYTHON_PREFIX}_EXECUTABLE)
# pick up include directory from configuration
execute_process (COMMAND "${${_PYTHON_PREFIX}_EXECUTABLE}" -c
"import sys; import sysconfig; sys.stdout.write(sysconfig.get_path('include'))"
RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT
OUTPUT_VARIABLE _${_PYTHON_PREFIX}_PATH
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
if (NOT _${_PYTHON_PREFIX}_RESULT)
file (TO_CMAKE_PATH "${_${_PYTHON_PREFIX}_PATH}" _${_PYTHON_PREFIX}_PATH)
list (APPEND _${_PYTHON_PREFIX}_INCLUDE_HINTS "${_${_PYTHON_PREFIX}_PATH}")
endif()
endif()
foreach (_${_PYTHON_PREFIX}_LIB IN ITEMS ${_PYTHON_PREFIX}_LIBRARY_RELEASE ${_PYTHON_PREFIX}_LIBRARY_DEBUG)
if (${_${_PYTHON_PREFIX}_LIB})
# Use the library's install prefix as a hint
if (${_${_PYTHON_PREFIX}_LIB} MATCHES "^(.+/Frameworks/Python.framework/Versions/[0-9.]+)")
list (APPEND _${_PYTHON_PREFIX}_INCLUDE_HINTS "${CMAKE_MATCH_1}")
elseif (${_${_PYTHON_PREFIX}_LIB} MATCHES "^(.+)/lib(64|32)?/python[0-9.]+/config")
list (APPEND _${_PYTHON_PREFIX}_INCLUDE_HINTS "${CMAKE_MATCH_1}")
elseif (DEFINED CMAKE_LIBRARY_ARCHITECTURE AND ${_${_PYTHON_PREFIX}_LIB} MATCHES "^(.+)/lib/${CMAKE_LIBRARY_ARCHITECTURE}")
list (APPEND _${_PYTHON_PREFIX}_INCLUDE_HINTS "${CMAKE_MATCH_1}")
else()
# assume library is in a directory under root
get_filename_component (_${_PYTHON_PREFIX}_PREFIX "${${_${_PYTHON_PREFIX}_LIB}}" DIRECTORY)
get_filename_component (_${_PYTHON_PREFIX}_PREFIX "${_${_PYTHON_PREFIX}_PREFIX}" DIRECTORY)
list (APPEND _${_PYTHON_PREFIX}_INCLUDE_HINTS "${_${_PYTHON_PREFIX}_PREFIX}")
endif()
endif()
endforeach()
list (REMOVE_DUPLICATES _${_PYTHON_PREFIX}_INCLUDE_HINTS)
if (APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "FIRST")
find_path (${_PYTHON_PREFIX}_INCLUDE_DIR
NAMES Python.h
HINTS ${_${_PYTHON_PREFIX}_HINTS}
PATHS ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS}
PATH_SUFFIXES include/python${_${_PYTHON_PREFIX}_VERSION}mu
include/python${_${_PYTHON_PREFIX}_VERSION}m
include/python${_${_PYTHON_PREFIX}_VERSION}u
include/python${_${_PYTHON_PREFIX}_VERSION}
include
NO_CMAKE_PATH
NO_CMAKE_ENVIRONMENT_PATH
NO_SYSTEM_ENVIRONMENT_PATH
NO_CMAKE_SYSTEM_PATH)
endif()
if (WIN32 AND _${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "FIRST")
find_path (${_PYTHON_PREFIX}_INCLUDE_DIR
NAMES Python.h
HINTS ${_${_PYTHON_PREFIX}_INCLUDE_HINTS} ${_${_PYTHON_PREFIX}_HINTS}
PATHS ${_${_PYTHON_PREFIX}_REGISTRY_PATHS}
PATH_SUFFIXES include/python${_${_PYTHON_PREFIX}_VERSION}mu
include/python${_${_PYTHON_PREFIX}_VERSION}m
include/python${_${_PYTHON_PREFIX}_VERSION}u
include/python${_${_PYTHON_PREFIX}_VERSION}
include
NO_SYSTEM_ENVIRONMENT_PATH
NO_CMAKE_SYSTEM_PATH)
endif()
find_path (${_PYTHON_PREFIX}_INCLUDE_DIR
NAMES Python.h
HINTS ${_${_PYTHON_PREFIX}_INCLUDE_HINTS} ${_${_PYTHON_PREFIX}_HINTS}
PATHS ${__${_PYTHON_PREFIX}_FRAMEWORK_PATHS}
${__${_PYTHON_PREFIX}_REGISTRY_PATHS}
PATH_SUFFIXES include/python${_${_PYTHON_PREFIX}_VERSION}mu
include/python${_${_PYTHON_PREFIX}_VERSION}m
include/python${_${_PYTHON_PREFIX}_VERSION}u
include/python${_${_PYTHON_PREFIX}_VERSION}
include
NO_SYSTEM_ENVIRONMENT_PATH
NO_CMAKE_SYSTEM_PATH)
endif()
if ((${_PYTHON_PREFIX}_LIBRARY_RELEASE OR ${_PYTHON_PREFIX}_LIBRARY_DEBUG) AND ${_PYTHON_PREFIX}_INCLUDE_DIR)
break()
endif()
endforeach()
# search header file in standard locations
find_path (${_PYTHON_PREFIX}_INCLUDE_DIR
NAMES Python.h)
endif()
if (${_PYTHON_PREFIX}_INCLUDE_DIR)
# retrieve version from header file
file (STRINGS "${${_PYTHON_PREFIX}_INCLUDE_DIR}/patchlevel.h" _${_PYTHON_PREFIX}_VERSION
REGEX "^#define[ \t]+PY_VERSION[ \t]+\"[^\"]+\"")
string (REGEX REPLACE "^#define[ \t]+PY_VERSION[ \t]+\"([^\"]+)\".*" "\\1"
_${_PYTHON_PREFIX}_VERSION "${_${_PYTHON_PREFIX}_VERSION}")
string (REGEX MATCHALL "[0-9]+" _${_PYTHON_PREFIX}_VERSIONS "${_${_PYTHON_PREFIX}_VERSION}")
list (GET _${_PYTHON_PREFIX}_VERSIONS 0 _${_PYTHON_PREFIX}_VERSION_MAJOR)
list (GET _${_PYTHON_PREFIX}_VERSIONS 1 _${_PYTHON_PREFIX}_VERSION_MINOR)
list (GET _${_PYTHON_PREFIX}_VERSIONS 2 _${_PYTHON_PREFIX}_VERSION_PATCH)
if (NOT ${_PYTHON_PREFIX}_Interpreter_FOUND AND NOT ${_PYTHON_PREFIX}_Compiler_FOUND)
# set public version information
set (${_PYTHON_PREFIX}_VERSION ${_${_PYTHON_PREFIX}_VERSION})
set (${_PYTHON_PREFIX}_VERSION_MAJOR ${_${_PYTHON_PREFIX}_VERSION_MAJOR})
set (${_PYTHON_PREFIX}_VERSION_MINOR ${_${_PYTHON_PREFIX}_VERSION_MINOR})
set (${_PYTHON_PREFIX}_VERSION_PATCH ${_${_PYTHON_PREFIX}_VERSION_PATCH})
endif()
endif()
# define public variables
include (${CMAKE_CURRENT_LIST_DIR}/../SelectLibraryConfigurations.cmake)
select_library_configurations (${_PYTHON_PREFIX})
if (${_PYTHON_PREFIX}_RUNTIME_LIBRARY_RELEASE)
set (${_PYTHON_PREFIX}_RUNTIME_LIBRARY "${${_PYTHON_PREFIX}_RUNTIME_LIBRARY_RELEASE}")
elseif (${_PYTHON_PREFIX}_RUNTIME_LIBRARY_DEBUG)
set (${_PYTHON_PREFIX}_RUNTIME_LIBRARY "${${_PYTHON_PREFIX}_RUNTIME_LIBRARY_DEBUG}")
else()
set (${_PYTHON_PREFIX}_RUNTIME_LIBRARY "$${_PYTHON_PREFIX}_RUNTIME_LIBRARY-NOTFOUND")
endif()
_python_set_library_dirs (${_PYTHON_PREFIX}_LIBRARY_DIRS
${_PYTHON_PREFIX}_LIBRARY_RELEASE ${_PYTHON_PREFIX}_LIBRARY_DEBUG)
if (UNIX)
if (${_PYTHON_PREFIX}_LIBRARY_RELEASE MATCHES "${CMAKE_SHARED_LIBRARY_SUFFIX}$"
OR ${_PYTHON_PREFIX}_LIBRARY_RELEASE MATCHES "${CMAKE_SHARED_LIBRARY_SUFFIX}$")
set (${_PYTHON_PREFIX}_RUNTIME_LIBRARY_DIRS ${${_PYTHON_PREFIX}_LIBRARY_DIRS})
endif()
else()
_python_set_library_dirs (${_PYTHON_PREFIX}_RUNTIME_LIBRARY_DIRS
${_PYTHON_PREFIX}_RUNTIME_LIBRARY_RELEASE ${_PYTHON_PREFIX}_RUNTIME_LIBRARY_DEBUG)
endif()
set (${_PYTHON_PREFIX}_INCLUDE_DIRS "${${_PYTHON_PREFIX}_INCLUDE_DIR}")
mark_as_advanced (${_PYTHON_PREFIX}_RUNTIME_LIBRARY_RELEASE
${_PYTHON_PREFIX}_RUNTIME_LIBRARY_DEBUG
${_PYTHON_PREFIX}_INCLUDE_DIR)
if ((${_PYTHON_PREFIX}_LIBRARY_RELEASE OR ${_PYTHON_PREFIX}_LIBRARY_DEBUG)
AND ${_PYTHON_PREFIX}_INCLUDE_DIR)
if (${_PYTHON_PREFIX}_Interpreter_FOUND OR ${_PYTHON_PREFIX}_Compiler_FOUND)
# development environment must be compatible with interpreter/compiler
if (${_${_PYTHON_PREFIX}_VERSION_MAJOR}.${_${_PYTHON_PREFIX}_VERSION_MINOR} VERSION_EQUAL ${${_PYTHON_PREFIX}_VERSION_MAJOR}.${${_PYTHON_PREFIX}_VERSION_MINOR})
set (${_PYTHON_PREFIX}_Development_FOUND TRUE)
endif()
elseif (${_PYTHON_PREFIX}_VERSION_MAJOR VERSION_EQUAL _${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR)
set (${_PYTHON_PREFIX}_Development_FOUND TRUE)
endif()
endif()
# Restore the original find library ordering
if (DEFINED _${_PYTHON_PREFIX}_CMAKE_FIND_LIBRARY_SUFFIXES)
set (CMAKE_FIND_LIBRARY_SUFFIXES ${_${_PYTHON_PREFIX}_CMAKE_FIND_LIBRARY_SUFFIXES})
endif()
endif()
if ("NumPy" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS AND ${_PYTHON_PREFIX}_Interpreter_FOUND)
if (${_PYTHON_PREFIX}_FIND_REQUIRED_NumPy)
list (APPEND _${_PYTHON_PREFIX}_REQUIRED_VARS ${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR)
list (APPEND _${_PYTHON_PREFIX}_CACHED_VARS ${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR)
endif()
execute_process(
COMMAND "${${_PYTHON_PREFIX}_EXECUTABLE}" -c
"from __future__ import print_function\ntry: import numpy; print(numpy.get_include(), end='')\nexcept:pass\n"
RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT
OUTPUT_VARIABLE _${_PYTHON_PREFIX}_NumPy_PATH
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
if (NOT _${_PYTHON_PREFIX}_RESULT)
find_path(${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR
NAMES "numpy/arrayobject.h" "numpy/numpyconfig.h"
HINTS "${_${_PYTHON_PREFIX}_NumPy_PATH}"
NO_DEFAULT_PATH)
endif()
if(${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR)
set(${_PYTHON_PREFIX}_NumPy_INCLUDE_DIRS "${${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR}")
set(${_PYTHON_PREFIX}_NumPy_FOUND TRUE)
endif()
if(${_PYTHON_PREFIX}_NumPy_FOUND)
execute_process(
COMMAND "${${_PYTHON_PREFIX}_EXECUTABLE}" -c
"from __future__ import print_function\ntry: import numpy; print(numpy.__version__, end='')\nexcept:pass\n"
RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT
OUTPUT_VARIABLE _${_PYTHON_PREFIX}_NumPy_VERSION)
if (NOT _${_PYTHON_PREFIX}_RESULT)
set(${_PYTHON_PREFIX}_NumPy_VERSION "${_${_PYTHON_PREFIX}_NumPy_VERSION}")
endif()
endif()
endif()
# final validation
if (${_PYTHON_PREFIX}_VERSION_MAJOR AND
NOT ${_PYTHON_PREFIX}_VERSION_MAJOR VERSION_EQUAL _${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR)
_python_display_failure ("Could NOT find ${_PYTHON_PREFIX}: Found unsuitable major version \"${${_PYTHON_PREFIX}_VERSION_MAJOR}\", but required major version is exact version \"${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR}\"")
endif()
find_package_handle_standard_args (${_PYTHON_PREFIX}
REQUIRED_VARS ${_${_PYTHON_PREFIX}_REQUIRED_VARS}
VERSION_VAR ${_PYTHON_PREFIX}_VERSION
HANDLE_COMPONENTS)
# Create imported targets and helper functions
if(_${_PYTHON_PREFIX}_CMAKE_ROLE STREQUAL "PROJECT")
if ("Interpreter" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS
AND ${_PYTHON_PREFIX}_Interpreter_FOUND
AND NOT TARGET ${_PYTHON_PREFIX}::Interpreter)
add_executable (${_PYTHON_PREFIX}::Interpreter IMPORTED)
set_property (TARGET ${_PYTHON_PREFIX}::Interpreter
PROPERTY IMPORTED_LOCATION "${${_PYTHON_PREFIX}_EXECUTABLE}")
endif()
if ("Compiler" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS
AND ${_PYTHON_PREFIX}_Compiler_FOUND
AND NOT TARGET ${_PYTHON_PREFIX}::Compiler)
add_executable (${_PYTHON_PREFIX}::Compiler IMPORTED)
set_property (TARGET ${_PYTHON_PREFIX}::Compiler
PROPERTY IMPORTED_LOCATION "${${_PYTHON_PREFIX}_COMPILER}")
endif()
if ("Development" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS
AND ${_PYTHON_PREFIX}_Development_FOUND AND NOT TARGET ${_PYTHON_PREFIX}::Python)
if (${_PYTHON_PREFIX}_LIBRARY_RELEASE MATCHES "${CMAKE_SHARED_LIBRARY_SUFFIX}$"
OR ${_PYTHON_PREFIX}_LIBRARY_DEBUG MATCHES "${CMAKE_SHARED_LIBRARY_SUFFIX}$"
OR ${_PYTHON_PREFIX}_RUNTIME_LIBRARY_RELEASE OR ${_PYTHON_PREFIX}_RUNTIME_LIBRARY_DEBUG)
set (_${_PYTHON_PREFIX}_LIBRARY_TYPE SHARED)
else()
set (_${_PYTHON_PREFIX}_LIBRARY_TYPE STATIC)
endif()
add_library (${_PYTHON_PREFIX}::Python ${_${_PYTHON_PREFIX}_LIBRARY_TYPE} IMPORTED)
set_property (TARGET ${_PYTHON_PREFIX}::Python
PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${${_PYTHON_PREFIX}_INCLUDE_DIR}")
if ((${_PYTHON_PREFIX}_LIBRARY_RELEASE AND ${_PYTHON_PREFIX}_RUNTIME_LIBRARY_RELEASE)
OR (${_PYTHON_PREFIX}_LIBRARY_DEBUG AND ${_PYTHON_PREFIX}_RUNTIME_LIBRARY_DEBUG))
# System manage shared libraries in two parts: import and runtime
if (${_PYTHON_PREFIX}_LIBRARY_RELEASE AND ${_PYTHON_PREFIX}_LIBRARY_DEBUG)
set_property (TARGET ${_PYTHON_PREFIX}::Python PROPERTY IMPORTED_CONFIGURATIONS RELEASE DEBUG)
set_target_properties (${_PYTHON_PREFIX}::Python
PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "C"
IMPORTED_IMPLIB_RELEASE "${${_PYTHON_PREFIX}_LIBRARY_RELEASE}"
IMPORTED_LOCATION_RELEASE "${${_PYTHON_PREFIX}_RUNTIME_LIBRARY_RELEASE}")
set_target_properties (${_PYTHON_PREFIX}::Python
PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "C"
IMPORTED_IMPLIB_DEBUG "${${_PYTHON_PREFIX}_LIBRARY_DEBUG}"
IMPORTED_LOCATION_DEBUG "${${_PYTHON_PREFIX}_RUNTIME_LIBRARY_DEBUG}")
else()
set_target_properties (${_PYTHON_PREFIX}::Python
PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_IMPLIB "${${_PYTHON_PREFIX}_LIBRARY}"
IMPORTED_LOCATION "${${_PYTHON_PREFIX}_RUNTIME_LIBRARY}")
endif()
else()
if (${_PYTHON_PREFIX}_LIBRARY_RELEASE AND ${_PYTHON_PREFIX}_LIBRARY_DEBUG)
set_property (TARGET ${_PYTHON_PREFIX}::Python PROPERTY IMPORTED_CONFIGURATIONS RELEASE DEBUG)
set_target_properties (${_PYTHON_PREFIX}::Python
PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "C"
IMPORTED_LOCATION_RELEASE "${${_PYTHON_PREFIX}_LIBRARY_RELEASE}")
set_target_properties (${_PYTHON_PREFIX}::Python
PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "C"
IMPORTED_LOCATION_DEBUG "${${_PYTHON_PREFIX}_LIBRARY_DEBUG}")
else()
set_target_properties (${_PYTHON_PREFIX}::Python
PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION "${${_PYTHON_PREFIX}_LIBRARY}")
endif()
endif()
if (_${_PYTHON_PREFIX}_CONFIG AND _${_PYTHON_PREFIX}_LIBRARY_TYPE STREQUAL "STATIC")
# extend link information with dependent libraries
execute_process (COMMAND "${_${_PYTHON_PREFIX}_CONFIG}" --ldflags
RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT
OUTPUT_VARIABLE _${_PYTHON_PREFIX}_FLAGS
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
if (NOT _${_PYTHON_PREFIX}_RESULT)
string (REGEX MATCHALL "-[Ll][^ ]+" _${_PYTHON_PREFIX}_LINK_LIBRARIES "${_${_PYTHON_PREFIX}_FLAGS}")
# remove elements relative to python library itself
list (FILTER _${_PYTHON_PREFIX}_LINK_LIBRARIES EXCLUDE REGEX "-lpython")
foreach (_${_PYTHON_PREFIX}_DIR IN LISTS ${_PYTHON_PREFIX}_LIBRARY_DIRS)
list (FILTER _${_PYTHON_PREFIX}_LINK_LIBRARIES EXCLUDE REGEX "-L${${_PYTHON_PREFIX}_DIR}")
endforeach()
set_property (TARGET ${_PYTHON_PREFIX}::Python
PROPERTY INTERFACE_LINK_LIBRARIES ${_${_PYTHON_PREFIX}_LINK_LIBRARIES})
endif()
endif()
#
# PYTHON_ADD_LIBRARY (<name> [STATIC|SHARED|MODULE] src1 src2 ... srcN)
# It is used to build modules for python.
#
function (__${_PYTHON_PREFIX}_ADD_LIBRARY prefix name)
cmake_parse_arguments (PARSE_ARGV 2 PYTHON_ADD_LIBRARY
"STATIC;SHARED;MODULE" "" "")
unset (type)
if (NOT (PYTHON_ADD_LIBRARY_STATIC
OR PYTHON_ADD_LIBRARY_SHARED
OR PYTHON_ADD_LIBRARY_MODULE))
set (type MODULE)
endif()
add_library (${name} ${type} ${ARGN})
target_link_libraries (${name} PRIVATE ${prefix}::Python)
# customize library name to follow module name rules
get_property (type TARGET ${name} PROPERTY TYPE)
if (type STREQUAL "MODULE_LIBRARY")
set_property (TARGET ${name} PROPERTY PREFIX "")
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
set_property (TARGET ${name} PROPERTY SUFFIX ".pyd")
endif()
endif()
endfunction()
endif()
if ("NumPy" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS AND ${_PYTHON_PREFIX}_NumPy_FOUND
AND NOT TARGET ${_PYTHON_PREFIX}::NumPy AND TARGET ${_PYTHON_PREFIX}::Python)
add_library (${_PYTHON_PREFIX}::NumPy INTERFACE IMPORTED)
set_property (TARGET ${_PYTHON_PREFIX}::NumPy
PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR}")
target_link_libraries (${_PYTHON_PREFIX}::NumPy INTERFACE ${_PYTHON_PREFIX}::Python)
endif()
endif()
# final clean-up
# Restore CMAKE_FIND_APPBUNDLE
if (DEFINED _${_PYTHON_PREFIX}_CMAKE_FIND_APPBUNDLE)
set (CMAKE_FIND_APPBUNDLE ${_${_PYTHON_PREFIX}_CMAKE_FIND_APPBUNDLE})
unset (_${_PYTHON_PREFIX}_CMAKE_FIND_APPBUNDLE)
else()
unset (CMAKE_FIND_APPBUNDLE)
endif()
# Restore CMAKE_FIND_FRAMEWORK
if (DEFINED _${_PYTHON_PREFIX}_CMAKE_FIND_FRAMEWORK)
set (CMAKE_FIND_FRAMEWORK ${_${_PYTHON_PREFIX}_CMAKE_FIND_FRAMEWORK})
unset (_${_PYTHON_PREFIX}_CMAKE_FIND_FRAMEWORK)
else()
unset (CMAKE_FIND_FRAMEWORK)
endif()
unset (_${_PYTHON_PREFIX}_CONFIG CACHE)
\ No newline at end of file
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
#[=======================================================================[.rst:
FindPython3
-----------
Find Python 3 interpreter, compiler and development environment (include
directories and libraries).
Three components are supported:
* ``Interpreter``: search for Python 3 interpreter
* ``Compiler``: search for Python 3 compiler. Only offered by IronPython.
* ``Development``: search for development artifacts (include directories and
libraries)
* ``NumPy``: search for NumPy include directories.
If no ``COMPONENTS`` is specified, ``Interpreter`` is assumed.
To ensure consistent versions between components ``Interpreter``, ``Compiler``,
``Development`` and ``NumPy``, specify all components at the same time::
find_package (Python3 COMPONENTS Interpreter Development)
This module looks only for version 3 of Python. This module can be used
concurrently with :module:`FindPython2` module to use both Python versions.
The :module:`FindPython` module can be used if Python version does not matter
for you.
.. note::
If components ``Interpreter`` and ``Development`` are both specified, this
module search only for interpreter with same platform architecture as the one
defined by ``CMake`` configuration. This contraint does not apply if only
``Interpreter`` component is specified.
Imported Targets
^^^^^^^^^^^^^^^^
This module defines the following :ref:`Imported Targets <Imported Targets>`
(when :prop_gbl:`CMAKE_ROLE` is ``PROJECT``):
``Python3::Interpreter``
Python 3 interpreter. Target defined if component ``Interpreter`` is found.
``Python3::Compiler``
Python 3 compiler. Target defined if component ``Compiler`` is found.
``Python3::Python``
Python 3 library. Target defined if component ``Development`` is found.
``Python3::NumPy``
NumPy library for Python 3. Target defined if component ``NumPy`` is found.
Result Variables
^^^^^^^^^^^^^^^^
This module will set the following variables in your project
(see :ref:`Standard Variable Names <CMake Developer Standard Variable Names>`):
``Python3_FOUND``
System has the Python 3 requested components.
``Python3_Interpreter_FOUND``
System has the Python 3 interpreter.
``Python3_EXECUTABLE``
Path to the Python 3 interpreter.
``Python3_INTERPRETER_ID``
A short string unique to the interpreter. Possible values include:
* Python
* ActivePython
* Anaconda
* Canopy
* IronPython
``Python3_STDLIB``
Standard platform independent installation directory.
Information returned by
``distutils.sysconfig.get_python_lib(plat_specific=False,standard_lib=True)``.
``Python3_STDARCH``
Standard platform dependent installation directory.
Information returned by
``distutils.sysconfig.get_python_lib(plat_specific=True,standard_lib=True)``.
``Python3_SITELIB``
Third-party platform independent installation directory.
Information returned by
``distutils.sysconfig.get_python_lib(plat_specific=False,standard_lib=False)``.
``Python3_SITEARCH``
Third-party platform dependent installation directory.
Information returned by
``distutils.sysconfig.get_python_lib(plat_specific=True,standard_lib=False)``.
``Python3_Compiler_FOUND``
System has the Python 3 compiler.
``Python3_COMPILER``
Path to the Python 3 compiler. Only offered by IronPython.
``Python3_COMPILER_ID``
A short string unique to the compiler. Possible values include:
* IronPython
``Python3_Development_FOUND``
System has the Python 3 development artifacts.
``Python3_INCLUDE_DIRS``
The Python 3 include directories.
``Python3_LIBRARIES``
The Python 3 libraries.
``Python3_LIBRARY_DIRS``
The Python 3 library directories.
``Python3_RUNTIME_LIBRARY_DIRS``
The Python 3 runtime library directories.
``Python3_VERSION``
Python 3 version.
``Python3_VERSION_MAJOR``
Python 3 major version.
``Python3_VERSION_MINOR``
Python 3 minor version.
``Python3_VERSION_PATCH``
Python 3 patch version.
``Python3_NumPy_FOUND``
System has the NumPy.
``Python3_NumPy_INCLUDE_DIRS``
The NumPy include directries.
``Python3_NumPy_VERSION``
The NumPy version.
Hints
^^^^^
``Python3_ROOT_DIR``
Define the root directory of a Python 3 installation.
``Python3_USE_STATIC_LIBS``
* If not defined, search for shared libraries and static libraries in that
order.
* If set to TRUE, search **only** for static libraries.
* If set to FALSE, search **only** for shared libraries.
``Python3_FIND_REGISTRY``
On Windows the ``Python3_FIND_REGISTRY`` variable determine the order
of preference between registry and environment variables.
the ``Python3_FIND_REGISTRY`` variable can be set to empty or one of the
following:
* ``FIRST``: Try to use registry before environment variables.
This is the default.
* ``LAST``: Try to use registry after environment variables.
* ``NEVER``: Never try to use registry.
``CMAKE_FIND_FRAMEWORK``
On OS X the :variable:`CMAKE_FIND_FRAMEWORK` variable determine the order of
preference between Apple-style and unix-style package components.
.. note::
Value ``ONLY`` is not supported so ``FIRST`` will be used instead.
.. note::
If a Python virtual environment is configured, set variable
``Python_FIND_REGISTRY`` (Windows) or ``CMAKE_FIND_FRAMEWORK`` (macOS) with
value ``LAST`` or ``NEVER`` to select it preferably.
Commands
^^^^^^^^
This module defines the command ``Python3_add_library`` (when
:prop_gbl:`CMAKE_ROLE` is ``PROJECT``), which has the same semantics as
:command:`add_library`, but takes care of Python module naming rules
(only applied if library is of type ``MODULE``), and adds a dependency to target
``Python3::Python``::
Python3_add_library (my_module MODULE src1.cpp)
If library type is not specified, ``MODULE`` is assumed.
#]=======================================================================]
set (_PYTHON_PREFIX Python3)
set (_Python3_REQUIRED_VERSION_MAJOR 3)
include (${CMAKE_CURRENT_LIST_DIR}/FindPython/Support.cmake)
if (COMMAND __Python3_add_library)
macro (Python3_add_library)
__Python3_add_library (Python3 ${ARGV})
endmacro()
endif()
unset (_PYTHON_PREFIX)
\ No newline at end of file
# FindRdKafka
# -------------
#
# Tries to find RdKafka on the system
#
# Available variables
# RDKAFKA_LIBRARIES - Path to the library
# RDKAFKA_INCLUDE_DIR - Path to the include dir
cmake_minimum_required(VERSION 3.7)
find_path(RDKAFKA_INCLUDE_DIR librdkafka/rdkafka.h HINTS ${RdKafka_DIR}/include)
find_library(RDKAFKA_LIBRARIES rdkafka++ HINTS ${RdKafka_DIR}/lib ${RdKafka_DIR}/lib64)
find_library(RDKAFKA_C_LIBRARIES rdkafka HINTS ${RdKafka_DIR}/lib ${RdKafka_DIR}/lib64)
IF(WIN32)
find_path(RDKAFKA_BIN_DIR rdkafka++.dll HINTS ${RdKafka_DIR}/bin ${RdKafka_DIR}/lib)
mark_as_advanced(RDKAFKA_BIN_DIR)
find_package_handle_standard_args(RdKafka REQUIRED_VARS RDKAFKA_INCLUDE_DIR RDKAFKA_C_LIBRARIES RDKAFKA_LIBRARIES RDKAFKA_BIN_DIR)
ELSE()
find_package_handle_standard_args(RdKafka REQUIRED_VARS RDKAFKA_INCLUDE_DIR RDKAFKA_C_LIBRARIES RDKAFKA_LIBRARIES)
ENDIF()
mark_as_advanced(RDKAFKA_LIBRARIES RDKAFKA_INCLUDE_DIR)
# ~~~
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ~~~
#[=======================================================================[.rst:
FindgRPC
--------
Locate and configure the ``gRPC`` library.
The following variables can be set and are optional:
``gRPC_DEBUG``
Show debug messages.
``gRPC_USE_STATIC_LIBS``
Set to ON to force the use of the static libraries.
Default is OFF.
Defines the following variables:
``gRPC_FOUND``
Found the gRPC library
``gRPC_VERSION``
Version of package found.
The following ``IMPORTED`` targets are also defined:
``gRPC::grpc++``
The gRPC C++ library.
``gRPC::grpc``
The gRPC C core library.
``gRPC::cpp_plugin``
The C++ plugin for the Protobuf protoc compiler.
The following cache variables are also available to set or use:
Example:
.. code-block:: cmake
find_package(gRPC REQUIRED)
add_executable(bar bar.cc)
target_link_libraries(bar PRIVATE gRPC::grpc++)
#]=======================================================================]
if (gRPC_DEBUG)
message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
"gRPC_USE_STATIC_LIBS = ${gRPC_USE_STATIC_LIBS}"
" gRPC_FOUND = ${gRPC_FOUND}")
endif ()
# gRPC always requires Thread support.
find_package(Threads REQUIRED)
# Load the module to find protobuf with proper targets. Do not use
# `find_package()` because we (have to) install this module in non-standard
# locations.
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
find_package(ProtobufWithTargets)
# The gRPC::grpc_cpp_plugin target is sometimes defined, but without a
# IMPORTED_LOCATION
function (_grpc_fix_grpc_cpp_plugin_target)
# The target may already exist, do not create it again if it does.
if (NOT TARGET gRPC::grpc_cpp_plugin)
add_executable(gRPC::grpc_cpp_plugin IMPORTED)
endif ()
get_target_property(_gRPC_CPP_PLUGIN_EXECUTABLE gRPC::grpc_cpp_plugin
IMPORTED_LOCATION)
if (gRPC_DEBUG)
message(
STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
"LOCATION=${_gRPC_CPP_PLUGIN_EXECUTABLE}")
endif ()
# Even if the target exists, gRPC CMake support files do not define the
# executable for the imported target (at least they do not in v1.19.1), so
# we need to define it ourselves.
if (NOT _gRPC_CPP_PLUGIN_EXECUTABLE)
find_program(_gRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin
DOC "The gRPC C++ plugin for protoc")
mark_as_advanced(_gRPC_CPP_PLUGIN_EXECUTABLE)
if (_gRPC_CPP_PLUGIN_EXECUTABLE)
set_property(
TARGET gRPC::grpc_cpp_plugin
PROPERTY IMPORTED_LOCATION ${_gRPC_CPP_PLUGIN_EXECUTABLE})
else ()
set(gRPC_FOUND "grpc_cpp_plugin-NOTFOUND")
endif ()
endif ()
endfunction ()
# The gRPC::* targets sometimes lack the right definitions to compile cleanly on
# WIN32
function (_grpc_fix_grpc_target_definitions)
# Including gRPC headers without this definition results in a build error.
if (WIN32)
set_property(
TARGET gRPC::grpc
APPEND
PROPERTY INTERFACE_COMPILE_DEFINITIONS _WIN32_WINNT=0x600)
set_property(
TARGET gRPC::grpc++
APPEND
PROPERTY INTERFACE_COMPILE_DEFINITIONS _WIN32_WINNT=0x600)
endif ()
endfunction ()
# First try to use the `gRPCConfig.cmake` or `grpc-config.cmake` file if it was
# installed. This is common on systems (or package managers) where gRPC was
# compiled and installed with `CMake`.
find_package(gRPC NO_MODULE QUIET)
if (gRPC_DEBUG)
message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
"NO_MODULE result gRPC_FOUND = ${gRPC_FOUND}")
endif ()
if (gRPC_FOUND)
_grpc_fix_grpc_cpp_plugin_target()
_grpc_fix_grpc_target_definitions()
return()
endif ()
include(SelectLibraryConfigurations)
# Internal function: search for normal library as well as a debug one if the
# debug one is specified also include debug/optimized keywords in *_LIBRARIES
# variable
function (_gRPC_find_library name filename)
if (${name}_LIBRARY)
# Use result recorded by a previous call.
return()
else ()
find_library(${name}_LIBRARY_RELEASE NAMES ${filename})
mark_as_advanced(${name}_LIBRARY_RELEASE)
find_library(${name}_LIBRARY_DEBUG NAMES ${filename}d ${filename})
mark_as_advanced(${name}_LIBRARY_DEBUG)
select_library_configurations(${name})
if (gRPC_DEBUG)
message(
STATUS
"[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
"${name} ${filename} RELEASE=${${name}_LIBRARY}"
" DEBUG=${${name}_LIBRARY_DEBUG} DEFAULT=${${name}_LIBRARY}"
)
endif ()
set(${name}_LIBRARY
"${${name}_LIBRARY}"
PARENT_SCOPE)
endif ()
endfunction ()
#
# Main
#
# Support preference of static libs by adjusting CMAKE_FIND_LIBRARY_SUFFIXES
if (_gRPC_USE_STATIC_LIBS)
set(_gRPC_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
if (WIN32)
set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
else ()
set(CMAKE_FIND_LIBRARY_SUFFIXES .a)
endif ()
endif ()
_grpc_find_library(_gRPC_grpc grpc)
_grpc_find_library(_gRPC_grpc++ grpc++)
if (NOT _gRPC_INCLUDE_DIR)
find_path(_gRPC_INCLUDE_DIR grpcpp/grpcpp.h)
mark_as_advanced(_gRPC_INCLUDE_DIR)
endif ()
if (gRPC_DEBUG)
message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
" _gRPC_grpc_LIBRARY = ${_gRPC_grpc_LIBRARY}")
message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
" _gRPC_grpc++_LIBRARY = ${_gRPC_grpc++_LIBRARY}")
message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
" _gRPC_INCLUDE_DIR = ${_gRPC_INCLUDE_DIR}")
endif ()
if (_gRPC_grpc_LIBRARY)
if (NOT TARGET gRPC::grpc)
add_library(gRPC::grpc UNKNOWN IMPORTED)
set_target_properties(
gRPC::grpc PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
"${_gRPC_INCLUDE_DIR}")
if (EXISTS "${_gRPC_grpc_LIBRARY}")
set_target_properties(gRPC::grpc PROPERTIES IMPORTED_LOCATION
"${_gRPC_grpc_LIBRARY}")
endif ()
if (EXISTS "${_gRPC_grpc_LIBRARY_RELEASE}")
set_property(
TARGET gRPC::grpc
APPEND
PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
set_target_properties(
gRPC::grpc PROPERTIES IMPORTED_LOCATION_RELEASE
"${_gRPC_grpc_LIBRARY_RELEASE}")
endif ()
if (EXISTS "${_gRPC_grpc_LIBRARY_DEBUG}")
set_property(
TARGET gRPC::grpc
APPEND
PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
set_target_properties(
gRPC::grpc PROPERTIES IMPORTED_LOCATION_DEBUG
"${_gRPC_grpc_LIBRARY_DEBUG}")
endif ()
set_property(
TARGET gRPC::grpc
APPEND
PROPERTY INTERFACE_LINK_LIBRARIES protobuf::libprotobuf
Threads::Threads)
endif ()
endif ()
if (_gRPC_grpc++_LIBRARY)
if (NOT TARGET gRPC::grpc++)
add_library(gRPC::grpc++ UNKNOWN IMPORTED)
set_target_properties(
gRPC::grpc++ PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
"${_gRPC++_INCLUDE_DIR}")
if (EXISTS "${_gRPC_grpc++_LIBRARY}")
set_target_properties(
gRPC::grpc++ PROPERTIES IMPORTED_LOCATION
"${_gRPC_grpc++_LIBRARY}")
endif ()
if (EXISTS "${_gRPC_grpc++_LIBRARY_RELEASE}")
set_property(
TARGET gRPC::grpc++
APPEND
PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
set_target_properties(
gRPC::grpc++ PROPERTIES IMPORTED_LOCATION_RELEASE
"${_gRPC_grpc++_LIBRARY_RELEASE}")
endif ()
if (EXISTS "${_gRPC_grpc++_LIBRARY_DEBUG}")
set_property(
TARGET gRPC::grpc++
APPEND
PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
set_target_properties(
gRPC::grpc++ PROPERTIES IMPORTED_LOCATION_DEBUG
"${_gRPC_grpc++_LIBRARY_DEBUG}")
endif ()
set_property(
TARGET gRPC::grpc++
APPEND
PROPERTY INTERFACE_LINK_LIBRARIES gRPC::grpc protobuf::libprotobuf
Threads::Threads)
if (CMAKE_VERSION VERSION_GREATER 3.8)
# gRPC++ requires C++14 (soon), but only CMake-3.8 introduced a
# compiler feature to meet that requirement.
set_property(
TARGET gRPC::grpc++
APPEND
PROPERTY INTERFACE_COMPILE_FEATURES cxx_std_14)
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
# CMake 3.5 is still alive and kicking in some older distros, use
# the compiler-specific versions in these cases.
set_property(
TARGET gRPC::grpc++
APPEND
PROPERTY INTERFACE_COMPILE_OPTIONS "-std=c++14")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set_property(
TARGET gRPC::grpc++
APPEND
PROPERTY INTERFACE_COMPILE_OPTIONS "-std=c++14")
else ()
message(
WARNING
"gRPC::grpc++ requires C++14, but this module"
" (${CMAKE_CURRENT_LIST_FILE})"
" cannot enable it for the library target in your CMake and"
" compiler versions. You need to enable C++14 in the"
" CMakeLists.txt for your project. Consider filing a bug"
" so we can fix this problem.")
endif ()
endif ()
endif ()
# Restore original find library prefixes
if (_gRPC_USE_STATIC_LIBS)
set(CMAKE_FIND_LIBRARY_PREFIXES "${_gRPC_ORIG_FIND_LIBRARY_PREFIXES}")
endif ()
file(
WRITE "${CMAKE_BINARY_DIR}/get_gRPC_version.cc"
[====[
#include <grpcpp/grpcpp.h>
#include <iostream>
int main() {
std::cout << grpc::Version(); // no newline to simplify CMake module
return 0;
}
]====])
try_run(
_gRPC_GET_VERSION_STATUS
_gRPC_GET_VERSION_COMPILE_STATUS
"${CMAKE_BINARY_DIR}"
"${CMAKE_BINARY_DIR}/get_gRPC_version.cc"
LINK_LIBRARIES
gRPC::grpc++
gRPC::grpc
COMPILE_OUTPUT_VARIABLE _gRPC_GET_VERSION_COMPILE_OUTPUT
RUN_OUTPUT_VARIABLE gRPC_VERSION)
file(REMOVE "${CMAKE_BINARY_DIR}/get_gRPC_version.cc")
_grpc_fix_grpc_cpp_plugin_target()
if (gRPC_DEBUG)
foreach (
_var
_gRPC_CPP_PLUGIN_EXECUTABLE
_gRPC_VERSION_RAW
_gRPC_GET_VERSION_STATUS
_gRPC_GET_VERSION_COMPILE_STATUS
_gRPC_GET_VERSION_COMPILE_OUTPUT
_gRPC_grpc_LIBRARY
_gRPC_grpc++_LIBRARY
_gRPC_INCLUDE_DIR)
message(
STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
"${_var} = ${${_var}}")
endforeach ()
unset(_var)
endif ()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
gRPC
REQUIRED_VARS _gRPC_grpc_LIBRARY _gRPC_INCLUDE_DIR
VERSION_VAR gRPC_VERSION)
......@@ -77,4 +77,4 @@ macro(select_library_configurations basename)
mark_as_advanced( ${basename}_LIBRARY_RELEASE
${basename}_LIBRARY_DEBUG
)
endmacro()
\ No newline at end of file
endmacro()
......@@ -18,9 +18,8 @@ if (( coverage < ASAPO_MINIMUM_COVERAGE )); then
echo "*****"
echo
echo ${TARGET} coverage is ${coverage}% - less than required ${ASAPO_MINIMUM_COVERAGE}%
echo
echo
echo "*****"
echo
exit 1
fi
......@@ -29,9 +29,8 @@ if (( coverage < ASAPO_MINIMUM_COVERAGE )); then
echo "*****"
echo
echo coverage is ${coverage}% - less than required ${ASAPO_MINIMUM_COVERAGE}%
echo
echo
echo "*****"
echo
exit 1
fi
......@@ -4,6 +4,7 @@ function(prepare_asapo)
get_target_property(DISCOVERY_FULLPATH asapo-discovery EXENAME)
get_target_property(AUTHORIZER_FULLPATH asapo-authorizer EXENAME)
get_target_property(FILE_TRANSFER_FULLPATH asapo-file-transfer EXENAME)
get_target_property(MONITORING_SERVER_FULLPATH asapo-monitoring-server EXENAME)
get_target_property(BROKER_FULLPATH asapo-broker EXENAME)
set(WORK_DIR ${CMAKE_CURRENT_BINARY_DIR})
......@@ -32,12 +33,19 @@ function(prepare_asapo)
else()
configure_file(${CMAKE_SOURCE_DIR}/tests/automatic/settings/receiver_tcp.json.tpl.lin.in receiver_tcp.json.tpl @ONLY)
configure_file(${CMAKE_SOURCE_DIR}/tests/automatic/settings/receiver_fabric.json.tpl.lin.in receiver_fabric.json.tpl @ONLY)
configure_file(${CMAKE_SOURCE_DIR}/tests/automatic/settings/receiver_kafka.json.tpl.lin.in receiver_kafka.json.tpl @ONLY)
configure_file(${CMAKE_SOURCE_DIR}/tests/automatic/settings/authorizer_settings.json.tpl.lin authorizer.json.tpl COPYONLY)
configure_file(${CMAKE_SOURCE_DIR}/tests/automatic/settings/monitoring_server_settings.json.tpl monitoring_server.json.tpl COPYONLY)
configure_file(${CMAKE_SOURCE_DIR}/config/nomad/monitoring.nmd.in monitoring.nmd @ONLY)
configure_file(${CMAKE_SOURCE_DIR}/tests/automatic/common_scripts/start_services.sh start_services.sh COPYONLY)
configure_file(${CMAKE_SOURCE_DIR}/tests/automatic/common_scripts/stop_services.sh stop_services.sh COPYONLY)
configure_file(${CMAKE_SOURCE_DIR}/config/nomad/receiver_tcp.nmd.in receiver_tcp.nmd @ONLY)
configure_file(${CMAKE_SOURCE_DIR}/config/nomad/receiver_fabric.nmd.in receiver_fabric.nmd @ONLY)
configure_file(${CMAKE_SOURCE_DIR}/config/nomad/receiver_kafka.nmd.in receiver_kafka.nmd @ONLY)
configure_file(${CMAKE_SOURCE_DIR}/config/nomad/nginx_kill_lin.nmd nginx_kill.nmd @ONLY)
endif()
......
......@@ -16,39 +16,64 @@ set (TOKENS "${TOKENS};BT_AAA_TOKEN=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGk
set (TOKENS "${TOKENS};BT_TEST_RUN_TOKEN=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJjMTk0NjYzaXB0Mzdma2w0YmVrMCIsInN1YiI6ImJ0X3Rlc3RfcnVuIiwiRXh0cmFDbGFpbXMiOnsiQWNjZXNzVHlwZXMiOlsicmVhZCJdfX0.QJjoGOlzMvOUk7dK2bbDgSEM5-1mO6wmpmESYL6McdU")
set (TOKENS "${TOKENS};BT_TEST_RUN_RW_TOKEN=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJjMjlzNDByaXB0M2JuczJtaTA1MCIsInN1YiI6ImJ0X3Rlc3RfcnVuIiwiRXh0cmFDbGFpbXMiOnsiQWNjZXNzVHlwZXMiOlsicmVhZCIsIndyaXRlIl19fQ.vwOak8smIF23TaRo5KzRgvA8d_fPLKnd9dXglMsm7d8")
function(add_coverage_targets)
find_program(GENHTML genhtml REQUIRED)
set(coverage_report_dir "${CMAKE_BINARY_DIR}/reports/coverage")
message(STATUS "coverage_report_dir=${coverage_report_dir}")
set(FASTCOV_CMD ${Python_EXECUTABLE} ${CMAKE_SOURCE_DIR}/3d_party/fastcov/fastcov.py)
set(LCOV_TO_COBERTURA_CMD ${Python_EXECUTABLE}
${CMAKE_SOURCE_DIR}/3d_party/lcov-to-cobertura-xml/lcov_cobertura/lcov_cobertura.py)
add_custom_target(
coverage_generate_report
COMMAND ${CMAKE_COMMAND} -E make_directory ${coverage_report_dir}
COMMAND ${FASTCOV_CMD} --process-gcno --gcov gcov --dump-statistic
--lcov -o "${coverage_report_dir}/cov.info"
--exclude "/usr/include/" "/usr/local/" "tests/" "unittests/" "3d_party/"
COMMAND ${GENHTML} "${coverage_report_dir}/cov.info" -o "${coverage_report_dir}"
COMMAND ${LCOV_TO_COBERTURA_CMD} "${coverage_report_dir}/cov.info"
--output "${coverage_report_dir}/coverage.xml"
--demangle --base-dir="${CMAKE_SOURCE_DIR}" --excludes "${CMAKE_BINARY_DIR}"
VERBATIM
)
add_custom_target(
coverage_reset_counters
COMMAND ${FASTCOV_CMD} --zerocounters
VERBATIM
)
endfunction()
if (BUILD_TESTS)
set(ASAPO_MINIMUM_COVERAGE 70)
find_package(GTest REQUIRED)
set(GTEST_LIBS GTest::gmock GTest::gmock_main)
add_definitions(-DUNIT_TESTS)
find_package(Threads)
find_program(MEMORYCHECK_COMMAND valgrind)
set(MEMORYCHECK_COMMAND_OPTIONS
"--trace-children=yes --leak-check=full --error-exitcode=1 --suppressions=${CMAKE_SOURCE_DIR}/tests/valgrind.suppressions")
if (NOT "$ENV{gtest_SOURCE_DIR}" STREQUAL "")
set(gtest_SOURCE_DIR $ENV{gtest_SOURCE_DIR})
endif ()
message(STATUS "Will look for google test at ${gtest_SOURCE_DIR}")
if (CMAKE_COMPILER_IS_GNUCXX)
include(CodeCoverage)
APPEND_COVERAGE_COMPILER_FLAGS()
endif ()
"--trace-children=yes --leak-check=full --error-exitcode=1 --num-callers=20 --suppressions=${CMAKE_SOURCE_DIR}/tests/valgrind.suppressions")
if (ENABLE_COVERAGE)
if (CMAKE_COMPILER_IS_GNUCXX)
set(COVERAGE_COMPILER_FLAGS "-g -O0 --coverage" CACHE INTERNAL "")
list(APPEND CMAKE_C_FLAGS "${COVERAGE_COMPILER_FLAGS}")
list(APPEND CMAKE_CXX_FLAGS "${COVERAGE_COMPILER_FLAGS}")
message(STATUS "Appending code coverage compiler flags: ${COVERAGE_COMPILER_FLAGS}")
add_coverage_targets()
endif ()
endif()
endif ()
#TODO: Call add_plain_unit_test in gtest
function(add_plain_unit_test target test_source_files linktarget)
if (BUILD_TESTS)
include_directories(SYSTEM ${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
link_directories(${gtest_SOURCE_DIR}/lib)
add_executable(test-${target} ${test_source_files})
if (NOT ${libs} STREQUAL "")
target_link_libraries(test-${target} ${libs})
endif ()
IF (WIN32 AND ${CMAKE_BUILD_TYPE} STREQUAL "Debug")
set(GTEST_LIBS gtestd gtest_maind gmockd)
ELSE ()
set(GTEST_LIBS gtest gmock gtest_main)
ENDIF (WIN32 AND ${CMAKE_BUILD_TYPE} STREQUAL "Debug")
target_link_libraries(test-${target} ${GTEST_LIBS} ${CMAKE_THREAD_LIBS_INIT})
GET_PROPERTY(ASAPO_COMMON_IO_LIBRARIES GLOBAL PROPERTY ASAPO_COMMON_IO_LIBRARIES)
......@@ -67,32 +92,18 @@ endfunction()
function(gtest target test_source_files linktarget)
if (BUILD_TESTS)
include_directories(SYSTEM ${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
link_directories(${gtest_SOURCE_DIR}/lib)
unset(libs)
FOREACH (lib ${linktarget})
if (NOT ${lib} STREQUAL "")
get_target_property(target_type ${lib} TYPE)
if (target_type STREQUAL "OBJECT_LIBRARY")
list(APPEND OBJECT "$<TARGET_OBJECTS:${lib}>")
else ()
list(APPEND libs "${lib}")
endif ()
list(APPEND libs "${lib}")
endif ()
ENDFOREACH ()
add_executable(test-${target} ${test_source_files} ${OBJECT})
add_executable(test-${target} ${test_source_files})
if (NOT ${libs} STREQUAL "")
if (libs)
target_link_libraries(test-${target} ${libs})
endif ()
IF (WIN32 AND ${CMAKE_BUILD_TYPE} STREQUAL "Debug")
set(GTEST_LIBS gtestd gtest_maind gmockd)
ELSE ()
set(GTEST_LIBS gtest gmock gtest_main)
ENDIF (WIN32 AND ${CMAKE_BUILD_TYPE} STREQUAL "Debug")
target_link_libraries(test-${target} ${GTEST_LIBS} ${CMAKE_THREAD_LIBS_INIT})
GET_PROPERTY(ASAPO_COMMON_IO_LIBRARIES GLOBAL PROPERTY ASAPO_COMMON_IO_LIBRARIES)
......@@ -105,28 +116,7 @@ function(gtest target test_source_files linktarget)
add_test(NAME test-${target} COMMAND test-${target})
set_tests_properties(test-${target} PROPERTIES LABELS "unit;all")
message(STATUS "Added test 'test-${target}'")
if (ARGN)
LIST(GET ARGN 0 NOCOV)
endif()
if (CMAKE_COMPILER_IS_GNUCXX AND NOT 1${NOCOV} STREQUAL "1nocov")
set(COVERAGE_EXCLUDES "*/unittests/*" "*/3d_party/*" "*/python/*")
if (ARGN)
set(COVERAGE_EXCLUDES ${COVERAGE_EXCLUDES} ${ARGN})
endif ()
SETUP_TARGET_FOR_COVERAGE(NAME coverage-${target} EXECUTABLE test-${target} ${target})
add_test(NAME coveragetest-${target}
COMMAND ${PROJECT_SOURCE_DIR}/CMakeModules/check_test.sh
coverage-${target} ${CMAKE_BINARY_DIR} ${ASAPO_MINIMUM_COVERAGE})
set_tests_properties(coveragetest-${target} PROPERTIES LABELS "coverage;all")
message(STATUS "Added test 'test-${target}-coverage'")
SET_TESTS_PROPERTIES(coveragetest-${target} PROPERTIES DEPENDS test-${target})
set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} PARENT_SCOPE)
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} PARENT_SCOPE)
endif ()
add_memory_test(${target} test-${target} "" "" "unit")
endif ()
endfunction()
......
......@@ -6,13 +6,14 @@ if (BUILD_TESTS)
set(ASAPO_MINIMUM_COVERAGE 80)
find_program(MEMORYCHECK_COMMAND valgrind)
set(MEMORYCHECK_COMMAND_OPTIONS
"--trace-children=yes --leak-check=full --error-exitcode=1 --suppressions=${CMAKE_SOURCE_DIR}/tests/valgrind.suppressions")
"--trace-children=yes --leak-check=full --error-exitcode=1 --num-callers=20 --suppressions=${CMAKE_SOURCE_DIR}/tests/valgrind.suppressions")
endif ()
function(gotest target source_dir test_source_files)
if (BUILD_TESTS)
add_test(NAME test-${target} COMMAND go test ${test_source_files}
WORKING_DIRECTORY ${source_dir})
set_tests_properties(test-${target} PROPERTIES LABELS "unit;all")
message(STATUS "Added test 'test-${target}'")
if (CMAKE_COMPILER_IS_GNUCXX)
add_test(NAME coveragetest-${target}
......