Commit Graph

2673 Commits

Author SHA1 Message Date
Lasse Collin 35eb57355a Build: Use AC_LINK_IFELSE instead of -Werror
AC_COMPILE_IFELSE needed -Werror because Clang <= 14 would merely
warn about the unsupported attribute and implicit function declaration.
Changing to AC_LINK_IFELSE handles the implicit declaration because
the symbol __crc32d is unlikely to exist in libc.

Note that the other part of the check is that #include <arm_acle.h>
must work. If the header is missing, most compilers give an error
and the linking step won't be attempted.

Avoiding -Werror makes the check more robust in case CFLAGS contains
warning flags that break -Werror anyway (but this isn't the only check
in configure.ac that has this problem). Using AC_LINK_IFELSE also makes
the check more similar to how it is done in CMakeLists.txt.
2024-06-26 15:48:56 +03:00
Lasse Collin 5a728813c3 Build: Sync the compile check changes from CMakeLists.txt
It's nice to keep these in sync. The use of main() will later allow
AC_LINK_IFELSE usage too which may avoid the more fragile -Werror.
2024-06-26 15:48:56 +03:00
Lasse Collin 5279828635 CMake: Not experimental anymore
While the CMake support has gotten a lot less testing than
the Autotools-based build, the supported features should now
be equal. The output may differ slightly, for example,
liblzma.pc may have

    Libs.private: -pthread -lpthread

with Autotools on GNU/Linux. CMake doesn't put any options
in Libs.private because on modern glibc the pthread functions
are in libc. The options options aren't required to link static
liblzma into an application.

Autotools-based build doesn't generate or install
lib/cmake/liblzma-*.cmake files. This means that on most
platforms one cannot rely on

    find_package(liblzma 5.2.5 REQUIRED CONFIG)

or such finding those files.
2024-06-26 15:48:56 +03:00
Lasse Collin de215a0517 CMake: Use configure_file() to copy a file
I had missed this simpler method before. It does create a dependency
so that if .in.h changes the copying is done again.
2024-06-25 16:13:39 +03:00
Lasse Collin e620f35097 CMake: Always add pthread flags into CMAKE_REQUIRED_LIBRARIES
It was weird to add CMAKE_THREAD_LIBS_INIT in CMAKE_REQUIRED_LIBRARIES
only if CLOCK_MONOTONIC is available. Alternative would be to remove
the thread libs from CMAKE_REQUIRED_LIBRARIES after the check for
pthread_condattr_setclock() but keeping the libs should be fine too.
Then it's ready in case more pthread functions were wanted some day.
2024-06-25 15:56:39 +03:00
Sam James 068a70e549 CMake: Tweak comments
Co-authored-by: Lasse Collin <lasse.collin@tukaani.org>
2024-06-25 14:55:15 +03:00
Lasse Collin 3c95c93bca CMake: Edit white space for consistency 2024-06-25 14:54:53 +03:00
Lasse Collin 114cba69db CMake: Fix three checks if building with -flto
In CMake, check_c_source_compiles() always links too. With
link-time optimization, unused functions may get omitted if
main() doesn't depend on them. Consider the following which
tries to check if somefunction() is available when <someheader.h>
has been included:

    #include <someheader.h>
    int foo(void) { return somefunction(); }
    int main(void) { return 0; }

LTO may omit foo() completely because the program as a whole doesn't
need it and then the program will link even if the symbol somefunction
isn't available in libc or other library being linked in, and then
the test may pass when it shouldn't.

What happens if <someheader.h> doesn't declare somefunction()?
Shouldn't the test fail in the compilation phase already? It should
but many compilers don't follow the C99 and later standards that
prohibit implicit function declarations. Instead such compilers
assume that somefunction() exists, compilation succeeds (with a
warning), and then linker with LTO omits the call to somefunction().

Change the tests so that they are part of main(). If compiler accepts
implicitly declared functions, LTO cannot omit them because it has to
assume that they might have side effects and thus linking will fail.
On the other hand, if the functions/intrinsics being used are supported,
they might get optimized away but in that case it's fine because they
really are supported.

It is fine to use __attribute__((target(...))) for main(). At least
it works with GCC 4.9 to 14.1 on x86-64.

Reported-by: Sam James <sam@gentoo.org>
2024-06-25 14:54:53 +03:00
Lasse Collin 78e882205e CMake: Use MATCHES instead of multiple STREQUAL 2024-06-25 14:54:53 +03:00
Lasse Collin d3f20382fc CMake: Improve the comment about LIBS 2024-06-25 14:54:53 +03:00
Lasse Collin 33ec377729 CMake: Fix a typo in a message
It was spotted with codespell.
2024-06-24 20:01:25 +03:00
Lasse Collin 2a47be823c Document CMake options in INSTALL 2024-06-24 19:59:04 +03:00
Lasse Collin 3faf4e8079 CI: Don't omit crc32 from the list with CMake anymore
XZ_CHECKS accepts it but works without too.
2024-06-24 18:15:58 +03:00
Lasse Collin 1bf83cded2 CI: Workaround buggy config.guess on Ubuntu 22.04LTS and 24.04LTS
Check for the wrong triplet from config.guess and override it with
the --build option on the configure command line. Then i386 assembly
autodetection will work.

