diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b51b0c63..fc9d04c9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -106,10 +106,10 @@ jobs: run: cmake --build build -j 2 - 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 - run: cmake --build build --target cpptest -j 2 -v + run: cmake --build build --target cpptest -j 2 - name: Interface test C++11 run: cmake --build build --target test_cmake_build @@ -125,7 +125,7 @@ jobs: -DPYTHON_EXECUTABLE=$(python -c "import sys; print(sys.executable)") - 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 }} run: cmake --build build2 --target pytest diff --git a/CMakeLists.txt b/CMakeLists.txt index 0337f0b0..d5a39b4d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,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: if(${CMAKE_VERSION} VERSION_LESS 3.18) cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) @@ -21,14 +21,19 @@ file( "${CMAKE_CURRENT_SOURCE_DIR}/include/pybind11/detail/common.h" pybind11_version_defines REGEX - "#define PYBIND11_VERSION_(MAJOR|MINOR|PATCH|TYPE) ") + "#define PYBIND11_VERSION_(MAJOR|MINOR|PATCH) ") 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}") endif() 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( pybind11 LANGUAGES @@ -42,10 +47,11 @@ include(GNUInstallDirs) include(CMakePackageConfigHelpers) include(CMakeDependentOption) +message(STATUS "pybind11 v${pybind11_VERSION} ${PYBIND11_VERSION_TYPE}") + # Check if pybind11 is being used directly or via add_subdirectory if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) set(PYBIND11_MASTER_PROJECT ON) - message(STATUS "pybind11 v${pybind11_VERSION} ${PYBIND11_VERSION_TYPE}") message(STATUS "CMake ${CMAKE_VERSION}") if(CMAKE_CXX_STANDARD) @@ -92,6 +98,9 @@ set(PYBIND11_HEADERS include/pybind11/stl.h include/pybind11/stl_bind.h ) + +# TODO: compare with grep and warn if missmatched + # cmake 3.12 added list(TRANSFORM PREPEND # But we can't use it yet 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 - # 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: add_library(pybind11 INTERFACE) @@ -139,21 +149,14 @@ if(CMAKE_VERSION VERSION_LESS 3.13) target_compile_features( pybind11 INTERFACE - cxx_auto_type - cxx_constexpr - cxx_defaulted_functions - cxx_lambdas - cxx_nullptr - cxx_range_for - cxx_right_angle_brackets - cxx_strong_enums + cxx_inheriting_constructors cxx_user_literals - cxx_variadic_templates + cxx_right_angle_brackets ) else() # 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+ - # 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) endif() @@ -170,13 +173,16 @@ if(CMAKE_VERSION VERSION_LESS 3.13) target_link_libraries(module INTERFACE "$<$:-undefined dynamic_lookup>") else() # 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 "$<$:SHELL:-undefined dynamic_lookup>") endif() -message(STATUS "CXX Compiler version: ${CMAKE_CXX_COMPILER_VERSION}") - # 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 "$,$,3.9>>>") set(no_register "$>") set(cxx_no_register "$,${no_register}>") @@ -214,6 +220,7 @@ if(PYBIND11_INSTALL) set(CMAKE_SIZEOF_VOID_P ${_PYBIND11_CMAKE_SIZEOF_VOID_P}) else() + # CMake 3.14+ natively supports header-only libraries write_basic_package_version_file( ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake VERSION diff --git a/docs/compiling.rst b/docs/compiling.rst index cef0d594..07f93e7c 100644 --- a/docs/compiling.rst +++ b/docs/compiling.rst @@ -97,7 +97,7 @@ Configuration variables ----------------------- 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 `CMAKE_CXX_STANDARD `_: @@ -124,7 +124,7 @@ For example: # Another method: 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)") .. find_package vs. add_subdirectory diff --git a/include/pybind11/detail/common.h b/include/pybind11/detail/common.h index 2d83e482..8923faef 100644 --- a/include/pybind11/detail/common.h +++ b/include/pybind11/detail/common.h @@ -11,8 +11,7 @@ #define PYBIND11_VERSION_MAJOR 2 #define PYBIND11_VERSION_MINOR 6 -#define PYBIND11_VERSION_PATCH 0 -#define PYBIND11_VERSION_TYPE "dev" +#define PYBIND11_VERSION_PATCH dev0 #define PYBIND11_NAMESPACE_BEGIN(name) namespace name { #define PYBIND11_NAMESPACE_END(name) }