diff --git a/.github/workflows/cmake-multi-platform.yml b/.github/workflows/cmake-multi-platform.yml index a69d4f8..2b1048b 100644 --- a/.github/workflows/cmake-multi-platform.yml +++ b/.github/workflows/cmake-multi-platform.yml @@ -1,85 +1,88 @@ -# This starter workflow is for a CMake project running on multiple platforms. There is a different starter workflow if you just want a single platform. -# See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-single-platform.yml name: CMake on multiple platforms on: push: - branches: [ "master"] + branches: [ "master" ] pull_request: - branches: [ "master"] + branches: [ "master" ] jobs: build: runs-on: ${{ matrix.os }} strategy: - # Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable. fail-fast: true - - # Set up a matrix to run the following 3 configurations: - # 1. - # 2. - # 3. - # - # To add more build types (Release, Debug, RelWithDebInfo, etc.) customize the build_type list. matrix: - os: [windows-latest, ubuntu-latest] + os: [ubuntu-latest, windows-latest] build_type: [Release] - c_compiler: [gcc, clang, cl] + c_compiler: [gcc, clang, cl, x86_64-w64-mingw32-gcc] + include: - os: windows-latest c_compiler: cl cpp_compiler: cl + exe_suffix: .exe + mingw: false + - os: ubuntu-latest c_compiler: gcc cpp_compiler: g++ + exe_suffix: "" + mingw: false + - os: ubuntu-latest c_compiler: clang cpp_compiler: clang++ + exe_suffix: "" + mingw: false + + - os: ubuntu-latest + c_compiler: x86_64-w64-mingw32-gcc + cpp_compiler: x86_64-w64-mingw32-g++ + exe_suffix: .exe + mingw: true + exclude: - os: windows-latest c_compiler: gcc - os: windows-latest c_compiler: clang + - os: windows-latest + c_compiler: x86_64-w64-mingw32-gcc - os: ubuntu-latest c_compiler: cl steps: - - uses: actions/checkout@v3 - - - name: Git update submodules - run: | - git submodule update --init --recursive --depth 1 + - uses: actions/checkout@v3 + + - name: Install MinGW (only if mingw is true) + if: matrix.mingw == true + run: | + sudo apt-get update + sudo apt-get install -y mingw-w64 - - name: Set reusable strings - # Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file. - id: strings - shell: bash - run: | - echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT" + - name: Update submodules + run: git submodule update --init --recursive --depth 1 - - name: Configure CMake - # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. - # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type - run: > - cmake -B ${{ steps.strings.outputs.build-output-dir }} - -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} - -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} - -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} - -S ${{ github.workspace }} + - name: Set build directory + id: vars + run: echo "dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT" - - name: Build - # Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). - run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} + - name: Configure CMake + run: > + cmake -S . -B ${{ github.workspace }}/build + -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} + -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} + -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} + ${{ matrix.mingw && '-DCMAKE_TOOLCHAIN_FILE=mingw-w64-x86_64.cmake' || '' }} - - name: Test windows - working-directory: ${{ steps.strings.outputs.build-output-dir }}/Example/Release - if: matrix.os == 'windows-latest' - run: | - ./ImageLoaderExample.exe + - name: Build + run: cmake --build ${{ github.workspace }}/build --config ${{ matrix.build_type }} - - name: Test Ubuntu - working-directory: ${{ steps.strings.outputs.build-output-dir }}/Example - if: matrix.os == 'ubuntu-latest' - run: | - ./ImageLoaderExample + - name: Run tests + if: matrix.mingw == false + working-directory: >- + ${{ github.workspace }}/build/Example${{ + matrix.os == 'windows-latest' && format('/{0}', matrix.build_type) || '' + }} + run: ./ImageLoaderExample${{ matrix.exe_suffix }} diff --git a/Codecs/CodecJPG/CMakeLists.txt b/Codecs/CodecJPG/CMakeLists.txt index ffc0f36..744bae1 100644 --- a/Codecs/CodecJPG/CMakeLists.txt +++ b/Codecs/CodecJPG/CMakeLists.txt @@ -21,8 +21,13 @@ endif() # ======== Platform-specific file extensions ======== if(WIN32) - set(JPG_RUNTIME_NAME "turbojpeg.dll") - set(JPG_IMPLIB_NAME "turbojpeg.lib") + if (MINGW) + set(JPG_RUNTIME_NAME "libturbojpeg.dll") + set(JPG_IMPLIB_NAME "libturbojpeg.dll.a") + else() + set(JPG_RUNTIME_NAME "turbojpeg.dll") + set(JPG_IMPLIB_NAME "turbojpeg.lib") + endif() elseif(APPLE) set(JPG_RUNTIME_NAME "libturbojpeg.dylib") set(JPG_IMPLIB_NAME "") # No import libs on macOS @@ -50,6 +55,10 @@ set(LibJpegTurboArgs -DCMAKE_INSTALL_PREFIX=${TurboJpegBinBaseDir}/install ) +if (CMAKE_TOOLCHAIN_FILE) + get_filename_component(CMAKE_TOOLCHAIN_FILE_ABSOLUTE "${CMAKE_TOOLCHAIN_FILE}" ABSOLUTE) + list(APPEND LibJpegTurboArgs -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE_ABSOLUTE}) +endif() # Enable NASM on Windows if needed if(WIN32 AND NOT ${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Linux") list(APPEND LibJpegTurboArgs -DCMAKE_ASM_NASM_COMPILER=${NASMPATH}) diff --git a/External/libpng b/External/libpng index 9924a6f..12b57f9 160000 --- a/External/libpng +++ b/External/libpng @@ -1 +1 @@ -Subproject commit 9924a6f13d9a33ce31788b004e616a89643c5e8d +Subproject commit 12b57f946408c09f04166061ebd3a8d3486e1078 diff --git a/mingw-w64-x86_64.cmake b/mingw-w64-x86_64.cmake new file mode 100644 index 0000000..563b540 --- /dev/null +++ b/mingw-w64-x86_64.cmake @@ -0,0 +1,43 @@ + +#Usage: cmake -DCMAKE_TOOLCHAIN_FILE=mingw-w64-x86_64.cmake + +set(CMAKE_SYSTEM_NAME Windows) + + +set(TOOLCHAIN_PREFIX x86_64-w64-mingw32) + +# cross compilers to use for C, C++ and Fortran +set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc) +set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++) +set(CMAKE_Fortran_COMPILER ${TOOLCHAIN_PREFIX}-gfortran) +set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres) + +set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX}) + +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_SYSTEM_PROCESSOR x86_64) +set(CMAKE_SYSTEM_VERSION 10) + + +function (createSymLink target symlink) + cmake_path(GET symlink PARENT_PATH parentPath) + file(MAKE_DIRECTORY ${parentPath}) + execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${target} ${symlink}) +endfunction() + +# MINGW defaults max SDK version to Windows server 2003 (0x0502) +# For supporting newer functionality, overriding is needed, otherwise code won't compile +# override with Windows 10 (0x0A00) SDK version +add_compile_definitions(_WIN32_WINNT=0x0A00) + +set(CASE_SENSITIVE_FIX_FOR_MINGW_PATH ${CMAKE_CURRENT_BINARY_DIR}/mingw-w64) +createSymLink(/usr/x86_64-w64-mingw32/include/windows.h ${CASE_SENSITIVE_FIX_FOR_MINGW_PATH}/Include/Windows.h) +createSymLink(/usr/x86_64-w64-mingw32/include/shlobj.h ${CASE_SENSITIVE_FIX_FOR_MINGW_PATH}/Include/ShlObj.h) +createSymLink(/usr/x86_64-w64-mingw32/include/dbghelp.h ${CASE_SENSITIVE_FIX_FOR_MINGW_PATH}/Include/DbgHelp.h) +createSymLink(/usr/x86_64-w64-mingw32/include/commctrl.h ${CASE_SENSITIVE_FIX_FOR_MINGW_PATH}/Include/CommCtrl.h) +createSymLink(/usr/x86_64-w64-mingw32/include/shellscalingapi.h ${CASE_SENSITIVE_FIX_FOR_MINGW_PATH}/Include/ShellScalingApi.h) +createSymLink(/usr/x86_64-w64-mingw32/include/psapi.h ${CASE_SENSITIVE_FIX_FOR_MINGW_PATH}/Include/Psapi.h) + +include_directories(${CASE_SENSITIVE_FIX_FOR_MINGW_PATH}/Include)