Skip to content

Commit 783e782

Browse files
committed
ENH: Add CTK_DEPRECATED_SINCE API deprecation framework
Introduces a versioned API deprecation system modeled after Qt's QT_DEPRECATED_SINCE so that future PRs can evolve CTK public APIs without breaking external projects. New header Libs/ctkDeprecated.h provides: CTK_VERSION_CHECK(major, minor, patch) CTK_DEPRECATED_SINCE(major, minor) CMakeLists.txt adds a CTK_DISABLE_DEPRECATED_BEFORE cache variable (hex 0xMMmmpp, default 0x000000 = keep all). ctkMacroBuildLib.cmake propagates the configured value as a PUBLIC compile definition so downstream consumers automatically inherit the project-wide setting, and adds ${CTK_SOURCE_DIR}/Libs to each library's include path so that ctkDeprecated.h can be included from anywhere in the build tree. Libs/ctkDeprecated.h is installed to ${CTK_INSTALL_INCLUDE_DIR} so that installed CTK headers can use the macros against external consumers. This commit only adds the framework. No CTK API is migrated yet. Follow-up PRs will use CTK_DEPRECATED_SINCE() to evolve specific APIs (e.g. ctkDICOMModalities) one at a time. Assisted-by: Claude Code -- mechanical refactor of commontk#1411 to isolate the deprecation framework from the ctkDICOMModalities migration
1 parent 430ff17 commit 783e782

4 files changed

Lines changed: 76 additions & 2 deletions

File tree

CMake/LastConfigureStep/CTKGenerateCTKConfig.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ foreach(lib ${CTK_LIBRARIES} CTKTesting)
150150
list(APPEND _include_dirs ${${lib}_INCLUDE_DIRS})
151151
set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(${lib}_INCLUDE_DIRS \"${${lib}_INCLUDE_DIRS}\")\n")
152152
endforeach()
153+
# ctkDeprecated.h lives directly under Libs/; build-tree consumers need it on the include path.
154+
list(APPEND _include_dirs ${CTK_SOURCE_DIR}/Libs)
153155
list(REMOVE_DUPLICATES _include_dirs)
154156
set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(CTK_INCLUDE_DIRS \"${_include_dirs}\")\n")
155157
set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}# CTK library directories that could be used for linking\n")

CMake/ctkMacroBuildLib.cmake

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ macro(ctkMacroBuildLib)
6363
set(my_includes
6464
${CMAKE_CURRENT_SOURCE_DIR}
6565
${CMAKE_CURRENT_BINARY_DIR}
66+
${CTK_SOURCE_DIR}/Libs # for ctkDeprecated.h
6667
)
6768

6869
# Add the include directories from the library dependencies
@@ -111,8 +112,11 @@ ${${MY_EXPORT_CUSTOM_CONTENT_FROM_VARIABLE}}
111112
${MY_RESOURCES}
112113
)
113114

114-
target_compile_definitions(${lib_name} PRIVATE
115-
HAVE_QT${CTK_QT_VERSION}
115+
target_compile_definitions(${lib_name}
116+
PUBLIC
117+
CTK_DISABLE_DEPRECATED_BEFORE=${CTK_DISABLE_DEPRECATED_BEFORE}
118+
PRIVATE
119+
HAVE_QT${CTK_QT_VERSION}
116120
)
117121

118122
# Configure CMake Qt automatic code generation

CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,14 @@ set(CTK_PATCH_VERSION 0)
171171
set(CTK_VERSION
172172
"${CTK_MAJOR_VERSION}.${CTK_MINOR_VERSION}.${CTK_PATCH_VERSION}")
173173

174+
# CTK_DISABLE_DEPRECATED_BEFORE controls which deprecated CTK APIs are compiled in.
175+
# Format is the hex encoding 0xMMmmpp (one byte each for major / minor / patch).
176+
# Example: -DCTK_DISABLE_DEPRECATED_BEFORE=0x000100 hides APIs deprecated in or before 0.1.0.
177+
# The default 0x000000 keeps all deprecated APIs available.
178+
# See Libs/ctkDeprecated.h for the CTK_DEPRECATED_SINCE() helper macro.
179+
set(CTK_DISABLE_DEPRECATED_BEFORE "0x000000" CACHE STRING
180+
"Disable CTK APIs deprecated in or before this version (hex: 0xMMmmpp)")
181+
174182
# Append the library version information to the library target
175183
# properties. A parent project may set its own properties and/or may
176184
# block this.
@@ -290,6 +298,10 @@ foreach(file
290298
install(FILES ${file} DESTINATION ${CTK_INSTALL_CMAKE_DIR} COMPONENT Development)
291299
endforeach()
292300

301+
# Public CTK headers that are not specific to any single library.
302+
install(FILES Libs/ctkDeprecated.h
303+
DESTINATION ${CTK_INSTALL_INCLUDE_DIR} COMPONENT Development)
304+
293305
install(FILES
294306
CMake/ctkLinkerAsNeededFlagCheck/CMakeLists.txt
295307
CMake/ctkLinkerAsNeededFlagCheck/A.cpp

Libs/ctkDeprecated.h

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*=========================================================================
2+
3+
Library: CTK
4+
5+
Copyright (c) Kitware Inc.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0.txt
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
=========================================================================*/
20+
21+
#ifndef __ctkDeprecated_h
22+
#define __ctkDeprecated_h
23+
24+
// CTK API deprecation framework, modeled after Qt's QT_DEPRECATED_SINCE.
25+
//
26+
// Usage in a CTK header:
27+
//
28+
// #include <ctkDeprecated.h>
29+
//
30+
// #if CTK_DEPRECATED_SINCE(0, 1)
31+
// CTK_FOO_EXPORT void oldApi(); // deprecated as of CTK 0.1
32+
// #endif
33+
//
34+
// Downstream projects can hide deprecated APIs by defining
35+
// CTK_DISABLE_DEPRECATED_BEFORE at compile time, e.g.
36+
//
37+
// -DCTK_DISABLE_DEPRECATED_BEFORE=0x000100 # hide APIs deprecated in or before 0.1.0
38+
//
39+
// The CTK build propagates the configured value as a PUBLIC compile
40+
// definition so consumers automatically inherit the project-wide setting
41+
// (see CMake/ctkMacroBuildLib.cmake).
42+
43+
// Encode a (major, minor, patch) triple into a comparable hex value.
44+
#define CTK_VERSION_CHECK(major, minor, patch) (((major) << 16) | ((minor) << 8) | (patch))
45+
46+
// Default: keep all deprecated APIs available.
47+
#ifndef CTK_DISABLE_DEPRECATED_BEFORE
48+
# define CTK_DISABLE_DEPRECATED_BEFORE 0x000000
49+
#endif
50+
51+
// Evaluates to true when an API deprecated in (major, minor) is still compiled
52+
// in; APIs deprecated in or before CTK_DISABLE_DEPRECATED_BEFORE are hidden.
53+
#define CTK_DEPRECATED_SINCE(major, minor) \
54+
(CTK_VERSION_CHECK(major, minor, 0) > CTK_DISABLE_DEPRECATED_BEFORE)
55+
56+
#endif

0 commit comments

Comments
 (0)