Skip to content

Commit

Permalink
Merge pull request #53 from edrosten/er/cmake-config
Browse files Browse the repository at this point in the history
Er/cmake config
  • Loading branch information
edrosten authored Aug 15, 2019
2 parents a6ac6e4 + 649d08c commit 08b0e07
Show file tree
Hide file tree
Showing 8 changed files with 184 additions and 136 deletions.
91 changes: 11 additions & 80 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,10 @@ option(CVD_ENABLE_EXAMPLES "Build libCVD examples" ON)
include(TestBigEndian)
include(CheckSymbolExists)

list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
set(CMAKE_DEBUG_POSTFIX _debug)

# Dependencies that can be automatically found by CMake.

find_package(JPEG)
find_package(PNG)
find_package(TIFF)
find_package(TooN)
find_package(X11)
find_package(dc1394v2)
find_package(OpenGL)
find_package(Threads REQUIRED)
include(cmake/CVDFindAllDeps.cmake)

# Detect endianness

Expand Down Expand Up @@ -179,7 +170,7 @@ set(HEADERS


# Library-specific source files, headers and definitions.
if(dc1394_FOUND)
if(CVD_dc1394v2_FOUND)
list(APPEND SRCS
cvd_src/videosource_dvbuffer.cc
cvd_src/Linux/dvbuffer3_dc1394v2.cc)
Expand Down Expand Up @@ -246,39 +237,18 @@ else()
endif()


find_path(AVCODEC_INCLUDE_DIR libavcodec/avcodec.h)
find_library(AVCODEC_LIBRARY NAMES avcodec)
find_path(AVDEVICE_INCLUDE_DIR libavdevice/avdevice.h)
find_library(AVDEVICE_LIBRARY NAMES avdevice)
find_path(AVFORMAT_INCLUDE_DIR libavformat/avformat.h)
find_library(AVFORMAT_LIBRARY NAMES avformat)
find_library(AVUTIL_LIBRARY NAMES avutil)
find_path(SWSCALE_INCLUDE_DIR libswscale/swscale.h)
find_library(SWSCALE_LIBRARY NAMES swscale)
find_library(SWRESAMPLE_LIBRARY NAMES swresample)
find_library(AVFILTER_LIBRARY NAMES avfilter)
if((AVCODEC_LIBRARY STREQUAL "AVCODEC_LIBRARY-NOTFOUND") OR
(AVDEVICE_LIBRARY STREQUAL "AVDEVICE_LIBRARY-NOTFOUND") OR
(AVFORMAT_LIBRARY STREQUAL "AVFORMAT_LIBRARY-NOTFOUND") OR
(AVUTIL_LIBRARY STREQUAL "AVUTIL_LIBRARY-NOTFOUND") OR
(SWSCALE_LIBRARY STREQUAL "SWSCALE_LIBRARY-NOTFOUND") OR
(AVCODEC_INCLUDE_DIR STREQUAL "AVCODEC_INCLUDE_DIR-NOTFOUND") OR
(AVDEVICE_INCLUDE_DIR STREQUAL "AVDEVICE_INCLUDE_DIR-NOTFOUND") OR
(AVFORMAT_INCLUDE_DIR STREQUAL "AVFORMAT_INCLUDE_DIR-NOTFOUND") OR
(SWSCALE_INCLUDE_DIR STREQUAL "SWSCALE_INCLUDE_DIR-NOTFOUND"))
set(CVD_HAVE_FFMPEG OFF)
message(STATUS "FFMPEG - not found")
list(APPEND SRCS
cvd_src/videosource_novideofilebuffer.cc)
else()
message(STATUS "FFMPEG - found")
if(CVD_FFMPEG_FOUND)
set(CVD_HAVE_FFMPEG ON)
list(APPEND SRCS
cvd_src/videofilebuffer2.cc
cvd_src/videosource_videofilebuffer.cc)
else()
set(CVD_HAVE_FFMPEG OFF)
list(APPEND SRCS
cvd_src/videosource_novideofilebuffer.cc)
endif()

if(TooN_FOUND)
if(CVD_TooN_FOUND)
set(CVD_HAVE_TOON ON)
list(APPEND SRCS
cvd_src/brezenham.cc
Expand Down Expand Up @@ -328,49 +298,10 @@ configure_file(cmake/config_internal.h.in include/cvd_src/config_internal.h)

add_library(${PROJECT_NAME} ${SRCS} ${HEADERS})
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_14)
target_include_directories(${PROJECT_NAME} PUBLIC "${PROJECT_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/include")
target_include_directories(${PROJECT_NAME} PUBLIC "${PROJECT_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/include" ${CVD_DEP_INCLUDES_PUBLIC} PRIVATE ${CVD_DEP_INCLUDES_PRIVATE})
target_link_libraries(${PROJECT_NAME} PRIVATE ${CVD_DEP_LIBS})

if(CVD_HAVE_FFMPEG)
target_include_directories(${PROJECT_NAME} PRIVATE ${AVCODEC_INCLUDE_DIR} ${AVDEVICE_INCLUDE_DIR} ${AVFORMAT_INCLUDE_DIR} ${SWSCALE_INCLUDE_DIR})
target_link_libraries(${PROJECT_NAME} PRIVATE ${AVDEVICE_LIBRARY} ${AVFILTER_LIBRARY} ${AVFORMAT_LIBRARY} ${AVCODEC_LIBRARY} ${AVUTIL_LIBRARY} ${SWSCALE_LIBRARY} ${SWRESAMPLE_LIBRARY})

set(CVD_FFMPEG_LIKELY_X_LIBS Xv Xext Xau Xdmcp xcb-xfixes xcb-shape xcb-shm xcb dl)
foreach(l IN LISTS CVD_FFMPEG_LIKELY_X_LIBS)
find_library(CVD_TMP_${l} NAMES ${l})
if(NOT (CVD_TMP_${l} STREQUAL "CVD_TMP_${l}-NOTFOUND"))
message(STATUS "Found ${l}: ${CVD_TMP_${l}}")
target_link_libraries(${PROJECT_NAME} PRIVATE ${CVD_TMP_${l}})
endif()
endforeach()
endif()

target_link_libraries(${PROJECT_NAME} PRIVATE Threads::Threads)
if(JPEG_FOUND)
target_include_directories(${PROJECT_NAME} PRIVATE ${JPEG_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} PRIVATE ${JPEG_LIBRARIES})
endif()
if(TIFF_FOUND)
target_include_directories(${PROJECT_NAME} PRIVATE ${TIFF_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} PRIVATE ${TIFF_LIBRARIES})
endif()
if(PNG_FOUND)
target_include_directories(${PROJECT_NAME} PRIVATE ${PNG_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} PRIVATE ${PNG_LIBRARIES})
endif()
if(TooN_FOUND)
target_include_directories(${PROJECT_NAME} PUBLIC ${TooN_INCLUDE_DIRS})
endif()
if(dc1394v2_FOUND)
target_include_directories(${PROJECT_NAME} PRIVATE ${dc1394v2_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} PRIVATE ${dc1394v2_LIBRARIES})
endif()
if(X11_FOUND)
target_include_directories(${PROJECT_NAME} PUBLIC ${X11_INCLUDE_DIR})
target_link_libraries(${PROJECT_NAME} PUBLIC ${X11_LIBRARIES})
endif()
if(OpenGL_OpenGL_FOUND)
target_link_libraries(${PROJECT_NAME} PUBLIC OpenGL::GL)
endif()
if(WIN32)
target_compile_definitions(${PROJECT_NAME} PRIVATE _CRT_SECURE_NO_WARNINGS)
endif()
Expand All @@ -381,7 +312,7 @@ foreach(file ${HEADERS})
install(FILES ${file} DESTINATION include/${dir})
endforeach()
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/cvd DESTINATION include)
install(FILES ${PROJECT_SOURCE_DIR}/cmake/CVDConfig.cmake DESTINATION cmake)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/cmake DESTINATION . FILES_MATCHING PATTERN *.cmake)

