Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cmake updates #333

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 76 additions & 27 deletions mjpg-streamer-experimental/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,57 +1,95 @@
cmake_minimum_required(VERSION 2.8.3)
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
cmake_minimum_required(VERSION 3.10.0)

project("mjpg-streamer" C)
# Add cmake modules of this project to the module path
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

# If the user doesn't manually specify a build type, use 'Release'
message("CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}")
if("${CMAKE_BUILD_TYPE}" STREQUAL "")
SET(CMAKE_BUILD_TYPE "Release")
# with at least one base tag, this can have dynamic (git) versioning:
# git describe last tag = 1.1.0
# git describe last tag + rev count = 1.1.0.45
#
# for now, set -DSCM_VERSION_INFO in the build env to override
if(NOT SCM_VERSION_INFO)
set(PACKAGE_VERSION "1.0.0")
set(SCM_VERSION_INFO ${PACKAGE_VERSION})
endif()

SET(COMPILE_DEFINITIONS -Werror -Wall)
project(mjpg-streamer
LANGUAGES C
VERSION ${SCM_VERSION_INFO}
)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_VERBOSE_MAKEFILE ON)

# eventually this should have some tests
option(BUILD_TESTING "build and run tests" ON)
option(ENABLE_WXP_COMPAT "" OFF)
option(ENABLE_HTTP_MANAGEMENT "" OFF)
option(ENABLE_INPUT_OPENCV "" OFF)

# If the user doesn't manually specify a build type, use 'Release'
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE
"Release"
CACHE STRING "Default build type: ${CMAKE_BUILD_TYPE}" FORCE
)
endif()
message(STATUS "CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}")

include(CheckLibraryExists)
include(CheckLibraryExists)
include(CheckIncludeFiles)
include(FeatureSummary)
include(CTest)
include(GNUInstallDirs)

set(MJPG_STREAMER_PLUGIN_INSTALL_PATH
"${CMAKE_INSTALL_LIBDIR}/mjpg-streamer/${CMAKE_INSTALL_LIBDIR}"
CACHE PATH "Install directory for plugin (.so) files"
)

set(MJPG_STREAMER_WWW_ROOT
"${CMAKE_INSTALL_DATAROOTDIR}/mjpg-streamer"
CACHE PATH "Install directory for example www server root"
)

include(mjpg_streamer_utils)

#
# Get the current git hash
#
execute_process(
COMMAND git rev-parse HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
RESULT_VARIABLE GIT_RESULT
OUTPUT_VARIABLE GIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
COMMAND git rev-parse HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
RESULT_VARIABLE GIT_RESULT
OUTPUT_VARIABLE GIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)

