Windows build 2/2?

This commit is contained in:
Martin Dvořák 2026-09-10 09:57:12 +02:00
commit 263d6d525f
6 changed files with 261 additions and 17 deletions

62
CMakeLists.txt Normal file
View file

@ -0,0 +1,62 @@
cmake_minimum_required(VERSION 3.16)
project(maturita C)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
# GTK4 is found through pkg-config everywhere: Linux/macOS packages, MSYS2,
# vcpkg and the native MSVC (gvsbuild) package all ship .pc files.
if(MSVC)
# On MSVC the Unix-style flags pkg-config prints are not understood, so
# ask for the native "/I" and ".lib" form instead.
find_program(PKG_CONFIG_EXECUTABLE
NAMES pkg-config pkg-config.exe pkgconf pkgconf.exe)
if(NOT PKG_CONFIG_EXECUTABLE)
message(FATAL_ERROR
"pkg-config was not found. A native GTK4 install for MSVC "
"(e.g. gvsbuild) provides it; set PKG_CONFIG_PATH to "
"<GTK>/lib/pkgconfig. See README.md.")
endif()
execute_process(
COMMAND "${PKG_CONFIG_EXECUTABLE}" --cflags gtk4 --msvc-syntax
OUTPUT_VARIABLE GTK4_CFLAGS_RAW
OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE GTK4_CFLAGS_RESULT)
execute_process(
COMMAND "${PKG_CONFIG_EXECUTABLE}" --libs gtk4 --msvc-syntax
OUTPUT_VARIABLE GTK4_LIBS_RAW
OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE GTK4_LIBS_RESULT)
if(NOT GTK4_CFLAGS_RESULT EQUAL 0 OR NOT GTK4_LIBS_RESULT EQUAL 0)
message(FATAL_ERROR
"pkg-config could not find GTK4. Set PKG_CONFIG_PATH to "
"<GTK>/lib/pkgconfig (for example C:\\gtk\\lib\\pkgconfig).")
endif()
separate_arguments(GTK4_CFLAGS WINDOWS_COMMAND "${GTK4_CFLAGS_RAW}")
separate_arguments(GTK4_LIBS WINDOWS_COMMAND "${GTK4_LIBS_RAW}")
else()
find_package(PkgConfig REQUIRED)
pkg_check_modules(GTK4 REQUIRED IMPORTED_TARGET gtk4)
endif()
# WIN32 suppresses the console window on Windows; the app still uses main(),
# so MSVC needs mainCRTStartup as the entry point.
if(WIN32)
add_executable(maturita WIN32 maturita.c)
else()
add_executable(maturita maturita.c)
endif()
if(MSVC)
target_compile_options(maturita PRIVATE ${GTK4_CFLAGS})
target_link_options(maturita PRIVATE ${GTK4_LIBS})
target_link_options(maturita PRIVATE /ENTRY:mainCRTStartup)
target_compile_definitions(maturita PRIVATE _CRT_SECURE_NO_WARNINGS)
else()
target_link_libraries(maturita PRIVATE PkgConfig::GTK4 m)
target_compile_options(maturita PRIVATE
-Wall -Wextra -Wno-deprecated-declarations)
endif()