CMAKE_MINIMUM_REQUIRED(VERSION 3.8.2 FATAL_ERROR)
PROJECT(mmm_api)

SET(CMAKE_CXX_STANDARD 14)
SET(CMAKE_CXX_STANDARD_REQUIRED ON)
SET(CMAKE_POSITION_INDEPENDENT_CODE ON)

add_definitions(-DPYBIND=1)
add_definitions(-DNOTORCH=1)

ADD_SUBDIRECTORY(pybind11)

INCLUDE_DIRECTORIES(midifile/include)
SET(SRCS
    midifile/src/Options.cpp
    midifile/src/Binasc.cpp
    midifile/src/MidiEvent.cpp
    midifile/src/MidiEventList.cpp
    midifile/src/MidiFile.cpp
    midifile/src/MidiMessage.cpp
)

SET(HDRS
    midifile/include/Binasc.h
    midifile/include/MidiEvent.h
    midifile/include/MidiEventList.h
    midifile/include/MidiFile.h
    midifile/include/MidiMessage.h
    midifile/include/Options.h
)

ADD_LIBRARY(midifile STATIC ${SRCS} ${HDRS})

INCLUDE(FindProtobuf)
FIND_PACKAGE(Protobuf REQUIRED)
INCLUDE_DIRECTORIES(${Protobuf_INCLUDE_DIRS})
PROTOBUF_GENERATE_CPP(PROTO_SRC PROTO_HEADER src/mmm_api/protobuf/midi.proto)
ADD_LIBRARY(proto ${PROTO_HEADER} ${PROTO_SRC})

PYBIND11_ADD_MODULE(mmm_api 
    src/mmm_api/lib.cpp
    src/mmm_api/dataset/lz4.c 
    src/mmm_api/protobuf/midi.pb.cc)
TARGET_LINK_LIBRARIES(
  mmm_api PRIVATE midifile proto ${Protobuf_LIBRARIES})