Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

export CMake Target #31

Closed
wants to merge 2 commits into from
Closed

export CMake Target #31

wants to merge 2 commits into from

Conversation

kuepe-sl
Copy link

@kuepe-sl kuepe-sl commented Mar 3, 2022

This allows other build systems to easily locate libjpeg under Windows.

Checklist

  • Used a personal fork of the feedstock to propose changes
  • Bumped the build number (if the version is unchanged)
  • Reset the build number to 0 (if the version changed)
  • Re-rendered with the latest conda-smithy (Use the phrase @conda-forge-admin, please rerender in a comment in this PR for automated rerendering)
  • Ensured the license file is being packaged.

@conda-forge-linter
Copy link

Hi! This is the friendly automated conda-forge-linting service.

I just wanted to let you know that I linted all conda-recipes in your PR (recipe) and found it was in an excellent condition.

This allows other build systems to easily locate libjpeg under Windows.
@kuepe-sl
Copy link
Author

kuepe-sl commented Mar 3, 2022

@conda-forge-admin, please rerender

@beckermr
Copy link
Member

beckermr commented Mar 8, 2022

I'm not comfortable merging this one. I don't know cmake at all and don't understand the patch.

Maybe someone from @conda-forge/jpeg can look at it?

@kuepe-sl
Copy link
Author

kuepe-sl commented Mar 8, 2022

It is unfortunate that me renaming the .patch file also obscures the actual changes.
I thought that renaming the .patch file is necessary, because it now creates 2 files instead of 1.

For better readability, here is the patch in more readable form (without some of the cosmetic changes I also did):

diff -Nru a/CMakeLists.txt b/CMakeLists.txt
--- a/CMakeLists.txt	2022-03-08 20:59:49.202400075 +0100
+++ b/CMakeLists.txt	2022-03-08 21:00:20.642490548 +0100
@@ -5,9 +5,13 @@
 # to use cmake and set the WINDOWS_EXPORT_ALL_SYMBOLS property
 # to create a DLL with all symbols exported and a implib (.lib)
 # that can be linked against.
+# This way we can also easily provide package configs for use
+# with other projects.
 
 cmake_minimum_required (VERSION 3.4)
-project (JPEG)
+project (libjpeg VERSION 9)
+
+include(GNUInstallDirs)
 
 set(JPEG_SRC jaricom.c jcapimin.c jcapistd.c jcarith.c jccoefct.c jccolor.c 
         jcdctmgr.c jchuff.c jcinit.c jcmainct.c jcmarker.c jcmaster.c 
@@ -18,8 +22,11 @@
         jfdctfst.c jfdctint.c jidctflt.c jidctfst.c jidctint.c jquant1.c 
         jquant2.c jutils.c jmemmgr.c jmemansi.c)
 add_library (libjpeg SHARED ${JPEG_SRC})
         
-target_include_directories (libjpeg PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
+target_include_directories (libjpeg PUBLIC
+  $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
+  $<INSTALL_INTERFACE:include>)
+
 set_target_properties(libjpeg PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
 add_definitions(-D_CRT_SECURE_NO_WARNINGS)
 
@@ -36,10 +43,33 @@
 
 add_library(jpeg STATIC ${JPEG_SRC})
 
+set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
+
 install(TARGETS libjpeg cjpeg djpeg jpegtran rdjpgcom wrjpgcom jpeg
+  EXPORT ${TARGETS_EXPORT_NAME}
   RUNTIME DESTINATION bin
   LIBRARY DESTINATION lib
   ARCHIVE DESTINATION lib)
   
 install(FILES jpeglib.h jconfig.h jmorecfg.h jerror.h jpegint.h DESTINATION include)  
  
+
+include(CMakePackageConfigHelpers)
+
+set(TARGETS_FILENAME "${TARGETS_EXPORT_NAME}.cmake")	# this variable is used by cmake-config.in
+set(JPEG_CONFIG_INSTALL_DIR "lib/cmake/${PROJECT_NAME}")
+set(JPEG_PROJECT_CONFIG "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake")
+set(JPEG_VERSION_CONFIG "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake")
+set(JPEG_TARGETS_CONFIG "${PROJECT_BINARY_DIR}/${TARGETS_FILENAME}")
+configure_package_config_file("${PROJECT_SOURCE_DIR}/cmake-config.in" "${JPEG_PROJECT_CONFIG}"
+  INSTALL_DESTINATION "${JPEG_CONFIG_INSTALL_DIR}")
+write_basic_package_version_file("${JPEG_VERSION_CONFIG}"
+  VERSION ${PROJECT_VERSION}
+  COMPATIBILITY SameMajorVersion)
+export(EXPORT ${TARGETS_EXPORT_NAME}
+  FILE ${JPEG_TARGETS_CONFIG})
+
+install(FILES ${JPEG_PROJECT_CONFIG} ${JPEG_VERSION_CONFIG}
+  DESTINATION ${JPEG_CONFIG_INSTALL_DIR})
+install(EXPORT ${TARGETS_EXPORT_NAME}
+  DESTINATION ${JPEG_CONFIG_INSTALL_DIR})
diff -Nru a/cmake-config.in b/cmake-config.in
--- a/cmake-config.in	1970-01-01 01:00:00.000000000 +0100
+++ b/cmake-config.in	2022-03-08 21:00:20.642490548 +0100
@@ -0,0 +1,4 @@
+@PACKAGE_INIT@
+
+include("${CMAKE_CURRENT_LIST_DIR}/@TARGETS_FILENAME@")
+check_required_components("@PROJECT_NAME@")

All the previously installed files are still installed the same way and to the same paths.
I only additionally install a CMake package config into lib/cmake/libjpeg/.
This allows users to find the package using CMake's find_package function.

@gillins
Copy link
Contributor

gillins commented Mar 9, 2022

I think I was involved in the original development of this patch. We did so since there was no MSVC support in jpeg and using cmake to do this seemed easiest, although I am definitely no expert in using it. @isuruf may have some thoughts?

My main concern with this is that it is only for Windows. Linux and OSX won't be improved by this patch - I think we should try to keep the platforms as similar as possible although I'm happy to be overruled.

@gillins
Copy link
Contributor

gillins commented Jun 30, 2022

@kuepe-sl does #36 address this problem? I think cmake has pkg_config support.

@kuepe-sl
Copy link
Author

kuepe-sl commented Aug 8, 2022

Sorry for the late reply.

Yes, the pkg-config files solve the problem.
I confirmed that GStreamer's install process can locate the jpeg library using pkg-config.

@kuepe-sl kuepe-sl closed this Aug 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants