diff --git a/.gitignore b/.gitignore index 3f031f5..923c729 100644 --- a/.gitignore +++ b/.gitignore @@ -26,5 +26,18 @@ *.a *.lib +# Cmake +CMakeLists.txt.user +CMakeCache.txt +CMakeFiles +CMakeScripts +Testing +Makefile +cmake_install.cmake +install_manifest.txt +compile_commands.json +CTestTestfile.cmake +_deps + # Executables -*.out \ No newline at end of file +FaultFinder \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json index c2453c8..3387a10 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -8,7 +8,7 @@ "name": "Build and Debug", "type": "cppdbg", "request": "launch", - "program": "${workspaceFolder}/FaultFinder.out", + "program": "${workspaceFolder}/FaultFinder", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 2b44cab..e1e076c 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -2,16 +2,26 @@ "version": "2.0.0", "tasks": [ { - "label": "make", + "label": "cmake", "type": "shell", - "command": "make", + "command": "cmake", "args": [ - "debug" + "." ], "group": { "kind": "build", "isDefault": true } + }, + { + "label": "make", + "type": "shell", + "command": "make", + "group": { + "kind": "build", + "isDefault": true + }, + "dependsOn": "cmake" } ] } \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..53c1f29 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,22 @@ +cmake_minimum_required(VERSION 2.8) +project( FaultFinder ) + +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) + +find_package( OpenCV REQUIRED ) +find_package( Ebus REQUIRED ) + +include_directories( + ${OpenCV_INCLUDE_DIRS} + ${Ebus_INCLUDE_DIRS} +) + +add_executable( FaultFinder + FaultFinder.cpp + StreamManager.cpp +) + +target_link_libraries( FaultFinder + ${OpenCV_LIBS} + ${Ebus_LIBRARIES} + ) diff --git a/Makefile b/Makefile deleted file mode 100644 index 9255ba7..0000000 --- a/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -CXXFLAGS = -c -std=c++11 - -all: FaultFinder.o StreamManager.o - g++ *.o -o FaultFinder.out -L /opt/pleora/ebus_sdk/Ubuntu-x86_64/lib -lPvAppUtils -lPtConvertersLib -lPvBase -lPvBuffer -lPvGenICam -lPvSystem -lPvStream -lPvDevice -lPvTransmitter -lPvVirtualDevice -lPvPersistence -lPvSerial -lPvCameraBridge -lPvGUI -lSimpleImagingLib - -run: all - ./FaultFinder.out - -FaultFinder.o: FaultFinder.cpp - g++ $(CXXFLAGS) -o FaultFinder.o FaultFinder.cpp -I /opt/pleora/ebus_sdk/Ubuntu-x86_64/include - -StreamManager.o: StreamManager.cpp - g++ $(CXXFLAGS) -o StreamManager.o StreamManager.cpp -I /opt/pleora/ebus_sdk/Ubuntu-x86_64/include - -debug: CXXFLAGS += -g -debug: clean all - -clean: - rm -rf *.out *.o \ No newline at end of file diff --git a/cmake/FindEbus.cmake b/cmake/FindEbus.cmake new file mode 100644 index 0000000..f0f15e2 --- /dev/null +++ b/cmake/FindEbus.cmake @@ -0,0 +1,151 @@ +# FindEbus.cmake - Find ebus sdk, version >= 4. +# quchao@seas.upenn.edu (Chao Qu) +# Modified from FindEigen.cmake by alexs.mac@gmail.com (Alex Stewart) +# +# This module defines the following variables: +# +# Ebus_FOUND: TRUE if ebus is found. +# Ebus_INCLUDE_DIRS: Include directories for ebus. +# Ebus_LIBRARIES: Libraries for all ebus component libraries +# and dependencies. +# +# Ebus_VERSION: Extracted from lib/PvBase.so.x.y.z +# Ebus_WORLD_VERSION: Equal to 4 if Ebus_VERSION = 4.0.5 +# Ebus_MAJOR_VERSION: Equal to 0 if Ebus_VERSION = 4.0.5 +# Ebus_MINOR_VERSION: Equal to 5 if Ebus_VERSION = 4.0.5 +# +# The following variables control the behaviour of this module: +# +# Ebus_INCLUDE_DIR_HINTS: List of additional directories in which to +# search for ebus includes, e.g: /foo/include. +# Ebus_LIBRARY_DIR_HINTS: List of additional directories in which to +# search for ebus libraries, e.g: /bar/lib. +# +# The following variables are also defined by this module, but in line with +# CMake recommended FindPackage() module style should NOT be referenced directly +# by callers (use the plural variables detailed above instead). These variables +# do however affect the behaviour of the module via FIND_[PATH/LIBRARY]() which +# are NOT re-called (i.e. search for library is not repeated) if these variables +# are set with valid values _in the CMake cache_. This means that if these +# variables are set directly in the cache, either by the user in the CMake GUI, +# or by the user passing -DVAR=VALUE directives to CMake when called (which +# explicitly defines a cache variable), then they will be used verbatim, +# bypassing the HINTS variables and other hard-coded search locations. +# +# Ebus_INCLUDE_DIR: Include directory for ebus, not including the +# include directory of any dependencies. +# Ebus_LIBRARY: ebus library, not including the libraries of any +# dependencies. + +# Called if we failed to find ebus or any of it's required dependencies, +# unsets all public (designed to be used externally) variables and reports +# error message at priority depending upon [REQUIRED/QUIET/] argument. +macro(Ebus_REPORT_NOT_FOUND REASON_MSG) + unset(Ebus_FOUND) + unset(Ebus_INCLUDE_DIRS) + unset(Ebus_LIBRARIES) + unset(Ebus_WORLD_VERSION) + unset(Ebus_MAJOR_VERSION) + unset(Ebus_MINOR_VERSION) + # Make results of search visible in the CMake GUI if ebus has not + # been found so that user does not have to toggle to advanced view. + mark_as_advanced(CLEAR Ebus_INCLUDE_DIR) + # Note _FIND_[REQUIRED/QUIETLY] variables defined by FindPackage() + # use the camelcase library name, not uppercase. + if(Ebus_FIND_QUIETLY) + message(STATUS "Failed to find ebus - " ${REASON_MSG} ${ARGN}) + elseif(Ebus_FIND_REQUIRED) + message(FATAL_ERROR "Failed to find ebus - " ${REASON_MSG} ${ARGN}) + else() + # Neither QUIETLY nor REQUIRED, use no priority which emits a message + # but continues configuration and allows generation. + message("-- Failed to find ebus - " ${REASON_MSG} ${ARGN}) + endif() +endmacro(Ebus_REPORT_NOT_FOUND) + +# Search user-installed locations first, so that we prefer user installs +# to system installs where both exist. +list(APPEND Ebus_CHECK_INCLUDE_DIRS + /opt/pleora/ebus_sdk/Ubuntu-x86_64/include) +list(APPEND Ebus_CHECK_LIBRARY_DIRS + /opt/pleora/ebus_sdk/Ubuntu-x86_64/lib) + +# Check general hints +if(Ebus_HINTS AND EXISTS ${Ebus_HINTS}) + set(Ebus_INCLUDE_DIR_HINTS ${Ebus_HINTS}/include) + set(Ebus_LIBRARY_DIR_HINTS ${Ebus_HINTS}/lib) +endif() + +# Search supplied hint directories first if supplied. +# Find include directory for ebus +find_path(Ebus_INCLUDE_DIR + NAMES PvBase.h + PATHS ${Ebus_INCLUDE_DIR_HINTS} + ${Ebus_CHECK_INCLUDE_DIRS} + NO_DEFAULT_PATH) +if(NOT Ebus_INCLUDE_DIR OR NOT EXISTS ${Ebus_INCLUDE_DIR}) + Ebus_REPORT_NOT_FOUND( + "Could not find ebus include directory, set Ebus_INCLUDE_DIR to " + "path to ebus include directory," + "e.g. /opt/pleora/ebus_sdk/Ubuntu-x86_64/include.") +else() + message(STATUS "ebus include dir found: " ${Ebus_INCLUDE_DIR}) +endif() + +# Find library directory for ebus +find_library(Ebus_LIBRARY + NAMES PvBase + PATHS ${Ebus_LIBRARY_DIR_HINTS} + ${Ebus_CHECK_LIBRARY_DIRS} + NO_DEFAULT_PATH) +if(NOT Ebus_LIBRARY OR NOT EXISTS ${Ebus_LIBRARY}) + Ebus_REPORT_NOT_FOUND( + "Could not find ebus library, set Ebus_LIBRARY " + "to full path to ebus library direcotory.") +else() + # TODO: need to fix this hacky solution for getting Ebus_LIBRARY_DIR + string(REGEX MATCH ".*/" Ebus_LIBRARY_DIR ${Ebus_LIBRARY}) +endif() + +# Mark internally as found, then verify. Ebus_REPORT_NOT_FOUND() unsets if +# called. +set(Ebus_FOUND TRUE) + +# Extract ebus version from ebus_sdk/Ubuntu-12.04-x86_64/lib/libPvBase.so.x.y.z +if(Ebus_LIBRARY_DIR) + file(GLOB Ebus_PVBASE + RELATIVE ${Ebus_LIBRARY_DIR} + ${Ebus_LIBRARY_DIR}/libPvBase.so.[0-9].[0-9].[0-9]) + # TODO: add version support + # string(REGEX MATCH "" + # Ebus_WORLD_VERSION ${Ebus_PVBASE}) + # message(STATUS "ebus world version: " ${Ebus_WORLD_VERSION}) +endif() + +# Catch case when caller has set Ebus_INCLUDE_DIR in the cache / GUI and +# thus FIND_[PATH/LIBRARY] are not called, but specified locations are +# invalid, otherwise we would report the library as found. +if(Ebus_INCLUDE_DIR AND NOT EXISTS ${Ebus_INCLUDE_DIR}/PvBase.h) + Ebus_REPORT_NOT_FOUND("Caller defined Ebus_INCLUDE_DIR: " + ${Ebus_INCLUDE_DIR} + " does not contain PvBase.h header.") +endif() + +# Set standard CMake FindPackage variables if found. +if(Ebus_FOUND) + set(Ebus_INCLUDE_DIRS ${Ebus_INCLUDE_DIR}) + file(GLOB Ebus_LIBRARIES ${Ebus_LIBRARY_DIR}libPv*.so) +endif() + +# Handle REQUIRED / QUIET optional arguments. +include(FindPackageHandleStandardArgs) +if(Ebus_FOUND) + FIND_PACKAGE_HANDLE_STANDARD_ARGS(Ebus DEFAULT_MSG + Ebus_INCLUDE_DIRS Ebus_LIBRARIES) +endif() + +# Only mark internal variables as advanced if we found ebus, otherwise +# leave it visible in the standard GUI for the user to set manually. +if(Ebus_FOUND) + mark_as_advanced(FORCE Ebus_INCLUDE_DIR Ebus_LIBRARY) +endif()