Skip to content

Avoid modifying CMAKE_DEBUG_POSTFIX globally in subprojects#548

Merged
mm2 merged 2 commits into
masterfrom
copilot/avoid-modifying-cmake-debug-postfix
Mar 26, 2026
Merged

Avoid modifying CMAKE_DEBUG_POSTFIX globally in subprojects#548
mm2 merged 2 commits into
masterfrom
copilot/avoid-modifying-cmake-debug-postfix

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 26, 2026

Setting CMAKE_DEBUG_POSTFIX via CACHE STRING in Lcms2Options.cmake pollutes the global CMake cache, silently overriding a parent project's postfix configuration when Little-CMS is consumed via add_subdirectory.

Changes

  • cmake/Lcms2Options.cmake — Remove the global CMAKE_DEBUG_POSTFIX cache entry entirely
  • cmake/Lcms2Library.cmake — Set DEBUG_POSTFIX "d" directly on each library target via _lcms2_apply_common_settings()
  • cmake/Lcms2Tools.cmake — Set DEBUG_POSTFIX "d" on each tool target in _lcms2_add_tool()
  • cmake/Lcms2Tests.cmake — Set DEBUG_POSTFIX "d" on the testcms target

Instead of relying on CMAKE_DEBUG_POSTFIX propagating to new targets at creation time, the postfix is now applied explicitly per-target:

# Before — contaminates global/cache scope
if(MSVC AND NOT DEFINED CMAKE_DEBUG_POSTFIX)
  set(CMAKE_DEBUG_POSTFIX "d" CACHE STRING "Debug postfix for binaries and libraries")
endif()

# After — scoped to this project's targets only
if(MSVC)
  set_target_properties(${tgt} PROPERTIES DEBUG_POSTFIX "d")
endif()

This preserves identical MSVC output naming behavior while having zero effect on any parent project's CMake state.

Original prompt

This section details on the original issue you should resolve

<issue_title>Avoid modifying CMAKE_DEBUG_POSTFIX globally in subprojects</issue_title>
<issue_description>The current code sets a default debug postfix as follows:

cmake/Lcms2Options.cmake

Default debug postfix for MSVC builds.

if(MSVC AND NOT DEFINED CMAKE_DEBUG_POSTFIX)
set(CMAKE_DEBUG_POSTFIX "d" CACHE STRING "Debug postfix for binaries and libraries")
endif()

However, modifying CMAKE_DEBUG_POSTFIX in this way affects the global CMake state. When this project is included via add_subdirectory, it unintentionally overrides the parent project's configuration.

This can lead to unexpected behavior in larger builds where different subprojects may rely on different postfix settings.</issue_description>

<agent_instructions>CMake scripts are still a test in progress, make a deep check that everything is ok. Don't change anything out of CMake scope</agent_instructions>

Comments on the Issue (you are @copilot in this section)


📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

Copilot AI changed the title [WIP] Fix issue with CMAKE_DEBUG_POSTFIX affecting global state Avoid modifying CMAKE_DEBUG_POSTFIX globally in subprojects Mar 26, 2026
Copilot AI requested a review from mm2 March 26, 2026 11:20
Copilot finished work on behalf of mm2 March 26, 2026 11:20
@mm2 mm2 marked this pull request as ready for review March 26, 2026 12:41
@mm2 mm2 merged commit 4cc0f1c into master Mar 26, 2026
16 checks passed
@mm2 mm2 deleted the copilot/avoid-modifying-cmake-debug-postfix branch March 26, 2026 12:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Avoid modifying CMAKE_DEBUG_POSTFIX globally in subprojects

2 participants