Skip to content

Commit 44d7c59

Browse files
loriabwjakob
authored andcommitted
make installation include and Config dirs configurable. set CMake project version from source.
1 parent 76e993a commit 44d7c59

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

CMakeLists.txt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,22 @@ if (PYBIND11_TEST)
179179
add_subdirectory(tests)
180180
endif()
181181

182+
include(GNUInstallDirs)
183+
184+
# extract project version from source
185+
file(STRINGS "${PYBIND11_INCLUDE_DIR}/pybind11/common.h" pybind11_version_defines
186+
REGEX "#define PYBIND11_VERSION_(MAJOR|MINOR|PATCH) ")
187+
foreach(ver ${pybind11_version_defines})
188+
if (ver MATCHES "#define PYBIND11_VERSION_(MAJOR|MINOR|PATCH) +([^ ]+)$")
189+
set(PYBIND11_VERSION_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}" CACHE INTERNAL "")
190+
endif()
191+
endforeach()
192+
set(${PROJECT_NAME}_VERSION ${PYBIND11_VERSION_MAJOR}.${PYBIND11_VERSION_MINOR}.${PYBIND11_VERSION_PATCH})
193+
182194
if (PYBIND11_INSTALL)
183-
install(FILES ${PYBIND11_HEADERS} DESTINATION include/pybind11)
195+
install(FILES ${PYBIND11_HEADERS}
196+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/pybind11)
197+
# GNUInstallDirs "DATADIR" wrong here; CMake search path wants "share".
198+
set(PYBIND11_CMAKECONFIG_INSTALL_DIR "share/cmake/${PROJECT_NAME}" CACHE STRING "install path for pybind11Config.cmake")
199+
184200
endif()

0 commit comments

Comments
 (0)