These Ubuntu versions (and as of writing, also Debian unstable)
ship config.guess version 2022-01-09 which contains a bug that
was fixed in version 2022-05-08. It results in a wrong configure
triplet when using CC="gcc -m32" to build i386 binaries.

Upstream fix:
https://git.savannah.gnu.org/cgit/config.git/commit/?id=f56a7140386d08a531bcfd444d632b28c61a6329

More information:
https://mail.gnu.org/archive/html/config-patches/2022-05/msg00003.html
2024-06-24 18:15:58 +03:00
Lasse Collin dbcdabf68f CI: Use CC="gcc -m32" to get i386 compiler on x86-64
The old method put it in CFLAGS which is a wrong place because
config.guess doesn't read CFLAGS.
2024-06-24 18:15:58 +03:00
Lasse Collin 0c1e6d900b CI: Let CMake use the CC environment variable
CC from environment is used to initialize CMAKE_C_COMPILER so
setting CMAKE_C_COMPILER explicitly isn't needed.

The syntax in ci_build.bash was broken in case one wished to put
spaces in CC.
2024-06-24 18:15:58 +03:00
Lasse Collin a3d6eb797c CMake: Add autodetection for 32-bit x86 CRC assembly usage 2024-06-24 18:15:58 +03:00
Lasse Collin dbc14f213e CMake: Move option(XZ_ASM_I386) downwards a few lines 2024-06-23 23:09:14 +03:00
Lasse Collin e5c2b07b48 DOS: Update Makefile and config.h for the CRC changes 2024-06-23 23:09:14 +03:00
Lasse Collin fe77c4e130 liblzma: Tidy up crc_common.h
Prefix ARM64_RUNTIME_DETECTION with CRC_ and reorder it to be with
the other ARM64-specific lines. That macro isn't used outside this
file.

ARM64 CLMUL implementation doesn't exist yet and thus CRC64_ARM64_CLMUL
isn't used anywhere yet.

It's not ideal that the single-letter CRC utility macros are here
as they pollute the namespace of the LZ encoder files. Those could
be moved their own crc_macros.h like they were in 5.2.x but in practice
this is fine enough already.
2024-06-23 23:09:14 +03:00
Lasse Collin 7484d37538 liblzma: Move lzma_crcXX_table[][] declarations to crc_common.h
LZ encoder needs lzma_crc32_table[0] but otherwise those tables
are private to the CRC code. In contrast, the other things in
check.h are needed in several places.
2024-06-23 15:37:46 +03:00
Lasse Collin 85b081f5d4 liblzma: Make 32-bit x86 CRC assembly co-exist with CLMUL
Now runtime detection of CLMUL support can pick between the CLMUL and
the generic assembly implementations. Whatever overhead this has for
builds that omit CLMUL completely isn't important because builds for
any non-ancient system is likely to include the CLMUL code too.

Handle the CRC tables in crcXX_fast.c files because now these files
are built even when assembly code is used.

If 32-bit x86 assembly is enabled then it will always be built even
if compiler flags were such that CLMUL would be allowed unconditionally.
That is, runtime detection will be used anyway. This keeps the build
rules simpler.

In LZ encoder, build and use lzma_lz_hash_table[256] if CLMUL CRC
is used without runtime detection. Previously this wasn't needed
because crc32_table.c included the lzma_crc32_table[][] in the build
unless encoder support had been disabled. Including an 8 KiB table
was silly when only 1 KiB is actually used. So now liblzma is 7 KiB
smaller if CLMUL is enabled without runtime detection.
2024-06-23 14:36:44 +03:00
Lasse Collin 6667d503b5 liblzma: CRC: Rename crcXX_generic to lzma_crcXX_generic
This prepares for the possibility that lzma_crc32_generic and
lzma_crc64_generic are extern functions.
2024-06-23 14:36:44 +03:00
Lasse Collin 1dca581ff2 CMake: Define HAVE_CRC_X86_ASM when 32-bit x86 CRC assembly is used 2024-06-23 14:36:44 +03:00
Lasse Collin f76837acb6 Build: Define HAVE_CRC_X86_ASM when 32-bit x86 CRC assembly is used
This makes it easier to determine when the CRC tables are needed.
2024-06-23 14:36:44 +03:00
Lasse Collin 9ce0866b07 CI: Update to the new renamed options in CMakeLists.txt 2024-06-21 00:47:27 +03:00
Lasse Collin 0232e66d5b CMake: Add XZ_EXTERNAL_SHA256 2024-06-20 21:53:07 +03:00
Lasse Collin 4535b80cae CMake: Move threading detection a few lines up
It feels clearer this way, and when support for external SHA-256
is added, this will keep the order of the library detection the
same as in configure.ac (check for pthreads before libmd) although
it shouldn't matter in practice.
2024-06-20 21:53:07 +03:00
Lasse Collin 94d062dbac CMake: Move the sandbox code out of the liblzma section
Sandboxing is for the command line tools, not liblzma.
No functional changes.
2024-06-20 21:53:07 +03:00
Lasse Collin 75ce4797d4 CMake: Keep existing options in LIBS when adding -lrt
This makes no difference yet because -lrt is currently the only option
that might be added to LIBS.
2024-06-20 21:53:07 +03:00
Lasse Collin 47aaa92516 CMake: Don't install scripts if the xz tool isn't built
The scripts need the xz tool.
2024-06-20 21:53:07 +03:00
Lasse Collin fb50c6ba1d CMake: Add XZ_TOOL_XZDEC and XZ_TOOL_LZMADEC 2024-06-20 21:53:07 +03:00
Lasse Collin def767f7d1 CMake: Add XZ_TOOL_LZMAINFO 2024-06-20 21:53:07 +03:00
Lasse Collin 5600e370fb CMake: Add XZ_TOOL_XZ 2024-06-20 21:53:07 +03:00
Lasse Collin 6a3c4aaa43 Windows: Drop Visual Studio 2013 support
This simplifies things a little. Building liblzma with VS2013 probably
still worked but building the command line tools was not supported.

