cmake_minimum_required(VERSION 3.16)
project(c_gaborator
        DESCRIPTION "C++ to C simple bridge for Gaborator"
        VERSION 1.7)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_INSTALL_RPATH "$ORIGIN")
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)


if(NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE Release)
endif()

set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -ggdb -O0 -fno-exceptions -fno-rtti")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -ggdb -O0 -fno-exceptions")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Ofast -fno-exceptions -fno-rtti")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Ofast -fno-exceptions")

if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
    set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -frecord-gcc-switches -Rpass=loop-vectorize -Rpass-missed=loop-vectorize -Rpass-analysis=loop-vectorize")
    set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -frecord-gcc-switches -Rpass=loop-vectorize -Rpass-missed=loop-vectorize -Rpass-analysis=loop-vectorize")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
    set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fopt-info-all -frecord-gcc-switches")
    set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fopt-info-all -frecord-gcc-switches")
endif()

add_definitions(-DGABORATOR_USE_PFFFT)

include_directories(include)
include_directories(lib/gaborator)
include_directories(lib/pffft)

add_executable(test test.cpp)
add_library(cgaborator SHARED cgaborator.cpp lib/pffft/pffft.c lib/pffft/fftpack.c)
set_target_properties(cgaborator PROPERTIES PUBLIC_HEADER "include/cgaborator.h")

target_link_libraries(test cgaborator)
add_test(test test)

set(target1 cgaborator)

set(pc_libs_private)
set(pc_req_private)
set(pc_req_public)

configure_file(cgaborator.pc.in cgaborator.pc @ONLY)

install(
        TARGETS cgaborator
        PUBLIC_HEADER DESTINATION include
)
install(
        FILES "${CMAKE_CURRENT_BINARY_DIR}/cgaborator.pc" DESTINATION lib/pkgconfig
)