Skip to content

[cmake] Do not vendor 2 lzma versions, but download one single source tarball#21423

Open
dpiparo wants to merge 1 commit intoroot-project:masterfrom
dpiparo:lzma_one_version_only
Open

[cmake] Do not vendor 2 lzma versions, but download one single source tarball#21423
dpiparo wants to merge 1 commit intoroot-project:masterfrom
dpiparo:lzma_one_version_only

Conversation

@dpiparo
Copy link
Member

@dpiparo dpiparo commented Feb 28, 2026

This PR updates the two vendored lzma versions to v5.8.2 downloading sources from the official GitHub repo.
For the moment, this is a test, to check whether the approach works for ROOT.

@dpiparo dpiparo self-assigned this Feb 28, 2026
@github-actions
Copy link

github-actions bot commented Feb 28, 2026

Test Results

    22 files      22 suites   3d 6h 27m 34s ⏱️
 3 808 tests  3 807 ✅ 1 💤 0 ❌
75 708 runs  75 699 ✅ 9 💤 0 ❌

Results for commit 4449de4.

♻️ This comment has been updated with latest results.

@dpiparo dpiparo force-pushed the lzma_one_version_only branch from ef735a9 to cf211b6 Compare February 28, 2026 11:59
@dpiparo dpiparo force-pushed the lzma_one_version_only branch from cf211b6 to 4449de4 Compare February 28, 2026 12:44
@dpiparo dpiparo changed the title [cmake] Do not vendor 2 lzma versions, but download 1 source tarball [cmake] Do not vendor 2 lzma versions, but download one single source tarball Feb 28, 2026
@dpiparo dpiparo marked this pull request as ready for review February 28, 2026 18:12
Comment on lines +348 to +349
set(LIBLZMA_CXXFLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${LIBLZMA_CXXFLAGS}")
set(LIBLZMA_CXXFLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${LIBLZMA_CXXFLAGS}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are composing here the default build flags for a given configuration of LIBLZMA out of the the default CXXFLAGS from ROOT and flags related to warnings or headers, which are build type independent. These should be better passed via CMAKE_CXX_FLAGS, and not CXX_BUILD_FLAGS_<config>. Because in the end, CMake will concatenate both anyway during the liblzma configuration.

-DCMAKE_CXX_FLAGS_RELEASE=${LIBLZMA_CXXFLAGS_RELEASE}
-DCMAKE_CXX_FLAGS_DEBUG=${LIBLZMA_CXXFLAGS_RELEASE}
BUILD_COMMAND ${CMAKE_COMMAND} --build . --config $<CONFIG> --target liblzma
INSTALL_COMMAND ${CMAKE_COMMAND} --install . --config $<CONFIG> --component liblzma_Development
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Different from MSVC, Ninja and Make are single-configuration generators, so the --config $<CONFIG> will not have no effect and is ignored. So the configuration (like Release, Debug, RelWithDebInfo) is not forwarded unless you use MSVC, which makes this code a bit misleading, considering also the DCMAKE_CXX_FLAGS_<config> flags above. I would rather put the --config $<CONFIG> in an extra-

Comment on lines +358 to +360
-DCMAKE_CXX_FLAGS_RELWITHDEBINFO=${LIBLZMA_CXXFLAGS_RELWITHDEBINFO}
-DCMAKE_CXX_FLAGS_RELEASE=${LIBLZMA_CXXFLAGS_RELEASE}
-DCMAKE_CXX_FLAGS_DEBUG=${LIBLZMA_CXXFLAGS_RELEASE}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forwarding these DCMAKE_CXX_FLAGS_<config> flags is unnecessary on Linux/macOS. We are not messing with these CMake variables to begin with, it only happens on Windows: https://github.com/dpiparo/root/blob/master/cmake/modules/SetUpWindows.cmake#L48

Copy link
Contributor

@guitargeek guitargeek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much! I think the code is a bit misleading though, because it reads as if the CMake build type is intended to be forwarded for all generators, but it only happened for Windows before. Also, it mixes configuration-type-depended CXX flags with other CXX flags. It's worth to clean this up a little to make the intent clearer. I'll make another PR showing what I mean, that should be the easiest way to understand it.

Also, the previous code on Linux/macOS changes the C flags and not the C++ flags, so there is a change in behavior now (losing the -O3 on the C-side of lzma might cause performance regressions).

@guitargeek
Copy link
Contributor

guitargeek commented Mar 1, 2026

Let me just comment here what I think would be a slightly more backwards compatible change:

if(builtin_lzma)
  set(lzma_version 5.8.2)
  set(LZMA_TARGET LZMA)
  message(STATUS "Downloading and building LZMA version ${lzma_version}")

  set(LIBLZMA_LIBRARIES ${CMAKE_BINARY_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}lzma${CMAKE_STATIC_LIBRARY_SUFFIX})

  if(MSVC)
    # In the MSVC case, we forward the default C++ configuration flags because
    # they are changed by ROOT in SetUpWindows.cmake.
    set(lzma_extra_cmake_args
        -DCMAKE_CXXFLAGS_RELWITHDEBINFO="${CMAKE_CXX_FLAGS_RELWITHDEBINFO}"
        -DCMAKE_CXXFLAGS_RELEASE="${CMAKE_CXX_FLAGS_RELEASE}"
        -DCMAKE_CXXFLAGS_DEBUG="${CMAKE_CXX_FLAGS_DEBUG}")
  else()
    # In the Linux/macOS case, we forward the compilers and set unconditional
    # flags for maximum optimization and suppression of warnings.
    if(CMAKE_CXX_COMPILER_ID MATCHES Clang)
      set(liblzma_flags "-Wno-format-nonliteral")
    endif()
    if(CMAKE_OSX_SYSROOT)
      set(liblzma_flags "${liblzma_flags} -isysroot ${CMAKE_OSX_SYSROOT}")
    endif()
    set(liblzma_flags "${liblzma_flags} -O3")
    set(lzma_extra_cmake_args
        -DCMAKE_C_FLAGS="${liblzma_flags}"
        -DCMAKE_C_COMPILER="${CMAKE_C_COMPILER}"
        -DCMAKE_CXX_COMPILER="${CMAKE_CXX_COMPILER}")
  endif()

  ExternalProject_Add(
    LZMA
    URL https://root.cern/download/xz-${lzma_version}.tar.gz
    URL_HASH SHA256=f21fdf2c1ee004de30ca40377a273e3369186e6b7ab7b50a410eaa2e2bbefafb
    INSTALL_DIR ${CMAKE_BINARY_DIR}
    CMAKE_ARGS -G ${CMAKE_GENERATOR} -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}
               ${lzma_extra_cmake_args}
    BUILD_COMMAND ${CMAKE_COMMAND} --build . --config $<CONFIG> --target liblzma
    INSTALL_COMMAND ${CMAKE_COMMAND} --install . --config $<CONFIG> --component liblzma_Development
    LOG_DOWNLOAD 1 LOG_CONFIGURE 1 LOG_BUILD 1 LOG_INSTALL 1 LOG_OUTPUT_ON_FAILURE 1
    BUILD_IN_SOURCE 1
    BUILD_BYPRODUCTS ${LIBLZMA_LIBRARIES}
    TIMEOUT 600
  )
  set(LIBLZMA_INCLUDE_DIR ${CMAKE_BINARY_DIR}/include)

  add_library(LibLZMA STATIC IMPORTED GLOBAL)
  add_library(LibLZMA::LibLZMA ALIAS LibLZMA)
  target_include_directories(LibLZMA INTERFACE ${LIBLZMA_INCLUDE_DIR})
  set_target_properties(LibLZMA PROPERTIES IMPORTED_LOCATION ${LIBLZMA_LIBRARIES})
endif()

Comment on lines -372 to -373
--with-pic --disable-shared --quiet
--disable-scripts --disable-xz --disable-xzdec --disable-lzmadec --disable-lzmainfo --disable-lzma-links
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do all of these options have CMake equivalents? They were probably introduced for a reason, I think we need to keep them (unless looked into it in detail and we concluded they are not necessary).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For windows, we never cared.

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.

2 participants