Skip to content

Commit

Permalink
[cmake] some cleaning
Browse files Browse the repository at this point in the history
- remove ALICEVISION_BUILD_SHARED and rely on standard BUILD_SHARED_LIBS
- add STRIP in src/CMakeLists.txt in release mode
  • Loading branch information
fabiencastan committed Apr 27, 2020
1 parent e989b8e commit 2e1eba0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 21 deletions.
18 changes: 8 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ option(AV_BUILD_ALICEVISION "Enable building of AliceVision" ON)

option(AV_USE_CUDA "Enable CUDA" ON)

option(INSTALL_DEPS_BUILD "Install all files from dependencies (it only makes sense if ALICEVISION_BUILD_DEPENDENCIES=ON)" OFF)

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type for AliceVision" FORCE)
endif()
Expand Down Expand Up @@ -92,8 +90,7 @@ include(ExternalProject)

set(BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/external")

set(CMAKE_CORE_BUILD_FLAGS -DCMAKE_BUILD_TYPE=${DEPS_CMAKE_BUILD_TYPE} -DBUILD_SHARED_LIBS:BOOL=ON -DCMAKE_INSTALL_DO_STRIP=${CMAKE_INSTALL_DO_STRIP})
set(CMAKE_CORE_BUILD_FLAGS_NOSHARED -DCMAKE_BUILD_TYPE=${DEPS_CMAKE_BUILD_TYPE} -DCMAKE_INSTALL_DO_STRIP=${CMAKE_INSTALL_DO_STRIP})
set(CMAKE_CORE_BUILD_FLAGS -DCMAKE_BUILD_TYPE=${DEPS_CMAKE_BUILD_TYPE} -DBUILD_SHARED_LIBS:BOOL=${BUILD_SHARED_LIBS} -DCMAKE_INSTALL_DO_STRIP:BOOL=${CMAKE_INSTALL_DO_STRIP} -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER})

if(AV_BUILD_ZLIB)
set(ZLIB_TARGET zlib)
Expand Down Expand Up @@ -297,7 +294,7 @@ ExternalProject_Add(${OPENEXR_TARGET}
CONFIGURE_COMMAND ${CMAKE_COMMAND} ${CMAKE_CORE_BUILD_FLAGS} -DOPENEXR_BUILD_PYTHON_LIBS=OFF -DOPENEXR_ENABLE_TESTS=OFF ${ZLIB_CMAKE_FLAGS} -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR> <SOURCE_DIR>
DEPENDS ${ZLIB_TARGET}
)
set(ILMBASE_CMAKE_FLAGS -DILMBASE_ROOT=${CMAKE_INSTALL_PREFIX} -DILMBASE_INCLUDE_PATH=${CMAKE_INSTALL_PREFIX}/include)
set(ILMBASE_CMAKE_FLAGS -DILMBASE_ROOT=${CMAKE_INSTALL_PREFIX} -DILMBASE_INCLUDE_PATH=${CMAKE_INSTALL_PREFIX}/include/OpenEXR)
set(OPENEXR_CMAKE_FLAGS ${ILMBASE_CMAKE_FLAGS} -DOPENEXR_ROOT=${CMAKE_INSTALL_PREFIX} -DOPENEXR_INCLUDE_PATH=${CMAKE_INSTALL_PREFIX}/include)

# Add LibTiff
Expand Down Expand Up @@ -435,7 +432,7 @@ ExternalProject_Add(${OPENIMAGEIO_TARGET}
)
# TODO: openjpeg
# -DOPENJPEG_INCLUDE_DIR=$OPENJPEG_INCLUDE_DIR/openjpeg-2.0 -DOPENJPEG_OPENJP2_LIBRARIES=$OPENJPEG_OPENJP2_LIBRARIES
set(OPENIMAGEIO_CMAKE_FLAGS -DOPENIMAGEIO_LIBRARY_DIR_HINTS=${CMAKE_INSTALL_PREFIX} -DOPENIMAGEIO_INCLUDE_DIR_HINTS=${CMAKE_INSTALL_PREFIX})
set(OPENIMAGEIO_CMAKE_FLAGS -DOpenImageIO_DIR=${CMAKE_INSTALL_PREFIX})

