Skip to content

Commit 3cacd6a

Browse files
authored
fix(cmake): make EXTRA_ARGS a multi-value argument (#65)
EXTRA_ARGS was a one-value keyword, so only the first token was kept and the rest was silently dropped. Also read the package version from pybind11_mkdoc/__init__.py instead of hardcoding it in cmake/CMakeLists.txt. Assisted-by: ClaudeCode:claude-fable-5
1 parent 5b03a0d commit 3cacd6a

6 files changed

Lines changed: 29 additions & 9 deletions

File tree

‎cmake/CMakeLists.txt‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
cmake_minimum_required(VERSION 3.25...4.3)
2-
project(pybind11_mkdoc)
2+
3+
# Read the version from the Python package; project() accepts numeric components only,
4+
# so any dev/pre-release suffix is dropped.
5+
file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/../pybind11_mkdoc/__init__.py" version_line
6+
REGEX "^__version__ *= *[\"']"
7+
)
8+
if(NOT version_line MATCHES "([0-9]+(\\.[0-9]+)*)")
9+
message(FATAL_ERROR "Could not read __version__ from pybind11_mkdoc/__init__.py")
10+
endif()
11+
12+
project(pybind11_mkdoc VERSION "${CMAKE_MATCH_1}")
313

414
include(CMakePackageConfigHelpers)
515

616
# Generate version file
717
write_basic_package_version_file(
818
"${CMAKE_CURRENT_BINARY_DIR}/pybind11_mkdocConfigVersion.cmake"
9-
VERSION 2.6.2
19+
VERSION ${PROJECT_VERSION}
1020
COMPATIBILITY SameMajorVersion
1121
)
1222

‎cmake/pybind11_mkdoc_functions.cmake‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# current source directory.
1212
#
1313
# The optional parameters are:
14-
# * EXTRA_ARGS - This string argument will be added verbatim to the pybind11-mkdoc command.
14+
# * EXTRA_ARGS - A list of arguments that will be added verbatim to the pybind11-mkdoc command.
1515
#
1616
# Example usage:
1717
# pybind11_add_module(my_pybind11_module src/my_pybind11_module.cc)
@@ -24,8 +24,8 @@
2424
# )
2525
function (pybind11_mkdoc)
2626
set(options)
27-
set(oneValueArgs OUTPUT PYBIND11_MODULE EXTRA_ARGS)
28-
set(multiValueArgs HEADERS)
27+
set(oneValueArgs OUTPUT PYBIND11_MODULE)
28+
set(multiValueArgs HEADERS EXTRA_ARGS)
2929
cmake_parse_arguments(PARSE_ARGV 0 arg
3030
"${options}" "${oneValueArgs}" "${multiValueArgs}"
3131
)

‎pybind11_mkdoc/share/cmake/pybind11_mkdoc/pybind11_mkdoc_functions.cmake‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# current source directory.
1212
#
1313
# The optional parameters are:
14-
# * EXTRA_ARGS - This string argument will be added verbatim to the pybind11-mkdoc command.
14+
# * EXTRA_ARGS - A list of arguments that will be added verbatim to the pybind11-mkdoc command.
1515
#
1616
# Example usage:
1717
# pybind11_add_module(my_pybind11_module src/my_pybind11_module.cc)
@@ -24,8 +24,8 @@
2424
# )
2525
function (pybind11_mkdoc)
2626
set(options)
27-
set(oneValueArgs OUTPUT PYBIND11_MODULE EXTRA_ARGS)
28-
set(multiValueArgs HEADERS)
27+
set(oneValueArgs OUTPUT PYBIND11_MODULE)
28+
set(multiValueArgs HEADERS EXTRA_ARGS)
2929
cmake_parse_arguments(PARSE_ARGV 0 arg
3030
"${options}" "${oneValueArgs}" "${multiValueArgs}"
3131
)

‎tests/cmake_docs/my_module_docs_extra_truth.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ This is the extended description for method1.
6464

6565
static const char *mkd_doc_Base_method3 = R"doc(A method that is only included if MY_EXTRA_DEFINE is defined.)doc";
6666

67+
static const char *mkd_doc_Base_method4 = R"doc(A method that is only included if MY_OTHER_DEFINE is defined.)doc";
68+
6769
static const char *mkd_doc_RootLevelSymbol =
6870
R"doc(Root-level symbol. Magna fermentum iaculis eu non diam phasellus
6971
vestibulum.)doc";

‎tests/cmake_test.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ def test_pybind11_mkdoc_cmake_extra_args(tmp_path: Path) -> None:
2727
# Run pybind11-mkdoc and put the output in a temp file
2828
build_dir = tmp_path / "build"
2929
env = os.environ.copy()
30-
env["PYBIND11_TEST_EXTRA_ARGS"] = "-DMY_EXTRA_DEFINE=1"
30+
# A CMake list, so it reaches the function as two separate arguments
31+
env["PYBIND11_TEST_EXTRA_ARGS"] = "-DMY_EXTRA_DEFINE=1;-DMY_OTHER_DEFINE=1"
3132

3233
subprocess.run(
3334
["cmake", "-B", build_dir, "-S", DIR / "cmake_docs", f"-DPython_EXECUTABLE={sys.executable}"],

‎tests/sample_header_docs/sample_header_2.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,11 @@ class Base {
4545
*/
4646
void method3();
4747
#endif
48+
49+
#ifdef MY_OTHER_DEFINE
50+
/**
51+
* @brief A method that is only included if MY_OTHER_DEFINE is defined.
52+
*/
53+
void method4();
54+
#endif
4855
};

0 commit comments

Comments
 (0)