Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions .github/workflows/debug.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: Test build
on:
push:
branches:
- '**'
paths:
- 'src/**'
- '.github/workflows/debug.yml'
- 'CMakeLists.txt'
- 'vcpkg.json'
pull_request:
branches:
- '**'
paths:
- 'src/**'
- '.github/workflows/debug.yml'
- 'CMakeLists.txt'
- 'vcpkg.json'

permissions:
contents: read

jobs:
debug-build:
runs-on: windows-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Verify tools
run: |
clang-cl --version
cmake --version

- name: Restore cached Primes
id: cache-restore
uses: actions/cache/restore@v4
with:
path: |
${{ github.workspace }}\build
key: ${{ runner.os }}-build-cache-${{ hashFiles('CMakeLists.txt', 'vcpkg.json') }}

- name: Configure (Debug)
run: >
cmake
-DCMAKE_BUILD_TYPE=Debug
-DCMAKE_EXPORT_COMPILE_COMMANDS=TRUE
-DCMAKE_C_COMPILER="C:\Program Files\LLVM\bin\clang-cl.exe"
-DCMAKE_CXX_COMPILER="C:\Program Files\LLVM\bin\clang-cl.exe"
-S "${{ github.workspace }}"
-B "${{ github.workspace }}\build"
-G "Ninja"

- name: Build (Debug)
run: >
cmake
--build "${{ github.workspace }}\build"
--config Debug
--target all

- name: Configure (Release)
if: github.event_name != 'pull_request'
run: >
cmake
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_EXPORT_COMPILE_COMMANDS=TRUE
-DCMAKE_C_COMPILER="C:\Program Files\LLVM\bin\clang-cl.exe"
-DCMAKE_CXX_COMPILER="C:\Program Files\LLVM\bin\clang-cl.exe"
-S "${{ github.workspace }}"
-B "${{ github.workspace }}\build"
-G "Ninja"

- name: Build (Release)
if: github.event_name != 'pull_request'
run: >
cmake
--build "${{ github.workspace }}\build"
--config Release
--target all

- name: Save Primes
if: steps.cache-restore.outputs.cache-hit != 'true' && github.event_name != 'pull_request'
id: cache-save
uses: actions/cache/save@v4
with:
path: |
${{ github.workspace }}\build
key: ${{ runner.os }}-build-cache-${{ hashFiles('CMakeLists.txt', 'vcpkg.json') }}
47 changes: 15 additions & 32 deletions .github/workflows/build.yml → .github/workflows/release_build.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,7 @@
name: Build & publish project
name: Build & Publish project

on:
workflow_dispatch:
push:
branches:
- main
paths:
- 'src/**'
- '.github/workflows/build.yml'
- 'CMakeLists.txt'
tags-ignore:
- '*'
pull_request:
branches:
- main
paths:
- 'src/**'
- '.github/workflows/build.yml'
- 'CMakeLists.txt'
release:
types: [published]

Expand All @@ -42,11 +26,8 @@ jobs:
uses: actions/cache/restore@v4
with:
path: |
${{ github.workspace }}\build\_deps\FreeImage
${{ github.workspace }}\build\FreeImage3180Win32Win64.zip
${{ github.workspace }}\build\_deps\raylib-src
${{ github.workspace }}\build\_deps\raylib-build
key: ${{ runner.os }}-build-cache-${{ hashFiles('CMakeLists.txt') }}
${{ github.workspace }}\build
key: ${{ runner.os }}-build-cache-${{ hashFiles('CMakeLists.txt', 'vcpkg.json') }}

- name: Verify tools
run: |
Expand All @@ -72,7 +53,6 @@ jobs:
--target all

- name: Configure (Release)
if: success() && github.event_name == 'release' && github.event.action == 'published'
run: >
cmake
-DCMAKE_BUILD_TYPE=Release
Expand All @@ -84,7 +64,6 @@ jobs:
-G "Ninja"

- name: Build (Release)
if: success() && github.event_name == 'release' && github.event.action == 'published'
run: >
cmake
--build "${{ github.workspace }}\build"
Expand All @@ -97,26 +76,30 @@ jobs:
uses: actions/cache/save@v4
with:
path: |
${{ github.workspace }}\build\_deps\FreeImage
${{ github.workspace }}\build\FreeImage3180Win32Win64.zip
${{ github.workspace }}\build\_deps\raylib-src
${{ github.workspace }}\build\_deps\raylib-build
key: ${{ runner.os }}-build-cache-${{ hashFiles('CMakeLists.txt') }}

${{ github.workspace }}\build
key: ${{ runner.os }}-build-cache-${{ hashFiles('CMakeLists.txt', 'vcpkg.json') }}

