Skip to content

Commit

Permalink
ci: Upload artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
madebr committed Oct 25, 2024
1 parent 71cf413 commit 406484e
Show file tree
Hide file tree
Showing 5 changed files with 351 additions and 8 deletions.
33 changes: 28 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ jobs:
fail-fast: false
matrix:
platform:
- { name: Windows (MSVC), os: windows-2019, shell: sh, msvc: true }
- { name: Windows (mingw64), os: windows-latest, shell: 'msys2 {0}', msystem: mingw64, msys-env: mingw-w64-x86_64 }
- { name: Linux, os: ubuntu-20.04, shell: sh }
- { name: Macos, os: macos-latest, shell: sh }
- { name: Windows (MSVC), os: windows-2019, shell: sh, msvc: true, artifact: 'SDL_gpu_shadercross-VC-x64' }
- { name: Windows (mingw64), os: windows-latest, shell: 'msys2 {0}', msystem: mingw64, msys-env: mingw-w64-x86_64, artifact: 'SDL_gpu_shadercross-mingw64' }
- { name: Linux, os: ubuntu-20.04, shell: sh, artifact: 'SDL_gpu_shadercross-linux-x64' }
- { name: Macos, os: macos-latest, shell: sh, artifact: 'SDL_gpu_shadercross-macos-x64' }


steps:
Expand Down Expand Up @@ -52,9 +52,32 @@ jobs:

- name: Configure (CMake)
run: |
cmake -S . -B build -GNinja -DBUILD_STATIC=ON -DBUILD_CLI=ON -DENABLE_WERROR=ON -DCMAKE_POLICY_DEFAULT_CMP0074=NEW
cmake -S . -B build -GNinja \
-DBUILD_STATIC=ON \
-DBUILD_CLI=ON \
-DENABLE_WERROR=ON \
-DENABLE_INSTALL=ON \
-DENABLE_INSTALL_CPACK=ON \
-DCMAKE_INSTALL_PREFIX=prefix
- name: Build (CMake)
id: build
run: |
cmake --build build --config Release --parallel --verbose
- name: Install (CMake)
if: ${{ always() && steps.build.outcome == 'success' }}
run: |
cmake --install build/ --config Release
- name: Package (CPack)
id: package
if: ${{ always() && steps.build.outcome == 'success' }}
run: |
cmake --build build/ --target package
- uses: actions/upload-artifact@v4
if: ${{ always() && steps.package.outcome == 'success' }}
with:
if-no-files-found: error
name: ${{ matrix.platform.artifact }}
path: build/dist/SDL*
27 changes: 24 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,20 @@ set(SDL_REQUIRED_VERSION "3.1.3")

project(SDL_gpu_shadercross LANGUAGES C VERSION "${MAJOR_VERSION}.${MINOR_VERSION}.${MICRO_VERSION}")

include("${CMAKE_CURRENT_LIST_DIR}/cmake/PrivateSdlFunctions.cmake")
include(CMakeDependentOption)
include("${CMAKE_CURRENT_LIST_DIR}/cmake/PrivateSdlFunctions.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/cmake/sdlcpu.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/cmake/sdlplatform.cmake")

find_package(SDL3 REQUIRED COMPONENTS SDL3-shared)

# Options
option(BUILD_STATIC "Build static library" ON)
option(BUILD_CLI "Build command line executable" ON)
cmake_dependent_option(BUILD_CLI_STATIC "Link CLI with static libraries" OFF "BUILD_CLI;BUILD_STATIC;TARGET SDL3::SDL3-static" OFF)
option(ENABLE_WERROR "Enable Werror" OFF)
option(ENABLE_INSTALL "Enable installation" OFF)
cmake_dependent_option(BUILD_CLI_STATIC "Link CLI with static libraries" OFF "BUILD_CLI;BUILD_STATIC;TARGET SDL3::SDL3-static" OFF)
cmake_dependent_option(ENABLE_INSTALL_CPACK "Enable CPack installation" OFF "ENABLE_INSTALL" OFF)

sdl_calculate_derived_version_variables(${MAJOR_VERSION} ${MINOR_VERSION} ${MICRO_VERSION})

Expand Down Expand Up @@ -117,6 +120,7 @@ if(BUILD_CLI)
endif()

if(ENABLE_INSTALL)
include(GNUInstallDirs)
if(WIN32 AND NOT MINGW)
set(INSTALL_CMAKEDIR_ROOT_DEFAULT "cmake")
else()
Expand All @@ -131,7 +135,6 @@ if(ENABLE_INSTALL)
set(SDLGPUSHADERCROSS_INSTALL_CMAKEDIR "${SDLGPUSHADERCROSS_INSTALL_CMAKEDIR_ROOT}/SDL_gpu_shadercross")
endif()