if(CVD_ENABLE_TESTS)
add_subdirectory(tests)
Expand Down
8 changes: 6 additions & 2 deletions cmake/CVDConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
# CVD_LIBRARIES - List of libraries when using CVD.
# CVD_FOUND - True if CVD found.


include(CVDFindAllDeps.cmake)


find_path(CVD_INCLUDE_DIR NAMES cvd/config.h PATH_SUFFIXES include)
find_library(CVD_LIBRARY_RELEASE NAMES cvd PATH_SUFFIXES lib)
find_library(CVD_LIBRARY_DEBUG NAMES cvd_debug PATH_SUFFIXES lib)
Expand All @@ -25,8 +29,8 @@ mark_as_advanced(CVD_LIBRARY_RELEASE CVD_LIBRARY_DEBUG)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(CVD REQUIRED_VARS CVD_LIBRARY CVD_INCLUDE_DIR)

if(CVD_FOUND)
set(CVD_INCLUDE_DIRS ${CVD_INCLUDE_DIR})
set(CVD_LIBRARIES ${CVD_LIBRARY})
set(CVD_INCLUDE_DIRS ${CVD_INCLUDE_DIR} ${CVD_DEP_INCLUDES_PUBLIC})
set(CVD_LIBRARIES ${CVD_LIBRARY} ${CVD_DEP_LIBS})
endif()

