cmake_minimum_required(VERSION 3.0.0)
project(ml VERSION 0.1.0)

set(CMAKE_CXX_STANDARD          17)
# set(CMAKE_CXX_STANDARD_REQUIRED ON)
# set(CMAKE_CXX_EXTENSIONS        OFF)
# set(CMAKE_OSX_DEPLOYMENT_TARGET "10.14")

set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})

# stack 16MB
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-stack_size -Wl,0x1000000")
# otool -lV build/ml | grep stack

# set(CMAKE_CXX_FLAGS "-Wall -Wextra")
# set(CMAKE_CXX_FLAGS_RELEASE "-O3")

include_directories(/usr/local/opt/openssl/include ${CMAKE_SOURCE_DIR}/clib ${CMAKE_SOURCE_DIR} )

link_directories(/usr/local/lib /usr/local/opt/openssl/lib)


project(ml)
set(PROJECT_NAME ml)

set(SOURCE
	ml.cpp
	ml_io.cpp
	ml_date.cpp
	ml_string.cpp
	ml_util.cpp
	ml_profiler.cpp
	ml_usql.cpp
	clib/csvparser.cpp
	clib/sslclient.cpp
	clib/json11.cpp
	clib/printf.cpp
	clib/linenoise.c
	usql/exception.cpp
	usql/lexer.cpp
	usql/parser.cpp
	usql/usql.cpp
	usql/table.cpp
	usql/table.h
	usql/row.cpp
	usql/csvreader.cpp
	usql/usql.cpp)

add_executable(${PROJECT_NAME} ${SOURCE})

target_link_libraries(${PROJECT_NAME} stdc++ m ssl crypto)

set(CMAKE_INSTALL_PREFIX "/usr/local")
INSTALL(TARGETS ml
		CONFIGURATIONS Release
		RUNTIME DESTINATION bin)

INSTALL(DIRECTORY stdlib/ DESTINATION var/mlisp
        FILES_MATCHING PATTERN "*.lsp")
