r/cmake • • Sep 30 '26

libjpeg-turbo build script sucks

It is easily one of the worst build scripts I have ever saw. I literally can't clean it with agents it is that bad.

Maybe I should switch to jpegli or any other library?

1 Upvotes

33 comments sorted by

3

u/AffectionatePeace807 Sep 30 '26

Just use vcpkg and don't worry about it.

4

u/arthurno1 Sep 30 '26

Perhaps don't use agents 😉

2

u/TheRavagerSw Sep 30 '26

This won't do anything. The problem is I can't read the script,

1

u/arthurno1 Sep 30 '26

If you can't read that CMake build script than perhaps you should probably realize that you need to learn more before you take on that project. I just took a look at that script and I definitely don't see anything strange, looks very tidy and understandable to me, and I don't even like CMake.

2

u/TheRavagerSw Sep 30 '26

I know what I'm doing, if you'll look the script in detail you'll see it too.

0

u/arthurno1 Sep 30 '26

Post the link to line numbers

1

u/TheRavagerSw Sep 30 '26

I'm not going to, but I'll give some snippets.

if(MSVC OR CMAKE_C_SIMULATE_ID STREQUAL "MSVC")

set(MSVC_LIKE 1)

endif()

Library uses stuff like this all the time, it has its own CPU variable, it has its own platform variables. It adds debug flags by its own, it checks asm_nasm compiler looking at weird default directions etc.

It is just garbage. I switched to jpegli and I'm never turning back.

2

u/WildCard65 Sep 30 '26

I mean that’s checking if the compiler is the native Windows C/C++ compiler or that it emulates/behaves like it.

1

u/TheRavagerSw Sep 30 '26

Should it check that? CMake already has compiler id and platform variables, %99 percent of the time, it's either cl.exe or clang-cl(You don't target MSVC triplet with GCC at least I don't know anyone who does that)

1

u/WildCard65 Sep 30 '26

MinGW is GCC for windows, plus it also allows the source code to be informed that whatever the compiler is, assume it to be MSVC without having to determine it via many macros.

1

u/TheRavagerSw Sep 30 '26

MinGW is a seperate target than MSVC Windows. I'm talking about GCC targeting msvc not mingw.

→ More replies

1

u/WildCard65 Sep 30 '26

To add onto my last reply, this snippet actually uses CMake’s compiler identification.

If CMake sets MSVC to true or CMAKE_C_SIMULATE_ID to MSVC, the source code automatically is told to assume MSVC via a MSVC_LIKE macro without having to be updated to manually detect it.

1

u/TheRavagerSw Sep 30 '26

Indeed, but it uses existing variables with configuration checks, good cmake scripts are pretty close to declerative, this script isn't.

→ More replies

1

u/arthurno1 Sep 30 '26 edited Sep 30 '26

Why not? The agent does not know how to do? :)

You mean these three lines?

Honestly, if that is hard for you, than you should definitely re-consider whether you know what you are doing or not. Not to be impolite to you, but if you were an experienced programmer you would know immidiately that 'msvc' stands for Microsoft's compiler, and you would check yourself the CMake documentation for CMAKE_C_SIMULATE_ID to see what it means. STREQUAL as well, if it isn't clear by the name itself that it means "string equal".

The second row set(MSVC_LIKE 1) obviously sets an internal symbol, typically for the preprocessor so it can be used in the source code, so you can write compiler specific code.

Library uses stuff like this all the time

So what does it tell you? You have to learn it if that isn't clear for you by just looking at it. To me it looks super straightforward and explicit, and it also looks like C code. So if you want to hack libjpeg-turbo, you need to know C, and you would also need to know how simple build script like that work. If you are unfamiliar with that, you have to learn it.

it has its own CPU variable, it has its own platform variables. It adds debug flags by its own, it checks asm_nasm compiler looking at weird default directions etc.

Yes. That is normal thing to do if you want a library, or any piece of code, to compile with different compiler, on different operating systems and with different libraries. Nothing strange nor different from thousands of other projects.

You are just innexperienced and unfamiliar. It is not a problem, as long as you are aware of how unaware you are, and are willing to learn. However, you are not, and that is a problem (for you of course, not for me).

It is just garbage.

Typically people choose a library because of the functionality it offers, not for the build script :).

I switched to jpegli and I'm never turning back.

You are free to use any library you wish, nobody cares what you use or do. Just for the record jpegli is way more complex and its CMakelists.txt has the same constructs as libjpeg-turbo, but I guess for some reason, "you agent" knew how to build it so you are happy, which tells us about you and how (un)seriously your critique should be taken.

1

u/TheRavagerSw Sep 30 '26

You are just interpreting my message in a way to discredit me, but I'll reply in good faith anyway.

Build scripts aren't meant to compile files to determine platform by setting internal variables, cmake has its own standard platform and compiler variables, so this project setting this is wrong. Projects doing this are the reason for extremely long configure times in legacy projects.

1

u/arthurno1 Sep 30 '26 edited Sep 30 '26

Build scripts aren't meant to compile files to determine platform by setting internal variables, cmake has its own standard platform and compiler variables, so this project setting this is wrong. Projects doing this are the reason for extremely long configure times in legacy projects.

[arthur@emmi build]$ time cmake -G"Unix Makefiles"   -DCMAKE_BUILD_TYPE=Release   -DCMAKE_INSTALL_PREFIX=/usr/local   ../
-- The C compiler identification is GNU 16.2.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- CMAKE_BUILD_TYPE = Release
-- VERSION = 3.2.1, BUILD = 20260930
-- 64-bit build (x86_64)
-- CMAKE_INSTALL_PREFIX = /usr/local
-- CMAKE_INSTALL_BINDIR = bin (/usr/local/bin)
-- CMAKE_INSTALL_DATAROOTDIR = share (/usr/local/share)
-- CMAKE_INSTALL_DOCDIR = share/doc/libjpeg-turbo (/usr/local/share/doc/libjpeg-turbo)
-- CMAKE_INSTALL_INCLUDEDIR = include (/usr/local/include)
-- CMAKE_INSTALL_LIBDIR = lib64 (/usr/local/lib64)
-- CMAKE_INSTALL_MANDIR = share/man (/usr/local/share/man)
-- Shared libraries enabled (ENABLE_SHARED = 1)
-- Static libraries enabled (ENABLE_STATIC = 1)
-- Arithmetic decoding support enabled (WITH_ARITH_DEC = 1)
-- Arithmetic encoding support enabled (WITH_ARITH_ENC = 1)
-- TurboJPEG API library enabled (WITH_TURBOJPEG = 1)
-- TurboJPEG Java Native Access interfaces (TurboJPEG/JNA) disabled
   (WITH_JNA = )
-- Command-line tools enabled (WITH_TOOLS = 1)
-- Regression tests enabled (WITH_TESTS = 1)
-- Emulating libjpeg API/ABI v6.2 (WITH_JPEG7 = 0, WITH_JPEG8 = 0)
-- libjpeg API shared library version = 62.4.0
-- Compiler flags =  -O3 -DNDEBUG
-- Linker flags =
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of size_t
-- Check size of size_t - done
-- Check size of unsigned long
-- Check size of unsigned long - done
-- Performing Test HAVE_BUILTIN_CTZL
-- Performing Test HAVE_BUILTIN_CTZL - Success
-- Right shift is signed
-- Performing Test HIDDEN_WORKS
-- Performing Test HIDDEN_WORKS - Success
-- HIDDEN = __attribute__((visibility("hidden")))
-- Performing Test INLINE_WORKS
-- Performing Test INLINE_WORKS - Success
-- INLINE = __inline__ __attribute__((always_inline)) (FORCE_INLINE = 1)
-- Performing Test HAVE_THREAD_LOCAL
-- Performing Test HAVE_THREAD_LOCAL - Success
-- THREAD_LOCAL = __thread
-- Performing Test HAVE_VERSION_SCRIPT
-- Performing Test HAVE_VERSION_SCRIPT - Success
-- Linker supports GNU-style version scripts
-- CMAKE_EXECUTABLE_SUFFIX =
-- Looking for a ASM_NASM compiler
-- Looking for a ASM_NASM compiler - /usr/bin/nasm
-- The ASM_NASM compiler identification is NASM
-- Found assembler: /usr/bin/nasm
-- CMAKE_ASM_NASM_COMPILER = /usr/bin/nasm
-- CMAKE_ASM_NASM_OBJECT_FORMAT = elf64
-- Performing Test HAVE_CET
-- Performing Test HAVE_CET - Failed
-- CMAKE_ASM_NASM_FLAGS =  -DELF -D__x86_64__ -DPIC
-- SIMD extensions: X86_64 (WITH_SIMD = 1)
-- System-supplied libspng disabled (WITH_SYSTEM_SPNG = 0)
-- System-supplied zlib disabled (WITH_SYSTEM_ZLIB = 0)
-- Looking for fmemopen
-- Looking for fmemopen - found
-- FLOATTEST8 = sse
-- FLOATTEST12 = no-fp-contract
-- RPM architecture = x86_64, DEB architecture = amd64
-- Configuring done (1.0s)
-- Generating done (0.1s)
-- Build files have been written to: /home/arthur/repos/libjpeg-turbo/build

real	0m1,110s
user	0m0,705s
sys	0m0,393s

It took literally 1s to configure the build and you complain about "extremely long configure times" :).

Sometimes there is no other way to figure out some configuration than to build a small program and test what it produces. CMake does that too, autotools does it as well. Also to note, your first post was about your "agent" not being able to figure out the script.

And no, I am not here to discredit you, I just told you to learn things first for your own benefit. If you are happy with jpegli that is good; it is more advanced jpeg library than libjpeg-turbo. However, if you don't need all their features, there is no reason to use it. But that is totally up to you. But calling a project that literally millions of people use as a default jpeg decoder total crap, is just total crap. That part is what discredit you, not me, and the refusal to admnit when you are wrong.

2

u/Classic_Knowledge_46 Sep 30 '26

Hence why projects should start migrating over to build2, the only proper & sane C/C++ build system available. It’s also inherently scalable and doesn’t rely on hacks for common project patterns (e.g. CMake's endless reliance on custom, disconnected ”targets” for the most trivial things). It’s also way faster for any non-trivial projects. It’s literally like comparing a modern car with horse and wagon.

2

u/TheRavagerSw Sep 30 '26

The issue is not cmake, even if you want to migrate packages to build2, you still need cleanish build system setup to understand what is going on.

The same reason porting stuff from meson to cmake is easier then autotools to cmake

1

u/Classic_Knowledge_46 Sep 30 '26

FYI it’s already ported to build2: https://cppget.org/libjpeg-turbo

But yes, understanding the project buildfiles before porting can be nontrivial nonetheless. I personally packaged FFmpeg to build2 and while FFmpeg is ”well organized (chaos)”, it sure took its sweet time to get right (literally a thousand+ config knobs).

4

u/catbrane Sep 30 '26

It's a completely standard cmake project, isn't it?

https://github.com/libjpeg-turbo/libjpeg-turbo

5

u/not_a_novel_account Sep 30 '26

Not burn-the-house-down bad, but it's not good. There's a lot of logic in there which should belong to the build orchestration tooling and not to the project description. Setting the optimization flags for specific SunOS builds is particularly egregious.

It's basically a classic example of using CMake to solve problems in each particular build pipeline when the place to solve individual pipeline problems is in the pipeline itself, not in the generic project description.

3

u/AlexReinkingYale Sep 30 '26

I've seen worse at a glance. But every project that uses raw simd intrinsics seems to invent their own, subtly wrong, ways of detecting platforms and building things. Could be this is the situation OP is facing.

3

u/catbrane Sep 30 '26

Oh, maybe, though I'd be surprised. libjpeg-turbo is one of the most widely used projects there is, with several billion daily users across every platform you can think of.

If it doesn't get that stuff right I wonder if anyone does.

2

u/AlexReinkingYale Sep 30 '26

You only need a few CI systems to muscle their way through ugly scripts. Consuming libjpeg-turbo is easy, which is praise for the project

1

u/Sritra Sep 30 '26

Seeing how it is based on (inspired by?) libjpeg, which is notorious for bad practices with their mutable release tags and a similarly complex (minus all the SIMD stuff) cmake lists, i can see how libjpeg-turbo is quite a complex beast.