1313# along with this program. If not, see <http://www.gnu.org/licenses/>.
1414
1515
16- cmake_minimum_required (VERSION 3.20 )
16+ cmake_minimum_required (VERSION 3.21 )
1717
18- if (POLICY CMP0122)
19- cmake_policy (SET CMP0122 NEW )
20- endif ()
21-
22- project (GROK)
18+ project (GROK
19+ VERSION 20.2.4
20+ LANGUAGES C CXX )
2321
2422#######################################
25- # GROK version
26- set (GROK_VERSION_MAJOR 20)
27- set (GROK_VERSION_MINOR 2)
28- set (GROK_VERSION_PATCH 4)
29- set (GROK_VERSION
30- "${GROK_VERSION_MAJOR} .${GROK_VERSION_MINOR} .${GROK_VERSION_PATCH} " )
31- set (PACKAGE_VERSION
32- "${GROK_VERSION_MAJOR} .${GROK_VERSION_MINOR} .${GROK_VERSION_PATCH} " )
23+ # GROK version — derived from project()
24+ set (GROK_VERSION_MAJOR ${PROJECT_VERSION_MAJOR } )
25+ set (GROK_VERSION_MINOR ${PROJECT_VERSION_MINOR } )
26+ set (GROK_VERSION_PATCH ${PROJECT_VERSION_PATCH } )
27+ set (GROK_VERSION "${PROJECT_VERSION } " )
28+ set (PACKAGE_VERSION "${PROJECT_VERSION } " )
3329
3430# As autotools does not support X.Y notation for SOVERSION, we have to use
3531# two different versions, one for Grok itself and one for its .so
3632if (NOT GROK_SOVERSION)
3733 set (GROK_SOVERSION 1)
38- endif (NOT GROK_SOVERSION )
34+ endif ()
3935set (GROK_LIBRARY_PROPERTIES
4036 VERSION "${GROK_VERSION_MAJOR} .${GROK_VERSION_MINOR} .${GROK_VERSION_PATCH} "
4137 SOVERSION "${GROK_SOVERSION} "
@@ -53,13 +49,13 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
5349
5450if (CMAKE_SYSTEM_PROCESSOR MATCHES "unknown" )
5551 # uname -p is broken on this system. Try uname -m
56- EXECUTE_PROCESS ( COMMAND uname -m
57- OUTPUT_STRIP_TRAILING_WHITESPACE
58- ERROR_QUIET
59- OUTPUT_VARIABLE GRK_ARCH )
60- else ( CMAKE_SYSTEM_PROCESSOR MATCHES "unknown" )
52+ execute_process ( COMMAND uname -m
53+ OUTPUT_STRIP_TRAILING_WHITESPACE
54+ ERROR_QUIET
55+ OUTPUT_VARIABLE GRK_ARCH )
56+ else ( )
6157 set (GRK_ARCH ${CMAKE_SYSTEM_PROCESSOR } )
62- endif ( CMAKE_SYSTEM_PROCESSOR MATCHES "unknown" )
58+ endif ( )
6359message (STATUS "Architecture: " ${GRK_ARCH} )
6460
6561if (MSVC )
@@ -81,21 +77,22 @@ endif()
8177
8278include (CheckPIESupported OPTIONAL RESULT_VARIABLE CHECK_PIE_SUPPORTED )
8379check_pie_supported (LANGUAGES CXX )
84- if (CMAKE_CXX_LINK_PIE_SUPPORTED)
85- set (CMAKE_POSITION_INDEPENDENT_CODE TRUE )
80+ if (CMAKE_CXX_LINK_PIE_SUPPORTED)
81+ set (CMAKE_POSITION_INDEPENDENT_CODE TRUE )
8682endif ()
8783
88- set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO } -fno-omit-frame-pointer" )
89- set (CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO } -fno-omit-frame-pointer" )
90- set (CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO} -Wl,--build-id" )
84+ add_compile_options (
85+ $<$<AND :$<COMPILE_LANGUAGE :C ,CXX >,$<CONFIG :RelWithDebInfo >>:-fno -omit -frame -pointer >)
86+ add_link_options (
87+ $<$<CONFIG :RelWithDebInfo >:LINKER :--build -id >)
9188
9289
9390# Path to additional CMake modules
9491set (CMAKE_MODULE_PATH
9592 ${GROK_SOURCE_DIR } /cmake
9693 ${CMAKE_MODULE_PATH } )
9794
98- include (ExternalProject )
95+ include (ExternalProject )
9996# Install directories
10097include (GNUInstallDirs )
10198string (TOLOWER ${PROJECT_NAME } projectname)
@@ -106,16 +103,19 @@ if (APPLE)
106103endif ()
107104
108105# Big endian test:
109- include ( ${ CMAKE_ROOT } /Modules/ TestBigEndian.cmake )
110- if (NOT CMAKE_SYSTEM_NAME STREQUAL Emscripten)
111- TEST_BIG_ENDIAN (GROK_BIG_ENDIAN )
106+ include ( TestBigEndian )
107+ if (NOT CMAKE_SYSTEM_NAME STREQUAL Emscripten)
108+ test_big_endian (GROK_BIG_ENDIAN )
112109endif ()
113110
114111# Grok build configuration options.
115112option (BUILD_SHARED_LIBS "Build Grok shared library and link executables against it." ON )
116- set (EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR } /bin CACHE PATH "Single output directory for building all executables." )
117- set (LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR } /bin CACHE PATH "Single output directory for building all libraries." )
118- mark_as_advanced (LIBRARY_OUTPUT_PATH EXECUTABLE_OUTPUT_PATH )
113+ set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR } /bin CACHE PATH "Single output directory for building all executables." )
114+ set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR } /bin CACHE PATH "Single output directory for building all libraries." )
115+ set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR } /bin CACHE PATH "Single output directory for building all archives." )
116+ # Keep legacy alias for test scripts that reference EXECUTABLE_OUTPUT_PATH
117+ set (EXECUTABLE_OUTPUT_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY } )
118+ mark_as_advanced (CMAKE_RUNTIME_OUTPUT_DIRECTORY CMAKE_LIBRARY_OUTPUT_DIRECTORY CMAKE_ARCHIVE_OUTPUT_DIRECTORY )
119119
120120# Compiler specific flags:
121121if (CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU" )
@@ -130,14 +130,14 @@ include(ucm)
130130if (BUILD_SHARED_LIBS )
131131 ucm_set_runtime (DYNAMIC )
132132else ()
133- add_definitions ( -DGRK_STATIC )
133+ add_compile_definitions ( GRK_STATIC )
134134 ucm_set_runtime (STATIC )
135135endif ()
136136
137137if (WIN32 )
138- add_definitions ( -DNOMINMAX )
138+ add_compile_definitions ( NOMINMAX )
139139 if (BUILD_SHARED_LIBS )
140- add_definitions ( -DGRK_EXPORTS )
140+ add_compile_definitions ( GRK_EXPORTS )
141141 endif ()
142142endif ()
143143
@@ -161,33 +161,29 @@ option(BUILD_LUTS_GENERATOR "Build utility to generate t1_luts.h" OFF)
161161option (GRK_BUILD_CORE_EXAMPLES "Build core examples" ON )
162162option (GRK_BUILD_CODEC_EXAMPLES "Build codec examples" OFF )
163163
164+ # Locate test data (shared by examples and tests)
165+ find_path (GRK_DATA_ROOT README-GROK-TEST-DATA
166+ PATHS $ENV{GRK_DATA_ROOT} ${CMAKE_SOURCE_DIR } /../grok-test-data
167+ NO_CMAKE_FIND_ROOT_PATH )
168+
164169# examples use files from data folder
165- if (GRK_BUILD_CORE_EXAMPLES OR GRK_BUILD_CODEC_EXAMPLES)
166- add_subdirectory (examples )
167- find_path (GRK_DATA_ROOT README-GROK-TEST-DATA
168- PATHS $ENV{GRK_DATA_ROOT} ${CMAKE_SOURCE_DIR } /../grok-test-data
169- NO_CMAKE_FIND_ROOT_PATH )
170+ if (GRK_BUILD_CORE_EXAMPLES OR GRK_BUILD_CODEC_EXAMPLES)
171+ add_subdirectory (examples )
170172endif ()
171173
172- if (CMAKE_BUILD_TYPE STREQUAL "Release" )
173- if (WIN32 )
174- # Ensure no debug symbols & remove Debug Directory
175- set (CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE } /DEBUG:NONE /RELEASE" )
176- set (CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /DEBUG:NONE /RELEASE" )
177-
178- if (MSVC )
179- # Ensure MSVC does not generate .pdb files
180- set (CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "None" )
181- endif ()
182- elseif (APPLE )
183- # Strip all local symbols for macOS
184- set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS } -Wl,-x" )
185- set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS } -Wl,-x" )
186- else ()
187- # Strip all symbols for shared libraries on other non-Windows platforms (e.g., Linux)
188- set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS } -Wl,--strip-all" )
189- set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS } -Wl,--strip-all" )
190- endif ()
174+ if (WIN32 )
175+ add_link_options (
176+ $<$<CONFIG :Release >:/DEBUG :NONE >
177+ $<$<CONFIG :Release >:/RELEASE >)
178+ if (MSVC )
179+ set (CMAKE_MSVC_DEBUG_INFORMATION_FORMAT
180+ $<$<CONFIG :Release >:> $<$<NOT :$<CONFIG :Release >>:ProgramDatabase >)
181+ endif ()
182+ elseif (APPLE )
183+ add_link_options ($<$<CONFIG :Release >:LINKER :-x >)
184+ else ()
185+ # Strip all symbols in Release builds on Linux/other
186+ add_link_options ($<$<CONFIG :Release >:LINKER :--strip -all >)
191187endif ()
192188
193189# Build Applications
@@ -293,14 +289,14 @@ endif()
293289
294290# grk_config.h generation
295291configure_file (
296- ${CMAKE_CURRENT_SOURCE_DIR } /src/lib/core/grk_config.h.cmake.in
297- ${CMAKE_CURRENT_BINARY_DIR } /src/lib/core/grk_config.h
298- @ONLY )
292+ ${CMAKE_CURRENT_SOURCE_DIR } /src/lib/core/grk_config.h.cmake.in
293+ ${CMAKE_CURRENT_BINARY_DIR } /src/lib/core/grk_config.h
294+ @ONLY )
299295
300- configure_file (
301- ${CMAKE_CURRENT_SOURCE_DIR } /src/lib/core/grk_config_private.h.cmake.in
302- ${CMAKE_CURRENT_BINARY_DIR } /src/lib/core/grk_config_private.h
303- @ONLY )
296+ configure_file (
297+ ${CMAKE_CURRENT_SOURCE_DIR } /src/lib/core/grk_config_private.h.cmake.in
298+ ${CMAKE_CURRENT_BINARY_DIR } /src/lib/core/grk_config_private.h
299+ @ONLY )
304300
305301# Build DOCUMENTATION
306302option (GRK_BUILD_DOC "Build HTML documentation (with doxygen if available)." OFF )
@@ -313,9 +309,6 @@ option(BUILD_TESTING "Build tests." OFF)
313309if (BUILD_TESTING AND GRK_BUILD_CODEC AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR } /tests/CMakeLists.txt" )
314310 enable_testing ()
315311 include (CTest )
316- find_path (GRK_DATA_ROOT README-GROK-TEST-DATA
317- PATHS $ENV{GRK_DATA_ROOT} ${CMAKE_SOURCE_DIR } /../grok-test-data
318- NO_CMAKE_FIND_ROOT_PATH )
319312 add_subdirectory (tests )
320313 set (GRK_BUILD_CORE_EXAMPLES ON CACHE BOOL "Build core examples" FORCE )
321314endif ()
@@ -410,7 +403,9 @@ if(GRK_BUILD_JAVA_TESTS)
410403 endif ()
411404endif ()
412405
413- # install all targets referenced as GrokTargets
406+ # ===================================================================
407+ # PACKAGE CONFIGURATION - FIXED VERSION HANDLING
408+ # ===================================================================
414409if (BUILD_SHARED_LIBS AND NOT CMAKE_SYSTEM_NAME STREQUAL Emscripten)
415410 # Install the GrokTargets file
416411 install (EXPORT GrokTargets
@@ -425,8 +420,17 @@ if (BUILD_SHARED_LIBS AND NOT CMAKE_SYSTEM_NAME STREQUAL Emscripten)
425420 INSTALL_DESTINATION ${GROK_INSTALL_PACKAGE_DIR}
426421 PATH_VARS CMAKE_INSTALL_INCLUDEDIR )
427422
428- # Install the GrokConfig.cmake file
429- install (FILES ${CMAKE_CURRENT_BINARY_DIR } /GrokConfig.cmake
423+ # Generate the version file
424+ write_basic_package_version_file (
425+ "${CMAKE_CURRENT_BINARY_DIR } /GrokConfigVersion.cmake"
426+ VERSION "${GROK_VERSION} "
427+ COMPATIBILITY SameMinorVersion
428+ )
429+
430+ # Install both config and version files
431+ install (FILES
432+ ${CMAKE_CURRENT_BINARY_DIR } /GrokConfig.cmake
433+ ${CMAKE_CURRENT_BINARY_DIR } /GrokConfigVersion.cmake
430434 DESTINATION ${GROK_INSTALL_PACKAGE_DIR} )
431435endif ()
432436
@@ -452,4 +456,4 @@ if(GRK_BUILD_PKGCONFIG_FILES)
452456 ${CMAKE_CURRENT_BINARY_DIR } /libgrokj2kcodec.pc @ONLY )
453457 install ( FILES ${CMAKE_CURRENT_BINARY_DIR } /libgrokj2kcodec.pc DESTINATION
454458 ${CMAKE_INSTALL_LIBDIR} /pkgconfig )
455- endif ()
459+ endif ()
0 commit comments