Skip to content

Commit

Permalink
Add REQUESTED_PYTHON_VERSION CMAKE_ARGS option for Boost
Browse files Browse the repository at this point in the history
1) REQUESTED_PYTHON_VERSION added, tested for boost 1.66.0 and 1.68.0-p1 on Ubuntu
2) Example added showing how to use Hunter with Boost Python and the REQUESTED_PYTHON_VERSION option
2) Boost Package documentation updated with infor about REQUESTED_PYTHON_VERSION option
  • Loading branch information
Algomorph committed Dec 18, 2018
1 parent 0f6dc8f commit 186e0bb
Show file tree
Hide file tree
Showing 35 changed files with 191 additions and 32 deletions.
2 changes: 1 addition & 1 deletion cmake/projects/Boost/atomic/hunter.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ hunter_download(
Boost
PACKAGE_COMPONENT
atomic
PACKAGE_INTERNAL_DEPS_ID "36"
PACKAGE_INTERNAL_DEPS_ID "37"
)
2 changes: 1 addition & 1 deletion cmake/projects/Boost/chrono/hunter.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ hunter_download(
Boost
PACKAGE_COMPONENT
chrono
PACKAGE_INTERNAL_DEPS_ID "36"
PACKAGE_INTERNAL_DEPS_ID "37"
)
2 changes: 1 addition & 1 deletion cmake/projects/Boost/context/hunter.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ hunter_download(
Boost
PACKAGE_COMPONENT
context
PACKAGE_INTERNAL_DEPS_ID "36"
PACKAGE_INTERNAL_DEPS_ID "37"
)
2 changes: 1 addition & 1 deletion cmake/projects/Boost/contract/hunter.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ hunter_download(
Boost
PACKAGE_COMPONENT
contract
PACKAGE_INTERNAL_DEPS_ID "36"
PACKAGE_INTERNAL_DEPS_ID "37"
)
2 changes: 1 addition & 1 deletion cmake/projects/Boost/coroutine/hunter.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ hunter_download(
Boost
PACKAGE_COMPONENT
coroutine
PACKAGE_INTERNAL_DEPS_ID "36"
PACKAGE_INTERNAL_DEPS_ID "37"
)
2 changes: 1 addition & 1 deletion cmake/projects/Boost/date_time/hunter.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ hunter_download(
Boost
PACKAGE_COMPONENT
date_time
PACKAGE_INTERNAL_DEPS_ID "36"
PACKAGE_INTERNAL_DEPS_ID "37"
)
2 changes: 1 addition & 1 deletion cmake/projects/Boost/exception/hunter.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ hunter_download(
Boost
PACKAGE_COMPONENT
exception
PACKAGE_INTERNAL_DEPS_ID "36"
PACKAGE_INTERNAL_DEPS_ID "37"
)
2 changes: 1 addition & 1 deletion cmake/projects/Boost/fiber/hunter.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ hunter_download(
Boost
PACKAGE_COMPONENT
fiber
PACKAGE_INTERNAL_DEPS_ID "36"
PACKAGE_INTERNAL_DEPS_ID "37"
)
2 changes: 1 addition & 1 deletion cmake/projects/Boost/filesystem/hunter.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ hunter_download(
Boost
PACKAGE_COMPONENT
filesystem
PACKAGE_INTERNAL_DEPS_ID "36"
PACKAGE_INTERNAL_DEPS_ID "37"
)
2 changes: 1 addition & 1 deletion cmake/projects/Boost/graph/hunter.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ hunter_download(
Boost
PACKAGE_COMPONENT
graph
PACKAGE_INTERNAL_DEPS_ID "36"
PACKAGE_INTERNAL_DEPS_ID "37"
)
2 changes: 1 addition & 1 deletion cmake/projects/Boost/graph_parallel/hunter.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ hunter_download(
Boost
PACKAGE_COMPONENT
graph_parallel
PACKAGE_INTERNAL_DEPS_ID "36"
PACKAGE_INTERNAL_DEPS_ID "37"
)
4 changes: 2 additions & 2 deletions cmake/projects/Boost/hunter.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ hunter_add_version(
URL
"https://github.com/hunter-packages/boost/archive/v1.68.0-p1.tar.gz"
SHA1
0bb10b0a0fdc196646c87e0143c0290baa32357d
0bb10b0a0fdc196646c87e0143c0290baa32357d
)

