Skip to content

Commit 75f8d25

Browse files
author
Grok Compression
committed
cmake: fix broken module export
1 parent 244e14a commit 75f8d25

3 files changed

Lines changed: 96 additions & 94 deletions

File tree

CMakeLists.txt

Lines changed: 78 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,25 @@
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
3632
if(NOT GROK_SOVERSION)
3733
set(GROK_SOVERSION 1)
38-
endif(NOT GROK_SOVERSION)
34+
endif()
3935
set(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

5450
if (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()
6359
message(STATUS "Architecture: " ${GRK_ARCH})
6460

6561
if(MSVC)
@@ -81,21 +77,22 @@ endif()
8177

8278
include(CheckPIESupported OPTIONAL RESULT_VARIABLE CHECK_PIE_SUPPORTED)
8379
check_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)
8682
endif()
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
9491
set(CMAKE_MODULE_PATH
9592
${GROK_SOURCE_DIR}/cmake
9693
${CMAKE_MODULE_PATH})
9794

98-
include (ExternalProject)
95+
include(ExternalProject)
9996
# Install directories
10097
include(GNUInstallDirs)
10198
string(TOLOWER ${PROJECT_NAME} projectname)
@@ -106,16 +103,19 @@ if (APPLE)
106103
endif()
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)
112109
endif()
113110

114111
# Grok build configuration options.
115112
option(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:
121121
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
@@ -130,14 +130,14 @@ include(ucm)
130130
if(BUILD_SHARED_LIBS)
131131
ucm_set_runtime(DYNAMIC)
132132
else()
133-
add_definitions(-DGRK_STATIC)
133+
add_compile_definitions(GRK_STATIC)
134134
ucm_set_runtime(STATIC)
135135
endif()
136136

137137
if(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()
142142
endif()
143143

@@ -161,33 +161,29 @@ option(BUILD_LUTS_GENERATOR "Build utility to generate t1_luts.h" OFF)
161161
option(GRK_BUILD_CORE_EXAMPLES "Build core examples" ON)
162162
option(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)
170172
endif()
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>)
191187
endif()
192188

193189
# Build Applications
@@ -293,14 +289,14 @@ endif()
293289

294290
# grk_config.h generation
295291
configure_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
306302
option(GRK_BUILD_DOC "Build HTML documentation (with doxygen if available)." OFF)
@@ -313,9 +309,6 @@ option(BUILD_TESTING "Build tests." OFF)
313309
if(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)
321314
endif()
@@ -410,7 +403,9 @@ if(GRK_BUILD_JAVA_TESTS)
410403
endif()
411404
endif()
412405

413-
# install all targets referenced as GrokTargets
406+
# ===================================================================
407+
# PACKAGE CONFIGURATION - FIXED VERSION HANDLING
408+
# ===================================================================
414409
if (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})
431435
endif()
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()

cmake/GrokConfig.cmake.in

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,49 +3,41 @@
33
# GrokConfig.cmake - CMake configuration file for external projects.
44
#
55
# This file is configured by Grok and used to load Grok's settings for external projects.
6+
#
67
@PACKAGE_INIT@
78

8-
# The Grok version number
9+
# === Version Information ===
10+
set(Grok_VERSION "@GROK_VERSION@")
911
set(Grok_VERSION_MAJOR "@GROK_VERSION_MAJOR@")
1012
set(Grok_VERSION_MINOR "@GROK_VERSION_MINOR@")
1113
set(Grok_VERSION_PATCH "@GROK_VERSION_PATCH@")
12-
set(Grok_VERSION "@GROK_VERSION_MAJOR@.@GROK_VERSION_MINOR@.@GROK_VERSION_PATCH@")
1314

1415
# The libraries
1516
set(Grok_LIBRARIES "GROK::@GROK_CORE_NAME@" "GROK::@GROK_CODEC_NAME@")
1617

1718
# CMake macros directory
18-
set(Grok_CMAKE_DIR "@GROK_INSTALL_PACKAGE_DIR@")
19+
set(Grok_CMAKE_DIR "${CMAKE_CURRENT_LIST_DIR}")
1920

2021
# Configuration options
2122
set(Grok_BUILD_SHARED_LIBS "@BUILD_SHARED_LIBS@")
2223

23-
# Determine the prefix directory
24-
set(PACKAGE_PREFIX_DIR "@CMAKE_INSTALL_PREFIX@")
25-
26-
# Detect install or build tree
27-
get_filename_component(SELF_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
28-
if(EXISTS "${SELF_DIR}/GrokTargets.cmake")
24+
# Detect install or build tree and import targets
25+
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/GrokTargets.cmake")
2926
# Install tree
30-
include("${SELF_DIR}/GrokTargets.cmake")
31-
32-
# Include directories
27+
include("${CMAKE_CURRENT_LIST_DIR}/GrokTargets.cmake")
3328
set(Grok_INCLUDE_DIRS "@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@/@GROK_INSTALL_SUBDIR@")
34-
35-
elseif(EXISTS "${SELF_DIR}/GrokExports.cmake")
29+
elseif(EXISTS "${CMAKE_CURRENT_LIST_DIR}/GrokExports.cmake")
3630
# Build tree
37-
include("${SELF_DIR}/GrokExports.cmake")
38-
39-
# Include directories for build tree
31+
include("${CMAKE_CURRENT_LIST_DIR}/GrokExports.cmake")
4032
set(Grok_INCLUDE_DIRS "@GROK_INCLUDE_PATH@")
41-
4233
else()
43-
# Error if neither install nor build tree targets are found
4434
message(FATAL_ERROR
4535
"Could not find GrokTargets.cmake (install tree) or GrokExports.cmake (build tree). "
4636
"Ensure Grok is built and installed correctly.")
4737
endif()
4838

49-
# Backward compatibility variables
39+
# Backward compatibility
5040
set(Grok_FOUND TRUE)
5141

42+
include("${CMAKE_CURRENT_LIST_DIR}/GrokConfigVersion.cmake" OPTIONAL)
43+
check_required_components(Grok)

src/lib/core/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,12 @@ if(GRK_ENABLE_LIBCURL AND GRK_HAVE_LIBCURL)
261261
endif(GRK_ENABLE_LIBCURL AND GRK_HAVE_LIBCURL)
262262

263263

264+
# Public include directory for consumers of the library
265+
target_include_directories(${GROK_CORE_NAME} PUBLIC
266+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
267+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${GROK_INSTALL_SUBDIR}>
268+
)
269+
264270
# bundle all static libraries into a single library
265271
if (GRK_BUNDLE_STATIC_CORE AND NOT BUILD_SHARED_LIBS AND NOT APPLE)
266272
include(BundleStatic)

0 commit comments

Comments
 (0)