diff options
author | cen1 <cen.is.imba@gmail.com> | 2025-04-18 15:28:40 +0200 |
---|---|---|
committer | cen1 <cen.is.imba@gmail.com> | 2025-05-25 19:42:45 +0200 |
commit | 4b38800ab7eba3db99935b5aa3d79c02395cfc95 (patch) | |
tree | b93af75e349e1644dbf02186125f3e20095775fa | |
parent | da046e71d9cfdfc0e143b6be0e496fddb9c6bab9 (diff) |
- modernize CMake by adding target_ where missing, split add_library and sources (target_sources), some reordering
- make tests it's own CMake project
- add CMake option to override hardcoded test data paths
- improve CMake documentation, document all options
- add basic CI build for Debian, Fedora and Windows
- add release pipeline to create .deb, .rpm and Windows li/dll archives
-rw-r--r-- | .github/workflows/build.yml | 87 | ||||
-rw-r--r-- | .github/workflows/release.yml | 187 | ||||
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | CMakeLists.txt | 49 | ||||
-rw-r--r-- | README.md | 52 | ||||
-rw-r--r-- | test/CMakeLists.txt | 20 | ||||
-rwxr-xr-x | test/StormTest.cpp | 22 |
7 files changed, 377 insertions, 43 deletions
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..1adb852 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,87 @@ +name: CMake + +on: [push, pull_request] + +env: + BUILD_TYPE: Release + +jobs: + debian-bookworm: + runs-on: ubuntu-latest + container: + image: debian:bookworm + + strategy: + matrix: + storm_use_bundled_libraries: [ ON, OFF ] + with_libtomcrypt: [ ON, OFF ] + build_shared_libs: [ ON, OFF ] + unicode: [ ON, OFF ] + + steps: + - uses: actions/checkout@v4 + + - name: Install dependencies + run: apt-get -y update && apt-get install -y build-essential cmake + + - name: Conditionally install libtomcrypt-dev + if: matrix.with_libtomcrypt == 'ON' + run: apt-get install -y libtomcrypt-dev pkg-config + + - name: CMake Configuration + run: | + cmake -B build \ + -D CMAKE_BUILD_TYPE=Release \ + -D STORM_USE_BUNDLED_LIBRARIES=${{ matrix.storm_use_bundled_libraries }} \ + -D WITH_LIBTOMCRYPT=${{ matrix.with_libtomcrypt }} \ + -D BUILD_SHARED_LIBS=${{ matrix.build_shared_libs }} \ + -D STORM_UNICODE=${{ matrix.unicode }} + + - name: Build + run: cmake --build build --config Release + + fedora-latest: + if: true + runs-on: ubuntu-latest + container: + image: fedora:latest + + steps: + - uses: actions/checkout@v4 + + - name: Install dependencies + run: dnf -y install cmake gcc gcc-c++ + + - name: Cmake + run: cmake -B build -D CMAKE_BUILD_TYPE=$BUILD_TYPE -D BUILD_SHARED_LIBS=ON + + - name: Build + run: cmake --build build --config Release + + windows-latest-x64: + if: true + runs-on: windows-latest + + steps: + - uses: actions/checkout@v4 + + - uses: TheMrMilchmann/setup-msvc-dev@v3 + with: + arch: x64 + + - name: Cmake + run: cmake -B build -D CMAKE_BUILD_TYPE=$BUILD_TYPE -D BUILD_SHARED_LIBS=ON + + - name: Build + run: cmake --build build --config Release + + - name: Debug + shell: bash + run: ls -la build + + - name: Check PE + shell: bash + working-directory: ./build/Release + run: | + file "stormlib.dll" + file "stormlib.dll" |grep "x86-64"
\ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..18702ed --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,187 @@ +name: Release + +on: + push: + tags: + - '*' + +jobs: + deb: + if: true + runs-on: ubuntu-latest + container: + image: debian:bookworm + env: + BUILD_TYPE: Release + + steps: + - uses: actions/checkout@v4 + + - name: Install dependencies + run: apt-get -y update && apt-get install -y build-essential cmake + + - name: Cmake + run: cmake -B build -D BUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=$BUILD_TYPE + + - name: Build + run: cmake --build build --config $BUILD_TYPE + + - name: Package + id: package + working-directory: build + run: | + cpack -G "DEB" -D CPACK_PACKAGE_FILE_NAME=libstorm-dev_${{ github.ref_name }}_amd64 + + - uses: actions/upload-artifact@v4 + with: + retention-days: 1 + overwrite: true + name: libstorm-dev_${{ github.ref_name }}_amd64.deb + path: build/libstorm-dev_${{ github.ref_name }}_amd64.deb + + rpm: + if: true + runs-on: ubuntu-latest + container: + image: fedora:latest + env: + BUILD_TYPE: Release + + steps: + - uses: actions/checkout@v4 + + - name: Install dependencies + run: dnf -y install cmake gcc gcc-c++ rpm-build + + - name: Cmake + run: cmake -B build -D BUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=$BUILD_TYPE + + - name: Build + run: cmake --build build --config $BUILD_TYPE + + - name: Package + working-directory: build + run: cpack -G "RPM" -D CPACK_PACKAGE_FILE_NAME=libstorm-devel-${{ github.ref_name }}.x86_64 + + - uses: actions/upload-artifact@v4 + with: + retention-days: 1 + overwrite: true + name: libstorm-devel-${{ github.ref_name }}.x86_64.rpm + path: build/libstorm-devel-${{ github.ref_name }}.x86_64.rpm + + build_win: + if: true + runs-on: windows-latest + strategy: + matrix: + arch: [ amd64, x86 ] + build_type: [ Release, Debug ] + unicode: [ ON, OFF ] + shared: [ ON, OFF ] + + steps: + - uses: actions/checkout@v4 + + - uses: TheMrMilchmann/setup-msvc-dev@v3 + with: + arch: ${{ matrix.arch }} + + - name: Configure CMake for amd64 + if: ${{ matrix.arch == 'amd64' }} + shell: cmd + run: cmake -B build -DBUILD_SHARED_LIBS=${{ matrix.shared }} -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DSTORM_UNICODE=${{ matrix.unicode }} + + - name: Configure CMake for x86 + if: ${{ matrix.arch == 'x86' }} + shell: cmd + run: cmake -B build -DBUILD_SHARED_LIBS=${{ matrix.shared }} -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DSTORM_UNICODE=${{ matrix.unicode }} -A Win32 + + - name: Build + shell: cmd + run: cmake --build build --config ${{ matrix.build_type }} + + - name: Check PE + if: ${{ matrix.shared == 'ON' }} + shell: bash + working-directory: ./build/${{ matrix.build_type }} + run: | + file "stormlib.dll" + if [[ "${{ matrix.arch }}" == "x86" ]]; then + file "stormlib.dll" | grep -E "Intel 80386|Intel i386" + else + file "stormlib.dll" | grep "x86-64" + fi + + - name: Install to staging area + shell: cmd + run: cmake --install build --prefix build/staging --config ${{ matrix.build_type }} + + - name: Create Archive + shell: pwsh + id: create_archive + working-directory: ./build/staging + run: | + $r = if ("${{ matrix.build_type }}" -eq "Release") { "R" } else { "D" } + $a = if ("${{ matrix.unicode }}" -eq "ON") { "U" } else { "A" } + $s = if ("${{ matrix.shared }}" -eq "ON") { "D" } else { "S" } + + $zipSuffix = "${r}${a}${s}" + $zipName = "stormlib_${{ github.ref_name }}_${{ matrix.arch }}_${zipSuffix}.zip" + "zip_name=$zipName" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append + + Compress-Archive -Path include -DestinationPath $zipName + + $binItems = Get-ChildItem -Path bin\* -ErrorAction SilentlyContinue + if ($binItems) { + Compress-Archive -Path bin/* -DestinationPath $zipName -Update + } + $libItems = Get-ChildItem -Path lib\* -ErrorAction SilentlyContinue + if ($libItems) { + Compress-Archive -Path "lib/*" -DestinationPath $zipName -Update + } + - uses: actions/upload-artifact@v4 + with: + retention-days: 1 + overwrite: true + name: ${{ steps.create_archive.outputs.zip_name }} + path: build/staging/${{ steps.create_archive.outputs.zip_name }} + + release: + needs: [deb, rpm, build_win] + runs-on: ubuntu-latest + + steps: + - name: Download deb + uses: actions/download-artifact@v4 + with: + name: libstorm-dev_${{ github.ref_name }}_amd64.deb + + - name: Download rpm + uses: actions/download-artifact@v4 + with: + name: libstorm-devel-${{ github.ref_name }}.x86_64.rpm + + - name: Download win + uses: actions/download-artifact@v4 + with: + pattern: "*.zip" + merge-multiple: true + + - name: Generate SHA256 checksums + run: | + for file in *.zip *.deb *.rpm; do + sha256sum "$file" >> "release.sha256" + done + + - name: Create GitHub Release + uses: softprops/action-gh-release@v1 + with: + files: | + *.deb + *.sha256 + *.rpm + *.zip + tag_name: ${{ github.ref_name }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
\ No newline at end of file @@ -109,6 +109,9 @@ stylecop.* ~$* *.dbmdl Generated_Code #added for RIA/Silverlight projects +.idea/ +cmake-build-*/ +build/ # Backup & report files from converting an old project file to a newer # Visual Studio version. Backup files are not needed, because we have git ;-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8d17ebe..c78e88a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ -project(StormLib) cmake_minimum_required(VERSION 3.10) +project(StormLib) set(LIBRARY_NAME storm) set(CMAKE_CXX_STANDARD 11) @@ -9,17 +9,6 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) include(CMakeDependentOption) include(GNUInstallDirs) -option(STORM_UNICODE "Compile UNICODE version instead of ANSI one (Visual Studio only)" OFF) - -if(WIN32) - if(STORM_UNICODE) - message(STATUS "Build UNICODE version") - add_definitions(-DUNICODE -D_UNICODE) - else() - message(STATUS "Build ANSI version") - endif() -endif() - option(BUILD_SHARED_LIBS "Compile shared libraries" OFF) option(STORM_SKIP_INSTALL "Skip installing files" OFF) option(STORM_USE_BUNDLED_LIBRARIES @@ -296,17 +285,15 @@ set(ZLIB_FILES src/zlib/zutil.c ) -set(TEST_SRC_FILES - test/StormTest.cpp -) +add_library(${LIBRARY_NAME} ${LIB_TYPE}) -add_definitions(-D_7ZIP_ST -DBZ_STRICT_ANSI) +target_compile_definitions(${LIBRARY_NAME} PRIVATE -D_7ZIP_ST -DBZ_STRICT_ANSI) set(LINK_LIBS) find_package(ZLIB) if (ZLIB_FOUND AND NOT STORM_USE_BUNDLED_LIBRARIES) set(LINK_LIBS ${LINK_LIBS} ZLIB::ZLIB) - add_definitions(-D__SYS_ZLIB) + target_compile_definitions(${LIBRARY_NAME} PRIVATE -D__SYS_ZLIB) else() set(SRC_FILES ${SRC_FILES} ${ZLIB_FILES}) endif() @@ -314,7 +301,7 @@ endif() find_package(BZip2) if (BZIP2_FOUND AND NOT STORM_USE_BUNDLED_LIBRARIES) set(LINK_LIBS ${LINK_LIBS} BZip2::BZip2) - add_definitions(-D__SYS_BZLIB) + target_compile_definitions(${LIBRARY_NAME} PRIVATE -D__SYS_BZLIB) else() set(SRC_FILES ${SRC_FILES} ${BZIP2_FILES}) endif() @@ -330,7 +317,7 @@ else() find_path(LIBTOMCRYPT_INCLUDE_DIR NAMES tomcrypt.h HINTS ${PC_LIBTOMCRYPT_INCLUDE_DIRS} REQUIRED) find_library(LIBTOMCRYPT_LIBRARY NAMES tomcrypt HINTS ${PC_LIBTOMCRYPT_LIBRARY_DIRS} REQUIRED) set(LINK_LIBS ${LINK_LIBS} ${LIBTOMCRYPT_LIBRARY}) - include_directories(${LIBTOMCRYPT_INCLUDE_DIR}) + target_include_directories(${LIBRARY_NAME} PRIVATE ${LIBTOMCRYPT_INCLUDE_DIR}) else() set(SRC_ADDITIONAL_FILES ${TOMCRYPT_FILES} ${TOMMATH_FILES}) endif() @@ -341,11 +328,22 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "(Free|Net|Open)BSD") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DO_LARGEFILE=0 -Dstat64=stat -Dlstat64=lstat -Dlseek64=lseek -Doff64_t=off_t -Dfstat64=fstat -Dftruncate64=ftruncate") endif() -add_library(${LIBRARY_NAME} ${LIB_TYPE} ${SRC_FILES} ${SRC_ADDITIONAL_FILES} ${STORM_DEF_FILES}) +target_sources(${LIBRARY_NAME} PRIVATE ${SRC_FILES} ${SRC_ADDITIONAL_FILES} ${STORM_DEF_FILES}) if(WIN32) set_target_properties(${LIBRARY_NAME} PROPERTIES OUTPUT_NAME "StormLib") endif() +option(STORM_UNICODE "Compile UNICODE version instead of ANSI one (Visual Studio only)" OFF) + +if(WIN32) + if(STORM_UNICODE) + message(STATUS "Build UNICODE version") + target_compile_definitions(${LIBRARY_NAME} PRIVATE UNICODE _UNICODE) + else() + message(STATUS "Build ANSI version") + endif() +endif() + target_link_libraries(${LIBRARY_NAME} ${LINK_LIBS}) add_library(${PROJECT_NAME}::${LIBRARY_NAME} ALIAS ${LIBRARY_NAME}) # Allow users to link StormLib::storm when using add_subdirectory target_compile_definitions(${LIBRARY_NAME} INTERFACE STORMLIB_NO_AUTO_LINK) #CMake will take care of the linking @@ -360,7 +358,7 @@ if(BUILD_SHARED_LIBS) endif() if(UNIX) SET(VERSION_MAJOR "9") - SET(VERSION_MINOR "22") + SET(VERSION_MINOR "30") SET(VERSION_PATCH "0") SET(VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}") set_target_properties(${LIBRARY_NAME} PROPERTIES VERSION "${VERSION_STRING}") @@ -392,8 +390,10 @@ if (NOT STORM_SKIP_INSTALL) SET(CPACK_PACKAGE_VERSION_MAJOR "${VERSION_MAJOR}") SET(CPACK_PACKAGE_VERSION_MINOR "${VERSION_MINOR}") SET(CPACK_PACKAGE_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}") + SET(CPACK_PACKAGING_INSTALL_PREFIX "/usr/local") #DEB configuration + set(CPACK_DEBIAN_PACKAGE_EPOCH 1) SET(CPACK_DEBIAN_PACKAGE_SECTION "libs") SET(CPACK_DEBIAN_PACKAGE_HOMEPAGE "http://www.zezula.net/en/mpq/stormlib.html") SET(CPACK_DEBIAN_PACKAGE_MAINTAINER "imbacen@gmail.com") @@ -401,6 +401,7 @@ if (NOT STORM_SKIP_INSTALL) SET(CPACK_DEBIAN_PACKAGE_DEPENDS "zlib1g,bzip2") #RPM configuration + set(CPACK_RPM_PACKAGE_EPOCH 1) SET(CPACK_RPM_PACKAGE_RELEASE 1) SET(CPACK_RPM_PACKAGE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE") SET(CPACK_RPM_PACKAGE_GROUP "${PROJECT_NAME}") @@ -411,9 +412,7 @@ if (NOT STORM_SKIP_INSTALL) endif() if(STORM_BUILD_TESTS) - find_package(ALSA REQUIRED) - add_executable(StormLib_test ${TEST_SRC_FILES}) - target_link_libraries(StormLib_test ${LIBRARY_NAME} ${ALSA_LIBRARIES}) - install(TARGETS StormLib_test RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + enable_testing() + add_subdirectory(test) endif() @@ -21,6 +21,23 @@ Note that you can also build the library using newer toolset, such as v143. To d 4. Choose "Rebuild" 5. The result libraries are in `.\bin\Win32` and `.\bin\x64` +### Windows (any Visual Studio version with CMake) +You can open the appropriate Visual Studio cmd prompt or launch regular cmd and load the necessary environment as specified below. +Change your VS version as needed. + +amd64 +``` +"C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/Build/vcvarsall.bat" x64 +cmake -G "Visual Studio 17 2022" -B build_amd64 -D BUILD_SHARED_LIBS=ON +cmake --build build --config Release +``` + +x86 +``` +"C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/Build/vcvarsall.bat" x86 +cmake -G "Visual Studio 17 2022" -B build_x86 -D BUILD_SHARED_LIBS=ON +``` + ### Windows (Test Project) 1. Include the main StormLib header: `#include <StormLib.h>` 2. Set the correct library directory for StormLibXYZ.lib: @@ -30,13 +47,32 @@ Note that you can also build the library using newer toolset, such as v143. To d 3. Rebuild ### Linux -1. Download latest release -2. Install StormLib: ``` -$ cd <path-to-StormLib> -$ cmake CMakeLists.txt -$ make -$ make install +git clone https://github.com/ladislav-zezula/StormLib.git +cd StormLib && git checkout <latest-release-tag> +cmake -B build -D BUILD_SHARED_LIBS=ON +cmake --build build --config Release +sudo cmake --install build ``` -3. Include StormLib in your project: `#include <StormLib.h>` -4. Make sure you compile your project with `-lstorm -lz -lbz2` + +Include StormLib in your project: `#include <StormLib.h>` +Make sure you compile your project with `-lstorm -lz -lbz2` + +To produce deb/rpm packages: +``` +cd build +cpack -G "DEB" -D CPACK_PACKAGE_FILE_NAME=libstorm-dev_v9.30_amd64 +cpack -G "RPM" -D CPACK_PACKAGE_FILE_NAME=libstorm-devel-v9.30.x86_64 +``` + +### List of all CMake options + +| Option Name | Description | Default | +|-------------------------------|-------------------------------------------------------------------|---------| +| `BUILD_SHARED_LIBS` | Compile shared libraries | OFF | +| `STORM_UNICODE` | Unicode or ANSI support | OFF | +| `STORM_SKIP_INSTALL` | Skip installing files | OFF | +| `STORM_USE_BUNDLED_LIBRARIES` | Force use of bundled dependencies instead of system libraries | OFF | +| `WITH_LIBTOMCRYPT` | Use system LibTomCrypt library (non-Windows only) | OFF | +| `STORM_BUILD_TESTS` | Compile StormLib test application | OFF | +| `STORMTEST_USE_OLD_PATHS` | Uses hardcoded paths for test files, OFF uses `build_folder/work` | ON | diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..b646613 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,20 @@ +cmake_minimum_required(VERSION 3.10) + +set(TEST_SRC_FILES + StormTest.cpp +) + +# Option to use the legacy hardcoded paths +option(STORMTEST_USE_OLD_PATHS "Use hardcoded OS-specific default paths for WORK_PATH_ROOT" ON) + +if(NOT STORMTEST_USE_OLD_PATHS) + set(WORK_PATH_ROOT "${CMAKE_CURRENT_BINARY_DIR}/work") + add_compile_definitions(WORK_PATH_ROOT="${WORK_PATH_ROOT}") +endif() + +find_package(ALSA REQUIRED) +add_executable(StormLib_test ${TEST_SRC_FILES}) +target_link_libraries(StormLib_test storm ${ALSA_LIBRARIES}) +install(TARGETS StormLib_test RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + +add_test(NAME StormLib_test COMMAND StormLib_test)
\ No newline at end of file diff --git a/test/StormTest.cpp b/test/StormTest.cpp index 5a442a5..f9f2a03 100755 --- a/test/StormTest.cpp +++ b/test/StormTest.cpp @@ -155,16 +155,18 @@ typedef struct _WAVE_FILE_HEADER //------------------------------------------------------------------------------
// Local variables
-#ifdef STORMLIB_WINDOWS
-#define WORK_PATH_ROOT _T("\\Multimedia\\MPQs")
-#endif
-
-#ifdef STORMLIB_LINUX
-#define WORK_PATH_ROOT "/media/ladik/MPQs"
-#endif
-
-#ifdef STORMLIB_HAIKU
-#define WORK_PATH_ROOT "~/StormLib/test"
+#ifndef WORK_PATH_ROOT
+ #ifdef STORMLIB_WINDOWS
+ #define WORK_PATH_ROOT _T("\\Multimedia\\MPQs")
+ #endif
+
+ #ifdef STORMLIB_LINUX
+ #define WORK_PATH_ROOT "/media/ladik/MPQs"
+ #endif
+
+ #ifdef STORMLIB_HAIKU
+ #define WORK_PATH_ROOT "~/StormLib/test"
+ #endif
#endif
// Definition of the path separator
|