# up until 1.63 sourcefourge was used
Expand Down Expand Up @@ -367,4 +367,4 @@ endif()

hunter_pick_scheme(DEFAULT url_sha1_boost)
hunter_cacheable(Boost)
hunter_download(PACKAGE_NAME Boost PACKAGE_INTERNAL_DEPS_ID "36")
hunter_download(PACKAGE_NAME Boost PACKAGE_INTERNAL_DEPS_ID "37")
2 changes: 1 addition & 1 deletion cmake/projects/Boost/hunter.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ hunter_download(
Boost
PACKAGE_COMPONENT
boost_component
PACKAGE_INTERNAL_DEPS_ID "36"
PACKAGE_INTERNAL_DEPS_ID "37"
)
2 changes: 1 addition & 1 deletion cmake/projects/Boost/iostreams/hunter.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ hunter_download(
Boost
PACKAGE_COMPONENT
iostreams
PACKAGE_INTERNAL_DEPS_ID "36"
PACKAGE_INTERNAL_DEPS_ID "37"
)
2 changes: 1 addition & 1 deletion cmake/projects/Boost/locale/hunter.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ hunter_download(
Boost
PACKAGE_COMPONENT
locale
PACKAGE_INTERNAL_DEPS_ID "36"
PACKAGE_INTERNAL_DEPS_ID "37"
)
2 changes: 1 addition & 1 deletion cmake/projects/Boost/log/hunter.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ hunter_download(
Boost
PACKAGE_COMPONENT
log
PACKAGE_INTERNAL_DEPS_ID "36"
PACKAGE_INTERNAL_DEPS_ID "37"
)
2 changes: 1 addition & 1 deletion cmake/projects/Boost/math/hunter.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ hunter_download(
Boost
PACKAGE_COMPONENT
math
PACKAGE_INTERNAL_DEPS_ID "36"
PACKAGE_INTERNAL_DEPS_ID "37"
)
2 changes: 1 addition & 1 deletion cmake/projects/Boost/mpi/hunter.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ hunter_download(
Boost
PACKAGE_COMPONENT
mpi
PACKAGE_INTERNAL_DEPS_ID "36"
PACKAGE_INTERNAL_DEPS_ID "37"
)
2 changes: 1 addition & 1 deletion cmake/projects/Boost/program_options/hunter.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ hunter_download(
Boost
PACKAGE_COMPONENT
program_options
PACKAGE_INTERNAL_DEPS_ID "36"
PACKAGE_INTERNAL_DEPS_ID "37"
)
2 changes: 1 addition & 1 deletion cmake/projects/Boost/python/hunter.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ hunter_download(
Boost
PACKAGE_COMPONENT
python
PACKAGE_INTERNAL_DEPS_ID "36"
PACKAGE_INTERNAL_DEPS_ID "37"
)
2 changes: 1 addition & 1 deletion cmake/projects/Boost/random/hunter.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ hunter_download(
Boost
PACKAGE_COMPONENT
random
PACKAGE_INTERNAL_DEPS_ID "36"
PACKAGE_INTERNAL_DEPS_ID "37"
)
2 changes: 1 addition & 1 deletion cmake/projects/Boost/regex/hunter.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ hunter_download(
Boost
PACKAGE_COMPONENT
regex
PACKAGE_INTERNAL_DEPS_ID "36"
PACKAGE_INTERNAL_DEPS_ID "37"
)
49 changes: 49 additions & 0 deletions cmake/projects/Boost/schemes/url_sha1_boost_library.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ include(hunter_status_print)
include(hunter_assert_not_empty_string)
include(hunter_user_error)
include(hunter_parse_boost_config_macros)
include(hunter_parse_cmake_args_for_keyword)

hunter_status_debug("Scheme: url_sha1_boost_library")

Expand Down Expand Up @@ -194,6 +195,8 @@ else()
set(link_opts link=shared)
endif()

# Modify Boost user jam file

