Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
pybind11
Commits
130c9954
Unverified
Commit
130c9954
authored
Jan 19, 2021
by
Henry Schreiner
Committed by
GitHub
Jan 19, 2021
Browse files
fix: support basic dual includes (#2804)
parent
eb83feef
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
32 additions
and
20 deletions
+32
-20
CMakeLists.txt
CMakeLists.txt
+24
-15
tests/test_cmake_build/CMakeLists.txt
tests/test_cmake_build/CMakeLists.txt
+4
-1
tests/test_cmake_build/subdirectory_embed/CMakeLists.txt
tests/test_cmake_build/subdirectory_embed/CMakeLists.txt
+2
-2
tests/test_cmake_build/subdirectory_function/CMakeLists.txt
tests/test_cmake_build/subdirectory_function/CMakeLists.txt
+1
-1
tests/test_cmake_build/subdirectory_target/CMakeLists.txt
tests/test_cmake_build/subdirectory_target/CMakeLists.txt
+1
-1
No files found.
CMakeLists.txt
View file @
130c9954
...
@@ -45,8 +45,13 @@ if(NOT pybind11_FIND_QUIETLY)
...
@@ -45,8 +45,13 @@ if(NOT pybind11_FIND_QUIETLY)
message
(
STATUS
"pybind11 v
${
pybind11_VERSION
}
${
pybind11_VERSION_TYPE
}
"
)
message
(
STATUS
"pybind11 v
${
pybind11_VERSION
}
${
pybind11_VERSION_TYPE
}
"
)
endif
()
endif
()
# Avoid infinite recursion if tests include this as a subdirectory
if
(
DEFINED PYBIND11_MASTER_PROJECT
)
set
(
PYBIND11_TEST OFF
)
endif
()
# Check if pybind11 is being used directly or via add_subdirectory
# Check if pybind11 is being used directly or via add_subdirectory
if
(
CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR
)
if
(
CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR
AND NOT DEFINED PYBIND11_MASTER_PROJECT
)
### Warn if not an out-of-source builds
### Warn if not an out-of-source builds
if
(
CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR
)
if
(
CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR
)
set
(
lines
set
(
lines
...
@@ -161,12 +166,24 @@ endif()
...
@@ -161,12 +166,24 @@ endif()
# You can also place ifs *in* the Config.in, but not here.
# You can also place ifs *in* the Config.in, but not here.
# This section builds targets, but does *not* touch Python
# This section builds targets, but does *not* touch Python
# Non-IMPORT targets cannot be defined twice
# Build the headers-only target (no Python included):
if
(
NOT TARGET pybind11_headers
)
# (long name used here to keep this from clashing in subdirectory mode)
# Build the headers-only target (no Python included):
add_library
(
pybind11_headers INTERFACE
)
# (long name used here to keep this from clashing in subdirectory mode)
add_library
(
pybind11::pybind11_headers ALIAS pybind11_headers
)
# to match exported target
add_library
(
pybind11_headers INTERFACE
)
add_library
(
pybind11::headers ALIAS pybind11_headers
)
# easier to use/remember
add_library
(
pybind11::pybind11_headers ALIAS pybind11_headers
)
# to match exported target
add_library
(
pybind11::headers ALIAS pybind11_headers
)
# easier to use/remember
target_include_directories
(
pybind11_headers
${
pybind11_system
}
INTERFACE $<BUILD_INTERFACE:
${
pybind11_INCLUDE_DIR
}
>
$<INSTALL_INTERFACE:
${
CMAKE_INSTALL_INCLUDEDIR
}
>
)
target_compile_features
(
pybind11_headers INTERFACE cxx_inheriting_constructors cxx_user_literals
cxx_right_angle_brackets
)
else
()
# It is invalid to install a target twice, too.
set
(
PYBIND11_INSTALL OFF
)
endif
()
include
(
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/tools/pybind11Common.cmake"
)
include
(
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/tools/pybind11Common.cmake"
)
...
@@ -177,14 +194,6 @@ elseif(USE_PYTHON_INCLUDE_DIR AND DEFINED PYTHON_INCLUDE_DIR)
...
@@ -177,14 +194,6 @@ elseif(USE_PYTHON_INCLUDE_DIR AND DEFINED PYTHON_INCLUDE_DIR)
file
(
RELATIVE_PATH CMAKE_INSTALL_INCLUDEDIR
${
CMAKE_INSTALL_PREFIX
}
${
PYTHON_INCLUDE_DIRS
}
)
file
(
RELATIVE_PATH CMAKE_INSTALL_INCLUDEDIR
${
CMAKE_INSTALL_PREFIX
}
${
PYTHON_INCLUDE_DIRS
}
)
endif
()
endif
()
# Fill in headers target
target_include_directories
(
pybind11_headers
${
pybind11_system
}
INTERFACE $<BUILD_INTERFACE:
${
pybind11_INCLUDE_DIR
}
>
$<INSTALL_INTERFACE:
${
CMAKE_INSTALL_INCLUDEDIR
}
>
)
target_compile_features
(
pybind11_headers INTERFACE cxx_inheriting_constructors cxx_user_literals
cxx_right_angle_brackets
)
if
(
PYBIND11_INSTALL
)
if
(
PYBIND11_INSTALL
)
install
(
DIRECTORY
${
pybind11_INCLUDE_DIR
}
/pybind11 DESTINATION
${
CMAKE_INSTALL_INCLUDEDIR
}
)
install
(
DIRECTORY
${
pybind11_INCLUDE_DIR
}
/pybind11 DESTINATION
${
CMAKE_INSTALL_INCLUDEDIR
}
)
set
(
PYBIND11_CMAKECONFIG_INSTALL_DIR
set
(
PYBIND11_CMAKECONFIG_INSTALL_DIR
...
...
tests/test_cmake_build/CMakeLists.txt
View file @
130c9954
...
@@ -25,7 +25,7 @@ function(pybind11_add_build_test name)
...
@@ -25,7 +25,7 @@ function(pybind11_add_build_test name)
endif
()
endif
()
if
(
NOT ARG_INSTALL
)
if
(
NOT ARG_INSTALL
)
list
(
APPEND build_options
"-D
PYBIND11_PROJECT
_DIR=
${
pybind11_SOURCE_DIR
}
"
)
list
(
APPEND build_options
"-D
pybind11_SOURCE
_DIR=
${
pybind11_SOURCE_DIR
}
"
)
else
()
else
()
list
(
APPEND build_options
"-DCMAKE_PREFIX_PATH=
${
pybind11_BINARY_DIR
}
/mock_install"
)
list
(
APPEND build_options
"-DCMAKE_PREFIX_PATH=
${
pybind11_BINARY_DIR
}
/mock_install"
)
endif
()
endif
()
...
@@ -79,3 +79,6 @@ if(PYBIND11_INSTALL)
...
@@ -79,3 +79,6 @@ if(PYBIND11_INSTALL)
endif
()
endif
()
add_dependencies
(
check test_cmake_build
)
add_dependencies
(
check test_cmake_build
)
add_subdirectory
(
subdirectory_target EXCLUDE_FROM_ALL
)
add_subdirectory
(
subdirectory_embed EXCLUDE_FROM_ALL
)
tests/test_cmake_build/subdirectory_embed/CMakeLists.txt
View file @
130c9954
...
@@ -16,7 +16,7 @@ set(PYBIND11_INSTALL
...
@@ -16,7 +16,7 @@ set(PYBIND11_INSTALL
CACHE BOOL
""
)
CACHE BOOL
""
)
set
(
PYBIND11_EXPORT_NAME test_export
)
set
(
PYBIND11_EXPORT_NAME test_export
)
add_subdirectory
(
${
PYBIND11_PROJECT
_DIR
}
pybind11
)
add_subdirectory
(
"
${
pybind11_SOURCE
_DIR
}
"
pybind11
)
# Test basic target functionality
# Test basic target functionality
add_executable
(
test_subdirectory_embed ../embed.cpp
)
add_executable
(
test_subdirectory_embed ../embed.cpp
)
...
@@ -24,7 +24,7 @@ target_link_libraries(test_subdirectory_embed PRIVATE pybind11::embed)
...
@@ -24,7 +24,7 @@ target_link_libraries(test_subdirectory_embed PRIVATE pybind11::embed)
set_target_properties
(
test_subdirectory_embed PROPERTIES OUTPUT_NAME test_cmake_build
)
set_target_properties
(
test_subdirectory_embed PROPERTIES OUTPUT_NAME test_cmake_build
)
add_custom_target
(
check_subdirectory_embed $<TARGET_FILE:test_subdirectory_embed>
add_custom_target
(
check_subdirectory_embed $<TARGET_FILE:test_subdirectory_embed>
${
PROJECT_SOURCE_DIR
}
/../test.py
)
"
${
PROJECT_SOURCE_DIR
}
/../test.py
"
)
# Test custom export group -- PYBIND11_EXPORT_NAME
# Test custom export group -- PYBIND11_EXPORT_NAME
add_library
(
test_embed_lib ../embed.cpp
)
add_library
(
test_embed_lib ../embed.cpp
)
...
...
tests/test_cmake_build/subdirectory_function/CMakeLists.txt
View file @
130c9954
...
@@ -11,7 +11,7 @@ endif()
...
@@ -11,7 +11,7 @@ endif()
project
(
test_subdirectory_function CXX
)
project
(
test_subdirectory_function CXX
)
add_subdirectory
(
"
${
PYBIND11_PROJECT
_DIR
}
"
pybind11
)
add_subdirectory
(
"
${
pybind11_SOURCE
_DIR
}
"
pybind11
)
pybind11_add_module
(
test_subdirectory_function ../main.cpp
)
pybind11_add_module
(
test_subdirectory_function ../main.cpp
)
set_target_properties
(
test_subdirectory_function PROPERTIES OUTPUT_NAME test_cmake_build
)
set_target_properties
(
test_subdirectory_function PROPERTIES OUTPUT_NAME test_cmake_build
)
...
...
tests/test_cmake_build/subdirectory_target/CMakeLists.txt
View file @
130c9954
...
@@ -11,7 +11,7 @@ endif()
...
@@ -11,7 +11,7 @@ endif()
project
(
test_subdirectory_target CXX
)
project
(
test_subdirectory_target CXX
)
add_subdirectory
(
${
PYBIND11_PROJECT
_DIR
}
pybind11
)
add_subdirectory
(
"
${
pybind11_SOURCE
_DIR
}
"
pybind11
)
add_library
(
test_subdirectory_target MODULE ../main.cpp
)
add_library
(
test_subdirectory_target MODULE ../main.cpp
)
set_target_properties
(
test_subdirectory_target PROPERTIES OUTPUT_NAME test_cmake_build
)
set_target_properties
(
test_subdirectory_target PROPERTIES OUTPUT_NAME test_cmake_build
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment