Skip to content

Commit 076d5ef

Browse files
committed
source
1 parent e0148bd commit 076d5ef

8 files changed

Lines changed: 9121 additions & 2 deletions

File tree

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
indent_size = 4
6+
indent_style = space
7+
trim_trailing_whitespace = true
8+
end_of_line = lf
9+
insert_final_newline = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false
13+
14+
[*.{yml,json}]
15+
indent_size = 2

.github/workflows/ci.yml

Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
name: CI
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
push:
7+
branches:
8+
- main
9+
10+
env:
11+
CI_PARAMS: -DCMAKE_BUILD_TYPE=Release
12+
13+
jobs:
14+
linux:
15+
name: Linux
16+
runs-on: ubuntu-latest
17+
# container:
18+
# image: centos:7
19+
strategy:
20+
fail-fast: false
21+
matrix:
22+
ARCH: [x64]
23+
include:
24+
- ARCH: x64
25+
env:
26+
CI_ARCH: ${{matrix.ARCH}}
27+
defaults:
28+
run:
29+
shell: bash
30+
steps:
31+
- uses: actions/checkout@v4
32+
with:
33+
fetch-depth: 3
34+
- name: Configure build
35+
run: |
36+
cmake -B build $CI_PARAMS -DCMAKE_C_FLAGS="-std=c99 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0"
37+
- name: Build
38+
run: |
39+
cmake --build build --parallel
40+
strip build/libtinyfd.so
41+
- name: Upload artifact
42+
uses: actions/upload-artifact@v4
43+
with:
44+
name: linux-${{matrix.ARCH}}
45+
path: build/libtinyfd.so
46+
if-no-files-found: error
47+
48+
linux-cross:
49+
name: Linux Cross
50+
runs-on: ubuntu-24.04
51+
strategy:
52+
fail-fast: false
53+
matrix:
54+
ARCH: [arm32, arm64, ppc64le, riscv64]
55+
include:
56+
# ----
57+
- ARCH: arm32
58+
CROSS_ARCH: armhf
59+
TRIPLET: arm-linux-gnueabihf
60+
# ----
61+
- ARCH: arm64
62+
CROSS_ARCH: arm64
63+
TRIPLET: aarch64-linux-gnu
64+
# ----
65+
- ARCH: ppc64le
66+
CROSS_ARCH: ppc64el
67+
TRIPLET: powerpc64le-linux-gnu
68+
# ----
69+
- ARCH: riscv64
70+
CROSS_ARCH: riscv64
71+
TRIPLET: riscv64-linux-gnu
72+
env:
73+
CI_ARCH: ${{matrix.ARCH}}
74+
defaults:
75+
run:
76+
shell: bash
77+
steps:
78+
- name: Install build dependencies
79+
run: |
80+
DEBIAN_FRONTEND=noninteractive sudo apt-get -yq update
81+
DEBIAN_FRONTEND=noninteractive sudo apt-get -yq install cmake gcc-${{matrix.TRIPLET}} libc6-dev-${{matrix.CROSS_ARCH}}-cross
82+
- uses: actions/checkout@v4
83+
with:
84+
fetch-depth: 4
85+
- name: Prepare cross-compilation for ${{matrix.CROSS_ARCH}}
86+
run: |
87+
cat <<EOF > deb822sources
88+
Types: deb
89+
URIs: http://archive.ubuntu.com/ubuntu/
90+
Suites: noble noble-updates noble-security noble-backports
91+
Components: main restricted multiverse universe
92+
Architectures: amd64
93+
94+
Types: deb
95+
URIs: http://security.ubuntu.com/ubuntu/
96+
Suites: noble-security
97+
Components: main restricted universe
98+
Architectures: amd64
99+
100+
Types: deb
101+
URIs: http://azure.ports.ubuntu.com/ubuntu-ports/
102+
Suites: noble noble-updates noble-security noble-backports
103+
Components: main restricted multiverse universe
104+
Architectures: ${{matrix.CROSS_ARCH}}
105+
EOF
106+
107+
sudo mv deb822sources /etc/apt/sources.list.d/ubuntu.sources
108+
109+
sudo dpkg --add-architecture ${{matrix.CROSS_ARCH}}
110+
sudo apt-get update || true
111+
# - name: Install dependencies
112+
# run: DEBIAN_FRONTEND=noninteractive sudo apt-get -yq install libxrandr-dev:${{matrix.CROSS_ARCH}} libxinerama-dev:${{matrix.CROSS_ARCH}} libxcursor-dev:${{matrix.CROSS_ARCH}} libxi-dev:${{matrix.CROSS_ARCH}} libxext-dev:${{matrix.CROSS_ARCH}} libxkbcommon-dev:${{matrix.CROSS_ARCH}} libwayland-dev:${{matrix.CROSS_ARCH}}
113+
- name: Configure build
114+
run: PKG_CONFIG_PATH=${PKG_CONFIG_PATH}:${CMAKE_SYSROOT}/usr/lib/${{matrix.TRIPLET}}/pkgconfig CC=${{matrix.TRIPLET}}-gcc cmake -B build $CI_PARAMS -DCMAKE_C_FLAGS="-std=c99 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0"
115+
- name: Build
116+
run: |
117+
cmake --build build --parallel
118+
${{matrix.TRIPLET}}-strip build/libtinyfd.so
119+
- name: Upload artifact
120+
uses: actions/upload-artifact@v4
121+
with:
122+
name: linux-${{matrix.ARCH}}
123+
path: build/libtinyfd.so
124+
if-no-files-found: error
125+
126+
freebsd-cross:
127+
name: FreeBSD Cross
128+
runs-on: ubuntu-latest
129+
strategy:
130+
fail-fast: false
131+
steps:
132+
- uses: actions/checkout@v4
133+
with:
134+
fetch-depth: 3
135+
- name: Build
136+
uses: cross-platform-actions/action@v0.29.0
137+
with:
138+
operating_system: freebsd
139+
architecture: x86-64
140+
version: '14.3'
141+
memory: 4G
142+
shell: bash
143+
environment_variables: CI_PARAMS
144+
run: |
145+
sudo pkg install -y cmake gmake pkgconf
146+
cmake -B build $CI_PARAMS -DCMAKE_C_FLAGS="-std=c99 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0"
147+
cmake --build build --parallel
148+
strip build/libtinyfd.so
149+
- name: Upload artifact
150+
uses: actions/upload-artifact@v4
151+
with:
152+
name: freebsd-x64
153+
path: build/libtinyfd.so
154+
if-no-files-found: error
155+
156+
macos:
157+
name: macOS
158+
runs-on: macos-latest
159+
strategy:
160+
matrix:
161+
ARCH: [x64, arm64]
162+
include:
163+
- ARCH: x64
164+
CMAKE_PARAMS: -DCMAKE_OSX_DEPLOYMENT_TARGET=10.11 -DCMAKE_OSX_ARCHITECTURES=x86_64
165+
- ARCH: arm64
166+
CMAKE_PARAMS: -DCMAKE_OSX_DEPLOYMENT_TARGET=11.0 -DCMAKE_OSX_ARCHITECTURES=arm64
167+
steps:
168+
- uses: actions/checkout@v4
169+
with:
170+
fetch-depth: 3
171+
- name: Configure build
172+
run: cmake -B build $CI_PARAMS ${{matrix.CMAKE_PARAMS}}
173+
- name: Build
174+
run: |
175+
cmake --build build --parallel
176+
strip -u -r build/libtinyfd.dylib
177+
- name: Upload artifact
178+
uses: actions/upload-artifact@v4
179+
with:
180+
name: macos-${{matrix.ARCH}}
181+
path: build/libtinyfd.dylib
182+
if-no-files-found: error
183+
184+
windows:
185+
name: Windows
186+
runs-on: windows-latest
187+
strategy:
188+
matrix:
189+
ARCH: [x64, arm64]
190+
include:
191+
- ARCH: x64
192+
PLATFORM: x64
193+
- ARCH: arm64
194+
PLATFORM: ARM64
195+
defaults:
196+
run:
197+
shell: cmd
198+
steps:
199+
- uses: actions/checkout@v4
200+
with:
201+
fetch-depth: 3
202+
- name: Configure build
203+
run: cmake -B build -G "Visual Studio 17 2022" -A ${{matrix.PLATFORM}} %CI_PARAMS% -DUSE_MSVC_RUNTIME_LIBRARY_DLL=OFF
204+
- name: Build
205+
run: cmake --build build --parallel --config Release
206+
- name: Upload artifact
207+
uses: actions/upload-artifact@v4
208+
with:
209+
name: windows-${{matrix.ARCH}}
210+
path: build\Release\tinyfd.dll
211+
if-no-files-found: error

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,8 @@ CMakeUserPresets.json
1616
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
1717
# and can be added to the global gitignore or merged into this file. For a more nuclear
1818
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
19-
#cmake-build-*
19+
cmake-build-*
20+
21+
build/
22+
.idea/
23+
.vscode/