set(toolset_full_name ${toolset_name})
string(COMPARE NOTEQUAL "${toolset_version}" "" has_toolset_version)
if(has_toolset_version)
Expand Down Expand Up @@ -286,6 +289,52 @@ file(
"${using_mpi}\n"
)

# handle requested python version if such is specified
hunter_parse_cmake_args_for_keyword(
CMAKE_ARGS "@HUNTER_Boost_CMAKE_ARGS@"
KEYWORD REQUESTED_PYTHON_VERSION
OUTPUT requested_python
)

# set up paths for python in boost.user.jam
if(NOT requested_python STREQUAL "")
find_package(PythonInterp ${requested_python} EXACT QUIET)
if(NOT PYTHONINTERP_FOUND)
hunter_user_error("Python Interpreter for Python version ${requested_python} not found.")
endif()
set(python_executable ${PYTHON_EXECUTABLE})
execute_process(
COMMAND "${python_executable}" -c "import os.path, sysconfig; info = sysconfig.get_paths(); print(info['include'])"
RESULT_VARIABLE python_process
OUTPUT_VARIABLE python_include_directory
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NOT python_process EQUAL 0)
hunter_user_error("Python include directory for Python version ${requested_python} not found.")
endif()
if(NOT EXISTS "${python_include_directory}")
hunter_internal_error("Directory not found: ${python_include_directory}")
endif()
execute_process(
COMMAND "${python_executable}" -c "import os.path, sysconfig; info = sysconfig.get_paths(); print(os.path.dirname(info['stdlib']))"
RESULT_VARIABLE python_process
OUTPUT_VARIABLE python_library_directory
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NOT python_process EQUAL 0)
hunter_user_error("Python runtime library directory for Python version ${requested_python} not found.")
endif()
if(NOT EXISTS "${python_library_directory}")
hunter_internal_error("Directory not found: ${python_library_directory}")
endif()
file(
APPEND ${boost_user_jam}
"using python : ${requested_python} : \"${python_executable}\" : \"${python_include_directory}\" : \"${python_library_directory}\" ;\n"
)
endif()

# Handle ./b2 build options

list(APPEND build_opts ${b2_component_opts})

if(CMAKE_EXE_LINKER_FLAGS)
Expand Down
2 changes: 1 addition & 1 deletion cmake/projects/Boost/serialization/hunter.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ hunter_download(
Boost
PACKAGE_COMPONENT
serialization
PACKAGE_INTERNAL_DEPS_ID "36"
PACKAGE_INTERNAL_DEPS_ID "37"
)
2 changes: 1 addition & 1 deletion cmake/projects/Boost/signals/hunter.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ hunter_download(
Boost
PACKAGE_COMPONENT
signals
PACKAGE_INTERNAL_DEPS_ID "36"
PACKAGE_INTERNAL_DEPS_ID "37"
)
2 changes: 1 addition & 1 deletion cmake/projects/Boost/stacktrace/hunter.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ hunter_download(
Boost
PACKAGE_COMPONENT
stacktrace
PACKAGE_INTERNAL_DEPS_ID "36"
PACKAGE_INTERNAL_DEPS_ID "37"
)
2 changes: 1 addition & 1 deletion cmake/projects/Boost/system/hunter.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ hunter_download(
Boost
PACKAGE_COMPONENT
system
PACKAGE_INTERNAL_DEPS_ID "36"
PACKAGE_INTERNAL_DEPS_ID "37"
)
2 changes: 1 addition & 1 deletion cmake/projects/Boost/test/hunter.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ hunter_download(
Boost
PACKAGE_COMPONENT
test
PACKAGE_INTERNAL_DEPS_ID "36"
PACKAGE_INTERNAL_DEPS_ID "37"
)
2 changes: 1 addition & 1 deletion cmake/projects/Boost/thread/hunter.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ hunter_download(
Boost
PACKAGE_COMPONENT
thread
PACKAGE_INTERNAL_DEPS_ID "36"
PACKAGE_INTERNAL_DEPS_ID "37"
)
2 changes: 1 addition & 1 deletion cmake/projects/Boost/timer/hunter.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ hunter_download(
Boost
PACKAGE_COMPONENT
timer
PACKAGE_INTERNAL_DEPS_ID "36"
PACKAGE_INTERNAL_DEPS_ID "37"
)
2 changes: 1 addition & 1 deletion cmake/projects/Boost/wave/hunter.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ hunter_download(
Boost
PACKAGE_COMPONENT
wave
PACKAGE_INTERNAL_DEPS_ID "36"
PACKAGE_INTERNAL_DEPS_ID "37"
)
64 changes: 63 additions & 1 deletion docs/packages/pkg/Boost.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ config file (``boost/config/user.hpp``):
options <http://www.boost.org/doc/libs/1_57_0/libs/iostreams/doc/index.html?path=7>`__

- Options ``CONFIG_MACRO_<ID>=<VALUE>`` will append ``#define <ID> <VALUE>``
to the default boost user config file. And options
to the default boost user config header file. And options
``CONFIG_MACRO=<ID_1>;<ID_2>;...;<ID_n>`` will append ``#define <ID_1>``,
``#define <ID_2>``, ..., ``#define <ID_n>``.
Example:
Expand All @@ -88,6 +88,68 @@ config file (``boost/config/user.hpp``):
#define BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS
#define BOOST_MPL_LIMIT_LIST_SIZE 3
Python
------

To require Boost Python to be built against a specific version of Python installed
on the system, option ``REQUESTED_PYTHON_VERSION=<VALUE>`` may be used. In this case,
if the required components of Python are located, ``user_config.jam``
will be appended with the following line:

.. code-block:: none
using python : <requested_version_number> : <path to Python executable> :
<path to Python include directory> : <path to directory containing the Python library> ;
Example for Python 2:

.. code-block:: cmake
# config.cmake
hunter_config(
Boost
VERSION ${HUNTER_Boost_VERSION}
CMAKE_ARGS
REQUESTED_PYTHON_VERSION=2.7.15
)
.. code-block:: cmake
# CMakeLists.txt
hunter_add_package(Boost COMPONENTS python)
if(Boost_VERSION VERSION_LESS 106700)
find_package(Boost CONFIG REQUIRED python)
else()
find_package(Boost CONFIG REQUIRED python27)
endif()
.. note::

Python<x> component arguments to ``find_package(Boost ...)`` after Boost version 1.67 require
a specific version suffix, e.g. python37.

Example for Python 3:

.. code-block:: cmake
# config.cmake
hunter_config(
Boost
VERSION ${HUNTER_Boost_VERSION}
CMAKE_ARGS
REQUESTED_PYTHON_VERSION=3.6.7
)
.. code-block:: cmake
# CMakeLists.txt
hunter_add_package(Boost COMPONENTS python)
if(Boost_VERSION VERSION_LESS 106700)
find_package(Boost CONFIG REQUIRED python3)
else()
find_package(Boost CONFIG REQUIRED python36)
endif()
Math
----

Expand Down
33 changes: 33 additions & 0 deletions examples/Boost-python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright (c) 2013, Ruslan Baratov
# Modified work: Copyright (c) 2018, Gregory Kramida
# All rights reserved.

cmake_minimum_required(VERSION 3.2)
option(HUNTER_BUILD_SHARED_LIBS "..." ON)

# Configure:
set(REQUESTED_PYTHON_VERSION 3.6.7)
set(TESTING_CONFIG_OPT FILEPATH "${CMAKE_CURRENT_LIST_DIR}/config.cmake")

# Emulate HunterGate:
# * https://github.com/hunter-packages/gate
include("../common.cmake")

project(download-boost)

# Requires python version 3.6.7. Change this in config.cmake if necessary.
hunter_add_package(Boost COMPONENTS python)
find_package(Boost CONFIG REQUIRED python36)
find_package(PythonLibs ${REQUESTED_PYTHON_VERSION} EXACT REQUIRED)

add_library(foo foo.cpp)
target_link_libraries(
foo
PUBLIC
Boost::python36
)
target_include_directories(
foo
PUBLIC
${PYTHON_INCLUDE_DIR}
)
Loading

0 comments on commit 186e0bb

Please sign in to comment.