Skip to content

[BUG]: module being stripped if no build type selected (2.10.2 regression) #4454

Open
@tttapa

Description

@tttapa

Required prerequisites

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

Is this a regression? Put the last known working version here if it is.

1f04cc7

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions