cmake_minimum_required(VERSION 3.1)

project(zinnia VERSION 0.1
			   LANGUAGES C CXX)
set(CMAKE_CXX_STANDARD 17)

# ## Thanks to yipdw/ninjawedding for this snippet: https://gitlab.peach-bun.com/snippets/103
# If ld.gold is available, use it -- it's faster.  Also enable incremental
# linking for debug and release.

# TODO: It's probably a good idea to enable -z relro for non-development
# builds.  That's more CMake archaeology, though, and I'm not really in the
# mood for that now.
# option(USE_LD_GOLD "Use GNU gold linker" ON)
# execute_process(COMMAND ${CMAKE_C_COMPILER} -fuse-ld=gold -Wl,--version ERROR_QUIET OUTPUT_VARIABLE LD_VERSION)
# if(USE_LD_GOLD)
#     execute_process(COMMAND ${CMAKE_C_COMPILER} -fuse-ld=gold -Wl,--version ERROR_QUIET OUTPUT_VARIABLE LD_VERSION)
#     if("${LD_VERSION}" MATCHES "GNU gold")
#         set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=gold -Wl,-z,norelro -Wl,--incremental")
#     else()
#         message(WARNING "GNU gold linker isn't available, using the default system linker.")
#     endif()
# endif()


find_package(PkgConfig REQUIRED)
find_package(OpenGL REQUIRED)
pkg_check_modules(GTK3 REQUIRED gtk+-3.0)
pkg_search_module(GLFW REQUIRED glfw3)

include_directories(deps/imgui deps/imgui/examples/opengl3_example)
file(GLOB IMGUI_SOURCE
	deps/imgui/imgui.cpp
	deps/imgui/imgui_draw.cpp
	deps/imgui/imgui_demo.cpp
	deps/imgui/examples/opengl3_example/imgui_impl_glfw_gl3.cpp)

include_directories(deps/cpptoml/include)
include_directories(deps/inotify)
include_directories(deps/handmademath)
add_subdirectory(deps/gl3w gl3w)

include_directories(${PROJECT_SOURCE_DIR})
add_executable(zinnia src/main.cpp src/geom.cpp src/gui/gui.cpp src/project.cpp
	src/shaders.cpp
	${IMGUI_SOURCE})

target_link_libraries(zinnia stdc++fs)

target_link_libraries(zinnia gl3w)
target_link_libraries(zinnia ${OPENGL_LIBRARIES})
target_link_libraries(zinnia ${GLFW_LIBRARIES})
target_link_libraries(zinnia ${GTK3_LIBRARIES})