- name: Package builds
if: github.event_name == 'release' && github.event.action == 'published'
run: |
7z a ImageViewer_debug-${{ github.event.release.tag_name }}.zip .\output\Debug\*
7z a ImageViewer_release-${{ github.event.release.tag_name }}.zip .\output\Release\*

- name: Publish GitHub Release
- name: Conventional Changelog Action
if: github.event_name == 'release' && github.event.action == 'published'
id: changelog
uses: TriPSs/conventional-changelog-action@v5
with:
github-token: ${{ secrets.github_token }}
output-file: "false"

- name: Publish GitHub Release
if: ${{ steps.changelog.outputs.skipped == 'false' }} && github.event_name == 'release' && github.event.action == 'published'
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.event.release.tag_name }}
name: "ImageViewer ${{ github.event.release.tag_name }}"
body_path: FEATURES.md
body: ${{ steps.changelog.outputs.clean_changelog }}
files: |
ImageViewer_release-${{ github.event.release.tag_name }}.zip
ImageViewer_debug-${{ github.event.release.tag_name }}.zip
Expand Down
92 changes: 26 additions & 66 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,35 @@
cmake_minimum_required(VERSION 3.31.6)

# Static runtime linking for MSVC
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>" CACHE STRING "" FORCE)

set(VCPKG_TARGET_TRIPLET "x64-windows-static" CACHE STRING "Vcpkg target triplet" FORCE)
set(VCPKG_BUILD_TYPE "${CMAKE_BUILD_TYPE}" CACHE STRING "Vcpkg build type" FORCE)

if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
if(DEFINED ENV{VCPKG_ROOT})
set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}\\scripts\\buildsystems\\vcpkg.cmake" CACHE STRING "Vcpkg toolchain file" FORCE)
message(STATUS "Using vcpkg toolchain from: $ENV{VCPKG_ROOT}")
elseif(DEFINED ENV{VCPKG_INSTALLATION_ROOT})
set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_INSTALLATION_ROOT}\\scripts\\buildsystems\\vcpkg.cmake" CACHE STRING "Vcpkg toolchain file" FORCE)
message(STATUS "Using vcpkg toolchain from: $ENV{VCPKG_INSTALLATION_ROOT}")
else()
message(WARNING "VCPKG_ROOT or VCPKG_INSTALLATION_ROOT not set - vcpkg will not be used.")
endif()
endif()

if(DEFINED ENV{PROGRAM_VERSION} AND NOT "$ENV{PROGRAM_VERSION}" STREQUAL "")
set(VERSION $ENV{PROGRAM_VERSION})
else()
set(VERSION 0.0.0)
message(STATUS "Local build (version not specified)")
message(STATUS "Debug or Local build (version not specified)")
endif()

project(ImageViewer VERSION ${VERSION} LANGUAGES CXX)

set(COMPANY_NAME "fr0zert")
set(PRODUCT_NAME "${PROJECT_NAME}")
set(FILE_DESCRIPTION "A simple ${PROJECT_NAME} appcation.")

set(FILE_DESCRIPTION "A simple ${PROJECT_NAME} application.")

# Generate compile_commands.json
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
Expand All @@ -22,68 +39,17 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

find_package(raylib CONFIG REQUIRED)
find_package(glfw3 REQUIRED)
find_package(freeimage CONFIG REQUIRED)

# Out folder for ready executables
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/output/${CMAKE_BUILD_TYPE}/${PROJECT_NAME}")

# static linking windows libs so i can distribute it without any dependencies for testing
# cl alternatives to /MT and /MTd
# https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-fms-runtime-lib
if (CMAKE_BUILD_TYPE STREQUAL "Release")
add_compile_options(-fms-runtime-lib="static")
add_link_options(-fms-runtime-lib="static")
elseif (CMAKE_BUILD_TYPE STREQUAL "Debug")
add_compile_options(-fms-runtime-lib="static_dbg")
add_link_options(-fms-runtime-lib="static_dbg")
endif()

# FIX for compiling, compiler trying to use WinMain while im need main because it is easier to access argc and argv
# hope to fix it later actually
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /ENTRY:mainCRTStartup")

# Dependencies
include(FetchContent)

# Define where to download and extract FreeImage
set(FREEIMAGE_URL "https://netix.dl.sourceforge.net/project/freeimage/Binary%20Distribution/3.18.0/FreeImage3180Win32Win64.zip?viasf=1")
set(FREEIMAGE_ZIP "${CMAKE_BINARY_DIR}/FreeImage3180Win32Win64.zip")
set(FREEIMAGE_EXTRACT_DIR "${CMAKE_BINARY_DIR}/_deps")

