Skip to content

Commit 84b0a49

Browse files
committedSep 10, 2020
fix: basic CMake support
1 parent ca375c8 commit 84b0a49

File tree

4 files changed

+21
-10
lines changed

4 files changed

+21
-10
lines changed
 

‎CMakeLists.txt

+13-9
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,19 @@ add_library(pybind11::headers ALIAS pybind11_headers) # easier to use/remember
161161

162162
include("${CMAKE_CURRENT_SOURCE_DIR}/tools/pybind11Common.cmake")
163163

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+
164177
if(NOT PYBIND11_MASTER_PROJECT AND NOT pybind11_FIND_QUIETLY)
165178
message(STATUS "Using pybind11: (version \"${pybind11_VERSION}\" ${pybind11_VERSION_TYPE})")
166179
endif()
@@ -269,12 +282,3 @@ if(NOT PYBIND11_MASTER_PROJECT)
269282
"${PYBIND11_INCLUDE_DIR}"
270283
CACHE INTERNAL "Directory where pybind11 headers are located")
271284
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)

‎include/pybind11/cast.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -560,4 +560,3 @@ PYBIND11_INLINE constexpr arg operator"" _a(const char *name, size_t) { return a
560560
}
561561

562562
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
563-

‎tools/pybind11NewTools.cmake

+4
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ function(pybind11_add_module target_name)
144144

145145
target_link_libraries(${target_name} PRIVATE pybind11::headers)
146146

147+
if(TARGET pybind11::lib)
148+
target_link_libraries(${target_name} PUBLIC pybind11::lib)
149+
endif()
150+
147151
if(type STREQUAL "MODULE")
148152
target_link_libraries(${target_name} PRIVATE pybind11::module)
149153
else()

‎tools/pybind11Tools.cmake

+4
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ function(pybind11_add_module target_name)
148148

149149
target_link_libraries(${target_name} PRIVATE pybind11::module)
150150

151+
if(TARGET pybind11::lib)
152+
target_link_libraries(${target_name} PUBLIC pybind11::lib)
153+
endif()
154+
151155
if(ARG_SYSTEM)
152156
message(
153157
STATUS

0 commit comments

Comments
 (0)
Please sign in to comment.