cmake_minimum_required (VERSION 3.13)

cmake_policy(SET CMP0077 NEW)

project (rbdlsim
	VERSION 0.0.1
	LANGUAGES CXX C)

# RBDL
set(RBDL_USE_SIMPLE_MATH On)
add_subdirectory (3rdparty/rbdl)

# libccd
set(ENABLE_DOUBLE_PRECISION On)
add_subdirectory (3rdparty/libccd)

# glfw
set(GLFW_BUILD_DOCS Off)
set(GLFW_BUILD_EXAMPLES Off)
set(GLFW_BUILD_TESTS Off)
set(GLFW_BUILD_INSTALL Off)
add_subdirectory (3rdparty/glfw)

# Library
add_library(${PROJECT_NAME})
target_include_directories(
		${PROJECT_NAME}
		PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
		PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/rbdl/include>
		PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/3rdparty/rbdl/include>)
target_link_libraries(${PROJECT_NAME} rbdl ccd)
target_sources(${PROJECT_NAME} PRIVATE src/rbdlsim.cc	src/utils.cc)

# Simulator Executable
add_executable(runsim)
target_include_directories(
		runsim
		PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
		PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/rbdl/include>
		PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/3rdparty/rbdl/include>)

target_link_libraries(runsim ${PROJECT_NAME})

target_sources(runsim PRIVATE src/main.cc)

# Visualization
add_executable(vissim)
target_include_directories(
		vissim
		PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
		PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/rbdl/include>
		PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/3rdparty/rbdl/include>
		PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/glfw/deps>
		PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/imgui>
		PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/vectorial/include>
		)
target_link_libraries(vissim ${PROJECT_NAME} glfw)

target_sources(vissim PRIVATE 
	src/srender.c
	3rdparty/glfw/deps/glad_gl.c
	3rdparty/imgui/imgui.cpp
	3rdparty/imgui/imgui_draw.cpp
	3rdparty/imgui/imgui_widgets.cpp
	3rdparty/imgui/imgui_demo.cpp
	3rdparty/imgui/backends/imgui_impl_glfw.cpp
	3rdparty/imgui/backends/imgui_impl_opengl3.cpp
	src/vissim.cc
	src/sthstry.c
	src/simulator.cc
	)

# Tests
add_executable(runtests)

target_sources(runtests PRIVATE tests/runtests.cc tests/CollisionTests.cc
	src/utils.cc src/sconvcol.c tests/sconvcolTests.cc)
target_include_directories(
		runtests
		PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
		PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
		PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/rbdl/include>
		PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/3rdparty/rbdl/include>
		PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/vectorial/include>
		)

target_link_libraries(runtests ${PROJECT_NAME})