mark_as_advanced(CVD_LIBRARY CVD_INCLUDE_DIR )
50 changes: 50 additions & 0 deletions cmake/CVDFindAllDeps.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
find_package(JPEG)
find_package(PNG)
find_package(TIFF)
find_package(X11)
find_package(OpenGL)
find_package(Threads REQUIRED)

include(${CMAKE_CURRENT_LIST_DIR}/CVDFindFFMPEG.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/CVDFindTooN.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/CVDFinddc1394v2.cmake)

SET(CVD_DEP_INCLUDES_PUBLIC)
SET(CVD_DEP_INCLUDES_PRIVATE)
SET(CVD_DEP_LIBS)

if(CVD_FFMPEG_FOUND)
list(APPEND CVD_DEP_INCLUDES_PRIVATE ${CVD_FFMPEG_INCLUDE_DIRS})
list(APPEND CVD_DEP_LIBS ${CVD_FFMPEG_LIBRARIES})
endif()

list(APPEND CVD_DEP_LIBS Threads::Threads)
if(JPEG_FOUND)
list(APPEND CVD_DEP_INCLUDES_PRIVATE ${JPEG_INCLUDE_DIRS})
list(APPEND CVD_DEP_LIBS ${JPEG_LIBRARIES})
endif()
if(TIFF_FOUND)
list(APPEND CVD_DEP_INCLUDES_PRIVATE ${TIFF_INCLUDE_DIRS})
list(APPEND CVD_DEP_LIBS ${TIFF_LIBRARIES})
endif()
if(PNG_FOUND)
list(APPEND CVD_DEP_INCLUDES_PRIVATE ${PNG_INCLUDE_DIRS})
list(APPEND CVD_DEP_LIBS ${PNG_LIBRARIES})
endif()
if(CVD_TooN_FOUND)
list(APPEND CVD_DEP_INCLUDES_PUBLIC ${CVD_TooN_INCLUDE_DIRS})
endif()
if(CVD_dc1394v2_FOUND)
list(APPEND CVD_DEP_INCLUDES_PRIVATE ${CVD_dc1394v2_INCLUDE_DIRS})
list(APPEND CVD_DEP_LIBS ${CVD_dc1394v2_LIBRARIES})
endif()
if(X11_FOUND)
list(APPEND CVD_DEP_INCLUDES_PUBLIC ${X11_INCLUDE_DIR})
list(APPEND CVD_DEP_LIBS ${X11_LIBRARIES})
endif()
if(OpenGL_OpenGL_FOUND)
list(APPEND CVD_DEP_LIBS ${OPENGL_gl_LIBRARY})
list(APPEND CVD_DEP_INCLUDES_PUBLIC ${OPENGL_INCLUDE_DIR})
endif()


72 changes: 72 additions & 0 deletions cmake/CVDFindFFMPEG.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
find_package(X11)
find_package(Threads REQUIRED)

find_path(CVD_AVCODEC_INCLUDE_DIR libavcodec/avcodec.h)
find_library(CVD_AVCODEC_LIBRARY NAMES avcodec)
find_path(CVD_AVDEVICE_INCLUDE_DIR libavdevice/avdevice.h)
find_library(CVD_AVDEVICE_LIBRARY NAMES avdevice)
find_path(CVD_AVFORMAT_INCLUDE_DIR libavformat/avformat.h)
find_library(CVD_AVFORMAT_LIBRARY NAMES avformat)
find_library(CVD_AVUTIL_LIBRARY NAMES avutil)
find_path(CVD_SWSCALE_INCLUDE_DIR libswscale/swscale.h)
find_library(CVD_SWSCALE_LIBRARY NAMES swscale)
find_library(CVD_SWRESAMPLE_LIBRARY NAMES swresample)
find_library(CVD_AVFILTER_LIBRARY NAMES avfilter)


FIND_PACKAGE_HANDLE_STANDARD_ARGS(CVD_FFMPEG REQUIRED_VARS
CVD_AVCODEC_INCLUDE_DIR CVD_AVCODEC_LIBRARY CVD_AVDEVICE_INCLUDE_DIR
CVD_AVDEVICE_LIBRARY CVD_AVFORMAT_INCLUDE_DIR CVD_AVFORMAT_LIBRARY
CVD_AVUTIL_LIBRARY CVD_SWSCALE_INCLUDE_DIR CVD_SWSCALE_LIBRARY
CVD_SWRESAMPLE_LIBRARY CVD_AVFILTER_LIBRARY)

if(CVD_FFMPEG_FOUND)
message(STATUS "FFMPEG - found")