CMakeLists.txt

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
cmake_minimum_required(VERSION 3.15)
2+
project(tinyfd VERSION 3.21.2 LANGUAGES C)
3+
4+
# Options
5+
option(BUILD_SHARED_LIBS "Build tinyfd as shared library" ON)
6+
option(TINYFD_BUILD_EXAMPLES "Build example programs" OFF)
7+
option(TINYFD_BUILD_TESTS "Build test programs" OFF)
8+
option(TINYFD_INSTALL "Generate install targets" ON)
9+
option(TINYFD_ENABLE_WARNINGS "Enable extra compiler warnings" ON)
10+
option(TINYFD_ENABLE_OPTIMIZATIONS "Enable compiler optimizations (Release-like)" ON)
11+
12+
# C standard
13+
set(CMAKE_C_STANDARD 11)
14+
set(CMAKE_C_STANDARD_REQUIRED ON)
15+
set(CMAKE_C_EXTENSIONS OFF)
16+
17+
# Output directories
18+
# Put runtime artifacts and libraries into the build tree under bin/ and lib/
19+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
20+
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
21+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
22+
23+
# Source and include directory variables (default to project directory)
24+
set(TINYFD_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}" CACHE PATH "Directory containing tinyfd source files")
25+
set(TINYFD_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}" CACHE PATH "Directory containing tinyfd header files")
26+
27+
# Prefer conventional src/ and include/ subdirectories if they exist
28+
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src")
29+
set(TINYFD_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src" CACHE PATH "Directory containing tinyfd source files" FORCE)
30+
endif()
31+
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/include")
32+
set(TINYFD_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include" CACHE PATH "Directory containing tinyfd header files" FORCE)
33+
endif()
34+
35+
# Require an explicit semicolon-separated list of source files.
36+
# Do NOT use globbing or auto-discovery. Provide paths relative to the
37+
# project root or absolute paths. Example: -DTINYFD_SOURCE_FILES="src/a.c;src/b.c"
38+
set(TINYFD_SOURCE_FILES "tinyfiledialogs.c" CACHE STRING "Semicolon-separated list of source files for tinyfd (required).")
39+
40+
# Fail early if the user didn't provide any source files — no auto-discovery allowed.
41+
if(NOT TINYFD_SOURCE_FILES)
42+
message(FATAL_ERROR "TINYFD_SOURCE_FILES is empty. Please set it to a semicolon-separated list of source files (no GLOB_RECURSE or discovery).")
43+
endif()
44+
45+
# Convert the semicolon-separated cache string into a CMake list and validate files.
46+
# Convert the semicolon-separated cache string into a CMake list and resolve
47+
# each entry to an absolute path (relative paths are resolved against the
48+
# project source directory). Validate existence and build the final list.
49+
set(TINYFD_SOURCE_LIST ${TINYFD_SOURCE_FILES})
50+
set(TINYFD_SOURCES "")
51+
foreach(_src IN LISTS TINYFD_SOURCE_LIST)
52+
if(NOT IS_ABSOLUTE "${_src}")
53+
set(_abs_src "${CMAKE_CURRENT_SOURCE_DIR}/${_src}")
54+
else()
55+
set(_abs_src "${_src}")
56+
endif()
57+
58+
if(NOT EXISTS "${_abs_src}")
59+
message(FATAL_ERROR "Source file '${_src}' (resolved to '${_abs_src}') listed in TINYFD_SOURCE_FILES does not exist.")
60+
endif()
61+
62+
list(APPEND TINYFD_SOURCES "${_abs_src}")
63+
endforeach()
64+
65+
add_library(tinyfd ${TINYFD_SOURCES})
66+
67+
target_include_directories(tinyfd PUBLIC
68+
$<BUILD_INTERFACE:${TINYFD_INCLUDE_DIR}>
69+
$<INSTALL_INTERFACE:include>
70+
)
71+
72+
if(TINYFD_ENABLE_WARNINGS)
73+
if(MSVC)
74+
target_compile_options(tinyfd PRIVATE /W4 /permissive-)
75+
else()
76+
target_compile_options(tinyfd PRIVATE -Wall -Wextra -Wpedantic)
77+
endif()
78+
endif()
79+
80+
# Enable optimizations when requested and only for Release-like configurations.
81+
# This supports both single-config generators (checks CMAKE_BUILD_TYPE) and
82+
# multi-config generators via generator expressions ($<CONFIG:...>).
83+
if(TINYFD_ENABLE_OPTIMIZATIONS)
84+
# Helper generator expressions for config-aware flags
85+
if(MSVC)
86+
# Apply /O2 for Release and RelWithDebInfo
87+
target_compile_options(tinyfd PRIVATE
88+
$<$<OR:$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>>:/O2>
89+
)
90+
# For single-config generators, also respect CMAKE_BUILD_TYPE variable
91+
if(NOT CMAKE_CONFIGURATION_TYPES)
92+
if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
93+
string(APPEND CMAKE_C_FLAGS " /O2")
94+
endif()
95+
endif()
96+
else()
97+
# Apply -O3 (and optionally -flto) for Release and RelWithDebInfo
98+
target_compile_options(tinyfd PRIVATE
99+
$<$<OR:$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>>:-O3>
100+
)
101+
102+
# Check for -flto support and add it in a config-aware manner
103+
include(CheckCCompilerFlag)
104+
check_c_compiler_flag("-flto" COMPILER_SUPPORTS_FLTO)
105+
if(COMPILER_SUPPORTS_FLTO)
106+
target_compile_options(tinyfd PRIVATE
107+
$<$<OR:$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>>:-flto>
108+
)
109+
endif()
110+
111+
# Single-config fallback: if using a single-config generator and the
112+
# build type is a release-like type, append flags to CMAKE_C_FLAGS
113+
if(NOT CMAKE_CONFIGURATION_TYPES)
114+
if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
115+
string(APPEND CMAKE_C_FLAGS " -O3")
116+
if(COMPILER_SUPPORTS_FLTO)
117+
string(APPEND CMAKE_C_FLAGS " -flto")
118+
endif()
119+
endif()
120+
endif()
121+
endif()
122+
endif()
123+
124+
if(TINYFD_INSTALL)
125+
install(TARGETS tinyfd
126+
EXPORT tinyfdTargets
127+
ARCHIVE DESTINATION lib
128+
LIBRARY DESTINATION lib
129+
RUNTIME DESTINATION bin)
130+
# Install headers from the configured include directory
131+
install(DIRECTORY "${TINYFD_INCLUDE_DIR}/" DESTINATION include)
132+
install(EXPORT tinyfdTargets FILE tinyfdTargets.cmake NAMESPACE tinyfd:: DESTINATION lib/cmake/tinyfd)
133+
endif()
134+
135+
# Optional subdirectories
136+
if(TINYFD_BUILD_EXAMPLES)
137+
add_subdirectory(examples)
138+
endif()
139+
140+
if(TINYFD_BUILD_TESTS)
141+
enable_testing()
142+
add_subdirectory(tests)
143+
endif()

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
# tinyfd-ci
2-
https://sourceforge.net/projects/tinyfiledialogs/
2+
3+
<https://sourceforge.net/projects/tinyfiledialogs/>
4+
5+
## Update
6+
7+
Run `py download.py` to update source files.

0 commit comments

Comments
 (0)