-- CMAKE_MINIMUM_REQUIRED(VERSION 3.5)

-- PROJECT(SJTU-RM-CV)
-- SET(CMAKE_CXX_STANDARD 11)
-- SET(CMAKE_BUILD_TYPE RELEASE)
-- SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
-- SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPATH=\"\\\"${PROJECT_SOURCE_DIR}\\\"\"")
-- SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D${CMAKE_SYSTEM_NAME}")
-- SET(BIN_NAME "run")
set_project("SJTU-RM-CV")
set_version("1.0.0")
set_languages("c++11")
set_optimize("fastest")
add_defines(string.format("PATH=\"%s\"", os.projectdir()))

if is_plat("linux") then 
    add_defines("Linux")
elseif is_plat("windows") then 
    add_defines("windows") 
elseif is_plat("macosx") then 
    add_defines("Darwin")
end

add_rules("plugin.compile_commands.autoupdate", {outputdir = ".vscode"})

add_rules("mode.debug", "mode.release")

add_requires("eigen", "opencv 4.x", {system = true})

if os.isfile("others/include/config/config.h") then 
    print("Found config.h")
    add_defines("WITH_CONFIG")
end 


set_policy("build.ccache", true)


add_includedirs("others/include", "energy/include", "armor/include")

target("run")
    set_kind("binary")
     add_files(
         "main.cpp",
         "others/src/**.cpp",
         "energy/src/**.cpp",
         "armor/src/**.cpp"
     )

add_linkdirs("others")
add_packages("eigen", "opencv")
add_syslinks("pthread")

if is_plat("linux") then 
    print("current platform: linux")
    add_links("MVSDK")
elseif is_plat("windows") then 
    print("current platform: windows") 
    add_links("MVCAMSDK_X64")
elseif is_plat("macosx") then 
    print("current platform: Mac")
    add_links("mvsdk")
else 
    print("Unsupported platform")
end 
-- SET(CMAKE_EXPORT_COMPILE_COMMANDS ON)


-- FIND_FILE(CONFIG_FOUND "config.h" "others/include/config")
-- if (CONFIG_FOUND)
--     MESSAGE("Found config.h")
--     SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DWITH_CONFIG")
-- endif()
-- 
-- 
-- FIND_PROGRAM(CCACHE_FOUND ccache)
-- IF(CCACHE_FOUND)
--     SET_PROPERTY(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
--     SET_PROPERTY(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
--     MESSAGE("< Use ccache for compiler >")
-- ENDIF()
-- 
-- FIND_PACKAGE(Eigen3 REQUIRED)
-- FIND_PACKAGE(OpenCV 4 REQUIRED)
-- FIND_PACKAGE(Threads)

-- LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/others)
-- 
-- INCLUDE_DIRECTORIES(${EIGEN3_INCLUDE_DIR})
-- INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/energy/include)
-- INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/armor/include)
-- INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/others/include)
-- 
-- FILE(GLOB_RECURSE sourcefiles "others/src/*.cpp" "energy/src/*cpp" "armor/src/*.cpp")
-- ADD_EXECUTABLE(${BIN_NAME} main.cpp ${sourcefiles})
-- 
-- TARGET_LINK_LIBRARIES(${BIN_NAME} ${CMAKE_THREAD_LIBS_INIT})
-- TARGET_LINK_LIBRARIES(${BIN_NAME} ${OpenCV_LIBS})
-- IF (CMAKE_SYSTEM_NAME MATCHES "Linux")
--     MESSAGE(STATUS "current platform: Linux ")
--     TARGET_LINK_LIBRARIES(${BIN_NAME} "${PROJECT_SOURCE_DIR}/others/libMVSDK.so")
-- ELSEIF (CMAKE_SYSTEM_NAME MATCHES "Windows")
--     MESSAGE(STATUS "current platform: Windows")
--     TARGET_LINK_LIBRARIES(${BIN_NAME} "${PROJECT_SOURCE_DIR}/others/MVCAMSDK_X64.lib")
-- ELSEIF (CMAKE_SYSTEM_NAME MATCHES "Darwin")
--     MESSAGE(STATUS "current platform: Mac")
--     TARGET_LINK_LIBRARIES(${BIN_NAME} "${PROJECT_SOURCE_DIR}/others/libmvsdk.dylib")
-- ELSE ()
--     MESSAGE(STATUS "Unsupport platform: ${CMAKE_SYSTEM_NAME}")
-- ENDIF()
-- 
-- ADD_CUSTOM_TARGET(create-startup COMMAND "${PROJECT_SOURCE_DIR}/tools/create-startup.sh" "${PROJECT_SOURCE_DIR}" "${CMAKE_BINARY_DIR}")
-- ADD_CUSTOM_TARGET(train-cnn COMMAND "gnome-terminal" "--" "bash" "-c" "${PROJECT_SOURCE_DIR}/tools/TrainCNN/backward.py")