@@ -19,7 +19,32 @@ execute_process(
1919 RESULT_VARIABLE NANOBIND_RESULT
2020 ERROR_QUIET
2121)
22- if (NOT NANOBIND_RESULT EQUAL 0)
22+ execute_process (
23+ COMMAND ${Python3_EXECUTABLE} -c "import nanobind; print(nanobind.include_dir(), end='')"
24+ OUTPUT_VARIABLE NANOBIND_INCLUDE_DIR
25+ RESULT_VARIABLE NANOBIND_INCLUDE_RESULT
26+ ERROR_QUIET
27+ )
28+
29+ if (NOT NANOBIND_RESULT EQUAL 0 OR NOT NANOBIND_INCLUDE_RESULT EQUAL 0)
30+ execute_process (
31+ COMMAND brew --prefix nanobind
32+ OUTPUT_VARIABLE NANOBIND_BREW_PREFIX
33+ OUTPUT_STRIP_TRAILING_WHITESPACE
34+ RESULT_VARIABLE NANOBIND_BREW_RESULT
35+ ERROR_QUIET
36+ )
37+ if (NANOBIND_BREW_RESULT EQUAL 0 AND EXISTS "${NANOBIND_BREW_PREFIX} " )
38+ if (NOT NANOBIND_CMAKE_DIR OR NOT EXISTS "${NANOBIND_CMAKE_DIR} " )
39+ set (NANOBIND_CMAKE_DIR "${NANOBIND_BREW_PREFIX} /share/nanobind/cmake" )
40+ endif ()
41+ if (NOT NANOBIND_INCLUDE_DIR OR NOT EXISTS "${NANOBIND_INCLUDE_DIR} " )
42+ set (NANOBIND_INCLUDE_DIR "${NANOBIND_BREW_PREFIX} /include" )
43+ endif ()
44+ endif ()
45+ endif ()
46+
47+ if (NOT NANOBIND_CMAKE_DIR OR NOT EXISTS "${NANOBIND_CMAKE_DIR} " )
2348 find_path (NANOBIND_CMAKE_DIR
2449 NAMES nanobind-config.cmake
2550 PATHS
@@ -31,14 +56,7 @@ if(NOT NANOBIND_RESULT EQUAL 0)
3156 /usr/lib/cmake/nanobind
3257 )
3358endif ()
34-
35- execute_process (
36- COMMAND ${Python3_EXECUTABLE} -c "import nanobind; print(nanobind.include_dir(), end='')"
37- OUTPUT_VARIABLE NANOBIND_INCLUDE_DIR
38- RESULT_VARIABLE NANOBIND_INCLUDE_RESULT
39- ERROR_QUIET
40- )
41- if (NOT NANOBIND_INCLUDE_RESULT EQUAL 0)
59+ if (NOT NANOBIND_INCLUDE_DIR OR NOT EXISTS "${NANOBIND_INCLUDE_DIR} " )
4260 find_path (NANOBIND_INCLUDE_DIR
4361 NAMES nanobind/nanobind.h
4462 PATHS
@@ -66,7 +84,22 @@ execute_process(
6684 RESULT_VARIABLE PYBIND11_RESULT
6785 ERROR_QUIET
6886)
87+
6988if (NOT PYBIND11_RESULT EQUAL 0)
89+ execute_process (
90+ COMMAND brew --prefix pybind11
91+ OUTPUT_VARIABLE PYBIND11_BREW_PREFIX
92+ OUTPUT_STRIP_TRAILING_WHITESPACE
93+ RESULT_VARIABLE PYBIND11_BREW_RESULT
94+ ERROR_QUIET
95+ )
96+ if (PYBIND11_BREW_RESULT EQUAL 0 AND EXISTS "${PYBIND11_BREW_PREFIX} " )
97+ set (PYBIND11_DIR "${PYBIND11_BREW_PREFIX} /share/cmake/pybind11" )
98+ endif ()
99+ endif ()
100+
101+ # それでも見つからない場合、システムパスを検索
102+ if (NOT PYBIND11_DIR OR NOT EXISTS "${PYBIND11_DIR} " )
70103 find_path (PYBIND11_DIR
71104 NAMES pybind11Config.cmake
72105 PATHS
@@ -78,6 +111,7 @@ if(NOT PYBIND11_RESULT EQUAL 0)
78111 /usr/lib/cmake/pybind11
79112 )
80113endif ()
114+
81115if (PYBIND11_DIR)
82116 message (STATUS "pybind11 dir: ${PYBIND11_DIR} " )
83117else ()
0 commit comments