PLAYERDRIVER_OPTION (camera1394 build_camera1394 ON)
PLAYERDRIVER_REJECT_OS (camera1394 build_camera1394 PLAYER_OS_WIN)
IF (build_camera1394)
    SET (c1394CFlags "-I${PROJECT_SOURCE_DIR}/server/drivers/blobfinder/cmvision -I${CMAKE_CURRENT_BINARY_DIR}")
    SET (DC1394_DMA_SETUP_CAPTURE_ARGS 0)
    SET (DC1394_2_LINUX 0)
    SET (c1394Sources camera1394.cc ${PROJECT_SOURCE_DIR}/server/drivers/blobfinder/cmvision/conversions.c)

    INCLUDE (CheckIncludeFiles)
    CHECK_INCLUDE_FILES (dc1394/control.h haveControlH)
    IF (haveControlH)
        SET (DC1394_DMA_SETUP_CAPTURE_ARGS 20)
        CHECK_INCLUDE_FILES (libraw1394/raw1394.h haveRaw1394H)
        IF (haveRaw1394H)
            SET (c1394LinkFlags "-lraw1394 -ldc1394")
        SET (HAVE_LIBRAW1394 1)
        ELSE (haveRaw1394H)
            SET (c1394LinkFlags "-ldc1394")
        ENDIF (haveRaw1394H)
        CHECK_INCLUDE_FILES ("dc1394/dc1394.h;dc1394/linux/control.h" haveLinuxControlH)
        IF (haveLinuxControlH)
            SET (DC1394_2_LINUX 1)
        ENDIF (haveLinuxControlH)
    ELSE (haveControlH)
        SET (c1394LinkFlags "-lraw1394 -ldc1394_control")
        PLAYERDRIVER_REQUIRE_HEADER (camera1394 build_camera1394 libraw1394/raw1394.h)
        PLAYERDRIVER_REQUIRE_HEADER (camera1394 build_camera1394 libdc1394/dc1394_control.h)
        IF (HAVE_HDR_LIBRAW1394_RAW1394_H)
            SET (HAVE_LIBRAW1394 1)
        ENDIF (HAVE_HDR_LIBRAW1394_RAW1394_H)
        SET (testArgsSource ${CMAKE_CURRENT_BINARY_DIR}/CMakeTmp/test_args.c)
        FILE (WRITE ${testArgsSource}
            "#include \"libdc1394/dc1394_control.h\"\nint main () {dc1394_dma_setup_capture (NULL, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL); return 0;}\n")
        TRY_COMPILE (argsIs11 ${CMAKE_CURRENT_BINARY_DIR} ${testArgsSource} CMAKE_FLAGS "-DLINK_LIBRARIES:STRING=raw1394;dc1394_control")
        IF (argsIs11)
            SET (DC1394_DMA_SETUP_CAPTURE_ARGS 11)
        ELSE (argsIs11)
            FILE (WRITE ${testArgsSource}
                "#include \"libdc1394/dc1394_control.h\"\nint main () {dc1394_dma_setup_capture (NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL); return 0;}\n")
            TRY_COMPILE (argsIs12 ${CMAKE_CURRENT_BINARY_DIR} ${testArgsSource} CMAKE_FLAGS "-DLINK_LIBRARIES:STRING=raw1394;dc1394_control")
            IF (argsIs12)
                SET (DC1394_DMA_SETUP_CAPTURE_ARGS 12)
            ENDIF (argsIs12)
        ENDIF (argsIs11)
    ENDIF (haveControlH)
ENDIF (build_camera1394)

SET (camera1394_h_in "${CMAKE_CURRENT_SOURCE_DIR}/camera1394.h.in")
SET (camera1394_h "${CMAKE_CURRENT_BINARY_DIR}/camera1394.h")
CONFIGURE_FILE (${camera1394_h_in} ${camera1394_h})

PLAYERDRIVER_ADD_DRIVER (camera1394 build_camera1394 LINKFLAGS ${c1394LinkFlags}
                         CFLAGS ${c1394CFlags} -I${PROJECT_SOURCE_DIR}/server/drivers/blobfinder/cmvision
                         SOURCES ${c1394Sources} ${camera1394_h})