if(GIT_RESULT EQUAL 0)
add_definitions("-DGIT_HASH=\"${GIT_HASH}\"")
add_compile_definitions(GIT_HASH=\"${GIT_HASH}\")
endif()

#
# Options
#
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DDEBUG")
# SCM_VERSION_INFO can be defined by cmake args and passed into the code as a
# define here (see PACKAGE_VERSION near the top of this file)
add_compile_definitions(SOURCE_VERSION=\"${SCM_VERSION_INFO}\")

add_feature_option(WXP_COMPAT "Enable compatibility with WebcamXP" OFF)
add_compile_options(-Wall)

add_feature_option(WXP_COMPAT "Enable compatibility with WebcamXP" ${ENABLE_WXP_COMPAT})

if (WXP_COMPAT)
add_definitions(-DWXP_COMPAT)
endif (WXP_COMPAT)

set (MJPG_STREAMER_PLUGIN_INSTALL_PATH "lib/mjpg-streamer")

#
# Global dependencies
#

find_library(JPEG_LIB jpeg)


#
# Input plugins
#
Expand Down Expand Up @@ -84,23 +122,34 @@ add_subdirectory(plugins/output_zmqserver)
# need to do it

set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--enable-new-dtags")
set (CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set (CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/${MJPG_STREAMER_PLUGIN_INSTALL_PATH})
set (CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)


add_executable(mjpg_streamer mjpg_streamer.c
utils.c)

target_link_libraries(mjpg_streamer pthread dl)
install(TARGETS mjpg_streamer DESTINATION bin)

install(TARGETS mjpg_streamer
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
)

if(BUILD_TESTING)
enable_testing()

# tell ctest to run main app as a test; note this is mainly for illustration
add_test(NAME main_test
COMMAND mjpg_streamer --version
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
)
endif()

# what to do with this...
# MJPG_STREAMER_PLUGIN_INSTALL_PATH

#
# www directory
#

install(DIRECTORY www DESTINATION share/mjpg-streamer)

install(DIRECTORY ${CMAKE_SOURCE_DIR}/www DESTINATION "${MJPG_STREAMER_WWW_ROOT}")

#
# Show enabled/disabled features
Expand Down
15 changes: 8 additions & 7 deletions mjpg-streamer-experimental/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,24 @@

.DEFAULT_GOAL: all
.PHONY: all clean distclean install

CMAKE_BUILD_TYPE ?= Release

CMAKE_INSTALL_PREFIX ?= /usr/local

all:
[ -d _build ] || mkdir _build
[ -f _build/Makefile ] || (cd _build && cmake -DCMAKE_BUILD_TYPE=$(CMAKE_BUILD_TYPE) ..)
[ -f _build/Makefile ] || (cd _build && cmake -DCMAKE_INSTALL_PREFIX=$(CMAKE_INSTALL_PREFIX) -DCMAKE_BUILD_TYPE=$(CMAKE_BUILD_TYPE) ..)
make -C _build

@cp _build/mjpg_streamer .
@find _build -name "*.so" -type f -exec cp {} . \;

install:
make -C _build install

clean:
[ ! -f _build/Makefile ] || make -C _build clean
rm -f mjpg_streamer *.so

distclean: clean
rm -rf _build
rm -rf _build
20 changes: 11 additions & 9 deletions mjpg-streamer-experimental/cmake/FindGphoto2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,23 @@
# From: https://github.com/darktable-org/darktable/blob/master/cmake/modules/FindGphoto2.cmake
#=============================================================================

include(FindPkgConfig)

SET(GPHOTO2_FIND_REQUIRED ${Gphoto2_FIND_REQUIRED})

find_path(GPHOTO2_INCLUDE_DIR gphoto2/gphoto2.h)
mark_as_advanced(GPHOTO2_INCLUDE_DIR)
find_path(Gphoto2_INCLUDE_DIR gphoto2/gphoto2.h)
mark_as_advanced(Gphoto2_INCLUDE_DIR)

set(GPHOTO2_NAMES ${GPHOTO2_NAMES} gphoto2 libgphoto2)
set(GPHOTO2_PORT_NAMES ${GPHOTO2_PORT_NAMES} gphoto2_port libgphoto2_port)
find_library(GPHOTO2_LIBRARY NAMES ${GPHOTO2_NAMES} )
find_library(Gphoto2_LIBRARY NAMES ${GPHOTO2_NAMES} )
find_library(GPHOTO2_PORT_LIBRARY NAMES ${GPHOTO2_PORT_NAMES} )
mark_as_advanced(GPHOTO2_LIBRARY)
mark_as_advanced(Gphoto2_LIBRARY)
mark_as_advanced(GPHOTO2_PORT_LIBRARY)

# Detect libgphoto2 version
if(NOT PkgConfig_FOUND)
find_package(PkgConfig)
endif()

pkg_check_modules(PC_GPHOTO2 libgphoto2)
if(PC_GPHOTO2_FOUND)
set(GPHOTO2_VERSION_STRING "${PC_GPHOTO2_VERSION}")
Expand All @@ -41,11 +43,11 @@ endif()
# handle the QUIETLY and REQUIRED arguments and set GPHOTO2_FOUND to TRUE if
# all listed variables are TRUE
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(GPHOTO2 DEFAULT_MSG GPHOTO2_LIBRARY GPHOTO2_INCLUDE_DIR)
find_package_handle_standard_args(Gphoto2 DEFAULT_MSG Gphoto2_LIBRARY Gphoto2_INCLUDE_DIR)

IF(GPHOTO2_FOUND)
SET(Gphoto2_LIBRARIES ${GPHOTO2_LIBRARY} ${GPHOTO2_PORT_LIBRARY})
SET(Gphoto2_INCLUDE_DIRS ${GPHOTO2_INCLUDE_DIR})
SET(Gphoto2_LIBRARIES ${Gphoto2_LIBRARY} ${GPHOTO2_PORT_LIBRARY})
SET(Gphoto2_INCLUDE_DIRS ${Gphoto2_INCLUDE_DIR})

# libgphoto2 dynamically loads and unloads usb library
# without calling any cleanup functions (since they are absent from libusb-0.1).
Expand Down
24 changes: 12 additions & 12 deletions mjpg-streamer-experimental/cmake/mjpg_streamer_utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ macro(MJPG_STREAMER_PLUGIN_OPTION MODULE_NAME DESCRIPTION)

cmake_parse_arguments(MSPOM
"" "" "ONLYIF" ${ARGN})

string(TOUPPER "PLUGIN_${MODULE_NAME}" OPT_ENABLE)
string(TOUPPER "PLUGIN_${MODULE_NAME}_AVAILABLE" OPT_AVAILABLE)

cmake_dependent_option(${OPT_ENABLE} "${DESCRIPTION}" ON "${MSPOM_ONLYIF}" OFF)

if (${OPT_AVAILABLE})
add_feature_info(${OPT_ENABLE} ${OPT_ENABLE} "${DESCRIPTION}")
else()
Expand All @@ -36,23 +36,23 @@ endmacro()
# other args: source files
#
macro(MJPG_STREAMER_PLUGIN_COMPILE MODULE_NAME)

string(TOUPPER "${MODULE_NAME}" ARGU)
set(OPT_ENABLE "PLUGIN_${ARGU}")

if (${OPT_ENABLE})

set(MOD_SRC)
foreach(arg ${ARGN})
list(APPEND MOD_SRC "${arg}")
list(APPEND MOD_SRC "${arg}")
endforeach()
add_library(${MODULE_NAME} SHARED ${MOD_SRC})

add_library(${MODULE_NAME} MODULE ${MOD_SRC})
set_target_properties(${MODULE_NAME} PROPERTIES PREFIX "")
install(TARGETS ${MODULE_NAME} DESTINATION ${MJPG_STREAMER_PLUGIN_INSTALL_PATH})

install(TARGETS ${MODULE_NAME} DESTINATION ${MJPG_STREAMER_PLUGIN_INSTALL_PATH})
endif()

endmacro()


Expand Down
4 changes: 0 additions & 4 deletions mjpg-streamer-experimental/mjpg_streamer.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,7 @@ int main(int argc, char *argv[])

case 'v':
printf("MJPG Streamer Version: %s\n",
#ifdef GIT_HASH
GIT_HASH
#else
SOURCE_VERSION
#endif
);
return 0;
break;
Expand Down
9 changes: 8 additions & 1 deletion mjpg-streamer-experimental/mjpg_streamer.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@

#ifndef MJPG_STREAMER_H
#define MJPG_STREAMER_H
#define SOURCE_VERSION "2.0"

#ifndef SOURCE_VERSION
#ifdef GIT_HASH
#define SOURCE_VERSION GIT_HASH
#else
#define SOURCE_VERSION "1.0"
#endif
#endif

/* FIXME take a look to the output_http clients thread marked with fixme if you want to set more then 10 plugins */
#define MAX_INPUT_PLUGINS 10
Expand Down
14 changes: 7 additions & 7 deletions mjpg-streamer-experimental/plugins/input_opencv/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@

# TODO: which components do I need?
# To fix the error: "undefined symbol: _ZN2cv12VideoCaptureC1Ev"
find_package(OpenCV COMPONENTS core imgproc highgui videoio)
if(ENABLE_INPUT_OPENCV)
find_package(OpenCV COMPONENTS core imgproc highgui videoio)
endif()

MJPG_STREAMER_PLUGIN_OPTION(input_opencv "OpenCV input plugin"
ONLYIF OpenCV_FOUND ${OpenCV_VERSION_MAJOR} EQUAL 3)

if (PLUGIN_INPUT_OPENCV)
if(PLUGIN_INPUT_OPENCV)
enable_language(CXX)
include_directories(${OpenCV_INCLUDE_DIRS})

MJPG_STREAMER_PLUGIN_COMPILE(input_opencv input_opencv.cpp)

target_link_libraries(input_opencv ${OpenCV_LIBS})

add_subdirectory(filters/cvfilter_cpp)
add_subdirectory(filters/cvfilter_py)

endif()


endif()
3 changes: 3 additions & 0 deletions mjpg-streamer-experimental/plugins/input_opencv/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ This input plugin uses OpenCV to read from supported video sources, optionally
running the image through a filter plugin that can be specified on the command
line.

Enable this plugin by adding `-DENABLE_INPUT_OPENCV` to the cmake build config.
You must have the OpenCV development packages installed.

If you're not using the image filtering functionality of this plugin, you're
probably better off using some other input plugin as this plugin will probably
consume more CPU resources.
Expand Down
6 changes: 3 additions & 3 deletions mjpg-streamer-experimental/plugins/input_ptp2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
find_package(Gphoto2)

MJPG_STREAMER_PLUGIN_OPTION(input_ptp2 "PTP2 input plugin"
ONLYIF GPHOTO2_FOUND)
ONLYIF Gphoto2_FOUND)

if (PLUGIN_INPUT_PTP2)
include_directories(${GPHOTO2_INCLUDE_DIR})

MJPG_STREAMER_PLUGIN_COMPILE(input_ptp2 input_ptp2.c)

target_link_libraries(input_ptp2 ${Gphoto2_LIBRARIES})

endif()


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

add_feature_option(ENABLE_HTTP_MANAGEMENT "Enable experimental HTTP management option" OFF)
add_feature_option(ENABLE_HTTP_MANAGEMENT "Enable experimental HTTP management option" ${ENABLE_HTTP_MANAGEMENT})

if (ENABLE_HTTP_MANAGEMENT)
add_definitions(-DMANAGMENT)
Expand Down
Loading