From 22ee1c0c0ccf6267f7f95c64630891914a6a13b6 Mon Sep 17 00:00:00 2001 From: Andrews Sobral <andrewssobral@gmail.com> Date: Sun, 26 Feb 2017 00:33:00 +0100 Subject: [PATCH] Some fixes on CMakeLists --- .gitignore | 6 +-- CMakeLists.txt | 83 +++++++++++++++++++++++++----------------- README_CMAKE_USERS.txt | 63 +++++++++++++++----------------- run_camera.sh | 3 +- run_demo.bat | 3 ++ run_demo.sh | 1 - run_demo2.bat | 3 ++ run_demo2.sh | 2 + run_video.sh | 3 +- 9 files changed, 91 insertions(+), 76 deletions(-) create mode 100644 run_demo.bat create mode 100644 run_demo2.bat create mode 100644 run_demo2.sh diff --git a/.gitignore b/.gitignore index 905cdaf..3f5e0f7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ etc/ +build_*/ binaries/ -package_bgs/pt/ java_gui/dist/ java_gui/build/ java_gui/bgslibrary.exe @@ -9,6 +9,4 @@ qt_gui/ fet/etc/ *.exe *.pdb -vs2010mfc/src/bgslibrary_vs2010_mfc.aps -*.suo -vs2010mfc/src/bgslibrary_vs2010_mfc.v12.suo \ No newline at end of file +*.suo \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 03338e5..d8e60da 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,20 +1,33 @@ cmake_minimum_required(VERSION 2.8) -project(bgs) +project(bgslibrary) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99") #set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake-modules) +set( bgs_out_dir "." ) +# First for the generic no-config case (e.g. with mingw) +set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${bgs_out_dir} ) +set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${bgs_out_dir} ) +set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${bgs_out_dir} ) +# Second, for multi-config builds (e.g. msvc) +foreach( OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES} ) + string( TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG ) + set( CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${bgs_out_dir} ) + set( CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${bgs_out_dir} ) + set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${bgs_out_dir} ) +endforeach( OUTPUTCONFIG CMAKE_CONFIGURATION_TYPES ) + IF(UNIX) - # add some standard warnings - ADD_DEFINITIONS(-Wno-variadic-macros -Wno-long-long -Wall -Wextra -Winit-self -Woverloaded-virtual -Wsign-promo -Wno-unused-parameter -pedantic -Woverloaded-virtual -Wno-unknown-pragmas) - - # -ansi does not compile with sjn module - #ADD_DEFINITIONS(-ansi) - - # if you like to have warinings about conversions, e.g. double->int or double->float etc., or float compare - #ADD_DEFINITIONS(-Wconversion -Wfloat-equal) + # add some standard warnings + ADD_DEFINITIONS(-Wno-variadic-macros -Wno-long-long -Wall -Wextra -Winit-self -Woverloaded-virtual -Wsign-promo -Wno-unused-parameter -pedantic -Woverloaded-virtual -Wno-unknown-pragmas) + + # -ansi does not compile with sjn module + #ADD_DEFINITIONS(-ansi) + + # if you like to have warinings about conversions, e.g. double->int or double->float etc., or float compare + #ADD_DEFINITIONS(-Wconversion -Wfloat-equal) endif(UNIX) find_package(OpenCV REQUIRED) @@ -25,11 +38,11 @@ message(STATUS " libraries: ${OpenCV_LIBS}") message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}") if(${OpenCV_VERSION} VERSION_EQUAL 3 OR ${OpenCV_VERSION} VERSION_GREATER 3) - message (FATAL_ERROR "OpenCV version is not compatible: ${OpenCV_VERSION}") + message(FATAL_ERROR "OpenCV version is not compatible: ${OpenCV_VERSION}") endif() if(${OpenCV_VERSION} VERSION_LESS 2.3.1) - message (FATAL_ERROR "OpenCV version is not compatible: ${OpenCV_VERSION}") + message(FATAL_ERROR "OpenCV version is not compatible: ${OpenCV_VERSION}") endif() file(GLOB sources FrameProcessor.cpp PreProcessor.cpp VideoAnalysis.cpp VideoCapture.cpp) @@ -37,40 +50,44 @@ file(GLOB main Main.cpp) file(GLOB demo Demo.cpp) file(GLOB demo2 Demo2.cpp) -list(REMOVE_ITEM sources ${demo} ${demo2}) +# list(REMOVE_ITEM sources ${demo} ${demo2}) -file(GLOB_RECURSE analysis package_analysis/*.cpp) -file(GLOB_RECURSE bgs package_bgs/*.cpp package_bgs/*.c) +file(GLOB_RECURSE analysis_src package_analysis/*.cpp) +file(GLOB_RECURSE bgs_src package_bgs/*.cpp package_bgs/*.c) file(GLOB_RECURSE bgs_include package_bgs/*.h) # GMG is not available in older OpenCV versions if(${OpenCV_VERSION} VERSION_LESS 2.4.3) - file(GLOB gmg package_bgs/GMG.cpp) - list(REMOVE_ITEM bgs ${gmg}) + file(GLOB gmg package_bgs/GMG.cpp) + list(REMOVE_ITEM bgs_src ${gmg}) endif() include_directories(${CMAKE_SOURCE_DIR}) -add_library(bgs SHARED ${sources} ${bgs} ${analysis}) -target_link_libraries(bgs ${OpenCV_LIBS}) -set_property(TARGET bgs PROPERTY PUBLIC_HEADER ${bgs_include}) +add_library(libbgs STATIC ${sources} ${bgs_src} ${analysis_src}) +target_link_libraries(libbgs ${OpenCV_LIBS}) +set_property(TARGET libbgs PROPERTY PUBLIC_HEADER ${bgs_include}) +if(WIN32) + # set_property(TARGET libbgs PROPERTY SUFFIX ".lib") +else() + set_property(TARGET libbgs PROPERTY OUTPUT_NAME "bgs") +endif() -add_executable(bgs_bin ${main}) -target_link_libraries(bgs_bin ${OpenCV_LIBS} bgs) -set_target_properties(bgs_bin - PROPERTIES OUTPUT_NAME bgs) +add_executable(bgslibrary ${main}) +target_link_libraries(bgslibrary ${OpenCV_LIBS} libbgs) +# set_target_properties(bgslibrary PROPERTIES OUTPUT_NAME bgs) add_executable(bgs_demo ${demo}) -target_link_libraries(bgs_demo ${OpenCV_LIBS} bgs) +target_link_libraries(bgs_demo ${OpenCV_LIBS} libbgs) add_executable(bgs_demo2 ${demo2}) -target_link_libraries(bgs_demo2 ${OpenCV_LIBS} bgs) - -INSTALL(TARGETS bgs - bgs_bin - RUNTIME DESTINATION bin COMPONENT app - LIBRARY DESTINATION lib COMPONENT runtime - ARCHIVE DESTINATION lib COMPONENT runtime - PUBLIC_HEADER DESTINATION include/package_bgs COMPONENT dev - FRAMEWORK DESTINATION "/Library/Frameworks" +target_link_libraries(bgs_demo2 ${OpenCV_LIBS} libbgs) + +INSTALL(TARGETS libbgs + bgslibrary + RUNTIME DESTINATION bin COMPONENT app + LIBRARY DESTINATION lib COMPONENT runtime + ARCHIVE DESTINATION lib COMPONENT runtime + PUBLIC_HEADER DESTINATION include/package_bgs COMPONENT dev + FRAMEWORK DESTINATION "/Library/Frameworks" ) diff --git a/README_CMAKE_USERS.txt b/README_CMAKE_USERS.txt index 9e4a680..974e941 100644 --- a/README_CMAKE_USERS.txt +++ b/README_CMAKE_USERS.txt @@ -1,14 +1,14 @@ ------------------------------------------------- -------------- WINDOWS CMAKE USERS -------------- -How to build BGSLibrary with OpenCV 2.4.10 and Visual Studio 2010 from CMAKE. +How to build BGSLibrary with OpenCV 2.4.10 and Visual Studio 2013 from CMAKE. For Linux users, please see the instruction in README_LINUX_USERS.txt file. Dependencies: * GIT (tested with git version 2.7.2.windows.1). * CMAKE for Windows (tested with cmake version 3.1.1). -* Microsoft Visual Studio (tested with VS2015). +* Microsoft Visual Studio (tested with VS2013). Please follow the instructions below: @@ -24,59 +24,54 @@ e.g.: C:\bgslibrary\build>_ e.g.: \> setlocal \> set OpenCV_DIR=C:\OpenCV2.4.10\build -\> cmake -DOpenCV_DIR=%OpenCV_DIR% -G "Visual Studio 10" .. +\> cmake -DOpenCV_DIR=%OpenCV_DIR% -G "Visual Studio 12" .. or: -\> cmake -DOpenCV_DIR=%OpenCV_DIR% -G "Visual Studio 10 Win64" .. +\> cmake -DOpenCV_DIR=%OpenCV_DIR% -G "Visual Studio 12 Win64" .. -Now, you will see something like: +Now, you will see something like (for win64): ------------------------------------------------- -C:\bgslibrary\build>cmake -DOpenCV_DIR=C:\OpenCV2.4.10\build -G "Visual Studio 10" .. --- The C compiler identification is MSVC 16.0.40219.1 --- The CXX compiler identification is MSVC 16.0.40219.1 --- Check for working C compiler using: Visual Studio 10 2010 --- Check for working C compiler using: Visual Studio 10 2010 -- works +-- The C compiler identification is MSVC 18.0.40629.0 +-- The CXX compiler identification is MSVC 18.0.40629.0 +-- Check for working C compiler using: Visual Studio 12 2013 Win64 +-- Check for working C compiler using: Visual Studio 12 2013 Win64 -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done --- Check for working CXX compiler using: Visual Studio 10 2010 --- Check for working CXX compiler using: Visual Studio 10 2010 -- works +-- Check for working CXX compiler using: Visual Studio 12 2013 Win64 +-- Check for working CXX compiler using: Visual Studio 12 2013 Win64 -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done --- OpenCV ARCH: x86 --- OpenCV RUNTIME: vc10 +-- Detecting CXX compile features +-- Detecting CXX compile features - done +-- OpenCV ARCH: x64 +-- OpenCV RUNTIME: vc12 -- OpenCV STATIC: OFF --- Found OpenCV 2.4.10 in C:/OpenCV2.4.10/build/x86/vc10/lib --- You might need to add C:\OpenCV2.4.10\build\x86\vc10\bin to your PATH to be able to run your appl -ications. +-- Found OpenCV 2.4.10 in C:/OpenCV2.4.10/build/x64/vc12/lib +-- You might need to add C:\OpenCV2.4.10\build\x64\vc12\bin to your PATH to be able to run your applications. -- Configuring done -- Generating done --- Build files have been written to: E:/GitHubbkp2/bgslibrary_opencv2/build -C:\bgslibrary\build> +-- Build files have been written to: C:/bgslibrary/build ------------------------------------------------- 3) Include OpenCV binaries in the system path: -\> set PATH=%PATH%;%OpenCV_DIR%\x86\vc10\bin +\> set PATH=%PATH%;%OpenCV_DIR%\x86\vc12\bin or: -\> set PATH=%PATH%;%OpenCV_DIR%\x64\vc10\bin +\> set PATH=%PATH%;%OpenCV_DIR%\x64\vc12\bin 4) Open 'bgs.sln' in Visual Studio and switch to 'RELEASE' mode -4.1) Note if you are using a Visual Studio version superior than 10, you will need to CANCEL the project wizard update. However, you can go to step (2) and change the Visual Studio version, e.g.: -G "Visual Studio XXX", where XXX is your Visual Studio version. +4.1) Note if you are using a Visual Studio version superior than 2013, you will need to CANCEL the project wizard update. However, you can go to step (2) and change the Visual Studio version, e.g.: -G "Visual Studio XX", where XX is your Visual Studio version. -5) Click on 'bgs' project, and set: -[Configuration Type] Static library (.lib) -[Target Extension] .lib +5) Click on 'ALL_BUILD' project and build! -6) Click on 'ALL_BUILD' project and build! +6) If everything goes well, you can run bgslibrary in the Windows console as follows: -7) If everything goes well, you can run bgslibrary in the Windows console as follows: +6.1) Running BGSLibrary with a webcamera: +C:\bgslibrary> build\bgslibrary.exe --use_cam --camera=0 -7.1) Running BGSLibrary with a webcamera: -C:\bgslibrary> build\Release\bgs.exe --use_cam --camera=0 +6.2) Running demo code: +C:\bgslibrary> build\bgs_demo.exe dataset/video.avi -7.2) Running demo code: -C:\bgslibrary> build\Release\bgs_demo.exe dataset/video.avi - -7.3) Running demo2 code: -C:\bgslibrary> build\Release\bgs_demo2.exe +6.3) Running demo2 code: +C:\bgslibrary> build\bgs_demo2.exe Additional information: * Note that bgslibrary requires a 'config' folder in the working directory. diff --git a/run_camera.sh b/run_camera.sh index f000519..7e8abe5 100644 --- a/run_camera.sh +++ b/run_camera.sh @@ -1,3 +1,2 @@ #!/bin/bash -./build/bgs --use_cam --camera=0 - +./build/bgslibrary --use_cam --camera=0 diff --git a/run_demo.bat b/run_demo.bat new file mode 100644 index 0000000..216799f --- /dev/null +++ b/run_demo.bat @@ -0,0 +1,3 @@ +@echo off +cls +build\bgs_demo.exe dataset/video.avi \ No newline at end of file diff --git a/run_demo.sh b/run_demo.sh index e734f06..2a7777d 100644 --- a/run_demo.sh +++ b/run_demo.sh @@ -1,3 +1,2 @@ #!/bin/bash ./build/bgs_demo dataset/video.avi - diff --git a/run_demo2.bat b/run_demo2.bat new file mode 100644 index 0000000..c7aba15 --- /dev/null +++ b/run_demo2.bat @@ -0,0 +1,3 @@ +@echo off +cls +build\bgs_demo2.exe \ No newline at end of file diff --git a/run_demo2.sh b/run_demo2.sh new file mode 100644 index 0000000..910099c --- /dev/null +++ b/run_demo2.sh @@ -0,0 +1,2 @@ +#!/bin/bash +./build/bgs_demo2 diff --git a/run_video.sh b/run_video.sh index 0ae1bcb..38d86d9 100644 --- a/run_video.sh +++ b/run_video.sh @@ -1,3 +1,2 @@ #!/bin/bash -./build/bgs -uf -fn=dataset/video.avi - +./build/bgslibrary -uf -fn=dataset/video.avi -- GitLab