include(GNUInstallDirs)
if(TARGET SDL_gpu_shadercross-shared)
install(TARGETS SDL_gpu_shadercross-shared EXPORT SDL_gpu_shadercross-shared-export
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT devel
Expand Down Expand Up @@ -161,6 +164,9 @@ if(ENABLE_INSTALL)
FILES "${CMAKE_CURRENT_SOURCE_DIR}/include/SDL_gpu_shadercross.h"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" COMPONENT DEVEL
)
if(BUILD_CLI)
install(TARGETS shadercross RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
endif()

include(CMakePackageConfigHelpers)
configure_package_config_file(cmake/SDL_gpu_shadercrossConfig.cmake.in SDL_gpu_shadercrossConfig.cmake
Expand Down Expand Up @@ -193,4 +199,19 @@ if(ENABLE_INSTALL)
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/licenses/${PROJECT_NAME}"
COMPONENT library
)
if(ENABLE_INSTALL_CPACK)
SDL_DetectTargetCPUArchitectures(SDL_CPU_NAMES)
SDL_DetectCMakePlatform()
if(MSVC)
set(CPACK_GENERATOR "ZIP")
else()
set(CPACK_GENERATOR "TGZ")
endif()
configure_file(cmake/CPackProjectConfig.cmake.in CPackProjectConfig.cmake @ONLY)
set(CPACK_PROJECT_CONFIG_FILE "${PROJECT_BINARY_DIR}/CPackProjectConfig.cmake")
# CPACK_SOURCE_PACKAGE_FILE_NAME must end with "-src" (so we can block creating a source archive)
set(CPACK_SOURCE_PACKAGE_FILE_NAME "SDL_gpu_shadercross-${PROJECT_VERSION}-src")
set(CPACK_PACKAGE_DIRECTORY "${CMAKE_BINARY_DIR}/dist")
include(CPack)
endif()
endif()
37 changes: 37 additions & 0 deletions cmake/CPackProjectConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
if(CPACK_PACKAGE_FILE_NAME MATCHES ".*-src$")
message(FATAL_ERROR "Creating source archives is not supported.")
endif()

set(PROJECT_NAME "@PROJECT_NAME@")
set(PROJECT_VERSION "@PROJECT_VERSION@")
set(PROJECT_SOURCE_DIR "@PROJECT_SOURCE_DIR@")
set(SDL_CMAKE_PLATFORM "@SDL_CMAKE_PLATFORM@")
set(SDL_CPU_NAMES "@SDL_CPU_NAMES@")
list(SORT SDL_CPU_NAMES)

string(TOLOWER "${SDL_CMAKE_PLATFORM}" SDL_CMAKE_PLATFORM)
string(TOLOWER "${SDL_CPU_NAMES}" SDL_CPU_NAMES)
if(lower_sdl_cmake_platform STREQUAL lower_sdl_cpu_names)
set(SDL_CPU_NAMES_WITH_DASHES)
endif()

string(REPLACE ";" "-" SDL_CPU_NAMES_WITH_DASHES "${SDL_CPU_NAMES}")
if(SDL_CPU_NAMES_WITH_DASHES)
set(SDL_CPU_NAMES_WITH_DASHES "-${SDL_CPU_NAMES_WITH_DASHES}")
endif()

set(MSVC @MSVC@)
set(MINGW @MINGW@)
if(MSVC)
set(SDL_CMAKE_PLATFORM "${SDL_CMAKE_PLATFORM}-VC")
elseif(MINGW)
set(SDL_CMAKE_PLATFORM "${SDL_CMAKE_PLATFORM}-mingw")
endif()

set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}-${SDL_CMAKE_PLATFORM}${SDL_CPU_NAMES_WITH_DASHES}")

if(CPACK_GENERATOR STREQUAL "DragNDrop")
set(CPACK_DMG_VOLUME_NAME "@PROJECT_NAME@ @PROJECT_VERSION@")
# FIXME: use pre-built/create .DS_Store through AppleScript (CPACK_DMG_DS_STORE/CPACK_DMG_DS_STORE_SETUP_SCRIPT)
set(CPACK_DMG_DS_STORE "${PROJECT_SOURCE_DIR}/Xcode/SDL/pkg-support/resources/SDL_DS_Store")
endif()
156 changes: 156 additions & 0 deletions cmake/sdlcpu.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
function(SDL_DetectTargetCPUArchitectures DETECTED_ARCHS)

set(known_archs EMSCRIPTEN ARM32 ARM64 ARM64EC LOONGARCH64 POWERPC32 POWERPC64 X86 X64)

if(APPLE AND CMAKE_OSX_ARCHITECTURES)
foreach(known_arch IN LISTS known_archs)
set(SDL_CPU_${known_arch} "0")
endforeach()
set(detected_archs)
foreach(osx_arch IN LISTS CMAKE_OSX_ARCHITECTURES)
if(osx_arch STREQUAL "x86_64")
set(SDL_CPU_X64 "1")
list(APPEND detected_archs "X64")
elseif(osx_arch STREQUAL "arm64")
set(SDL_CPU_ARM64 "1")
list(APPEND detected_archs "ARM64")
endif()
endforeach()
set("${DETECTED_ARCHS}" "${detected_archs}" PARENT_SCOPE)
return()
endif()

