Skip to content
Snippets Groups Projects
Commit 025a9304 authored by Florent Lamiraux's avatar Florent Lamiraux
Browse files

Add CMakeLists.txt

parent 2259ff86
No related branches found
Tags v1.0.1
No related merge requests found
# Copyright CNRS
# Author: Florent Lamiraux
# 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.
# 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
# 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.
cmake_minimum_required(VERSION 3.10)
include(cmake/python.cmake)
include(cmake/python-helpers.cmake)
set(PROJECT_DESCRIPTION "Solver of Generalized Travelling Salesman Problems using heuristics")
project(gtsp-laas)
set(PYTHON_COMPONENTS NumPy)
findpython()
python_install_on_site(gtsp_laas __init__.py)
python_install_on_site(gtsp_laas algorithm.py)
python_install_on_site(gtsp_laas gtsp.py)
python_install_on_site(gtsp_laas tour.py)
# Copyright (C) 2008-2023 LAAS-CNRS, JRL AIST-CNRS, INRIA.
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
# .rst: .. command:: PYTHON_INSTALL(MODULE FILE DEST)
#
# Compile and install a Python file.
#
macro(PYTHON_INSTALL MODULE FILE DEST)
python_build("${MODULE}" "${FILE}")
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/${MODULE}/${FILE}"
DESTINATION "${DEST}/${MODULE}")
endmacro()
# .rst: .. command:: PYTHON_INSTALL_ON_SITE (MODULE FILE)
#
# Compile and install a Python file in :cmake:variable:`PYTHON_SITELIB`.
#
macro(PYTHON_INSTALL_ON_SITE MODULE FILE)
python_install("${MODULE}" "${FILE}" ${PYTHON_SITELIB})
endmacro()
# PYTHON_BUILD_GET_TARGET(TARGET)
# -----------------------------------------
#
# Get the target associated to the PYTHON_BUILD procedure
#
function(PYTHON_BUILD_GET_TARGET python_build_target)
# Regex from IsValidTargetName in CMake/Source/cmGeneratorExpression.cxx
string(REGEX REPLACE "[^A-Za-z0-9_.+-]" "_" compile_pyc
"compile_pyc_${CMAKE_CURRENT_SOURCE_DIR}")
if(NOT TARGET ${compile_pyc})
add_custom_target(${compile_pyc} ALL)
endif()
set(${python_build_target}
${compile_pyc}
PARENT_SCOPE)
endfunction(PYTHON_BUILD_GET_TARGET NAME)
# PYTHON_BUILD(MODULE FILE DEST)
# --------------------------------------
#
# Build a Python file from the source directory in the build directory.
#
macro(PYTHON_BUILD MODULE FILE)
set(python_build_target "")
python_build_get_target(python_build_target)
set(INPUT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/${MODULE}/${FILE}")
if(CMAKE_GENERATOR MATCHES "Visual Studio|Xcode")
set(OUTPUT_FILE_DIR "${CMAKE_CURRENT_BINARY_DIR}/${MODULE}/$<CONFIG>")
else()
set(OUTPUT_FILE_DIR "${CMAKE_CURRENT_BINARY_DIR}/${MODULE}")
endif()
set(OUTPUT_FILE "${OUTPUT_FILE_DIR}/${FILE}c")
# Create directory accounting for the generator expression contained in
# ${OUTPUT_FILE_DIR}
add_custom_command(
TARGET ${python_build_target}
PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory "${OUTPUT_FILE_DIR}")
python_build_file(${INPUT_FILE} ${OUTPUT_FILE})
endmacro()
# PYTHON_BUILD_FILE(FILE [OUTPUT_FILE])
# --------------------------------------
#
# Build a Python a given file.
#
macro(PYTHON_BUILD_FILE FILE)
set(python_build_target "")
python_build_get_target(python_build_target)
set(extra_var "${ARGV1}")
if(NOT extra_var STREQUAL "")
set(OUTPUT_FILE "${ARGV1}")
else()
set(OUTPUT_FILE "${FILE}c")
endif()
add_custom_command(
TARGET ${python_build_target}
PRE_BUILD
COMMAND
"${PYTHON_EXECUTABLE}" -c
"import py_compile; py_compile.compile(\"${FILE}\",\"${OUTPUT_FILE}\")"
VERBATIM)
# Tag pyc file as generated.
set_source_files_properties("${OUTPUT_FILE}" PROPERTIES GENERATED TRUE)
# Clean generated files.
set_property(
DIRECTORY
APPEND
PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "${OUTPUT_FILE}")
endmacro()
# Copyright (C) 2008-2024 LAAS-CNRS, JRL AIST-CNRS, INRIA.
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
# .rst: .. command:: FINDPYTHON
#
# Find python interpreter and python libs. Arguments are passed to the
# find_package command so refer to `find_package` documentation to learn about
# valid arguments.
#
# To specify a specific Python version from the command line, use the command
# ``FINDPYTHON()`` and pass the following arguments to CMake
# ``-DPYTHON_EXECUTABLE=/usr/bin/python3.5 -DPYTHON_LIBRARY=
# /usr/lib/x86_64-linux-gnu/libpython3.5m.so.1``
#
# To specify a specific Python version within the CMakeLists.txt, use the
# command ``FINDPYTHON(2.7 EXACT REQUIRED)``.
#
# If PYTHON_PACKAGES_DIR is set, then the {dist,site}-packages will be replaced
# by the value contained in PYTHON_PACKAGES_DIR.
#
# .. warning:: According to the ``FindPythonLibs`` and ``FindPythonInterp``
# documentation, you could also set ``Python_ADDITIONAL_VERSIONS``. If you do
# this, you will not have an error if you found two different versions or
# another version that the requested one.
#
# .rst: .. variable:: PYTHON_SITELIB
#
# Relative path where Python files will be installed.
# .rst: .. variable:: PYTHON_EXT_SUFFIX
#
# Portable suffix of C++ Python modules.
# .rst: .. variable:: PYTHON_COMPONENTS
#
# Required components for python. Default: "Interpreter Development"
# .rst: .. variable:: PYTHON_EXPORT_DEPENDENCY
#
# Define this to forward `FINDPYTHON` to the exported CMake config. This is
# mainly useful for PUBLIC links to Python::Targets, so this setting change
# nothing for CMake < 3.12 which doesn't have those. This also export: -
# `FIND_NUMPY` and/or `SEARCH_FOR_BOOST_PYTHON` if necessary.
macro(FINDPYTHON)
if(DEFINED FINDPYTHON_ALREADY_CALLED)
message(
AUTHOR_WARNING
"Macro FINDPYTHON has already been called. Several call to FINDPYTHON may not find the same Python version (for a yet unknown reason)."
)
endif()
set(FINDPYTHON_ALREADY_CALLED TRUE)
if(NOT PYTHON_COMPONENTS)
set(PYTHON_COMPONENTS Interpreter Development)
endif()
list(FIND PYTHON_COMPONENTS "NumPy" _npindex)
if(NOT ${_npindex} EQUAL -1)
set(SEARCH_FOR_NUMPY TRUE)
endif()
if(CMAKE_VERSION VERSION_LESS "3.18")
# IF("Development.Module" IN_LIST PYTHON_COMPONENTS) -- require CMake 3.3
list(FIND PYTHON_COMPONENTS "Development.Module" _index)
if(NOT ${_index} EQUAL -1)
message(
STATUS
"For CMake < 3.18, Development.Module is not available. Falling back to Development"
)
list(REMOVE_ITEM PYTHON_COMPONENTS Development.Module)
set(PYTHON_COMPONENTS ${PYTHON_COMPONENTS} Development)
endif()
if(CMAKE_VERSION VERSION_LESS "3.14")
if(SEARCH_FOR_NUMPY)
message(
STATUS
"For CMake < 3.14, NumPy is not available. Falling back to custom FIND_NUMPY()"
)
list(REMOVE_ITEM PYTHON_COMPONENTS NumPy)
endif()
endif()
endif()
if(NOT CMAKE_VERSION VERSION_LESS "3.12")
if(DEFINED PYTHON_EXECUTABLE
OR DEFINED Python_EXECUTABLE
OR DEFINED Python2_EXECUTABLE
OR DEFINED Python3_EXECUTABLE)
if(NOT DEFINED PYTHON_EXECUTABLE)
if(DEFINED Python_EXECUTABLE)
set(PYTHON_EXECUTABLE ${Python_EXECUTABLE})
elseif(DEFINED Python2_EXECUTABLE)
set(PYTHON_EXECUTABLE ${Python2_EXECUTABLE})
elseif(DEFINED Python3_EXECUTABLE)
set(PYTHON_EXECUTABLE ${Python3_EXECUTABLE})
endif()
endif()
if(NOT DEFINED Python_EXECUTABLE)
set(Python_EXECUTABLE ${PYTHON_EXECUTABLE})
endif()
else()
# Search for the default python of the system, if exists
find_program(PYTHON_EXECUTABLE python)
endif()
if(PYTHON_EXECUTABLE)
if(NOT EXISTS ${PYTHON_EXECUTABLE})
message(
FATAL_ERROR
"${PYTHON_EXECUTABLE} is not a valid path to the Python executable")
endif()
execute_process(
COMMAND ${PYTHON_EXECUTABLE} --version
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
RESULT_VARIABLE _PYTHON_VERSION_RESULT_VARIABLE
OUTPUT_VARIABLE _PYTHON_VERSION_OUTPUT
ERROR_VARIABLE _PYTHON_VERSION_OUTPUT
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE)
if(NOT "${_PYTHON_VERSION_RESULT_VARIABLE}" STREQUAL "0")
message(FATAL_ERROR "${PYTHON_EXECUTABLE} --version did not succeed.")
endif()
string(REGEX REPLACE "Python " "" _PYTHON_VERSION
${_PYTHON_VERSION_OUTPUT})
string(REGEX REPLACE "\\." ";" _PYTHON_VERSION ${_PYTHON_VERSION})
list(GET _PYTHON_VERSION 0 _PYTHON_VERSION_MAJOR)
# Provide some hints according to the current PYTHON_EXECUTABLE
if(NOT DEFINED PYTHON_INCLUDE_DIR)
if(_PYTHON_VERSION_MAJOR EQUAL "2")
set(_PYTHON_INCLUDE_DIR_CMD
"import distutils.sysconfig as sysconfig; print(sysconfig.get_python_inc())"
)
else()
set(_PYTHON_INCLUDE_DIR_CMD
"import sysconfig; print(sysconfig.get_path('include'))")
endif()
execute_process(
COMMAND "${PYTHON_EXECUTABLE}" "-c" "${_PYTHON_INCLUDE_DIR_CMD}"
OUTPUT_VARIABLE PYTHON_INCLUDE_DIR
ERROR_QUIET)
string(STRIP "${PYTHON_INCLUDE_DIR}" PYTHON_INCLUDE_DIR)
file(TO_CMAKE_PATH "${PYTHON_INCLUDE_DIR}" PYTHON_INCLUDE_DIR)
endif()
# Hint for finding the right Python version
set(Python_EXECUTABLE ${PYTHON_EXECUTABLE})
set(Python${_PYTHON_VERSION_MAJOR}_EXECUTABLE ${PYTHON_EXECUTABLE})
set(Python${_PYTHON_VERSION_MAJOR}_INCLUDE_DIR ${PYTHON_INCLUDE_DIR})
find_package("Python${_PYTHON_VERSION_MAJOR}" REQUIRED
COMPONENTS ${PYTHON_COMPONENTS})
else()
# No hint was provided. We can then check for first Python 2, then Python
# 3
find_package(Python2 QUIET COMPONENTS ${PYTHON_COMPONENTS})
if(NOT Python2_FOUND)
find_package(Python3 QUIET COMPONENTS ${PYTHON_COMPONENTS})
if(NOT Python3_FOUND)
message(FATAL_ERROR "Python executable has not been found.")
else()
set(_PYTHON_VERSION_MAJOR 3)
endif()
else()
set(_PYTHON_VERSION_MAJOR 2)
endif()
endif()
set(_PYTHON_PREFIX "Python${_PYTHON_VERSION_MAJOR}")
if(${_PYTHON_PREFIX}_FOUND)
set(PYTHON_EXECUTABLE ${${_PYTHON_PREFIX}_EXECUTABLE})
set(PYTHON_LIBRARY ${${_PYTHON_PREFIX}_LIBRARIES})
set(PYTHON_LIBRARIES ${${_PYTHON_PREFIX}_LIBRARIES})
set(PYTHON_INCLUDE_DIR ${${_PYTHON_PREFIX}_INCLUDE_DIRS})
set(PYTHON_INCLUDE_DIRS ${${_PYTHON_PREFIX}_INCLUDE_DIRS})
set(PYTHON_VERSION_STRING ${${_PYTHON_PREFIX}_VERSION})
set(PYTHONLIBS_VERSION_STRING ${${_PYTHON_PREFIX}_VERSION})
set(PYTHON_FOUND ${${_PYTHON_PREFIX}_FOUND})
set(PYTHONLIBS_FOUND ${${_PYTHON_PREFIX}_FOUND})
set(PYTHON_VERSION_MAJOR ${${_PYTHON_PREFIX}_VERSION_MAJOR})
set(PYTHON_VERSION_MINOR ${${_PYTHON_PREFIX}_VERSION_MINOR})
set(PYTHON_VERSION_PATCH ${${_PYTHON_PREFIX}_VERSION_PATCH})
else()
message(FATAL_ERROR "Python executable has not been found.")
endif()
if(SEARCH_FOR_NUMPY)
set(NUMPY_INCLUDE_DIRS
"${Python${_PYTHON_VERSION_MAJOR}_NumPy_INCLUDE_DIRS}")
string(REPLACE "\\" "/" NUMPY_INCLUDE_DIRS "${NUMPY_INCLUDE_DIRS}")
file(TO_CMAKE_PATH "${NUMPY_INCLUDE_DIRS}" NUMPY_INCLUDE_DIRS)
endif()
else()
find_package(PythonInterp ${ARGN})
if(NOT ${PYTHONINTERP_FOUND} STREQUAL TRUE)
message(FATAL_ERROR "Python executable has not been found.")
endif()
message(STATUS "PythonInterp: ${PYTHON_EXECUTABLE}")
# Set PYTHON_INCLUDE_DIR variables if it is not defined by the user
if(DEFINED PYTHON_EXECUTABLE)
# Retrieve the corresponding value of PYTHON_INCLUDE_DIR if it is not
# defined
if(NOT DEFINED PYTHON_INCLUDE_DIR)
if(PYTHON_VERSION_MAJOR EQUAL "2")
set(_PYTHON_INCLUDE_DIR_CMD
"import distutils.sysconfig as sysconfig; print(sysconfig.get_python_inc())"
)
else()
set(_PYTHON_INCLUDE_DIR_CMD
"import sysconfig; print(sysconfig.get_path('include'))")
endif()
execute_process(
COMMAND "${PYTHON_EXECUTABLE}" "-c" "${_PYTHON_INCLUDE_DIR_CMD}"
OUTPUT_VARIABLE PYTHON_INCLUDE_DIR
ERROR_QUIET)
string(STRIP "${PYTHON_INCLUDE_DIR}" PYTHON_INCLUDE_DIR)
endif()
set(PYTHON_INCLUDE_DIRS ${PYTHON_INCLUDE_DIR})
endif()
# Inform PythonLibs of the required version of PythonInterp
set(PYTHONLIBS_VERSION_STRING ${PYTHON_VERSION_STRING})
find_package(PythonLibs ${ARGN})
message(STATUS "PythonLibraries: ${PYTHON_LIBRARIES}")
if(NOT ${PYTHONLIBS_FOUND} STREQUAL TRUE)
message(FATAL_ERROR "Python has not been found.")
endif()
string(REPLACE "." ";" _PYTHONLIBS_VERSION ${PYTHONLIBS_VERSION_STRING})
list(GET _PYTHONLIBS_VERSION 0 PYTHONLIBS_VERSION_MAJOR)
list(GET _PYTHONLIBS_VERSION 1 PYTHONLIBS_VERSION_MINOR)
if(NOT ${PYTHON_VERSION_MAJOR} EQUAL ${PYTHONLIBS_VERSION_MAJOR}
OR NOT ${PYTHON_VERSION_MINOR} EQUAL ${PYTHONLIBS_VERSION_MINOR})
message(
FATAL_ERROR
"Python interpreter and libraries are in different version: ${PYTHON_VERSION_STRING} vs ${PYTHONLIBS_VERSION_STRING}"
)
endif()
endif()
# Find PYTHON_LIBRARY_DIRS
get_filename_component(PYTHON_LIBRARY_DIRS "${PYTHON_LIBRARIES}" PATH)
message(STATUS "PythonLibraryDirs: ${PYTHON_LIBRARY_DIRS}")
message(STATUS "PythonLibVersionString: ${PYTHONLIBS_VERSION_STRING}")
if(PYTHON_SITELIB)
file(TO_CMAKE_PATH "${PYTHON_SITELIB}" PYTHON_SITELIB)
else()
# Use either site-packages (default) or dist-packages (Debian packages)
# directory
option(PYTHON_DEB_LAYOUT "Enable Debian-style Python package layout" OFF)
# ref. https://docs.python.org/3/library/site.html
option(PYTHON_STANDARD_LAYOUT "Enable standard Python package layout" OFF)
if(PYTHON_STANDARD_LAYOUT)
set(_PYTHON_SITELIB_CMD
"import sys, os; print(os.sep.join(['lib', 'python' + '.'.join(sys.version.split('.')[:2]), 'site-packages']))"
)
else()
if(PYTHON_VERSION_MAJOR EQUAL "2")
set(_PYTHON_SITELIB_CMD
"from distutils import sysconfig; print(sysconfig.get_python_lib(prefix='', plat_specific=False))"
)
else()
set(_PYTHON_SITELIB_CMD
"import sysconfig; from pathlib import Path; print(Path(sysconfig.get_path('purelib')).relative_to(sysconfig.get_path('data')))"
)
endif()
endif()
execute_process(
COMMAND "${PYTHON_EXECUTABLE}" "-c" "${_PYTHON_SITELIB_CMD}"
OUTPUT_VARIABLE PYTHON_SITELIB
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
# Keep compatility with former jrl-cmake-modules versions
if(PYTHON_DEB_LAYOUT)
string(REPLACE "site-packages" "dist-packages" PYTHON_SITELIB
"${PYTHON_SITELIB}")
endif()
# If PYTHON_PACKAGES_DIR is defined, then force the Python packages
# directory name
if(PYTHON_PACKAGES_DIR)
string(REGEX
REPLACE "(site-packages|dist-packages)" "${PYTHON_PACKAGES_DIR}"
PYTHON_SITELIB "${PYTHON_SITELIB}")
endif()
endif()
message(STATUS "Python site lib: ${PYTHON_SITELIB}")
message(STATUS "Python include dirs: ${PYTHON_INCLUDE_DIRS}")
# Get PYTHON_SOABI We should be in favor of using PYTHON_EXT_SUFFIX in future
# for better portability. However we keep it here for backward compatibility.
set(PYTHON_SOABI "")
if(PYTHON_VERSION_MAJOR EQUAL 3 AND NOT WIN32)
execute_process(
COMMAND
"${PYTHON_EXECUTABLE}" "-c"
"from sysconfig import get_config_var; print('.' + get_config_var('SOABI'))"
OUTPUT_VARIABLE PYTHON_SOABI)
string(STRIP ${PYTHON_SOABI} PYTHON_SOABI)
endif()
# Get PYTHON_EXT_SUFFIX
set(PYTHON_EXT_SUFFIX "")
if(PYTHON_VERSION_MAJOR EQUAL 3)
execute_process(
COMMAND
"${PYTHON_EXECUTABLE}" "-c"
"from sysconfig import get_config_var; print(get_config_var('EXT_SUFFIX'))"
OUTPUT_VARIABLE PYTHON_EXT_SUFFIX)
string(STRIP ${PYTHON_EXT_SUFFIX} PYTHON_EXT_SUFFIX)
endif()
if("${PYTHON_EXT_SUFFIX}" STREQUAL "")
if(WIN32)
set(PYTHON_EXT_SUFFIX ".pyd")
else()
set(PYTHON_EXT_SUFFIX ".so")
endif()
endif()
if(PYTHON_EXPORT_DEPENDENCY)
install_jrl_cmakemodules_file("python.cmake")
install_jrl_cmakemodules_file("python-helpers.cmake")
string(
CONCAT PYTHON_EXPORT_DEPENDENCY_MACROS
"list(APPEND PYTHON_COMPONENTS ${PYTHON_COMPONENTS})\n"
"list(REMOVE_DUPLICATES PYTHON_COMPONENTS)\n"
"if(NOT FINDPYTHON_ALREADY_CALLED)\n"
"FINDPYTHON()\n"
"endif()\n")
endif()
if(SEARCH_FOR_NUMPY)
find_numpy()
if(PYTHON_EXPORT_DEPENDENCY)
set(PYTHON_EXPORT_DEPENDENCY_MACROS
"set(SEARCH_FOR_NUMPY TRUE)\n${PYTHON_EXPORT_DEPENDENCY_MACROS}")
endif()
endif()
if(SEARCH_FOR_NUMPY)
message(STATUS "NumPy include dir: ${NUMPY_INCLUDE_DIRS}")
list(APPEND NUMPY_INCLUDE_DIRS)
endif()
# Log Python variables
list(
APPEND
LOGGING_WATCHED_VARIABLES
PYTHONINTERP_FOUND
PYTHONLIBS_FOUND
PYTHON_LIBRARY_DIRS
PYTHONLIBS_VERSION_STRING
PYTHON_EXECUTABLE
PYTHON_SOABI
PYTHON_EXT_SUFFIX)
endmacro(FINDPYTHON)
# .rst: .. command:: FIND_NUMPY()
#
# Detect numpy module and define the variable NUMPY_INCLUDE_DIRS if it is not
# already set.
#
macro(FIND_NUMPY)
# Detect numpy.
message(STATUS "Checking for NumPy")
execute_process(
COMMAND "${PYTHON_EXECUTABLE}" "-c" "import numpy; print (True)"
OUTPUT_VARIABLE IS_NUMPY
ERROR_QUIET)
if(NOT IS_NUMPY)
message(FATAL_ERROR "Failed to detect numpy")
else()
if(NOT NUMPY_INCLUDE_DIRS)
execute_process(
COMMAND "${PYTHON_EXECUTABLE}" "-c"
"import numpy; print (numpy.get_include())"
OUTPUT_VARIABLE NUMPY_INCLUDE_DIRS
ERROR_QUIET)
string(REGEX REPLACE "\n$" "" NUMPY_INCLUDE_DIRS "${NUMPY_INCLUDE_DIRS}")
file(TO_CMAKE_PATH "${NUMPY_INCLUDE_DIRS}" NUMPY_INCLUDE_DIRS)
endif()
message(STATUS " NUMPY_INCLUDE_DIRS=${NUMPY_INCLUDE_DIRS}")
# Retrive NUMPY_VERSION
execute_process(
COMMAND "${PYTHON_EXECUTABLE}" "-c"
"import numpy; print (numpy.__version__)"
OUTPUT_VARIABLE NUMPY_VERSION
ERROR_QUIET)
string(REGEX REPLACE "\n$" "" NUMPY_VERSION "${NUMPY_VERSION}")
message(STATUS " NUMPY_VERSION=${NUMPY_VERSION}")
endif()
endmacro()
# .rst: .. command:: FIND_SCIPY()
#
# Detect scipy module.
#
macro(FIND_SCIPY)
message(STATUS "Checking for SciPy")
execute_process(
COMMAND "${PYTHON_EXECUTABLE}" "-c" "import scipy; print (True)"
OUTPUT_VARIABLE IS_SCIPY
ERROR_QUIET)
if(NOT IS_SCIPY)
message(FATAL_ERROR "Failed to detect scipy")
else()
# Retrive SCIPY_VERSION
execute_process(
COMMAND "${PYTHON_EXECUTABLE}" "-c"
"import scipy; print (scipy.__version__)"
OUTPUT_VARIABLE SCIPY_VERSION
ERROR_QUIET)
string(REGEX REPLACE "\n$" "" SCIPY_VERSION "${SCIPY_VERSION}")
message(STATUS " SCIPY_VERSION=${SCIPY_VERSION}")
endif()
endmacro()
include(${CMAKE_CURRENT_LIST_DIR}/python-helpers.cmake)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment