Last active
March 21, 2023 02:14
-
-
Save Nuclearfossil/3ac61771bfc0d34d52561153b32d95b3 to your computer and use it in GitHub Desktop.
Using cmake to build zlib ... and others!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Let's start with building zlib. | |
## First | |
You're going to want to set up a build structure for doing anything with cmake build systems. | |
Let's say you're keeping all your source projects on your D: drive. You'll want to have a build structure that looks like this: | |
D: | |
- dev // where I like to keep all my development projects | |
- git // where we get our git based projects | |
- usr // where locally built libraries go. (including header files) | |
With that in place, let's grab zlib. from the root of our d drive: | |
<--- Terminal dump begins ---------------------------------------------------------------> | |
nucle@DESKTOP-9K54U4B MINGW64 /d/dev | |
$ ls | |
bin/ git/ usr/ | |
nucle@DESKTOP-9K54U4B MINGW64 /d/dev | |
$ cd git | |
nucle@DESKTOP-9K54U4B MINGW64 /d/dev/git | |
$ git clone https://github.com/zlib-ng/zlib-ng.git | |
Cloning into 'zlib-ng'... | |
remote: Enumerating objects: 25, done. | |
remote: Counting objects: 100% (25/25), done. | |
remote: Compressing objects: 100% (21/21), done. | |
remote: Total 8069 (delta 9), reused 7 (delta 4), pack-reused 8044 | |
Receiving objects: 100% (8069/8069), 4.72 MiB | 8.91 MiB/s, done. | |
Resolving deltas: 100% (5483/5483), done. | |
nucle@DESKTOP-9K54U4B MINGW64 /d/dev/git | |
$ ls | |
zlib-ng/ | |
nucle@DESKTOP-9K54U4B MINGW64 /d/dev/git | |
$ cd zlib-ng/ | |
nucle@DESKTOP-9K54U4B MINGW64 /d/dev/git/zlib-ng (develop) | |
$ ls | |
adler32.c crc32.c deflate_p.h gzclose.c inffast.c inftrees.h tools/ zconf.h.in zlib.pc.in | |
adler32_p.h crc32.h deflate_slow.c gzguts.h inffast.h LICENSE.md trees.c zconf-ng.h.in zlib-ng.h | |
arch/ crc32_p.h doc/ gzlib.c inffixed.h Makefile.in trees.h zendian.h zlib-ng.map | |
cmake/ deflate.c fallback_builtins.h gzread.c inflate.c match_p.h trees_p.h zlib.3 zutil.c | |
CMakeLists.txt deflate.h FAQ.zlib gzwrite.c inflate.h memcopy.h uncompr.c zlib.h zutil.h | |
compress.c deflate_fast.c functable.c INDEX inflate_p.h README.md win32/ zlib.map | |
configure* deflate_medium.c functable.h infback.c inftrees.c test/ zbuild.h zlib.pc.cmakein | |
nucle@DESKTOP-9K54U4B MINGW64 /d/dev/git/zlib-ng (develop) | |
$ mkdir build && cd build | |
nucle@DESKTOP-9K54U4B MINGW64 /d/dev/git/zlib-ng/build (develop) | |
$ cmake -G "Visual Studio 16 2019" .. -DCMAKE_INSTALL_PREFIX=D:/dev/usr | |
-- Using CMake version 3.15.3 | |
-- ZLIB_HEADER_VERSION: 1.2.11 | |
-- ZLIBNG_HEADER_VERSION: 1.9.9 | |
-- The C compiler identification is MSVC 19.23.28107.0 | |
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.23.28105/bin/Hostx64/x64/cl.exe | |
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.23.28105/bin/Hostx64/x64/cl.exe -- works | |
-- Detecting C compiler ABI info | |
-- Detecting C compiler ABI info - done | |
-- Detecting C compile features | |
-- Detecting C compile features - done | |
-- Arch detected: 'x86_64' | |
-- Basearch of 'x86_64' has been detected as: 'x86' | |
-- 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 | |
-- Looking for sys/sdt.h | |
-- Looking for sys/sdt.h - not found | |
-- Check size of off64_t | |
-- Check size of off64_t - failed | |
-- Check size of _off64_t | |
-- Check size of _off64_t - failed | |
-- Check size of __off64_t | |
-- Check size of __off64_t - failed | |
-- Looking for fseeko | |
-- Looking for fseeko - not found | |
-- Looking for strerror | |
-- Looking for strerror - found | |
-- Looking for unistd.h | |
-- Looking for unistd.h - not found | |
-- Performing Test HAVE_ATTRIBUTE_VISIBILITY_HIDDEN | |
-- Performing Test HAVE_ATTRIBUTE_VISIBILITY_HIDDEN - Failed | |
-- Performing Test HAVE_ATTRIBUTE_VISIBILITY_INTERNAL | |
-- Performing Test HAVE_ATTRIBUTE_VISIBILITY_INTERNAL - Failed | |
-- Performing Test HAVE_BUILTIN_CTZL | |
-- Performing Test HAVE_BUILTIN_CTZL - Failed | |
-- Performing Test HAVE_PTRDIFF_T | |
-- Performing Test HAVE_PTRDIFF_T - Success | |
-- Performing Test HAVE_SSE2_INTRIN | |
-- Performing Test HAVE_SSE2_INTRIN - Success | |
-- Performing Test HAVE_SSE42CRC_INLINE_ASM | |
-- Performing Test HAVE_SSE42CRC_INLINE_ASM - Failed | |
-- Performing Test HAVE_SSE42CRC_INTRIN | |
-- Performing Test HAVE_SSE42CRC_INTRIN - Success | |
-- Performing Test HAVE_PCLMULQDQ_INTRIN | |
-- Performing Test HAVE_PCLMULQDQ_INTRIN - Success | |
-- Architecture-specific source files: arch/x86/x86.c;arch/x86/insert_string_sse.c;arch/x86/deflate_quick.c;arch/x86/fill_window_sse.c;arch/x86/slide_sse.c;arch/x86/crc_folding.c | |
-- The following features have been enabled: | |
* CMAKE_BUILD_TYPE, Build type: Release (default) | |
* WITH_OPTIM, Build with optimisation | |
* WITH_NEW_STRATEGIES, Use new strategies | |
* SSE42_CRC, Support CRC hash generation using the SSE4.2 instruction set, using "" | |
* SSE42_DEFLATE_QUICK, Support SSE4.2-accelerated quick compression | |
* PCLMUL_CRC, Support CRC hash generation using PCLMULQDQ, using " " | |
-- The following features have been disabled: | |
* ZLIB_COMPAT, Provide a zlib-compatible API | |
* WITH_GZFILEOP, Compile with support for gzFile-related functions | |
* WITH_SANITIZERS, Build with address sanitizer and all supported sanitizers other than memory sanitizer | |
* WITH_MSAN, Build with memory sanitizer | |
* WITH_FUZZERS, Build test/fuzz | |
* MAINTAINER, Build with maintainer warnings and tests enabled | |
-- Configuring done | |
-- Generating done | |
-- Build files have been written to: D:/dev/git/zlib-ng/build | |
nucle@DESKTOP-9K54U4B MINGW64 /d/dev/git/zlib-ng/build (develop) | |
$ cmake --build . --config Release --target INSTALL | |
Microsoft (R) Build Engine version 16.3.2+e481bbf88 for .NET Framework | |
Copyright (C) Microsoft Corporation. All rights reserved. | |
Checking Build System | |
Building Custom Rule D:/dev/git/zlib-ng/CMakeLists.txt | |
adler32.c | |
compress.c | |
crc32.c | |
deflate.c | |
deflate_fast.c | |
deflate_medium.c | |
deflate_slow.c | |
functable.c | |
inflate.c | |
infback.c | |
inftrees.c | |
inffast.c | |
trees.c | |
uncompr.c | |
zutil.c | |
x86.c | |
insert_string_sse.c | |
deflate_quick.c | |
fill_window_sse.c | |
slide_sse.c | |
Generating Code... | |
Compiling... | |
crc_folding.c | |
Generating Code... | |
Creating library D:/dev/git/zlib-ng/build/Release/zlib.lib and object D:/dev/git/zlib-ng/build/Release/zlib.exp | |
zlib.vcxproj -> D:\dev\git\zlib-ng\build\Release\zlib1.dll | |
Building Custom Rule D:/dev/git/zlib-ng/CMakeLists.txt | |
example.c | |
gzclose.c | |
gzlib.c | |
gzread.c | |
gzwrite.c | |
Generating Code... | |
example.vcxproj -> D:\dev\git\zlib-ng\build\Release\example.exe | |
Building Custom Rule D:/dev/git/zlib-ng/CMakeLists.txt | |
makecrct.c | |
makecrct.vcxproj -> D:\dev\git\zlib-ng\build\Release\makecrct.exe | |
Building Custom Rule D:/dev/git/zlib-ng/CMakeLists.txt | |
makefixed.c | |
inftrees.c | |
Generating Code... | |
makefixed.vcxproj -> D:\dev\git\zlib-ng\build\Release\makefixed.exe | |
Building Custom Rule D:/dev/git/zlib-ng/CMakeLists.txt | |
maketrees.c | |
trees.c | |
zutil.c | |
Generating Code... | |
maketrees.vcxproj -> D:\dev\git\zlib-ng\build\Release\maketrees.exe | |
Building Custom Rule D:/dev/git/zlib-ng/CMakeLists.txt | |
minigzip.c | |
gzclose.c | |
gzlib.c | |
gzread.c | |
gzwrite.c | |
Generating Code... | |
minigzip.vcxproj -> D:\dev\git\zlib-ng\build\Release\minigzip.exe | |
Building Custom Rule D:/dev/git/zlib-ng/CMakeLists.txt | |
switchlevels.c | |
gzclose.c | |
gzlib.c | |
gzread.c | |
gzwrite.c | |
Generating Code... | |
switchlevels.vcxproj -> D:\dev\git\zlib-ng\build\Release\switchlevels.exe | |
Building Custom Rule D:/dev/git/zlib-ng/CMakeLists.txt | |
adler32.c | |
compress.c | |
crc32.c | |
deflate.c | |
deflate_fast.c | |
deflate_medium.c | |
deflate_slow.c | |
functable.c | |
inflate.c | |
infback.c | |
inftrees.c | |
inffast.c | |
trees.c | |
uncompr.c | |
zutil.c | |
x86.c | |
insert_string_sse.c | |
deflate_quick.c | |
fill_window_sse.c | |
slide_sse.c | |
Generating Code... | |
Compiling... | |
crc_folding.c | |
Generating Code... | |
zlibstatic.vcxproj -> D:\dev\git\zlib-ng\build\Release\zlibstatic.lib | |
Building Custom Rule D:/dev/git/zlib-ng/CMakeLists.txt | |
-- Install configuration: "Release" | |
-- Installing: D:/dev/usr/lib/zlib.lib | |
-- Installing: D:/dev/usr/bin/zlib1.dll | |
-- Installing: D:/dev/usr/lib/zlibstatic.lib | |
-- Installing: D:/dev/usr/include/zlib-ng.h | |
-- Installing: D:/dev/usr/include/zconf-ng.h | |
-- Installing: D:/dev/usr/share/man/man3/zlib-ng.3 | |
-- Installing: D:/dev/usr/share/pkgconfig/zlib-ng.pc | |
<--- Terminal dump ends ---------------------------------------------------------------> | |
What we have now done is build and install the release version of zlib into D:/dev/usr. At this point, we'll want to have any new projects we pull down from git that use cmake to use that folder (D:/dev/usr) as the home for all external libraries. | |
We'd also want to build debug librares as well using the command line: | |
$ cmake --build . --config Release --target INSTALL | |
Please note, I've used the cygwin shell for all this. But there is no reason you can't use as standard cmd shell (or powershell) for this. | |
You can get zlib from here: https://github.com/zlib-ng/zlib-ng | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment