cmake_minimum_required(VERSION 3.12)
project(osdialog C)

set(SOURCES osdialog.c osdialog.h)

if(WIN32)
    list(APPEND SOURCES osdialog_win.c)
elseif(APPLE)
    list(APPEND SOURCES osdialog_mac.m)
elseif(UNIX)
    list(APPEND SOURCES osdialog_gtk3.c)
else()
    message(FATAL_ERROR "Cannot detect your system")
endif()

add_library(osdialog STATIC "${SOURCES}")
add_executable(osdialog_test ${SOURCES} test.c)

if(MSVC)
	target_compile_options(osdialog PUBLIC -MP -W4 -WX /utf-8 -wd4996)
	target_compile_options(osdialog_test PUBLIC -MP -W4 /utf-8 -wd4996)
else()
	target_compile_options(osdialog PUBLIC -g -Wall -Wextra -std=c99)
	target_compile_options(osdialog_test PUBLIC -g -Wall -Wextra -std=c99)
endif()
if(WIN32)
    target_link_libraries(osdialog comdlg32)
elseif(APPLE)
    target_link_libraries(osdialog "-framework AppKit")
    target_link_libraries(osdialog_test "-framework AppKit")
    target_compile_options(osdialog PUBLIC)
    target_compile_options(osdialog_test PUBLIC)
elseif(UNIX)
    find_package(PkgConfig REQUIRED)
    pkg_check_modules(GTK3 "gtk+-3.0")
    if (GTK3_FOUND)
        INCLUDE_DIRECTORIES(${GTK3_INCLUDE_DIRS})
        message("GTK3_INCLUDE_DIRS = ${GTK3_INCLUDE_DIRS}")
        LINK_DIRECTORIES(${GTK3_LIBRARY_DIRS})
        message("GTK3_LIBRARY_DIRS = ${GTK3_LIBRARY_DIRS}")
        target_link_libraries(osdialog ${GTK3_LIBRARIES})
        target_link_libraries(osdialog_test ${GTK3_LIBRARIES})
        message("GTK3_LIBRARIES = ${GTK3_LIBRARIES}")
        add_definitions(${GTK3_CFLAGS} ${GTK3_CFLAGS_OTHER})
        message("GTK3_CFLAGS = ${GTK3_CFLAGS}")
        message("GTK3_CFLAGS_OTHER = ${GTK3_CFLAGS_OTHER}")
    else()
        message(FATAL_ERROR "GTK not found")
    endif()
else()
    message(FATAL_ERROR "Cannot detect your system")
endif()