# Download FreeImage zip if not already present
if(NOT EXISTS "${FREEIMAGE_ZIP}")
message(STATUS "Downloading FreeImage...")
file(DOWNLOAD "${FREEIMAGE_URL}" "${FREEIMAGE_ZIP}" SHOW_PROGRESS)
endif()

# Extract FreeImage with 7z if not already extracted
if(NOT EXISTS "${FREEIMAGE_EXTRACT_DIR}/FreeImage/Dist/x64/FreeImage.lib")
message(STATUS "Extracting FreeImage using 7z...")
file(MAKE_DIRECTORY "${FREEIMAGE_EXTRACT_DIR}")
execute_process(
COMMAND 7z x "${FREEIMAGE_ZIP}" "-o${FREEIMAGE_EXTRACT_DIR}" -y
RESULT_VARIABLE result
)
if(NOT result EQUAL 0)
message(FATAL_ERROR "7z extraction failed! Is 7z installed and in your PATH?")
endif()
endif()

# Include directories and libraries for FreeImage
include_directories("${FREEIMAGE_EXTRACT_DIR}/FreeImage/Dist/x64")
link_directories("${FREEIMAGE_EXTRACT_DIR}/FreeImage/Dist/x64")

FetchContent_Declare(
raylib
GIT_REPOSITORY https://github.com/raysan5/raylib.git
GIT_TAG 5.5
GIT_SHALLOW TRUE
)

# idk if works, someone said it dont, and i need use config.h | figure it out later
set(BUILD_AUDIO OFF CACHE BOOL "" FORCE)
set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set(BUILD_GAMES OFF CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(raylib)

# src directory
set(SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src")

Expand All @@ -92,6 +58,7 @@ configure_file(
"${SOURCE_DIR}/metadata/version.rc"
@ONLY
)

# src files
file(GLOB SOURCE_FILES "${SOURCE_DIR}/*.cpp" "${SOURCE_DIR}/*.hpp" "${SOURCE_DIR}/*.c" "${SOURCE_DIR}/*.h" "${SOURCE_DIR}/metadata/version.rc")

Expand All @@ -102,11 +69,4 @@ else()
add_executable(${PROJECT_NAME} WIN32 ${SOURCE_FILES})
endif()

target_link_libraries(${PROJECT_NAME} PRIVATE raylib FreeImage)

# Copy FreeImage.dll after build
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${FREEIMAGE_EXTRACT_DIR}/FreeImage/Dist/x64/FreeImage.dll"
"$<TARGET_FILE_DIR:${PROJECT_NAME}>/FreeImage.dll"
)
target_link_libraries(${PROJECT_NAME} PRIVATE raylib freeimage::FreeImage freeimage::FreeImagePlus glfw winmm)
21 changes: 0 additions & 21 deletions FEATURES.md

This file was deleted.

14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
# 🖼️ ImageViewer
<h1 align="center">🌄 ImageViewer</h1>

> **ImageViewer** — inspired by Google's [Picasa Image Viewer](https://en.wikipedia.org/wiki/Picasa).

(The name of the project may change in the future.)

---

## ⚙️ Tech Stack

- **Language**: C/C++
- **Frameworks/Libs**: raylib (current implementation), FreeImage
- **Build System**: CMake 4.0.2 + Clang/LLVM (Clang-cl 20.1.6)

---
<ul>
<li><b>Language: </b>C/C++</li>
<li><b>Frameworks/Libs: </b>raylib, FreeImage</li>
<li><b>Build System: </b>CMake + vcpkg + Clang/LLVM (Clang-cl)</li>
</ul>

## 🚧 Roadmap

Expand Down
4 changes: 3 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

#include <FreeImage.h>
#include <filesystem>
#include <iostream>
#include <raylib.h>
Expand All @@ -14,6 +14,7 @@ namespace Settings {
} // namespace Settings

int main(int argc, char *argv[]) {
FreeImage_Initialise();
if (argc <= 1) return 1;
std::filesystem::path workingDir = std::filesystem::current_path(); // get current working directory
SetConfigFlags(FLAG_WINDOW_UNDECORATED | FLAG_WINDOW_TRANSPARENT | FLAG_WINDOW_RESIZABLE | FLAG_WINDOW_MAXIMIZED | FLAG_VSYNC_HINT);
Expand Down Expand Up @@ -48,5 +49,6 @@ int main(int argc, char *argv[]) {
if (Settings::drawDebugInfo) DrawFPS(10, 10);
EndDrawing();
}
FreeImage_DeInitialise();
CloseWindow();
}
Loading