Skip to content

Commit ce0b0f1

Browse files
committed
- Added a CMake option called JAS_ENABLE_CMAKE_PACKAGE_CONFIG to enable
CMake package config file generation. - Fixed a bug in jpeglib.h header detection.
1 parent 7516835 commit ce0b0f1

4 files changed

Lines changed: 78 additions & 1 deletion

File tree

CMakeLists.txt

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ endif()
108108

109109
option(JAS_PACKAGING "Enable packaging mode (e.g., disable RPATH)" OFF)
110110

111+
option(JAS_ENABLE_CMAKE_PACKAGE_CONFIG "Enable CMake package config file generation" OFF)
112+
111113
option(JAS_ENABLE_PIC "Enable position-independent code" ON)
112114
set(CMAKE_POSITION_INDEPENDENT_CODE ${JAS_ENABLE_PIC})
113115

@@ -756,11 +758,13 @@ if(JAS_ENABLE_LIBJPEG)
756758
# (e.g., stdio.h and stdint.h). So, we cannot reliably use
757759
# check_include_file here.
758760
jas_get_includes_from_targets(CMAKE_REQUIRED_INCLUDES JPEG::JPEG)
761+
message("JPEG include directories: ${CMAKE_REQUIRED_INCLUDES}")
759762
check_c_source_compiles("
760763
#include <stdio.h>
761764
#include <stdint.h>
765+
#include <stddef.h>
762766
#include <jpeglib.h>
763-
int main() {}
767+
int main(void) {}
764768
" JAS_HAVE_JPEGLIB_H)
765769
if(JAS_HAVE_JPEGLIB_H)
766770
set(JAS_HAVE_LIBJPEG 1)
@@ -875,3 +879,43 @@ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/build/pkgconfig/jasper.pc"
875879
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
876880

877881
install(FILES "README.md" DESTINATION "${CMAKE_INSTALL_DOCDIR}")
882+
883+
################################################################################
884+
# CMake package config files for find_package(JasPer CONFIG ...)
885+
################################################################################
886+
887+
if(JAS_ENABLE_CMAKE_PACKAGE_CONFIG)
888+
889+
include(CMakePackageConfigHelpers)
890+
891+
# Create a version file for the package.
892+
write_basic_package_version_file(
893+
"${CMAKE_CURRENT_BINARY_DIR}/JasPerConfigVersion.cmake"
894+
VERSION ${JAS_VERSION}
895+
COMPATIBILITY AnyNewerVersion
896+
)
897+
898+
# Configure the config file that downstream projects will include.
899+
configure_package_config_file(
900+
"${CMAKE_CURRENT_SOURCE_DIR}/build/cmake/modules/JasPerConfig.cmake.in"
901+
"${CMAKE_CURRENT_BINARY_DIR}/JasPerConfig.cmake"
902+
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/JasPer"
903+
)
904+
905+
# Export the targets.
906+
install(EXPORT JasPerTargets
907+
FILE JasPerTargets.cmake
908+
NAMESPACE JasPer::
909+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/JasPer"
910+
)
911+
912+
# Install the config and version files.
913+
install(FILES
914+
"${CMAKE_CURRENT_BINARY_DIR}/JasPerConfig.cmake"
915+
"${CMAKE_CURRENT_BINARY_DIR}/JasPerConfigVersion.cmake"
916+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/JasPer"
917+
)
918+
919+
endif()
920+
921+
################################################################################

build/build

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ enable_strict=1
125125
cmake_generator=
126126
enable_32bit=0
127127
enable_cxx=1
128+
enable_cmake_package_config=0
128129

129130
while [ $# -gt 0 ]; do
130131
option="$1"
@@ -144,6 +145,15 @@ while [ $# -gt 0 ]; do
144145
cmake_generator="Ninja"
145146
;;
146147

148+
--cmake-package-config)
149+
shift 1
150+
enable_cmake_package_config=1
151+
;;
152+
--no-cmake-package-config)
153+
shift 1
154+
enable_cmake_package_config=0
155+
;;
156+
147157
--clean-build-dir)
148158
shift 1
149159
clean_build_dir=1
@@ -486,6 +496,14 @@ configure_opts=()
486496
configure_opts+=(-B"$build_dir")
487497
configure_opts+=(-H"$source_dir")
488498

499+
#configure_opts+=(--trace-expand)
500+
501+
if [ -n "$enable_cmake_package_config" ]; then
502+
configure_opts+=(
503+
-D "JAS_ENABLE_CMAKE_PACKAGE_CONFIG=$enable_cmake_package_config"
504+
)
505+
fi
506+
489507
if [ -n "$cmake_generator" ]; then
490508
configure_opts+=(-G "$cmake_generator")
491509
fi
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@PACKAGE_INIT@
2+
3+
set(JasPer_FOUND TRUE)
4+
5+
include("${CMAKE_CURRENT_LIST_DIR}/JasPerTargets.cmake")

src/libjasper/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,16 @@ add_library(libjasper ${libjasper_type}
168168
${libjasper_ras_sources}
169169
)
170170

171+
if(JAS_ENABLE_CMAKE_PACKAGE_CONFIG)
172+
install(TARGETS libjasper
173+
EXPORT JasPerTargets
174+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
175+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
176+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
177+
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
178+
)
179+
endif()
180+
171181
# The JasPer include directories in the source and build tree must be included
172182
# before any other directories that may contain the include directory for an
173183
# already installed version of the JasPer library.

0 commit comments

Comments
 (0)