[BUG]: module being stripped if no build type selected (2.10.2 regression)
@henryiii is already working on this.
Since Feb 4, 2023.
- Dominant language
- C++
- Stars
- 18k
- Forks
- 2.3k
- Avg merge
- 5d 17h
- Merged PRs (30d)
- 10
Description
Required prerequisites
- Make sure you've read the documentation. Your issue may be addressed there.
- Search the issue tracker and Discussions to verify that this hasn't already been reported. +1 or comment there if it has.
- Consider asking first in the Gitter chat room or in a Discussion.
What version (or hash if on master) of pybind11 are you using?
2.10.3
Problem description
If no CMAKE_BUILD_TYPE is specified, the seemingly innocuous quotes that were added in 88b019a8a5e116d7e4a4ffae6399a426364d4bcd cause the pybind11_add_module function to strip the module, even for debug builds.
By relying on CMAKE_BUILD_TYPE at configure time rather than on $<CONFIG> at generation time, multi-configuration generators like Ninja Multi-Config cannot work correctly. It might be better to use a generator expression (e.g. https://stackoverflow.com/questions/45455350/cmake-how-to-add-a-custom-command-that-is-only-executed-for-one-configuration).
Reproducible example code
CMakeLists.txt
cmake_minimum_required(VERSION 3.20)
project(test-project)
# Use case-insensitive comparison to match the result of $<CONFIG:cfgs>
string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
if(NOT MSVC AND NOT ${uppercase_CMAKE_BUILD_TYPE} MATCHES DEBUG|RELWITHDEBINFO)
# Strip unnecessary sections of the binary on Linux/macOS
message(STATUS "Without quotes: strip")
else()
message(STATUS "Without quotes: no strip")
endif()
# Use case-insensitive comparison to match the result of $<CONFIG:cfgs>
string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
if(NOT MSVC AND NOT "${uppercase_CMAKE_BUILD_TYPE}" MATCHES DEBUG|RELWITHDEBINFO)
# Strip unnecessary sections of the binary on Linux/macOS
message(STATUS "With quotes: strip")
else()
message(STATUS "With quotes: no strip")
endif()
Run CMake without build type
cmake -Bbuild -S.
-- Without quotes: no strip
-- With quotes: strip
Is this a regression? Put the last known working version here if it is.
1f04cc7062e33481c62c78231e9561b318bca67b
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.