mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-22 05:05:11 +00:00
update: address review points
This commit is contained in:
parent
f64d5aa6da
commit
1651c32492
6
.github/workflows/ci.yml
vendored
6
.github/workflows/ci.yml
vendored
@ -106,10 +106,10 @@ jobs:
|
|||||||
run: cmake --build build -j 2
|
run: cmake --build build -j 2
|
||||||
|
|
||||||
- name: Python tests C++11
|
- name: Python tests C++11
|
||||||
run: cmake --build build --target pytest -j 2 -v
|
run: cmake --build build --target pytest -j 2
|
||||||
|
|
||||||
- name: C++11 tests
|
- name: C++11 tests
|
||||||
run: cmake --build build --target cpptest -j 2 -v
|
run: cmake --build build --target cpptest -j 2
|
||||||
|
|
||||||
- name: Interface test C++11
|
- name: Interface test C++11
|
||||||
run: cmake --build build --target test_cmake_build
|
run: cmake --build build --target test_cmake_build
|
||||||
@ -125,7 +125,7 @@ jobs:
|
|||||||
-DPYTHON_EXECUTABLE=$(python -c "import sys; print(sys.executable)")
|
-DPYTHON_EXECUTABLE=$(python -c "import sys; print(sys.executable)")
|
||||||
|
|
||||||
- name: Build C++${{ matrix.max-cxx-std }}
|
- name: Build C++${{ matrix.max-cxx-std }}
|
||||||
run: cmake --build build2 -j 2 -v
|
run: cmake --build build2 -j 2
|
||||||
|
|
||||||
- name: Python tests C++${{ matrix.max-cxx-std }}
|
- name: Python tests C++${{ matrix.max-cxx-std }}
|
||||||
run: cmake --build build2 --target pytest
|
run: cmake --build build2 --target pytest
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
cmake_minimum_required(VERSION 3.7)
|
cmake_minimum_required(VERSION 3.7)
|
||||||
|
|
||||||
# VERSION 3.7...3.18, but some versions of VS have a patched CMake 3.11
|
# VERSION 3.7...3.18, but some versions of MCVS have a patched CMake 3.11
|
||||||
# that do not work properly with this syntax, so using the following workaround:
|
# that do not work properly with this syntax, so using the following workaround:
|
||||||
if(${CMAKE_VERSION} VERSION_LESS 3.18)
|
if(${CMAKE_VERSION} VERSION_LESS 3.18)
|
||||||
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
|
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
|
||||||
@ -21,14 +21,19 @@ file(
|
|||||||
"${CMAKE_CURRENT_SOURCE_DIR}/include/pybind11/detail/common.h"
|
"${CMAKE_CURRENT_SOURCE_DIR}/include/pybind11/detail/common.h"
|
||||||
pybind11_version_defines
|
pybind11_version_defines
|
||||||
REGEX
|
REGEX
|
||||||
"#define PYBIND11_VERSION_(MAJOR|MINOR|PATCH|TYPE) ")
|
"#define PYBIND11_VERSION_(MAJOR|MINOR|PATCH) ")
|
||||||
|
|
||||||
foreach(ver ${pybind11_version_defines})
|
foreach(ver ${pybind11_version_defines})
|
||||||
if (ver MATCHES [=[#define PYBIND11_VERSION_(MAJOR|MINOR|PATCH|TYPE) +"?([^ ^"]+)"?$]=])
|
if (ver MATCHES [[#define PYBIND11_VERSION_(MAJOR|MINOR|PATCH) +([^ ]+)$]])
|
||||||
set(PYBIND11_VERSION_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}")
|
set(PYBIND11_VERSION_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}")
|
||||||
endif()
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
|
if(PYBIND11_VERSION_PATCH MATCHES [[([a-zA-Z]+)]])
|
||||||
|
set(PYBIND11_VERSION_TYPE "${CMAKE_MATCH_1}")
|
||||||
|
endif()
|
||||||
|
string(REGEX MATCH "[0-9]+" PYBIND11_VERSION_PATCH "${PYBIND11_VERSION_PATCH}")
|
||||||
|
|
||||||
project(
|
project(
|
||||||
pybind11
|
pybind11
|
||||||
LANGUAGES
|
LANGUAGES
|
||||||
@ -42,10 +47,11 @@ include(GNUInstallDirs)
|
|||||||
include(CMakePackageConfigHelpers)
|
include(CMakePackageConfigHelpers)
|
||||||
include(CMakeDependentOption)
|
include(CMakeDependentOption)
|
||||||
|
|
||||||
|
message(STATUS "pybind11 v${pybind11_VERSION} ${PYBIND11_VERSION_TYPE}")
|
||||||
|
|
||||||
# Check if pybind11 is being used directly or via add_subdirectory
|
# Check if pybind11 is being used directly or via add_subdirectory
|
||||||
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
|
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
|
||||||
set(PYBIND11_MASTER_PROJECT ON)
|
set(PYBIND11_MASTER_PROJECT ON)
|
||||||
message(STATUS "pybind11 v${pybind11_VERSION} ${PYBIND11_VERSION_TYPE}")
|
|
||||||
message(STATUS "CMake ${CMAKE_VERSION}")
|
message(STATUS "CMake ${CMAKE_VERSION}")
|
||||||
|
|
||||||
if(CMAKE_CXX_STANDARD)
|
if(CMAKE_CXX_STANDARD)
|
||||||
@ -92,6 +98,9 @@ set(PYBIND11_HEADERS
|
|||||||
include/pybind11/stl.h
|
include/pybind11/stl.h
|
||||||
include/pybind11/stl_bind.h
|
include/pybind11/stl_bind.h
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# TODO: compare with grep and warn if missmatched
|
||||||
|
|
||||||
# cmake 3.12 added list(TRANSFORM <list> PREPEND
|
# cmake 3.12 added list(TRANSFORM <list> PREPEND
|
||||||
# But we can't use it yet
|
# But we can't use it yet
|
||||||
string(REPLACE "include/" "${CMAKE_CURRENT_SOURCE_DIR}/include/"
|
string(REPLACE "include/" "${CMAKE_CURRENT_SOURCE_DIR}/include/"
|
||||||
@ -125,6 +134,7 @@ endif()
|
|||||||
|
|
||||||
# Note: when creating targets, you cannot use if statements at configure time -
|
# Note: when creating targets, you cannot use if statements at configure time -
|
||||||
# you need generator expressions, because those will be placed in the target file.
|
# you need generator expressions, because those will be placed in the target file.
|
||||||
|
# You can also place ifs *in* the Config.in, but not here.
|
||||||
|
|
||||||
# Build an interface library target:
|
# Build an interface library target:
|
||||||
add_library(pybind11 INTERFACE)
|
add_library(pybind11 INTERFACE)
|
||||||
@ -139,21 +149,14 @@ if(CMAKE_VERSION VERSION_LESS 3.13)
|
|||||||
target_compile_features(
|
target_compile_features(
|
||||||
pybind11
|
pybind11
|
||||||
INTERFACE
|
INTERFACE
|
||||||
cxx_auto_type
|
cxx_inheriting_constructors
|
||||||
cxx_constexpr
|
|
||||||
cxx_defaulted_functions
|
|
||||||
cxx_lambdas
|
|
||||||
cxx_nullptr
|
|
||||||
cxx_range_for
|
|
||||||
cxx_right_angle_brackets
|
|
||||||
cxx_strong_enums
|
|
||||||
cxx_user_literals
|
cxx_user_literals
|
||||||
cxx_variadic_templates
|
cxx_right_angle_brackets
|
||||||
)
|
)
|
||||||
else()
|
else()
|
||||||
# This was added in CMake 3.8, but we are keeping a consistent breaking
|
# This was added in CMake 3.8, but we are keeping a consistent breaking
|
||||||
# point for the config file at 3.13. A config generated by CMake 3.13+
|
# point for the config file at 3.13. A config generated by CMake 3.13+
|
||||||
# can ony be read in 3.13+ due to the SHELL usage later, so this is safe to do.
|
# can only be read in 3.13+ due to the SHELL usage later, so this is safe to do.
|
||||||
target_compile_features(pybind11 INTERFACE cxx_std_11)
|
target_compile_features(pybind11 INTERFACE cxx_std_11)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
@ -170,13 +173,16 @@ if(CMAKE_VERSION VERSION_LESS 3.13)
|
|||||||
target_link_libraries(module INTERFACE "$<$<PLATFORM_ID:Darwin>:-undefined dynamic_lookup>")
|
target_link_libraries(module INTERFACE "$<$<PLATFORM_ID:Darwin>:-undefined dynamic_lookup>")
|
||||||
else()
|
else()
|
||||||
# SHELL (3.12+) forces this to remain together, and link_options was added in 3.13+
|
# SHELL (3.12+) forces this to remain together, and link_options was added in 3.13+
|
||||||
|
# This is safer, because you are ensured the deduplication pass in CMake will not consider
|
||||||
|
# these separate and remove one but not the other.
|
||||||
target_link_options(module INTERFACE "$<$<PLATFORM_ID:Darwin>:SHELL:-undefined dynamic_lookup>")
|
target_link_options(module INTERFACE "$<$<PLATFORM_ID:Darwin>:SHELL:-undefined dynamic_lookup>")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
message(STATUS "CXX Compiler version: ${CMAKE_CXX_COMPILER_VERSION}")
|
|
||||||
|
|
||||||
# Workaround for Python 2.7 and C++17 (C++14 as a warning) incompatibility
|
# Workaround for Python 2.7 and C++17 (C++14 as a warning) incompatibility
|
||||||
|
# This adds the flags -Wno-register and -Wno-deprecated-register if the compiler
|
||||||
|
# is Clang 3.9+ or AppleClang and the compile language is CXX, or /wd5033 for MSVC (all languages,
|
||||||
|
# since MSVC didn't recognize COMPILE_LANGUAGE until CMake 3.11+).
|
||||||
set(clang_4plus "$<AND:$<CXX_COMPILER_ID:Clang>,$<NOT:$<VERSION_LESS:$<CXX_COMPILER_VERSION>,3.9>>>")
|
set(clang_4plus "$<AND:$<CXX_COMPILER_ID:Clang>,$<NOT:$<VERSION_LESS:$<CXX_COMPILER_VERSION>,3.9>>>")
|
||||||
set(no_register "$<OR:${clang_4plus},$<CXX_COMPILER_ID:AppleClang>>")
|
set(no_register "$<OR:${clang_4plus},$<CXX_COMPILER_ID:AppleClang>>")
|
||||||
set(cxx_no_register "$<AND:$<COMPILE_LANGUAGE:CXX>,${no_register}>")
|
set(cxx_no_register "$<AND:$<COMPILE_LANGUAGE:CXX>,${no_register}>")
|
||||||
@ -214,6 +220,7 @@ if(PYBIND11_INSTALL)
|
|||||||
|
|
||||||
set(CMAKE_SIZEOF_VOID_P ${_PYBIND11_CMAKE_SIZEOF_VOID_P})
|
set(CMAKE_SIZEOF_VOID_P ${_PYBIND11_CMAKE_SIZEOF_VOID_P})
|
||||||
else()
|
else()
|
||||||
|
# CMake 3.14+ natively supports header-only libraries
|
||||||
write_basic_package_version_file(
|
write_basic_package_version_file(
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
|
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
|
||||||
VERSION
|
VERSION
|
||||||
|
@ -97,7 +97,7 @@ Configuration variables
|
|||||||
-----------------------
|
-----------------------
|
||||||
|
|
||||||
By default, pybind11 will compile modules with the compiler default or the
|
By default, pybind11 will compile modules with the compiler default or the
|
||||||
minimum standard required by PyBind11, whichever is higher. You can set the
|
minimum standard required by pybind11, whichever is higher. You can set the
|
||||||
standard explicitly with
|
standard explicitly with
|
||||||
`CMAKE_CXX_STANDARD <https://cmake.org/cmake/help/latest/variable/CMAKE_CXX_STANDARD.html>`_:
|
`CMAKE_CXX_STANDARD <https://cmake.org/cmake/help/latest/variable/CMAKE_CXX_STANDARD.html>`_:
|
||||||
|
|
||||||
@ -124,7 +124,7 @@ For example:
|
|||||||
# Another method:
|
# Another method:
|
||||||
cmake -DPYTHON_EXECUTABLE=/path/to/python ..
|
cmake -DPYTHON_EXECUTABLE=/path/to/python ..
|
||||||
|
|
||||||
# You will often see this idiom:
|
# This often is a good way to get the current Python, works in environments:
|
||||||
cmake -DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)") ..
|
cmake -DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)") ..
|
||||||
|
|
||||||
find_package vs. add_subdirectory
|
find_package vs. add_subdirectory
|
||||||
|
@ -11,8 +11,7 @@
|
|||||||
|
|
||||||
#define PYBIND11_VERSION_MAJOR 2
|
#define PYBIND11_VERSION_MAJOR 2
|
||||||
#define PYBIND11_VERSION_MINOR 6
|
#define PYBIND11_VERSION_MINOR 6
|
||||||
#define PYBIND11_VERSION_PATCH 0
|
#define PYBIND11_VERSION_PATCH dev0
|
||||||
#define PYBIND11_VERSION_TYPE "dev"
|
|
||||||
|
|
||||||
#define PYBIND11_NAMESPACE_BEGIN(name) namespace name {
|
#define PYBIND11_NAMESPACE_BEGIN(name) namespace name {
|
||||||
#define PYBIND11_NAMESPACE_END(name) }
|
#define PYBIND11_NAMESPACE_END(name) }
|
||||||
|
Loading…
Reference in New Issue
Block a user