set(CVD_FFMPEG_INCLUDE_DIRS ${CVD_AVCODEC_INCLUDE_DIR}
${CVD_AVDEVICE_INCLUDE_DIR} ${CVD_AVFORMAT_INCLUDE_DIR}
${CVD_SWSCALE_INCLUDE_DIR})

set(CVD_FFMPEG_LIBRARIES
${CVD_AVDEVICE_LIBRARY}
${CVD_AVFILTER_LIBRARY}
${CVD_AVFORMAT_LIBRARY}
${CVD_AVCODEC_LIBRARY}
${CVD_AVUTIL_LIBRARY}
${CVD_SWSCALE_LIBRARY}
${CVD_SWRESAMPLE_LIBRARY}
)


set(CVD_FFMPEG_LIKELY_X_LIBS xcb-xfixes xcb-shape xcb-shm xcb)
foreach(l IN LISTS CVD_FFMPEG_LIKELY_X_LIBS)
find_library(CVD_TMP_${l} NAMES ${l})
if(NOT (CVD_TMP_${l} STREQUAL "CVD_TMP_${l}-NOTFOUND"))
message(STATUS "Found ${l}: ${CVD_TMP_${l}}")
list(APPEND CVD_FFMPEG_LIBRARIES ${CVD_TMP_${l}})
endif()
endforeach()

list(APPEND CVD_FFMPEG_LIBRARIES ${CMAKE_DL_LIBS} Threads::Threads)

if(X11_FOUND)
list(APPEND CVD_FFMPEG_LIBRARIES ${X11_LIBRARIES})
endif()
if(X11_Xv_FOUND)
list(APPEND CVD_FFMPEG_LIBRARIES ${X11_Xv_LIB})
endif()
if(X11_Xext_FOUND)
list(APPEND CVD_FFMPEG_LIBRARIES ${X11_Xext_LIB})
endif()
if(X11_Xau_FOUND)
list(APPEND CVD_FFMPEG_LIBRARIES ${X11_Xau_LIB})
endif()
if(X11_Xdmcp_FOUND)
list(APPEND CVD_FFMPEG_LIBRARIES ${X11_Xdmcp_LIB})
endif()
else()
message(STATUS "FFMPEG - not found")
endif()



25 changes: 25 additions & 0 deletions cmake/CVDFindTooN.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#.rst:
# CVDFindTooN
# -----------
#
# Find the native TooN includes.
#
# Result Variables
# ^^^^^^^^^^^^^^^^
#
# This module defines the following variables:
#
# ::
#
# CVD_TooN_INCLUDE_DIRS - where to find the TooN includes.
# CVD_TooN_FOUND - True if TooN found.

find_path(CVD_TooN_INCLUDE_DIR NAMES TooN/TooN.h PATH_SUFFIXES include)

FIND_PACKAGE_HANDLE_STANDARD_ARGS(CVD_TooN REQUIRED_VARS CVD_TooN_INCLUDE_DIR)

if(CVD_TooN_FOUND)
set(CVD_TooN_INCLUDE_DIRS ${CVD_TooN_INCLUDE_DIR})
endif()

mark_as_advanced(CVD_TooN_INCLUDE_DIR )
20 changes: 20 additions & 0 deletions cmake/CVDFinddc1394v2.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# This module defines the following variables:
#
# ::
#
# CVD_dc1394v2_INCLUDE_DIRS - where to find the dc1394v2 includes.
# CVD_dc1394v2_LIBRARIES - where to find the dc1394v2 libraries.
# CVD_dc1394v2_FOUND - True if dc1394v2 found.

find_path(CVD_dc1394_INCLUDE_DIR NAMES dc1394/control.h PATH_SUFFIXES include)

find_library(CVD_dc1394_LIBRARY NAMES dc1394 PATH_SUFFIXES lib)
find_library(CVD_raw1394_LIBRARY NAMES raw1394 PATH_SUFFIXES lib)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(CVD_dc1394v2 REQUIRED_VARS CVD_dc1394_INCLUDE_DIR CVD_dc1394_LIBRARY CVD_raw1394_LIBRARY)

if(CVD_dc1394v2_FOUND)
set(CVD_dc1394v2_INCLUDE_DIRS ${CVD_dc1394_INCLUDE_DIR})
set(CVD_dc1394v2_LIBRARIES ${CVD_dc1394_LIBRARY} ${CVD_raw1394_LIBRARY})
endif()

mark_as_advanced(CVD_dc1394_INCLUDE_DIR CVD_dc1394_LIBRARY CVD_raw1394_LIBRARY)
25 changes: 0 additions & 25 deletions cmake/FindTooN.cmake

This file was deleted.

29 changes: 0 additions & 29 deletions cmake/Finddc1394v2.cmake

This file was deleted.

0 comments on commit 08b0e07

Please sign in to comment.