@@ -132,3 +132,60 @@ add_custom_target(shared_lib
132132add_custom_target (lib
133133 DEPENDS static_lib shared_lib
134134)
135+
136+ # Install the main executable
137+ install (TARGETS kanzi
138+ RUNTIME DESTINATION bin
139+ )
140+
141+ # Install the libraries (static and shared)
142+ install (TARGETS libkanzi libkanzi_shared
143+ ARCHIVE DESTINATION lib # For static libraries (.a, .lib)
144+ LIBRARY DESTINATION lib # For shared libraries (.so, .dylib, .dll)
145+ )
146+
147+ # Dynamically discover and install public headers
148+ # We assume all header files (.h and .hpp) in the project directories
149+ # (excluding test/ and app/ directories) are public headers.
150+
151+ # Define the base directories where headers might reside
152+ # PROJECT_SOURCE_DIR refers to the directory containing CMakeLists.txt
153+ set (HEADER_BASE_DIRS
154+ ${CMAKE_CURRENT_SOURCE_DIR} # For headers like Global.h, Event.h at root
155+ ${CMAKE_CURRENT_SOURCE_DIR} /api
156+ ${CMAKE_CURRENT_SOURCE_DIR} /bitstream
157+ ${CMAKE_CURRENT_SOURCE_DIR} /entropy
158+ ${CMAKE_CURRENT_SOURCE_DIR} /io
159+ ${CMAKE_CURRENT_SOURCE_DIR} /transform
160+ )
161+
162+ # List to hold all found header files
163+ set (ALL_HEADERS)
164+
165+ # Iterate through the base directories and find headers
166+ foreach (dir IN LISTS HEADER_BASE_DIRS)
167+ file (GLOB_RECURSE CURRENT_DIR_HEADERS "${dir} /*.h" "${dir} /*.hpp" )
168+ list (APPEND ALL_HEADERS ${CURRENT_DIR_HEADERS} )
169+ endforeach ()
170+
171+ # Install each header, preserving its relative path within the 'kanzi' include directory
172+ foreach (header_file IN LISTS ALL_HEADERS)
173+ # Calculate the relative path from the project root
174+ file (RELATIVE_PATH REL_PATH ${CMAKE_CURRENT_SOURCE_DIR} ${header_file} )
175+
176+ # Install to include/kanzi/ followed by its relative path
177+ install (FILES "${header_file} "
178+ DESTINATION "include/kanzi/${REL_PATH} "
179+ )
180+ endforeach ()
181+
182+ # Uninstall all files added during install
183+ configure_file (
184+ "${CMAKE_CURRENT_SOURCE_DIR} /cmake_uninstall.cmake.in"
185+ "${CMAKE_CURRENT_BINARY_DIR} /cmake_uninstall.cmake"
186+ @ONLY)
187+
188+ add_custom_target (uninstall
189+ COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR} /cmake_uninstall.cmake
190+ COMMENT "Uninstalling..."
191+ )
0 commit comments