3535# No need to copy Teem's use of 3.25 because we don't need "try_compile" since
3636# here the AIR_EXISTS macro always expands into a airExists() function call.
3737# 3.12 improved find_package() (including its use for ZLIB and BZip2).
38- cmake_minimum_required (VERSION 3.12)
38+ cmake_minimum_required (VERSION 3.12...3.31 )
3939project (NrrdIO
4040 DESCRIPTION "NrrdIO: C library for NRRD file IO (with optional compressions)"
4141 LANGUAGES C)
4242
43+ # Set NRRDIO_PREFIX manually when configuring with cmake
44+ # so that the generated library does not conflict with the
45+ # public name of the Teem library. By default this variable
46+ # is empty and the library name defaults to the project name
47+ # of NrrdIO.
48+ set (NRRDIO_LIBRARY_NAME ${NRRDIO_PREFIX}${PROJECT_NAME} )
49+
4350set (nrrdio_SRCS
4451 754.c
4552 accessors.c
@@ -90,11 +97,18 @@ set(nrrdio_SRCS
9097# the proper dll export def's are used.
9198add_definitions (-DTEEM_BUILD=1)
9299
93- set (NRRDIO_COMPRESSION_LIBRARIES "" )
100+ if ( NOT "${NRRDIO_PREFIX} " STREQUAL "ITK" ) # <-- ITK START_REMOVE
101+
102+ # Configure (and learn how to find) NrrdIO.h
103+ configure_file (${NrrdIO_SOURCE_DIR} /NrrdIO.h.in ${NrrdIO_BINARY_DIR} /NrrdIO.h)
104+ include_directories ( ${NrrdIO_BINARY_DIR} )
105+
106+ ## Override configuring zlib in ../CMakeLists.txt
107+
94108option (NRRDIO_USE_ZLIB "Enable support for ZLIB compression" ON )
95109if (NRRDIO_USE_ZLIB)
96110 # Possibly turn on usage of zlib compression (requires linking with libz)
97- # (i.e., programs compiled with ITKNrrdIO must also be compiled with zlib)
111+ # (i.e., programs compiled with ${NRRDIO_LIBRARY_NAME}NrrdIO must also be compiled with zlib)
98112 add_definitions (-DTEEM_ZLIB=1)
99113 find_package (ZLIB)
100114 list (APPEND NRRDIO_COMPRESSION_LIBRARIES ZLIB::ZLIB)
@@ -103,21 +117,50 @@ endif()
103117option (NRRDIO_USE_BZIP2 "Enable support for BZIP2 compression" OFF )
104118if (NRRDIO_USE_BZIP2)
105119 # Possibly turn on usage of bzip2 compression (requires linking with bz2)
106- # (i.e., programs compiled with ITKNrrdIO must also be compiled with bz2)
120+ # (i.e., programs compiled with ${NRRDIO_LIBRARY_NAME}NrrdIO must also be compiled with bz2)
107121 add_definitions (-DTEEM_BZIP2=1)
108122 find_package (BZip2)
109123 list (APPEND NRRDIO_COMPRESSION_LIBRARIES BZip2::BZip2)
110124endif ()
111125
112126# Build the library
113- add_library (NrrdIO ${nrrdio_SRCS} )
114-
127+ add_library (${NRRDIO_LIBRARY_NAME} ${nrrdio_SRCS} )
115128# Link optional compression libs
116129if (NRRDIO_USE_ZLIB OR NRRDIO_USE_BZIP2)
117- target_link_libraries (NrrdIO PRIVATE ${NRRDIO_COMPRESSION_LIBRARIES} )
130+ target_link_libraries (${NRRDIO_LIBRARY_NAME} PRIVATE ${NRRDIO_COMPRESSION_LIBRARIES} )
118131endif ()
119132
133+ else () # <-- ITK START_REPLACE
120134## These are ITK-specific
121- #target_link_libraries(NrrdIO ${ITK_ZLIB_LIBRARIES} )
122- #install_targets(/lib/InsightToolkit ITKNrrdIO)
123- #install_files(/include/InsightToolkit/Utilities/NrrdIO "(\\.h)$")
135+ # Build the library
136+ add_library (${NRRDIO_LIBRARY_NAME} ${nrrdio_SRCS} )
137+ target_link_libraries (${NRRDIO_LIBRARY_NAME} PRIVATE ${NRRDIO_COMPRESSION_LIBRARIES} )
138+ if (NOT BUILD_SHARED_LIBS )
139+ set (TEEM_STATIC 1)
140+ endif ()
141+
142+ set (MANGLE_PREFIX itk)
143+ configure_file (${NrrdIO_SOURCE_DIR} /itk_NrrdIO_mangle.h.in
144+ ${NrrdIO_BINARY_DIR} /itk_NrrdIO_mangle.h
145+ @ONLY
146+ )
147+
148+ if (ITK_LIBRARY_PROPERTIES)
149+ set_target_properties (${NRRDIO_LIBRARY_NAME} PROPERTIES ${ITK_LIBRARY_PROPERTIES} )
150+ endif ()
151+
152+ install (TARGETS ${NRRDIO_LIBRARY_NAME}
153+ EXPORT ${ITK3P_INSTALL_EXPORT_NAME}
154+ RUNTIME DESTINATION ${ITK3P_INSTALL_RUNTIME_DIR} COMPONENT RuntimeLibraries
155+ LIBRARY DESTINATION ${ITK3P_INSTALL_LIBRARY_DIR} COMPONENT RuntimeLibraries
156+ ARCHIVE DESTINATION ${ITK3P_INSTALL_ARCHIVE_DIR} COMPONENT Development
157+ )
158+
159+ install (FILES ${NrrdIO_BINARY_DIR} /NrrdIO.h ${NrrdIO_BINARY_DIR} /itk_NrrdIO_mangle.h
160+ DESTINATION ${ITK3P_INSTALL_INCLUDE_DIR} # TODO: itk_NrrdIO.h #include "itkNrrdIO/NrrdIO.h"
161+ COMPONENT Development)
162+
163+ if (CMAKE_COMPILER_IS_GNUCXX)
164+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-strict-aliasing" )
165+ endif ()
166+ endif () # <-- ITK END_REPLACE
0 commit comments