diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml index f259dc3e1c5..dd9fb0be1cf 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/build_test.yml @@ -77,6 +77,12 @@ jobs: -DJPEGXL_ENABLE_TRANSCODE_JPEG=OFF -DJPEGXL_ENABLE_PLUGINS=OFF -DJPEGXL_ENABLE_VIEWERS=OFF + # Build with jxl_cms based on lcms2 library. + - name: release-lcms2 + mode: release + cmake_args: >- + -DJPEGXL_ENABLE_SKCMS=OFF + apt_pkgs: liblcms2-2 # Build optimized for binary size, all features not needed for # reconstructing pixels is disabled. - name: release:minimal diff --git a/.github/workflows/build_test_md.yml b/.github/workflows/build_test_md.yml index aea22d4d4e1..e109523a31e 100644 --- a/.github/workflows/build_test_md.yml +++ b/.github/workflows/build_test_md.yml @@ -31,6 +31,7 @@ jobs: - name: scalar - name: asan - name: release-nojpeg + - name: release-lcms2 - name: release:gcc8 runs-on: ubuntu-latest steps: diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index e103e9199cc..20eb591aa22 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -31,6 +31,8 @@ target_link_libraries(encode_oneshot PkgConfig::Jxl PkgConfig::JxlCms PkgConfig: # depends on the platform, and building static binaries in general has problems. # If you don't need static binaries you can remove this section. add_library(StaticJxl INTERFACE IMPORTED GLOBAL) +list(REMOVE_ITEM Jxl_STATIC_LDFLAGS "-ljxl_cms") + set_target_properties(StaticJxl PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${Jxl_STATIC_INCLUDE_DIR}" INTERFACE_COMPILE_OPTIONS "${Jxl_STATIC_CFLAGS_OTHER}" @@ -48,9 +50,7 @@ set_target_properties(StaticJxlThreads PROPERTIES ) add_executable(decode_oneshot_static decode_oneshot.cc) -target_link_libraries(decode_oneshot_static - -static StaticJxl StaticJxlThreads) +target_link_libraries(decode_oneshot_static -static StaticJxl StaticJxlThreads) add_executable(encode_oneshot_static encode_oneshot.cc) -target_link_libraries(encode_oneshot_static - -static StaticJxl StaticJxlThreads) +target_link_libraries(encode_oneshot_static -static StaticJxl StaticJxlThreads) diff --git a/examples/examples.cmake b/examples/examples.cmake index dbf799cb9fe..fd159578bce 100644 --- a/examples/examples.cmake +++ b/examples/examples.cmake @@ -4,8 +4,8 @@ # license that can be found in the LICENSE file. add_executable(decode_oneshot ${CMAKE_CURRENT_LIST_DIR}/decode_oneshot.cc) -target_link_libraries(decode_oneshot jxl_dec jxl_cms jxl_threads) +target_link_libraries(decode_oneshot jxl_dec jxl_threads) add_executable(decode_progressive ${CMAKE_CURRENT_LIST_DIR}/decode_progressive.cc) -target_link_libraries(decode_progressive jxl_dec jxl_cms jxl_threads) +target_link_libraries(decode_progressive jxl_dec jxl_threads) add_executable(encode_oneshot ${CMAKE_CURRENT_LIST_DIR}/encode_oneshot.cc) -target_link_libraries(encode_oneshot jxl jxl_cms jxl_threads) +target_link_libraries(encode_oneshot jxl jxl_threads) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 24d1930a34e..2bea5bea40a 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -124,6 +124,13 @@ else () endif() # WIN32 endif() #!MSVC +if (JPEGXL_ENABLE_SKCMS) + list(APPEND JPEGXL_INTERNAL_FLAGS -DJPEGXL_ENABLE_SKCMS=1) + if (JPEGXL_BUNDLE_SKCMS) + list(APPEND JPEGXL_INTERNAL_FLAGS -DJPEGXL_BUNDLE_SKCMS=1) + endif () +endif () + # strips the -static suffix from all the elements in LIST function(strip_static OUTPUT_VAR LIB_LIST) foreach(lib IN LISTS ${LIB_LIST}) diff --git a/lib/jxl.cmake b/lib/jxl.cmake index 92d8d43a3ca..1843dc10357 100644 --- a/lib/jxl.cmake +++ b/lib/jxl.cmake @@ -136,9 +136,14 @@ set_target_properties(jxl_enc-obj PROPERTIES # for tests. add_library(jxl_dec-static STATIC $ + ${JXL_CMS_OBJECTS} +) +target_link_libraries(jxl_dec-static PUBLIC + ${JPEGXL_COVERAGE_FLAGS} + ${JPEGXL_DEC_INTERNAL_LIBS} + ${JXL_CMS_LIBS} + jxl_base ) -target_link_libraries(jxl_dec-static - PUBLIC ${JPEGXL_COVERAGE_FLAGS} ${JPEGXL_DEC_INTERNAL_LIBS} jxl_base) # The list of objects in the static and shared libraries. set(JPEGXL_INTERNAL_OBJECTS @@ -157,6 +162,7 @@ add_library(jxl-static STATIC target_link_libraries(jxl-static PUBLIC ${JPEGXL_COVERAGE_FLAGS} ${JPEGXL_INTERNAL_LIBS} + ${JXL_CMS_LIBS} jxl_base ) target_include_directories(jxl-static PUBLIC diff --git a/lib/jxl/libjxl_cms.pc.in b/lib/jxl/libjxl_cms.pc.in index fb8dfa7603f..aa134f608bb 100644 --- a/lib/jxl/libjxl_cms.pc.in +++ b/lib/jxl/libjxl_cms.pc.in @@ -7,7 +7,7 @@ Name: libjxl_cms Description: CMS support library for libjxl Version: @JPEGXL_LIBRARY_VERSION@ Requires.private: @JPEGXL_CMS_LIBRARY_REQUIRES@ -Libs: -L${libdir} -ljxl_cms +Libs: @JXL_CMS_PK_LIBS@ -L${libdir} -ljxl_cms Libs.private: -lm Cflags: -I${includedir} Cflags.private: -DJXL_STATIC_DEFINE diff --git a/lib/jxl_cms.cmake b/lib/jxl_cms.cmake index 6f030df5e79..59decda2a8a 100644 --- a/lib/jxl_cms.cmake +++ b/lib/jxl_cms.cmake @@ -38,51 +38,42 @@ target_include_directories(jxl_cms-obj PUBLIC "$") set(JXL_CMS_OBJECTS $) +set(JXL_CMS_LIBS "") +set(JXL_CMS_PK_LIBS "") if (JPEGXL_ENABLE_SKCMS) target_include_directories(jxl_cms-obj PRIVATE $ ) list(APPEND JXL_CMS_OBJECTS $) - target_compile_definitions(jxl_cms-obj PRIVATE JPEGXL_ENABLE_SKCMS=1) - if (JPEGXL_BUNDLE_SKCMS) - target_compile_definitions(jxl_cms-obj PRIVATE JPEGXL_BUNDLE_SKCMS=1) - else () - target_link_libraries(jxl_cms-obj INTERFACE skcms) - endif () + if (NOT JPEGXL_BUNDLE_SKCMS) + message(ERROR "Non-bundles skcms is not currently supported") + set(JXL_CMS_LIBS "skcms") + set(JXL_CMS_PK_LIBS "-lskcms") + endif () else () target_include_directories(jxl_cms-obj PRIVATE - $ + $ ) - target_link_libraries(jxl_cms-obj INTERFACE lcms2) + list(APPEND JXL_CMS_OBJECTS $) endif () - -add_library(jxl_cms-static STATIC ${JXL_CMS_OBJECTS}) -if (NOT WIN32 OR MINGW) - set_target_properties(jxl_cms-static PROPERTIES OUTPUT_NAME "jxl_cms") -endif() - -install(TARGETS jxl_cms-static DESTINATION ${CMAKE_INSTALL_LIBDIR}) - -if (BUILD_SHARED_LIBS AND NOT MINGW) -add_library(jxl_cms SHARED ${JXL_CMS_OBJECTS}) -target_link_libraries(jxl_cms PRIVATE hwy) - -set_target_properties(jxl_cms PROPERTIES - VERSION ${JPEGXL_LIBRARY_VERSION} - SOVERSION ${JPEGXL_LIBRARY_SOVERSION} - LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" - RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}") - -install(TARGETS jxl_cms - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) - -else() # BUILD_SHARED_LIBS - -add_library(jxl_cms ALIAS jxl_cms-static) - +target_link_libraries(jxl_cms-obj PUBLIC ${JXL_CMS_LIBS}) + +if (BUILD_SHARED_LIBS) + add_library(jxl_cms SHARED ${JXL_CMS_OBJECTS}) + target_link_libraries(jxl_cms INTERFACE ${JXL_CMS_LIBS}) + target_link_libraries(jxl_cms PRIVATE hwy) + + set_target_properties(jxl_cms PROPERTIES + VERSION ${JPEGXL_LIBRARY_VERSION} + SOVERSION ${JPEGXL_LIBRARY_SOVERSION} + LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}") + + install(TARGETS jxl_cms + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) endif() # BUILD_SHARED_LIBS set(JPEGXL_CMS_LIBRARY_REQUIRES "") diff --git a/lib/jxl_extras.cmake b/lib/jxl_extras.cmake index 03693747dcd..c38d4f4d2e0 100644 --- a/lib/jxl_extras.cmake +++ b/lib/jxl_extras.cmake @@ -145,7 +145,6 @@ add_library(jxl_extras-static STATIC EXCLUDE_FROM_ALL ${JXL_EXTRAS_OBJECTS}) target_link_libraries(jxl_extras-static PUBLIC ${JXL_EXTRAS_CODEC_INTERNAL_LIBRARIES} jxl-static - jxl_cms-static jxl_threads-static ) if(JPEGXL_ENABLE_JPEGLI) diff --git a/third_party/lcms2.cmake b/third_party/lcms2.cmake index c4551de862d..20ff3462436 100644 --- a/third_party/lcms2.cmake +++ b/third_party/lcms2.cmake @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -add_library(lcms2 STATIC EXCLUDE_FROM_ALL +add_library(lcms2-obj OBJECT EXCLUDE_FROM_ALL lcms/src/cmsalpha.c lcms/src/cmscam02.c lcms/src/cmscgats.c @@ -41,37 +41,37 @@ add_library(lcms2 STATIC EXCLUDE_FROM_ALL lcms/src/cmsxform.c lcms/src/lcms2_internal.h ) -target_include_directories(lcms2 +target_include_directories(lcms2-obj PUBLIC "${CMAKE_CURRENT_LIST_DIR}/lcms/include") # This warning triggers with gcc-8. if (CMAKE_C_COMPILER_ID MATCHES "GNU") -target_compile_options(lcms2 - PRIVATE - # gcc-only flags. - -Wno-stringop-truncation - -Wno-strict-aliasing -) + target_compile_options(lcms2-obj + PRIVATE + # gcc-only flags. + -Wno-stringop-truncation + -Wno-strict-aliasing + ) endif() # By default LCMS uses sizeof(void*) for memory alignment, but in arm 32-bits we # can't access doubles not aligned to 8 bytes. This forces the alignment to 8 # bytes. -target_compile_definitions(lcms2 +target_compile_definitions(lcms2-obj PRIVATE "-DCMS_PTR_ALIGNMENT=8") -target_compile_definitions(lcms2 +target_compile_definitions(lcms2-obj PUBLIC "-DCMS_NO_REGISTER_KEYWORD=1") # Ensure that a thread safe alternative of gmtime is used in LCMS include(CheckSymbolExists) check_symbol_exists(gmtime_r "time.h" HAVE_GMTIME_R) if (HAVE_GMTIME_R) - target_compile_definitions(lcms2 + target_compile_definitions(lcms2-obj PUBLIC "-DHAVE_GMTIME_R=1") else() check_symbol_exists(gmtime_s "time.h" HAVE_GMTIME_S) if (HAVE_GMTIME_S) - target_compile_definitions(lcms2 + target_compile_definitions(lcms2-obj PUBLIC "-DHAVE_GMTIME_S=1") endif() endif() -set_property(TARGET lcms2 PROPERTY POSITION_INDEPENDENT_CODE ON) +set_property(TARGET lcms2-obj PROPERTY POSITION_INDEPENDENT_CODE ON) diff --git a/third_party/skcms.cmake b/third_party/skcms.cmake index bf7af616ee6..1c4598a3035 100644 --- a/third_party/skcms.cmake +++ b/third_party/skcms.cmake @@ -15,17 +15,10 @@ add_library(skcms-obj OBJECT EXCLUDE_FROM_ALL skcms/skcms.cc) target_include_directories(skcms-obj PUBLIC "${CMAKE_CURRENT_LIST_DIR}/skcms/") -# This library is meant to be compiled/used by external libs (such as plugins) -# that need to use skcms. We use a wrapper for libjxl. -add_library(skcms-interface INTERFACE) -target_sources(skcms-interface INTERFACE ${CMAKE_CURRENT_LIST_DIR}/skcms/skcms.cc) -target_include_directories(skcms-interface INTERFACE ${CMAKE_CURRENT_LIST_DIR}/skcms) - include(CheckCXXCompilerFlag) check_cxx_compiler_flag("-Wno-psabi" CXX_WPSABI_SUPPORTED) if(CXX_WPSABI_SUPPORTED) target_compile_options(skcms-obj PRIVATE -Wno-psabi) - target_compile_options(skcms-interface INTERFACE -Wno-psabi) endif() if(JPEGXL_BUNDLE_SKCMS) @@ -45,7 +38,9 @@ set_target_properties(skcms-obj PROPERTIES VISIBILITY_INLINES_HIDDEN 1 ) -add_library(skcms STATIC EXCLUDE_FROM_ALL $) -target_include_directories(skcms - PUBLIC $) +if(NOT JPEGXL_BUNDLE_SKCMS) + add_library(skcms STATIC EXCLUDE_FROM_ALL $) + target_include_directories(skcms + PUBLIC $) +endif() diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index a5d9cb1b0be..0f36fa009e0 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -67,12 +67,11 @@ add_library(jxl_tool STATIC EXCLUDE_FROM_ALL codec_config.cc speed_stats.cc tool_version.cc + ${JXL_CMS_OBJECTS} ) target_compile_options(jxl_tool PUBLIC "${JPEGXL_INTERNAL_FLAGS}") target_include_directories(jxl_tool PUBLIC "${PROJECT_SOURCE_DIR}") target_link_libraries(jxl_tool PUBLIC hwy) -jxl_link_libraries(jxl_tool jxl_base) -jxl_link_libraries(jxl_tool jxl_cms-obj) # The JPEGXL_VERSION is set from the builders. if(NOT DEFINED JPEGXL_VERSION OR JPEGXL_VERSION STREQUAL "") @@ -354,7 +353,6 @@ foreach(FUZZER IN LISTS FUZZER_BINARIES) if(FUZZER STREQUAL djxl_fuzzer) target_link_libraries("${BINARY}" jxl_dec-static - jxl_cms-static jxl_threads-static ) elseif(FUZZER STREQUAL jpegli_dec_fuzzer) @@ -427,7 +425,7 @@ if (JNI_FOUND AND Java_FOUND) # decoder_jni_onload.cc might be necessary for Android; not used yet. add_library(jxl_jni SHARED jni/org/jpeg/jpegxl/wrapper/decoder_jni.cc) target_include_directories(jxl_jni PRIVATE "${JNI_INCLUDE_DIRS}" "${PROJECT_SOURCE_DIR}") - target_link_libraries(jxl_jni PUBLIC jxl_dec-static jxl_cms-static jxl_threads-static) + target_link_libraries(jxl_jni PUBLIC jxl_dec-static jxl_threads-static) if(NOT DEFINED JPEGXL_INSTALL_JNIDIR) set(JPEGXL_INSTALL_JNIDIR ${CMAKE_INSTALL_LIBDIR}) endif()