cmake_minimum_required(VERSION 3.15)
project(GraphiC_Community VERSION 7.0.0 LANGUAGES C)

set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)

option(BUILD_SHARED_LIBS "Build shared libraries" ON)
option(GRAPHIC_BUILD_STATIC "Also build static library" ON)

set(GRAPHIC_COMMUNITY_SOURCES
    Source/Arrow.c
    Source/Axesdraw.c
    Source/Barplt.c
    Source/Bothplt.c
    Source/Bplt.c
    Source/Circles.c
    Source/Color.c
    Source/Curves.c
    Source/Getxy.c
    Source/Gridopts.c
    Source/Insert.c
    Source/Labset.c
    Source/Legend.c
    Source/Lineattr.c
    Source/Lines.c
    Source/Linplt.c
    Source/Logplt.c
    Source/Lplt.c
    Source/Messagew.c
    Source/Panfil.c
    Source/Pclp.c
    Source/Position.c
    Source/Psfont.c
    Source/Roundoff.c
    Source/Simplt.c
    Source/Statfuns.c
    Source/Svc.c
    Source/Symbols.c
    Source/Tekint.c
    Source/Tplt.c
    Source/Truetype.c
    Source/Ttdisk.c
    Source/Ttfntld.c
    Source/Ttfntplt.c
    Source/baux_portable.c
    Source/community_stubs.c
    Source/gpc_driver_svg.c
    Source/gpcfor_compat.c
    Source/memory_portable.c
)

add_library(graphic SHARED ${GRAPHIC_COMMUNITY_SOURCES})
target_include_directories(graphic PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/Include)
target_compile_definitions(graphic PRIVATE GPC_PORTABLE=1 GPC_COMMUNITY=1)
target_link_libraries(graphic PRIVATE m)

if(GRAPHIC_BUILD_STATIC)
    add_library(graphic_static STATIC ${GRAPHIC_COMMUNITY_SOURCES})
    target_include_directories(graphic_static PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/Include)
    target_compile_definitions(graphic_static PRIVATE GPC_PORTABLE=1 GPC_COMMUNITY=1)
    target_link_libraries(graphic_static PRIVATE m)
endif()
