-
-
Notifications
You must be signed in to change notification settings - Fork 16
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
Conversation
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 ( |
This allows other build systems to easily locate libjpeg under Windows.
@conda-forge-admin, please rerender |
…nda-forge-pinning 2022.03.03.11.30.49
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? |
It is unfortunate that me renaming the .patch file also obscures the actual changes. 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 think I was involved in the original development of this patch. We did so since there was no MSVC support in 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. |
Sorry for the late reply. Yes, the pkg-config files solve the problem. |
This allows other build systems to easily locate libjpeg under Windows.
Checklist
0
(if the version changed)conda-smithy
(Use the phrase@conda-forge-admin, please rerender
in a comment in this PR for automated rerendering)