Open
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 88b019a 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