CMAKE_MINIMUM_REQUIRED(VERSION 3.1)

SET( ORIG_CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} )

SET(CMAKE_PREFIX_PATH ${CMINPACK_INSTALL_DIR} ${ORIG_CMAKE_PREFIX_PATH} )
FIND_PACKAGE(CMINPACK REQUIRED)
SET( CMINPACK_INCLUDE_DIR  ${CMINPACK_INCLUDE_DIR} PARENT_SCOPE )
SET( CMINPACK_LIBRARIES  ${CMINPACK_LIBRARIES} PARENT_SCOPE )

SET(CMAKE_PREFIX_PATH ${CODEELI_INSTALL_DIR} ${ORIG_CMAKE_PREFIX_PATH} )
FIND_PACKAGE(CodeEli 0.3.6 REQUIRED)
SET( CodeEli_INCLUDE_DIRS  ${CodeEli_INCLUDE_DIRS} PARENT_SCOPE )

SET( CMAKE_PREFIX_PATH ${CPPTEST_INSTALL_DIR} ${ORIG_CMAKE_PREFIX_PATH} )
FIND_PACKAGE(CPPTest REQUIRED)

SET( CMAKE_PREFIX_PATH ${DELABELLA_INSTALL_DIR} ${ORIG_CMAKE_PREFIX_PATH} )
FIND_PACKAGE(delabella REQUIRED)

# Add Eigen3 and Code-Eli
SET( CMAKE_PREFIX_PATH ${EIGEN_INSTALL_DIR} ${ORIG_CMAKE_PREFIX_PATH} )
FIND_PACKAGE(Eigen3 3.0.0 REQUIRED)
SET( EIGEN3_INCLUDE_DIR  ${EIGEN3_INCLUDE_DIR} PARENT_SCOPE )

SET(CMAKE_PREFIX_PATH ${LIBIGES_INSTALL_DIR} ${ORIG_CMAKE_PREFIX_PATH} )

find_library(LIBIGES_LIBRARIES NAMES iges_static
        HINTS ${LIBIGES_INSTALL_DIR}/lib ${LIBIGES_INSTALL_DIR}/bin
        )
SET( LIBIGES_LIBRARIES  ${LIBIGES_LIBRARIES} PARENT_SCOPE )

find_path(LIBIGES_INCLUDE_DIR iges/libigesconf.h
        HINTS ${LIBIGES_INSTALL_DIR}/include
        )
SET( LIBIGES_INCLUDE_DIR  ${LIBIGES_INCLUDE_DIR} ${LIBIGES_INCLUDE_DIR}/iges ${LIBIGES_INCLUDE_DIR}/geom PARENT_SCOPE )

SET( CMAKE_PREFIX_PATH ${LIBXML2_INSTALL_DIR} ${ORIG_CMAKE_PREFIX_PATH} )
FIND_PACKAGE(LibXml2 REQUIRED)

SET(STEPCODE_PREFIX_PATH ${STEPCODE_INSTALL_DIR} ${ORIG_CMAKE_PREFIX_PATH} )
FIND_PACKAGE(STEPCODE REQUIRED)
SET( STEPCODE_INCLUDE_DIR  ${STEPCODE_INCLUDE_DIR} PARENT_SCOPE )
SET( STEPCODE_LIBRARIES  ${STEPCODE_LIBRARIES} PARENT_SCOPE )

SET(CMAKE_PREFIX_PATH ${TRIANGLE_INSTALL_DIR} ${ORIG_CMAKE_PREFIX_PATH} )
FIND_PACKAGE(TRIANGLE REQUIRED)
SET( TRIANGLE_INCLUDE_DIR ${TRIANGLE_INCLUDE_DIR} PARENT_SCOPE )
SET( TRIANGLE_LIBRARIES ${TRIANGLE_LIBRARIES} PARENT_SCOPE )

IF( NOT VSP_NO_GRAPHICS )
    IF( NOT NOREGEXP )
        SET( CMAKE_PREFIX_PATH ${EXPRPARSE_INSTALL_DIR} ${ORIG_CMAKE_PREFIX_PATH} )
        FIND_PACKAGE(exprparse REQUIRED)
    ENDIF()

    SET( CMAKE_PREFIX_PATH ${FLTK_INSTALL_DIR} ${ORIG_CMAKE_PREFIX_PATH} )
    FIND_PACKAGE(FLTK REQUIRED)
    SET( FLTK_INCLUDE_DIR ${FLTK_INCLUDE_DIR} PARENT_SCOPE )
    SET( FLTK_LIBRARIES ${FLTK_LIBRARIES} PARENT_SCOPE )

    IF( UNIX )
        EXECUTE_PROCESS( COMMAND which ${FLTK_FLUID_EXECUTABLE}
                        OUTPUT_VARIABLE FLTK_FLUID_EXECUTABLE
                        OUTPUT_STRIP_TRAILING_WHITESPACE )
    ENDIF( UNIX )

    SET( FLTK_FLUID_EXECUTABLE ${FLTK_FLUID_EXECUTABLE} PARENT_SCOPE )
    SET( OPENGL_LIBRARIES ${OPENGL_LIBRARIES} PARENT_SCOPE )

    SET( CMAKE_PREFIX_PATH ${GLEW_INSTALL_DIR} ${ORIG_CMAKE_PREFIX_PATH} )
    # Use built-in FindGLEW.cmake
    FIND_PACKAGE(GLEW_VSP REQUIRED)

    SET( CMAKE_PREFIX_PATH ${GLM_INSTALL_DIR} ${ORIG_CMAKE_PREFIX_PATH} )
    FIND_PACKAGE( GLM )
    SET( GLM_INCLUDE_DIR  ${GLM_INCLUDE_DIR} PARENT_SCOPE )

    ADD_SUBDIRECTORY( glfont2 )

    ADD_SUBDIRECTORY( stb )

    ADD_SUBDIRECTORY( cartesian )
ENDIF()

SET( CMAKE_PREFIX_PATH ${ORIG_CMAKE_PREFIX_PATH} )

ADD_SUBDIRECTORY( clipper )
ADD_SUBDIRECTORY( nanoflann )
ADD_SUBDIRECTORY( Pinocchio )
ADD_SUBDIRECTORY( sixseries )
ADD_SUBDIRECTORY( tritri )
ADD_SUBDIRECTORY( wavedragEL )

SET( PCGCPP_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/pcg-cpp/include CACHE PATH "Path to PCG-CPP library")
