Skip to content
This repository has been archived by the owner on May 3, 2021. It is now read-only.

Commit

Permalink
Converting OpenCV over to an external project (Win32)
Browse files Browse the repository at this point in the history
* Removed OpenCV directory association with InitialSetup_Win32.bat
* Updated cmake scripts to use external project (Windows only)
  • Loading branch information
HipsterSloth committed Aug 6, 2016
1 parent 31dde02 commit c28f045
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 36 deletions.
68 changes: 64 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
cmake_minimum_required(VERSION 3.0)
project(PSMoveService VERSION 0.0.1)
include(ExternalProject)

set(ROOT_DIR ${CMAKE_CURRENT_LIST_DIR})

LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
IF (NOT MSVC)
Expand Down Expand Up @@ -30,15 +33,72 @@ endif()

# When not using MSVC, we recommend using system-wide libraries
# (installed via homebrew on Mac or apt-get in Linux/Ubuntu)
# In MSVC, we recommend downloading pre-compiled binaries where
# possible, and building Protobuf yourself (see README.md)
# In MSVC, we auto-download the source and make it an external_project

# OpenCV
# Override by adding "-DOpenCV_DIR=C:\path\to\opencv\build" to your cmake command
IF(NOT OpenCV_DIR)
IF(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
# Default location of pre-compiled OpenCV for Windows
set(OpenCV_DIR "C:/OpenCV-3.1.0/build")# CACHE PATH "Path to OpenCV" FORCE)
ExternalProject_Add(opencv
PREFIX ${ROOT_DIR}/deps/opencv
GIT_REPOSITORY https://github.com/opencv/opencv.git
GIT_TAG 3.1.0
CMAKE_GENERATOR ${gen}
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
-DCMAKE_INCLUDE_PATH=${ROOT_DIR}/deps/local/include
-DCMAKE_LIBRARY_PATH=${ROOT_DIR}/deps/local/lib
-DBUILD_WITH_STATIC_CRT:BOOL=ON
-DBUILD_SHARED_LIBS:BOOL=OFF
-DBUILD_DOCS:BOOL=OFF
-DBUILD_EXAMPLES:BOOL=OFF
-DBUILD_PACKAGE:BOOL=OFF
-DBUILD_TESTS:BOOL=OFF
-DBUILD_PERF_TESTS:BOOL=OFF
#-DCMAKE_BUILD_TYPE:STRING=Release
-DWITH_FFMPEG:BOOL=OFF
-DWITH_OPENEXR:BOOL=OFF
-DWITH_JASPER:BOOL=OFF
-DWITH_TIFF:BOOL=OFF
-DWITH_IPP:BOOL=OFF
-DBUILD_NEW_PYTHON_SUPPORT:BOOL=OFF
-DBUILD_opencv_apps:BOOL=OFF
-DBUILD_opencv_calib3d:BOOL=ON
-DBUILD_opencv_flann:BOOL=ON
-DBUILD_opencv_features2d:BOOL=ON
-DBUILD_opencv_objdetect:BOOL=ON
-DBUILD_opencv_photo:BOOL=ON
-DBUILD_opencv_ts:BOOL=OFF
-DBUILD_opencv_ml:BOOL=ON
-DBUILD_opencv_video:BOOL=ON
-DBUILD_opencv_java:BOOL=OFF
-DBUILD_opencv_python2:BOOL=OFF
-DBUILD_opencv_python3:BOOL=OFF
INSTALL_DIR ${ROOT_DIR}/deps/local/
)

add_definitions(-DHAS_OPENCV)

set(OpenCV_DIR ${ROOT_DIR}/deps/local)
set(OpenCV_INCLUDE_DIRS ${ROOT_DIR}/deps/local/include )
if (${CMAKE_C_SIZEOF_DATA_PTR} EQUAL 8)
set(OPENCV_LIBS_DIR ${ROOT_DIR}/deps/local/x64/vc14/staticlib)
else()
set(OPENCV_LIBS_DIR ${ROOT_DIR}/deps/local/x86/vc14/staticlib)
endif()

foreach(__CVLIB core calib3d features2d imgproc imgcodecs ml highgui objdetect video videoio)
set(OpenCV_${__CVLIB}_LIBRARY debug ${OPENCV_LIBS_DIR}/opencv_${__CVLIB}310d.lib optimized ${OPENCV_LIBS_DIR}/opencv_${__CVLIB}310.lib CACHE STRING "" FORCE)
set(OpenCV_LIBS ${OpenCV_LIBS} ${OpenCV_${__CVLIB}_LIBRARY})
endforeach(__CVLIB)

foreach(__CVLIB libjpeg libpng libwebp zlib)
set(OpenCV_${__CVLIB}_LIBRARY debug ${OPENCV_LIBS_DIR}/${__CVLIB}d.lib optimized ${OPENCV_LIBS_DIR}/${__CVLIB}.lib CACHE STRING "" FORCE)
set(OpenCV_LIBS ${OpenCV_LIBS} ${OpenCV_${__CVLIB}_LIBRARY})
endforeach(__CVLIB)

LIST(APPEND OpenCV_LIBS vfw32.lib)

ELSEIF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
# Location of homebrew opencv3
# Alternatively, can do `brew ln opencv3 --force`
Expand Down
2 changes: 1 addition & 1 deletion GenerateProjectFiles_Win32.bat
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ IF NOT EXIST build mkdir build
cd build

echo "Rebuilding PSMoveService Project files..."
cmake .. -G "Visual Studio 14 2015" -DOpenCV_DIR=%OPENCV_BUILD_PATH% -DBOOST_ROOT=%BOOST_ROOT_PATH% -DBOOST_LIBRARYDIR=%BOOST_LIB_PATH% -DPROTOBUF_SRC_ROOT_FOLDER=..\thirdparty\protobuf
cmake .. -G "Visual Studio 14 2015" -DBOOST_ROOT=%BOOST_ROOT_PATH% -DBOOST_LIBRARYDIR=%BOOST_LIB_PATH% -DPROTOBUF_SRC_ROOT_FOLDER=..\thirdparty\protobuf
pause
10 changes: 0 additions & 10 deletions InitialSetup_Win32.bat
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
@echo off
setlocal

::Select the path to the root opencv folder
set "psCommand="(new-object -COM 'Shell.Application')^
.BrowseForFolder(0,'Please select the root folder for Opencv (ex: c:\OpenCV-3.1.0).',0,0).self.path""
for /f "usebackq delims=" %%I in (`powershell %psCommand%`) do set "OPENCV_ROOT_PATH=%%I"
if NOT DEFINED OPENCV_ROOT_PATH (goto failure)

::Select the path to the root Boost folder
set "psCommand="(new-object -COM 'Shell.Application')^
.BrowseForFolder(0,'Please select the root folder for Boost (ex: c:\local\boost_1_61_0).',0,0).self.path""
for /f "usebackq delims=" %%I in (`powershell %psCommand%`) do set "BOOST_ROOT_PATH=%%I"
if NOT DEFINED BOOST_ROOT_PATH (goto failure)

::Substitute backslashes to forward slashes
set FWD_SLASH_OPENCV_ROOT_PATH=%OPENCV_ROOT_PATH:\=/%

:: Write out the paths to a config batch file
del SetBuildVars_Win32.bat
echo @echo off >> SetBuildVars_Win32.bat
echo set OPENCV_BUILD_PATH=%FWD_SLASH_OPENCV_ROOT_PATH%/build >> SetBuildVars_Win32.bat
echo set BOOST_ROOT_PATH=%BOOST_ROOT_PATH% >> SetBuildVars_Win32.bat
echo set BOOST_LIB_PATH=%BOOST_ROOT_PATH%/lib32-msvc-14.0 >> SetBuildVars_Win32.bat

Expand Down
12 changes: 5 additions & 7 deletions src/psmoveconfigtool/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,8 @@ list(APPEND PSMOVECONFIGTOOL_REQ_LIBS ${OPENVR_LIBRARIES})

# OpenCV
set(OpenCV_STATIC ON)
IF(NOT(${CMAKE_SYSTEM_NAME} MATCHES "Windows"))
FIND_PACKAGE(OpenCV REQUIRED)
IF ("${OpenCV_LIBS}" STREQUAL "")
message("OpenCV Libs was empty! Manually setting.")
list(APPEND OpenCV_LIBS opencv_core opencv_imgproc opencv_calib3d opencv_video opencv_features2d opencv_ml opencv_highgui opencv_objdetect)
ENDIF()
IF ("${OpenCV_INCLUDE_DIRS}" STREQUAL "" AND ${OpenCV_DIR})
message("OpenCV include dirs was empty! Manually setting.")
set (OpenCV_INCLUDE_DIRS ${OpenCV_DIR}\include)
ENDIF()
list(APPEND PSMOVECONFIGTOOL_INCL_DIRS ${OpenCV_INCLUDE_DIRS})
list(APPEND PSMOVECONFIGTOOL_REQ_LIBS ${OpenCV_LIBS})
Expand All @@ -75,6 +69,10 @@ add_executable(PSMoveConfigTool ${PSMOVECONFIGTOOL_SRC})
target_include_directories(PSMoveConfigTool PUBLIC ${PSMOVECONFIGTOOL_INCL_DIRS})
target_link_libraries(PSMoveConfigTool ${PSMOVECONFIGTOOL_REQ_LIBS})

IF(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
add_dependencies(PSMoveService opencv)
ENDIF()

# Allow access to the protocol buffers (extracting response parameters)
target_compile_definitions(PSMoveConfigTool PRIVATE HAS_PROTOCOL_ACCESS)

Expand Down
13 changes: 6 additions & 7 deletions src/psmoveservice/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,9 @@ list(APPEND PSMOVE_SERVICE_REQ_LIBS PSMoveMath)

# OpenCV
set(OpenCV_STATIC ON)

IF(NOT(${CMAKE_SYSTEM_NAME} MATCHES "Windows"))
FIND_PACKAGE(OpenCV REQUIRED)
IF ("${OpenCV_LIBS}" STREQUAL "")
message("OpenCV Libs was empty! Manually setting.")
list(APPEND OpenCV_LIBS opencv_core opencv_imgproc opencv_calib3d opencv_video opencv_features2d opencv_ml opencv_highgui opencv_objdetect)
ENDIF()
IF ("${OpenCV_INCLUDE_DIRS}" STREQUAL "" AND ${OpenCV_DIR})
message("OpenCV include dirs was empty! Manually setting.")
set (OpenCV_INCLUDE_DIRS ${OpenCV_DIR}\include)
ENDIF()
list(APPEND PSMOVE_SERVICE_INCL_DIRS ${OpenCV_INCLUDE_DIRS})
list(APPEND PSMOVE_SERVICE_REQ_LIBS ${OpenCV_LIBS})
Expand Down Expand Up @@ -234,6 +229,10 @@ add_executable(PSMoveService ${PSMOVESERVICE_SRC})
target_include_directories(PSMoveService PUBLIC ${PSMOVE_SERVICE_INCL_DIRS})
target_link_libraries(PSMoveService ${PSMOVE_SERVICE_REQ_LIBS})

IF(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
add_dependencies(PSMoveService opencv)
ENDIF()

# Only set the admin privilege escalation on MSVC builds (for service operations)
IF(MSVC)
set_target_properties(PSMoveService PROPERTIES LINK_FLAGS "/level='requireAdministrator' /uiAccess='false'")
Expand Down
11 changes: 4 additions & 7 deletions src/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,8 @@ list(APPEND TEST_CAMERA_REQ_LIBS ${Boost_LIBRARIES})

# OpenCV
set(OpenCV_STATIC ON)
IF(NOT(${CMAKE_SYSTEM_NAME} MATCHES "Windows"))
FIND_PACKAGE(OpenCV REQUIRED)
IF ("${OpenCV_LIBS}" STREQUAL "")
message("OpenCV Libs was empty! Manually setting.")
list(APPEND OpenCV_LIBS opencv_core opencv_imgproc opencv_calib3d opencv_video opencv_features2d opencv_ml opencv_highgui opencv_objdetect)
ENDIF()
IF ("${OpenCV_INCLUDE_DIRS}" STREQUAL "" AND ${OpenCV_DIR})
message("OpenCV include dirs was empty! Manually setting.")
set (OpenCV_INCLUDE_DIRS ${OpenCV_DIR}\include)
ENDIF()
list(APPEND TEST_CAMERA_INCL_DIRS ${OpenCV_INCLUDE_DIRS})
list(APPEND TEST_CAMERA_REQ_LIBS ${OpenCV_LIBS})
Expand Down Expand Up @@ -155,6 +149,9 @@ list(APPEND TEST_CAMERA_SRC
add_executable(test_camera ${CMAKE_CURRENT_LIST_DIR}/test_camera.cpp ${TEST_CAMERA_SRC})
target_include_directories(test_camera PUBLIC ${TEST_CAMERA_INCL_DIRS})
target_link_libraries(test_camera ${PLATFORM_LIBS} ${TEST_CAMERA_REQ_LIBS})
IF(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
add_dependencies(test_camera opencv)
ENDIF()
SET_TARGET_PROPERTIES(test_camera PROPERTIES FOLDER Test)

IF(${ISWIN32})
Expand Down

0 comments on commit c28f045

Please sign in to comment.