# Add Alembic: I/O for Point Cloud and Cameras
set(ALEMBIC_TARGET alembic)
Expand Down Expand Up @@ -468,7 +465,7 @@ ExternalProject_Add(opencv_contrib
INSTALL_COMMAND ""
)
ExternalProject_Add(${OPENCV_TARGET}
DEPENDS opencv_contrib ${TBB_TARGET} ${ZLIB_TARGET}
DEPENDS opencv_contrib ${TBB_TARGET} ${ZLIB_TARGET} ${OPENEXR_TARGET} ${TIFF_TARGET} ${PNG_TARGET} ${JPEG_TARGET} ${LIBRAW_TARGET}
# URL https://github.com/opencv/opencv/archive/4.2.0.zip
# URL_MD5 b02b54115f1f99cb9e885d1e5988ff70
URL https://github.com/opencv/opencv/archive/4.1.0.zip
Expand All @@ -481,8 +478,8 @@ ExternalProject_Add(${OPENCV_TARGET}
INSTALL_DIR ${CMAKE_INSTALL_PREFIX}
CONFIGURE_COMMAND ${CMAKE_COMMAND} ${CMAKE_CORE_BUILD_FLAGS} -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR> <SOURCE_DIR>
-DOPENCV_EXTRA_MODULES_PATH=${CMAKE_CURRENT_BINARY_DIR}/opencv_contrib/modules
${ZLIB_CMAKE_FLAGS}
${TBB_CMAKE_FLAGS}
${ZLIB_CMAKE_FLAGS} ${TBB_CMAKE_FLAGS}
${TIFF_CMAKE_FLAGS} ${PNG_CMAKE_FLAGS} ${JPEG_CMAKE_FLAGS} ${LIBRAW_CMAKE_FLAGS}
-DWITH_TBB=ON
-DBUILD_opencv_python2=OFF
-DBUILD_opencv_python3=OFF
Expand All @@ -494,6 +491,7 @@ ExternalProject_Add(${OPENCV_TARGET}
-DWITH_QT=OFF
-DWITH_OPENGL=OFF
-DWITH_VTK=OFF
-DWITH_OPENEXR=OFF # Build error on IlmBase includes without "OpenEXR/" prefix
-DENABLE_PRECOMPILED_HEADERS=OFF
-DBUILD_SHARED_LIBS=ON
-DWITH_CUDA=OFF
Expand Down Expand Up @@ -575,7 +573,7 @@ ExternalProject_Add(aliceVision
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src
BINARY_DIR ${BUILD_DIR}/aliceVision_build
INSTALL_DIR ${CMAKE_INSTALL_PREFIX}
CONFIGURE_COMMAND ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DBUILD_SHARED_LIBS:BOOL=ON -DTARGET_ARCHITECTURE=core -DALICEVISION_ROOT=${ALICEVISION_ROOT} -DALICEVISION_USE_ALEMBIC=ON -DMINIGLOG=ON -DALICEVISION_USE_CCTAG=${AV_BUILD_CCTAG} -DALICEVISION_USE_OPENCV=${AV_BUILD_OPENCV} -DALICEVISION_USE_OPENGV=${AV_BUILD_OPENGV} -DALICEVISION_USE_POPSIFT=${AV_BUILD_POPSIFT} -DALICEVISION_USE_CUDA=${AV_USE_CUDA} -DALICEVISION_BUILD_DOC=OFF -DALICEVISION_BUILD_EXAMPLES=OFF ${ZLIB_CMAKE_FLAGS} ${EIGEN_CMAKE_FLAGS} ${OPENIMAGEIO_CMAKE_FLAGS} ${OPENEXR_CMAKE_FLAGS} ${BOOST_CMAKE_FLAGS} ${ALEMBIC_CMAKE_FLAGS} ${GEOGRAM_CMAKE_FLAGS} ${LAPACK_CMAKE_FLAGS} ${CERES_CMAKE_FLAGS} ${CUDA_CMAKE_FLAGS} ${POPSIFT_CMAKE_FLAGS} ${OPENGV_CMAKE_FLAGS} ${OPENCV_CMAKE_FLAGS} ${CCTAG_CMAKE_FLAGS} -DALICEVISION_BUILD_SHARED=ON -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR> <SOURCE_DIR>
CONFIGURE_COMMAND ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DBUILD_SHARED_LIBS:BOOL=ON -DTARGET_ARCHITECTURE=core -DALICEVISION_ROOT=${ALICEVISION_ROOT} -DALICEVISION_USE_ALEMBIC=ON -DMINIGLOG=ON -DALICEVISION_USE_CCTAG=${AV_BUILD_CCTAG} -DALICEVISION_USE_OPENCV=${AV_BUILD_OPENCV} -DALICEVISION_USE_OPENGV=${AV_BUILD_OPENGV} -DALICEVISION_USE_POPSIFT=${AV_BUILD_POPSIFT} -DALICEVISION_USE_CUDA=${AV_USE_CUDA} -DALICEVISION_BUILD_DOC=OFF -DALICEVISION_BUILD_EXAMPLES=OFF ${ZLIB_CMAKE_FLAGS} ${EIGEN_CMAKE_FLAGS} ${OPENIMAGEIO_CMAKE_FLAGS} ${OPENEXR_CMAKE_FLAGS} ${BOOST_CMAKE_FLAGS} ${ALEMBIC_CMAKE_FLAGS} ${GEOGRAM_CMAKE_FLAGS} ${LAPACK_CMAKE_FLAGS} ${CERES_CMAKE_FLAGS} ${CUDA_CMAKE_FLAGS} ${POPSIFT_CMAKE_FLAGS} ${OPENGV_CMAKE_FLAGS} ${OPENCV_CMAKE_FLAGS} ${CCTAG_CMAKE_FLAGS} -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR> <SOURCE_DIR>
DEPENDS ${AV_DEPS}
)
endif()
Expand Down
39 changes: 28 additions & 11 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
# ==============================================================================
# AliceVision build options
# ==============================================================================
option(ALICEVISION_BUILD_SHARED "Build AliceVision shared libs" ON)
option(ALICEVISION_BUILD_SFM "Build AliceVision SfM part" ON)
option(ALICEVISION_BUILD_MVS "Build AliceVision MVS part" ON)
option(ALICEVISION_BUILD_HDR "Build AliceVision HDR part" ON)
Expand All @@ -72,18 +71,36 @@ option(ALICEVISION_REQUIRE_CERES_WITH_SUITESPARSE "Require Ceres with SuiteSpars

option(ALICEVISION_USE_RPATH "Add RPATH on software with relative paths to libraries" ON)

option(ALICEVISION_BUILD_TESTS "Build AliceVision tests" OFF)

if(NOT DEFINED BUILD_SHARED_LIBS)
# Use shared libs by default
set(BUILD_SHARED_LIBS ON)
endif()

# Default build is in Release mode
if(NOT CMAKE_BUILD_TYPE AND NOT MSVC)
set(CMAKE_BUILD_TYPE "Release")
endif()

# ==============================================================================
# Enable cmake UNIT TEST framework
# ==============================================================================
if(ALICEVISION_BUILD_TESTS AND NOT CMAKE_TESTING_ENABLED)
enable_testing()
endif()

# ==============================================================================
# GNUInstallDirs CMake module
# - Define GNU standard installation directories
# - Provides install directory variables as defined by the GNU Coding Standards.
# ==============================================================================
include(GNUInstallDirs)

if(CMAKE_BUILD_TYPE MATCHES Release)
message(STATUS "Force CMAKE_INSTALL_DO_STRIP in Release")
set(CMAKE_INSTALL_DO_STRIP TRUE)
endif()

if(ALICEVISION_USE_RPATH)
if(APPLE)
Expand Down Expand Up @@ -125,15 +142,11 @@ if(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} VERSION_LESS 3.10)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/compatibilityCUDA)
endif()

# Set shared or static mode
if(ALICEVISION_BUILD_SHARED)
set(BUILD_SHARED_LIBS ON)
if(BUILD_SHARED_LIBS)
if(WIN32)
# Export all symbols from the dynamic libraries by default (avoid dllexport markup)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
endif()
elseif()
set(BUILD_SHARED_LIBS OFF)
endif()

# ==============================================================================
Expand Down Expand Up @@ -264,9 +277,13 @@ endif()
# Disable BOOST autolink
add_definitions(-DBOOST_ALL_NO_LIB)

# Force BOOST to use dynamic libraries (avoid link error with boost program_options)
# https://lists.boost.org/boost-users/2009/11/54015.php
add_definitions(-DBOOST_ALL_DYN_LINK)
if(BUILD_SHARED_LIBS)
# Force BOOST to use dynamic libraries (avoid link error with boost program_options)
# https://lists.boost.org/boost-users/2009/11/54015.php
add_definitions(-DBOOST_ALL_DYN_LINK)
else()
set(Boost_USE_STATIC_LIBS ON)
endif()

if(BOOST_NO_CXX11)
# Avoid link errors on boost filesystem copy_file function
Expand All @@ -289,7 +306,7 @@ endif()
# OpenImageIO
# ==============================================================================
find_package(OpenImageIO 1.8 REQUIRED)
if(OPENIMAGEIO_FOUND)
if(OPENIMAGEIO_FOUND OR OpenImageIO_FOUND)
message(STATUS "OpenImageIO found.")
if(UNIX)
# Add DL dependency on linux
Expand Down Expand Up @@ -885,7 +902,7 @@ endif()
# ==============================================================================
message("\n")
message("** AliceVision version: " ${ALICEVISION_VERSION})
message("** Build Shared libs: " ${ALICEVISION_BUILD_SHARED})
message("** Build Shared libs: " ${BUILD_SHARED_LIBS})
message("** Build SfM part: " ${ALICEVISION_BUILD_SFM})
message("** Build MVS part: " ${ALICEVISION_BUILD_MVS})
message("** Build AliceVision tests: " ${ALICEVISION_BUILD_TESTS})
Expand Down

0 comments on commit 2e1eba0

Please sign in to comment.