@@ -7,24 +7,69 @@ include(ExternalProject)
77
88project (CCTag VERSION 1.0.0 LANGUAGES C CXX)
99
10+ # Set build path as a folder named as the platform (linux, windows, darwin...) plus the processor type
11+ set (CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR} /${CMAKE_SYSTEM_NAME} -${CMAKE_SYSTEM_PROCESSOR} " )
12+ set (CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR} /${CMAKE_SYSTEM_NAME} -${CMAKE_SYSTEM_PROCESSOR} " )
13+
14+ include (GNUInstallDirs)
15+
1016#CMakeDependentOption
1117option (CCTAG_SERIALIZE "Store all the output" OFF )
1218option (CCTAG_VISUAL_DEBUG "Enable visual debug" OFF )
1319option (CCTAG_NO_COUT "Disable output stream" ON )
1420option (CCTAG_WITH_CUDA "Compile the library with CUDA support" ON )
15- option (BUILD_APPS "Build the sample applications" ON )
21+ option (CCTAG_BUILD_APPS "Build the sample applications" ON )
1622option (CCTAG_CUDA_CC_CURRENT_ONLY "Set to on to build only for the current machine's CC" OFF )
1723option (CCTAG_NVCC_WARNINGS "Switch on several additional warnings for CUDA nvcc." OFF )
24+ option (CCTAG_EIGEN_NO_ALIGN "Disable Eigen alignment" ON )
1825
1926option (CCTAG_USE_POSITION_INDEPENDENT_CODE "Generate position independent code." ON )
2027option (CCTAG_ENABLE_SIMD_AVX2 "Enable AVX2 optimizations" OFF )
21- option (BUILD_TESTS "Build the unity tests" ON )
28+ option (CCTAG_BUILD_TESTS "Build the unity tests" ON )
2229option (CCTAG_NO_THRUST_COPY_IF "Do not use thrust::copy_if() on GPU. There may be a bug on CUDA 7 with GTX 980, 980Ti and 1080" OFF )
2330
24- if (NOT CMAKE_BUILD_TYPE AND NOT MSVC )
25- set (CMAKE_BUILD_TYPE "Release" )
31+ set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR} /cmake" )
32+
33+ # set(CMAKE_BUILD_TYPE Debug)
34+ if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES )
35+ set (CMAKE_BUILD_TYPE Release)
36+ message (STATUS "Build type not set, building in Release configuration" )
37+ # Set the possible values of build type for cmake-gui
38+ set_property (CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo" )
39+ else ()
40+ message (STATUS "Building in ${CMAKE_BUILD_TYPE} configuration" )
41+ endif ()
42+
43+ # ensure the proper linker flags when building the static version on MSVC
44+ if (MSVC AND NOT BUILD_SHARED_LIBS )
45+ foreach (config "DEBUG" "RELEASE" "MINSIZEREL" "RELWITHDEBINFO" )
46+ string (REPLACE /MD /MT CMAKE_C_FLAGS_${config} "${CMAKE_C_FLAGS_${config} }" )
47+ string (REPLACE /MD /MT CMAKE_CXX_FLAGS_${config} "${CMAKE_CXX_FLAGS_${config} }" )
48+ message (STATUS "CMAKE_C_FLAGS_${config} ${CMAKE_C_FLAGS_${config} }" )
49+ message (STATUS "CMAKE_CXX_FLAGS_${config} ${CMAKE_CXX_FLAGS_${config} }" )
50+ endforeach ()
2651endif ()
2752
53+ # this is to ensure that on MSVC the flags for the linker are properly propagate even to the intermediate
54+ # linking step. This seems not the case e.g. on vcpkg using ninja build.
55+ if (MSVC AND CMAKE_GENERATOR MATCHES "Ninja" )
56+ if (BUILD_SHARED_LIBS )
57+ set (CCTAG_MVSC_LINKER "/MD" )
58+ else ()
59+ set (CCTAG_MVSC_LINKER "/MT" )
60+ endif ()
61+ if (CMAKE_BUILD_TYPE STREQUAL "Debug" )
62+ set (CCTAG_MVSC_LINKER "${CCTAG_MVSC_LINKER} d" )
63+ endif ()
64+ list (APPEND CUDA_NVCC_FLAGS -Xcompiler ${CCTAG_MVSC_LINKER} )
65+ endif ()
66+
67+ set (CMAKE_CXX_STANDARD 11)
68+ set (CMAKE_CXX_STANDARD_REQUIRED ON )
69+ set (CMAKE_CUDA_STANDARD 11)
70+ set (CMAKE_CUDA_STANDARD_REQUIRED ON )
71+
72+
2873if (CCTAG_ENABLE_SIMD_AVX2)
2974 if (CMAKE_COMPILER_IS_GNUCXX OR (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" ))
3075 add_definitions (-mavx2)
@@ -36,14 +81,13 @@ if(CCTAG_ENABLE_SIMD_AVX2)
3681 message (STATUS "CCTAG: AVX2 optimizations enabled." )
3782endif ()
3883
39- if (CMAKE_CXX_COMPILER_ID STREQUAL " MSVC" )
84+ if (MSVC )
4085 add_definitions (/EHsc) # Enable Exception Handling
4186endif ()
4287
43- set (CMAKE_CXX_STANDARD 11)
44- set (CMAKE_CXX_STANDARD_REQUIRED ON )
45-
46- set (CMAKE_POSITION_INDEPENDENT_CODE ${CCTAG_USE_POSITION_INDEPENDENT_CODE} )
88+ if (NOT MSVC )
89+ set (CMAKE_POSITION_INDEPENDENT_CODE ${CCTAG_USE_POSITION_INDEPENDENT_CODE} )
90+ endif ()
4791
4892
4993# set the path where we can find the findXXX.cmake
@@ -77,7 +121,7 @@ else()
77121 set (BOOST_REQUIRED_COMPONENTS "${BOOST_REQUIRED_COMPONENTS} ;stacktrace_basic" )
78122endif ()
79123
80- if (BUILD_TESTS )
124+ if (CCTAG_BUILD_TESTS )
81125 set (BOOST_REQUIRED_COMPONENTS "${BOOST_REQUIRED_COMPONENTS} ;unit_test_framework" )
82126 enable_testing ()
83127 include (BoostTestHelper)
@@ -140,20 +184,22 @@ if(CCTAG_WITH_CUDA)
140184 CUDA_SELECT_NVCC_ARCH_FLAGS(ARCH_FLAGS ${CCTAG_CUDA_CC_LIST_BASIC} )
141185 LIST (APPEND CUDA_NVCC_FLAGS ${ARCH_FLAGS} )
142186
143- set (CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} ;-std=c++11" )
187+ if (NOT MSVC )
188+ set (CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} ;-std=c++11" )
189+ endif ()
144190 set (CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} ;--default-stream;per-thread" )
145191
146- if (CCTAG_USE_POSITION_INDEPENDENT_CODE)
192+ if (CCTAG_USE_POSITION_INDEPENDENT_CODE AND NOT MSVC )
147193 set (CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} ;-Xcompiler;-fPIC" )
148194 endif ()
149195
150- CCTAG_CHECK_NVCC_COMPILER_FLAG("--relaxed-constexpr" HAS_NVCC_RELAXED_CONSTEXPR )
151- if (HAS_NVCC_RELAXED_CONSTEXPR )
152- set (CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} ;--relaxed-constexpr" )
196+ CCTAG_CHECK_NVCC_COMPILER_FLAG("--expt- relaxed-constexpr" HAS_NVCC_EXPT_RELAXED_CONSTEXPR )
197+ if (HAS_NVCC_EXPT_RELAXED_CONSTEXPR )
198+ set (CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} ;--expt- relaxed-constexpr" )
153199 else ()
154- CCTAG_CHECK_NVCC_COMPILER_FLAG("--expt- relaxed-constexpr" HAS_NVCC_EXPT_RELAXED_CONSTEXPR )
155- if (HAS_NVCC_EXPT_RELAXED_CONSTEXPR )
156- set (CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} ;--expt- relaxed-constexpr" )
200+ CCTAG_CHECK_NVCC_COMPILER_FLAG("--relaxed-constexpr" HAS_NVCC_RELAXED_CONSTEXPR )
201+ if (HAS_NVCC_RELAXED_CONSTEXPR )
202+ set (CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} ;--relaxed-constexpr" )
157203 endif ()
158204 endif ()
159205
@@ -177,19 +223,54 @@ endif(CCTAG_WITH_CUDA)
177223find_package (OpenCV REQUIRED core videoio imgproc imgcodecs)
178224
179225# FIND Eigen
180- find_package (Eigen REQUIRED)
226+ set (CCTAG_EIGEN_REQUIRED_VERSION 3.3.4)
227+ if (MSVC AND CCTAG_WITH_CUDA)
228+ set (CCTAG_EIGEN_REQUIRED_VERSION 3.3.9)
229+ message (WARNING "Building CCTag with Cuda support under windows requires Eigen >= ${CCTAG_EIGEN_REQUIRED_VERSION} " )
230+ endif ()
231+ find_package (Eigen3 ${CCTAG_EIGEN_REQUIRED_VERSION} REQUIRED)
232+ message (STATUS "Found Eigen: version ${Eigen3_VERSION} " )
233+ if (CCTAG_EIGEN_NO_ALIGN)
234+ set (AV_EIGEN_DEFINITIONS -DEIGEN_MAX_ALIGN_BYTES=0 -DEIGEN_MAX_STATIC_ALIGN_BYTES=0)
235+ endif ()
181236
182237# FIND Intel TBB
183238# With MVSC, CMAKE_BUILD_TYPE will always be None, so TBB_USE_DEBUG_BUILD will always be false.
184239string (COMPARE EQUAL "${CMAKE_BUILD_TYPE} " Debug TBB_USE_DEBUG_BUILD)
185- find_package (TBB 4 REQUIRED)
240+ find_package (TBB REQUIRED)
186241
187242add_subdirectory (src)
188243
189244########### Add uninstall target ###############
190- CONFIGURE_FILE (
245+ configure_file (
191246 "${CMAKE_CURRENT_SOURCE_DIR} /cmake/cmake_uninstall.cmake.in"
192247 "${CMAKE_CURRENT_BINARY_DIR} /cmake/cmake_uninstall.cmake"
193248 IMMEDIATE @ONLY)
194- ADD_CUSTOM_TARGET (uninstall
249+ add_custom_target (cctag_uninstall
195250 "${CMAKE_COMMAND} " -P "${CMAKE_CURRENT_BINARY_DIR} /cmake/cmake_uninstall.cmake" )
251+
252+
253+ ######################################
254+ # SUMMARY
255+ ######################################
256+ message ("\n " )
257+ message ("******************************************" )
258+ message ("Building configuration:\n " )
259+ message (STATUS "CCTag version: " ${PROJECT_VERSION} )
260+ message (STATUS "Build type: " ${CMAKE_BUILD_TYPE} )
261+ message (STATUS "Build Shared libs: " ${BUILD_SHARED_LIBS} )
262+ message (STATUS "Build applications: " ${CCTAG_BUILD_APPS} )
263+ message (STATUS "Build tests: " ${CCTAG_BUILD_TESTS} )
264+ message (STATUS "Cuda support: " ${CCTAG_WITH_CUDA} )
265+ if (CCTAG_WITH_CUDA)
266+ message (STATUS "Compiling for CUDA CCs: ${ARCH_FLAGS} " )
267+ endif ()
268+ message (STATUS "Disable Eigen alignment: " ${CCTAG_EIGEN_NO_ALIGN} )
269+ message (STATUS "Enable AVX2 optimizations: " ${CCTAG_ENABLE_SIMD_AVX2} )
270+ message (STATUS "[debug] Serialize all the output: " ${CCTAG_SERIALIZE} )
271+ message (STATUS "[debug] Enable visual debug: " ${CCTAG_VISUAL_DEBUG} )
272+ message (STATUS "[debug] Disable output stream: " ${CCTAG_NO_COUT} )
273+ message (STATUS "[debug] nvcc additional warnings: " ${CCTAG_NVCC_WARNINGS} )
274+ message (STATUS "Install path: " ${CMAKE_INSTALL_PREFIX} )
275+ message ("\n ******************************************" )
276+ message ("\n " )
0 commit comments