Skip to content

Commit 240ec86

Browse files
committed
COMP: Promote ITK header paths for name mangling expat.h
When linking against ITK's expat library, the expat.h must be found from the ITK supplied expat.h so that name mangling is properly asserted. The source layout changes in 8ec19eb allowed the /usr/include/expat.h (i.e. without name mangling) to be found first and resulted in link errors due to name mangling. Simulate previous ITKv5 behavior for header path ordering by including an expat.h that does itk name mangling from the ITK include directories. - Fixed outstanding todo items. - Simplified configure_file paths - Changed itk install directory for third-party exap includes This resolves an issue with building SlicerExecutionModel against the ITK v6.0b03+ versions which requires using ITK expat.h and linking against ITK mangled expat libraries.
1 parent 1e4e9b8 commit 240ec86

4 files changed

Lines changed: 73 additions & 5 deletions

File tree

Modules/ThirdParty/Expat/CMakeLists.txt

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ if(ITK_USE_SYSTEM_EXPAT)
1717
else()
1818
set(
1919
ITKExpat_INCLUDE_DIRS
20-
${ITKExpat_BINARY_DIR}/src
21-
${ITKExpat_BINARY_DIR}/src/itkexpat
22-
${ITKExpat_SOURCE_DIR}/src
20+
${ITKExpat_BINARY_DIR} # <- for itk_expat.h
21+
${ITKExpat_BINARY_DIR}/src/itkexpat # <- for expat_config.h itk_expat_mangle.h
22+
${ITKExpat_SOURCE_DIR}/src # <- for itkexpat/lib/expat.h in build tree
2323
)
2424
set(ITKExpat_LIBRARIES ITKEXPAT)
2525
set(
@@ -43,6 +43,18 @@ else()
4343
)
4444
endif()
4545

46-
configure_file(src/itk_expat.h.in src/itk_expat.h)
46+
configure_file(itk_expat.h.in ${ITKExpat_BINARY_DIR}/itk_expat.h)
47+
if(NOT ITK_USE_SYSTEM_EXPAT AND NOT ITK_FUTURE_LEGACY_REMOVE)
48+
# Configure a file with the name <expat.h> as was the default in ITKv5 and earlier
49+
# so that "#include <expat.h>" finds the itk mangled symbols during linkage stage.
50+
# This is only needed to preserve behaviors of ITKv5 and earlier. ITKv6 and greater
51+
# should #include "itk_expat.h" to get the correctly mangled symbols.
52+
configure_file(itkv5_expat.h.in ${ITKExpat_BINARY_DIR}/expat.h)
53+
else()
54+
# Remove file if configuration changes occur
55+
if(EXISTS ${ITKExpat_BINARY_DIR}/expat.h)
56+
file(REMOVE ${ITKExpat_BINARY_DIR}/expat.h)
57+
endif()
58+
endif()
4759

4860
itk_module_impl()
File renamed without changes.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*=========================================================================
2+
*
3+
* Copyright NumFOCUS
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0.txt
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*=========================================================================*/
18+
19+
#ifndef itkv5_expat_h
20+
#define itkv5_expat_h
21+
22+
/* Use the expat library configured for ITK. */
23+
#cmakedefine ITK_USE_SYSTEM_EXPAT
24+
#ifdef ITK_USE_SYSTEM_EXPAT
25+
# error "This ITKv5 backward compatible stub file should never be used if requesting ITK_USE_SYSTEM_EXPAT=ON"
26+
#elif defined(ITK_FUTURE_LEGACY_REMOVE)
27+
# error "This ITKv5 backward compatible stub file should never be used if requesting ITK_FUTURE_LEGACY_REMOVE=ON"
28+
#else
29+
/* ITKv5 used the `#include <expat.h>` with itk mangled symbols and depends on compiler
30+
* include file order to find the ITKv5 version of expat.h before the system version.
31+
*
32+
* ITKv6 moves the itk mangled symbols and expects ITK dependant exapt to use
33+
* `#include "itk_expat.h"` to find the itk mangled symbols, or divert to `#include <expat.h>`
34+
* if ITK_USE_SYSTEM_EXPAT.
35+
*
36+
* This file is intended for ITKv5 drop in compatibility by generating a
37+
* the file that is found via include path precidence rules called "#include <expat.h>"
38+
* by placing an itk generated file "expat.h" in the ITK included files path to superceed
39+
* the system file when ITK_USE_SYSTEM_EXPAT=False and ITK_FUTURE_LEGACY_REMOVE=False.
40+
*/
41+
# include "itk_expat.h"
42+
#endif
43+
44+
#endif

Modules/ThirdParty/Expat/src/itkexpat/CMakeLists.txt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,12 +502,24 @@ install(TARGETS ITKEXPAT
502502
ARCHIVE DESTINATION ${ITK3P_INSTALL_ARCHIVE_DIR} COMPONENT Development
503503
)
504504

505+
install(FILES
506+
${ITKExpat_BINARY_DIR}/itk_expat.h
507+
DESTINATION ${ITK3P_INSTALL_INCLUDE_DIR}
508+
COMPONENT Development)
509+
510+
if(NOT ITK_USE_SYSTEM_EXPAT AND NOT ITK_FUTURE_LEGACY_REMOVE)
511+
install(FILES
512+
${ITKExpat_BINARY_DIR}/expat.h # <- The ITKv5 backward compatibile work-around-file to route to itk_expat.h
513+
DESTINATION ${ITK3P_INSTALL_INCLUDE_DIR}
514+
COMPONENT Development)
515+
endif()
516+
505517
install(FILES
506518
${ITK3P_EXPAT_BINARY_DIR}/itk_expat_mangle.h
507519
${ITK3P_EXPAT_BINARY_DIR}/expat_config.h
508520
${ITK3P_EXPAT_SOURCE_DIR}/lib/expat.h
509521
${ITK3P_EXPAT_SOURCE_DIR}/lib/expat_external.h
510-
DESTINATION ${ITK3P_INSTALL_INCLUDE_DIR} # TODO: itk_expat.h #include "itkexpat/expat.h"
522+
DESTINATION ${ITK3P_INSTALL_INCLUDE_DIR}/itkexpat/lib
511523
COMPONENT Development)
512524
# ITK --stop
513525

0 commit comments

Comments
 (0)