Microsoft ended support for VS2013 on 2024-04.
2024-06-20 21:53:07 +03:00
Lasse Collin 5d5c92b262 CMake: Add XZ_TOOL_SCRIPTS 2024-06-20 21:53:07 +03:00
Lasse Collin d274a2bc00 CMake: Add XZ_DOC 2024-06-20 21:53:07 +03:00
Lasse Collin 188143a50a CMake: Refactor XZ_SYMBOL_VERSIONING to match configure.ac
Make the available options and their behavior match
--enable-symbol-versions in configure.ac.

Don't enable symbol versions on Linux if not using glibc. Previously
the generic variant was selected on Microblaze or if using NVHPC
without checking that libc is glibc.

Leave the cache variable to "auto" or "yes" if that was specified
instead of setting it to the autodetected value by default. A downside
is that one cannot easily see which variant the autodetection code
has selected. The same applies to XZ_SANDBOX and XZ_THREADS though.
2024-06-20 21:53:03 +03:00
Lasse Collin cc52ef8ed3 CMake: Use the same option list for XZ_THREADS as in configure.ac
Also clarify that "yes" will fail if no threading support is found.
If no threading is wanted, it has to be disabled manually.

configure.ac doesn't behave this way at the moment. Instead it
assumes pthreads to be present if not targeting Windows. If pthreads
actually are missing, the build fails later.
2024-06-20 15:12:19 +03:00
Lasse Collin 37f7af3452 CMake: Use the same option list for XZ_SANDBOX as in configure.ac
It's simpler to document this way.
2024-06-20 15:00:05 +03:00
Lasse Collin c715dec8e8 CMake: Fix indentation 2024-06-20 15:00:05 +03:00
Lasse Collin ea379f2f18 CMake: Add warning options for GCC and Clang
The list was copied from configure.ac and should be kept in sync.
(Pretend that the deleted comment in CMakeLists.txt didn't exist.)

There is no need to add equivalent of --enable-werror as CMake >= 3.24
supports -DCMAKE_COMPILE_WARNING_AS_ERROR=ON.
2024-06-20 15:00:05 +03:00
Lasse Collin 7422333819 CMake: Use \040 instead of \x20 for a space
This is for consistency with 4c81c9611f
where \040 has to be used because \0x20F gets interpret at three hex
digits. Octals escapes are never longer than three digits.
2024-06-20 15:00:05 +03:00
Lasse Collin e8854b6bdc CMake: Add XZ_ASSUME_RAM 2024-06-20 15:00:05 +03:00
Lasse Collin e1127e75cb CMake: Rename liblzma_INSTALL_CMAKEDIR to XZ_INSTALL_CMAKEDIR 2024-06-20 15:00:05 +03:00
Lasse Collin 96abfe98c1 CMake: Refactor ADDITIONAL_CHECK_TYPES to XZ_CHECKS
Now "crc32" is in the list too for completeness but it doesn't
actually have any effect. The description of the cache variable
says that "crc32 is always built" so it should be clear enough.
2024-06-20 15:00:05 +03:00
Lasse Collin 679500ffe0 CMake: Rename the cache variable POSIX_SHELL to XZ_POSIX_SHELL
We still need the variable POSIX_SHELL for configure_file()
but it doesn't need to be a cache variable.
2024-06-20 15:00:05 +03:00
Lasse Collin e5c0eb2e50 CMake: Rename ENCODERS and DECODERS to use XZ_ prefix 2024-06-20 15:00:05 +03:00
Lasse Collin e7785e2061 CMake: Rename MATCH_FINDERS to XZ_MATCH_FINDERS 2024-06-20 15:00:05 +03:00
Lasse Collin 63294806b4 CMake: Rename SYMBOL_VERSIONING to XZ_SYMBOL_VERSIONING 2024-06-20 15:00:05 +03:00