@@ -161,6 +161,19 @@ add_library(pybind11::headers ALIAS pybind11_headers) # easier to use/remember
161
161
162
162
include ("${CMAKE_CURRENT_SOURCE_DIR} /tools/pybind11Common.cmake" )
163
163
164
+ option (PYBIND11_PRECOMPILE "Precompile parts of pybind11" ON )
165
+ if (PYBIND11_PRECOMPILE)
166
+ file (GLOB_RECURSE SOURCES ${CMAKE_SOURCE_DIR} /include /pybind11/*.cpp)
167
+ # Produce libpybind11.a, which contains position independent object files.
168
+ # that may be used to create a shared library.
169
+ add_library (pybind11_lib STATIC ${SOURCES} ${PYBIND11_HEADERS} )
170
+ set_property (TARGET pybind11_lib PROPERTY POSITION_INDEPENDENT_CODE ON )
171
+ target_compile_definitions (pybind11_lib PUBLIC -DPYBIND11_DECLARATIONS_ONLY=1)
172
+ add_library (pybind11::lib ALIAS pybind11_lib)
173
+ target_link_libraries (pybind11_lib PRIVATE pybind11::pybind11)
174
+ target_link_libraries (pybind11_lib PUBLIC pybind11::headers)
175
+ endif ()
176
+
164
177
if (NOT PYBIND11_MASTER_PROJECT AND NOT pybind11_FIND_QUIETLY)
165
178
message (STATUS "Using pybind11: (version \" ${pybind11_VERSION} \" ${pybind11_VERSION_TYPE} )" )
166
179
endif ()
@@ -269,12 +282,3 @@ if(NOT PYBIND11_MASTER_PROJECT)
269
282
"${PYBIND11_INCLUDE_DIR} "
270
283
CACHE INTERNAL "Directory where pybind11 headers are located" )
271
284
endif ()
272
-
273
- find_package (Python3 COMPONENTS Development)
274
- include_directories (${Python3_INCLUDE_DIRS} )
275
- add_definitions (-DPYBIND11_DECLARATIONS_ONLY=1)
276
- file (GLOB_RECURSE SOURCES ${CMAKE_SOURCE_DIR} /include /pybind11/*.cpp )
277
- # Produce libpybind11.a, which contains position independent object files.
278
- # that may be used to create a shared library.
279
- add_library (pybind11 STATIC ${SOURCES} )
280
- set_property (TARGET pybind11 PROPERTY POSITION_INDEPENDENT_CODE ON )
0 commit comments