function( pack_model model_name )
	file( GLOB archive_files ${PROJECT_SOURCE_DIR}/models/${model_name}/* )
	add_custom_command(
		COMMAND
		${CMAKE_COMMAND} -E tar "cf" "${PROJECT_BINARY_DIR}/models/${model_name}.fma" --format=zip ${archive_files}
		WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/models/${model_name}
		OUTPUT ${PROJECT_BINARY_DIR}/models/${model_name}.fma
		DEPENDS ${archive_files}
	)
	add_custom_target( fc2d_model_${model_name} ALL DEPENDS ${PROJECT_BINARY_DIR}/models/${model_name}.fma )
endfunction()

cmake_minimum_required( VERSION 3.2 )
project( Facecam2D VERSION 0.1.0 )
set( CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake )
add_subdirectory( "libs/Boxer" )
find_package( libzip REQUIRED )
find_package( fmt REQUIRED )
find_package( WebP REQUIRED )
find_package( OpenCV REQUIRED )
message (STATUS "Found OpenCV at: " ${OpenCV_INCLUDE_DIRS} )
find_package( OpenGL REQUIRED )
message (STATUS "Found OpenGL at: " ${OPENGL_INCLUDE_DIR} )
find_package( GLEW REQUIRED )
message (STATUS "Found GLEW at: " ${GLEW_INCLUDE_DIRS} )
find_package( glm REQUIRED )
message (STATUS "Found glm at: " ${GLM_INCLUDE_DIRS} )
find_package( FreeGLUT REQUIRED )
message (STATUS "Found FreeGLUT at: " ${GLUT_INCLUDE_DIR} )
find_package( wxWidgets REQUIRED core base )
message (STATUS "Found wxWidgets at: " ${wxWidgets_USE_FILE} )
include( ${wxWidgets_USE_FILE} )
include_directories( ${OpenCV_INCLUDE_DIRS} )
include_directories( ${OPENGL_INCLUDE_DIR} )
include_directories( ${GLEW_INCLUDE_DIRS} )
include_directories( ${GLM_INCLUDE_DIRS} )
include_directories( ${GLUT_INCLUDE_DIR} )
include_directories( ${PROJECT_SOURCE_DIR}/src )
configure_file( ${PROJECT_SOURCE_DIR}/src/config.hpp.in ${PROJECT_SOURCE_DIR}/src/config.hpp @ONLY )
file( 
	COPY 
	${PROJECT_SOURCE_DIR}/cvdata
	
	DESTINATION
	${PROJECT_BINARY_DIR} )
file( MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/models )
pack_model( "test" )
pack_model( "rms" )
if (APPLE)
	file (
		COPY
		${PROJECT_SOURCE_DIR}/Info.plist
		DESTINATION
		$ {PROJECT_BINARY_DIR} )
endif (APPLE)
add_executable( fc2d
	src/main.cpp
	src/graphics.cpp
	src/modelpart.cpp
	src/cv.cpp
	src/paths.cpp
	src/args.cpp
	src/model.cpp
	src/toml.c
	src/tomlcpp.cpp
	src/error.cpp
	src/eye.cpp
	src/configfile.cpp
)
target_link_libraries( fc2d ${OpenCV_LIBS} ${OPENGL_LIBRARIES} ${WEBP_LIBRARIES}
	FreeGLUT::freeglut GLEW::glew zip Boxer fmt )
add_executable( fc2dconfig
	src/fc2dconfig.cpp
	src/paths.cpp
	src/modellist.cpp
	src/configfile.cpp
	src/toml.c
	src/tomlcpp.cpp
)
target_link_libraries( fc2dconfig  ${wxWidgets_LIBRARIES} )