set(detected_archs)
foreach(known_arch IN LISTS known_archs)
if(SDL_CPU_${known_arch})
list(APPEND detected_archs "${known_arch}")
endif()
endforeach()

if(detected_archs)
set("${DETECTED_ARCHS}" "${detected_archs}" PARENT_SCOPE)
return()
endif()

set(arch_check_ARM32 "defined(__arm__) || defined(_M_ARM)")
set(arch_check_ARM64 "defined(__aarch64__) || defined(_M_ARM64)")
set(arch_check_ARM64EC "defined(_M_ARM64EC)")
set(arch_check_EMSCRIPTEN "defined(__EMSCRIPTEN__)")
set(arch_check_LOONGARCH64 "defined(__loongarch64)")
set(arch_check_POWERPC32 "(defined(__PPC__) || defined(__powerpc__)) && !defined(__powerpc64__)")
set(arch_check_POWERPC64 "defined(__PPC64__) || defined(__powerpc64__)")
set(arch_check_X86 "defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__) ||defined( __i386) || defined(_M_IX86)")
set(arch_check_X64 "(defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(_M_X64) || defined(_M_AMD64)) && !defined(_M_ARM64EC)")

set(src_vars "")
set(src_main "")
foreach(known_arch IN LISTS known_archs)
set(detected_${known_arch} "0")

string(APPEND src_vars "
#if ${arch_check_${known_arch}}
#define ARCH_${known_arch} \"1\"
#else
#define ARCH_${known_arch} \"0\"
#endif
const char *arch_${known_arch} = \"INFO<${known_arch}=\" ARCH_${known_arch} \">\";
")
string(APPEND src_main "
result += arch_${known_arch}[argc];")
endforeach()

set(src_arch_detect "${src_vars}
int main(int argc, char *argv[]) {
(void)argv;
int result = 0;
${src_main}
return result;
}")

if(CMAKE_C_COMPILER)
set(ext ".c")
elseif(CMAKE_CXX_COMPILER)
set(ext ".cpp")
else()
enable_language(C)
set(ext ".c")
endif()
set(path_src_arch_detect "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/CMakeTmp/SDL_detect_arch${ext}")
file(WRITE "${path_src_arch_detect}" "${src_arch_detect}")
set(path_dir_arch_detect "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/CMakeTmp/SDL_detect_arch")
set(path_bin_arch_detect "${path_dir_arch_detect}/bin")

set(detected_archs)

set(msg "Detecting Target CPU Architecture")
message(STATUS "${msg}")

include(CMakePushCheckState)

set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY")

cmake_push_check_state(RESET)
try_compile(SDL_CPU_CHECK_ALL
"${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/CMakeTmp/SDL_detect_arch"
SOURCES "${path_src_arch_detect}"
COPY_FILE "${path_bin_arch_detect}"
)
cmake_pop_check_state()
if(NOT SDL_CPU_CHECK_ALL)
message(STATUS "${msg} - <ERROR>")
message(WARNING "Failed to compile source detecting the target CPU architecture")
else()
set(re "INFO<([A-Z0-9]+)=([01])>")
file(STRINGS "${path_bin_arch_detect}" infos REGEX "${re}")

foreach(info_arch_01 IN LISTS infos)
string(REGEX MATCH "${re}" A "${info_arch_01}")
if(NOT "${CMAKE_MATCH_1}" IN_LIST known_archs)
message(WARNING "Unknown architecture: \"${CMAKE_MATCH_1}\"")
continue()
endif()
set(arch "${CMAKE_MATCH_1}")
set(arch_01 "${CMAKE_MATCH_2}")
set(detected_${arch} "${arch_01}")
endforeach()

foreach(known_arch IN LISTS known_archs)
if(detected_${known_arch})
list(APPEND detected_archs ${known_arch})
endif()
endforeach()
endif()

if(detected_archs)
foreach(known_arch IN LISTS known_archs)
set("SDL_CPU_${known_arch}" "${detected_${known_arch}}" CACHE BOOL "Detected architecture ${known_arch}")
endforeach()
message(STATUS "${msg} - ${detected_archs}")
else()
include(CheckCSourceCompiles)
cmake_push_check_state(RESET)
foreach(known_arch IN LISTS known_archs)
if(NOT detected_archs)
set(cache_variable "SDL_CPU_${known_arch}")
set(test_src "
int main(int argc, char *argv[]) {
#if ${arch_check_${known_arch}}
return 0;
#else
choke
#endif
}
")
check_c_source_compiles("${test_src}" "${cache_variable}")
if(${cache_variable})
set(SDL_CPU_${known_arch} "1" CACHE BOOL "Detected architecture ${known_arch}")
set(detected_archs ${known_arch})
else()
set(SDL_CPU_${known_arch} "0" CACHE BOOL "Detected architecture ${known_arch}")
endif()
endif()
endforeach()
cmake_pop_check_state()
endif()
set("${DETECTED_ARCHS}" "${detected_archs}" PARENT_SCOPE)
endfunction()
Loading

0 comments on commit 406484e

Please sign in to comment.