project(RobodocDemo)

cmake_minimum_required(VERSION 2.6)

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)

set(REQUIRED_CISST_LIBS cisstCommon cisstVector cisstOSAbstraction cisstMultiTask 
                        cisstRobot  cisstNumerical cisstParameterTypes)

# find cisst and make sure the required libraries have been compiled
find_package (cisst REQUIRED ${REQUIRED_CISST_LIBRARIES})
find_package (OpenGL REQUIRED)
find_package (GLUT REQUIRED)

if (cisst_FOUND_AS_REQUIRED AND OPENGL_FOUND AND GLUT_FOUND)
    # Modify CMake configuration to use cisst
    include (${CISST_USE_FILE})

    set(INCLUDE_DIRS ${PROJECT_SOURCE_DIR} ${PROJECT_BINARY_DIR})

    if(WIN32)
        add_definitions(-D_SCL_SECURE_NO_WARNINGS)
    endif(WIN32)
    if(UNIX)
        add_definitions(-Wno-write-strings)  # deprecated conversion from string constant to char *
        add_definitions(-Wno-pointer-arith)  # NULL used in arithmetic
    ENDIF(UNIX)

    # Deploy sawGLUTSimulator component
    find_package(sawGLUTSimulator REQUIRED HINTS "${cisst_saw_BINARY_DIR}/saw/components")
    IF(sawGLUTSimulator_FOUND)
        #INCLUDE_DIRECTORIES(${sawGLUTSimulator_INCLUDE_DIR})
        set (INCLUDE_DIRS ${INCLUDE_DIRS} ${sawGLUTSimulator_INCLUDE_DIR})
        LINK_DIRECTORIES(${sawGLUTSimulator_LIBRARY_DIR})
        SET(REQUIRED_SAW_COMPONENT ${sawGLUTSimulator_LIBRARIES})
    ENDIF(sawGLUTSimulator_FOUND)

    include_directories(${INCLUDE_DIRS})

    add_executable(RobodocDemo main.cpp TestComponent.cpp)

    cisst_target_link_libraries(RobodocDemo ${REQUIRED_CISST_LIBS})

    set (LINK_LIBRARIES ${REQUIRED_CISST_LIBS} ${REQUIRED_SAW_COMPONENT})
    #if (IS_LINUX)
    #  set (LINK_LIBRARIES ${LINK_LIBRARIES} glut)
    #endif (IS_LINUX)
    target_link_libraries(RobodocDemo ${LINK_LIBRARIES} ${OPENGL_LIBRARIES} ${GLUT_LIBRARIES})
else (cisst_FOUND_AS_REQUIRED AND OPENGL_FOUND AND GLUT_FOUND)
  message("Check if cisst, opengl, and glut exist")
  cisst_information_message_missing_libraries (${REQUIRED_CISST_LIBRARIES})
endif (cisst_FOUND_AS_REQUIRED AND OPENGL_FOUND AND GLUT_FOUND)
