1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329
|
cmake_minimum_required( VERSION 3.6 )
set( SFCGAL_VERSION_MAJOR 2 )
set( SFCGAL_VERSION_MINOR 2 )
set( SFCGAL_VERSION_PATCH 0 )
set( SFCGAL_VERSION "${SFCGAL_VERSION_MAJOR}.${SFCGAL_VERSION_MINOR}.${SFCGAL_VERSION_PATCH}" )
project( SFCGAL VERSION ${SFCGAL_VERSION} )
set( CMAKE_DEBUG_POSTFIX "d" )
set(CMAKE_CXX_STANDARD 17)
# ignore system installed SFCGAL to avoid conflicts during build/edit
list(APPEND CMAKE_IGNORE_PREFIX_PATH "/usr/include/SFCGAL")
list(APPEND CMAKE_IGNORE_PREFIX_PATH "/usr/local/include/SFCGAL")
#
# Cmake policies
#
if(POLICY CMP0077)
cmake_policy(SET CMP0077 NEW)
endif()
if(POLICY CMP0167)
cmake_policy(SET CMP0167 NEW)
endif()
#----------------------------------------------------------------------------
# build options
#----------------------------------------------------------------------------
# Windows M_PI
add_compile_definitions(_USE_MATH_DEFINES)
# Set a default build type if none was specified
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to 'Release' as none was specified.")
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "RelWithDebInfo")
endif()
option( SFCGAL_BUILD_EXAMPLES "build examples" OFF )
option( SFCGAL_BUILD_TESTS "build unit and regress tests" OFF )
option( SFCGAL_BUILD_BENCH "Build benchmarks" OFF )
option( SFCGAL_BUILD_DOC "Build documentation" OFF )
option( SFCGAL_WITH_OSG "Compile with OpenSceneGraph support" OFF )
option( SFCGAL_VALGRIND "Compile with Valgrind support" OFF )
option( SFCGAL_TSAN "Enable ThreadSanitizer (Debug only)" OFF)
# Configure CCache if available
if(NOT MSVC)
option(USE_CCACHE "Use ccache" ON)
if (USE_CCACHE)
find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
message(STATUS "ccache found")
endif(CCACHE_FOUND)
endif(USE_CCACHE)
endif(NOT MSVC)
#-- include finders and co
set( CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules;${CMAKE_MODULE_PATH}" )
if (CMAKE_CXX_COMPILER MATCHES ".*clang")
set(CMAKE_COMPILER_IS_CLANGXX 1)
endif ()
#-----------------------------------------------------------
# dependencies
#-----------------------------------------------------------
if( SFCGAL_VALGRIND )
# valgrind tends to alter how CGAL works. To avoid the '-frounding-math' warning we need to activate this define:
add_definitions( "-DCGAL_DISABLE_ROUNDING_MATH_CHECK" )
endif()
# Require Debug build if SFCGAL_TSAN is ON
if ( SFCGAL_TSAN )
if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
message(FATAL_ERROR "SFCGAL_TSAN is enabled but CMAKE_BUILD_TYPE is not Debug. Please configure with -DCMAKE_BUILD_TYPE=Debug")
endif()
message(STATUS "ThreadSanitizer enabled (C & C++)")
add_compile_options(-fsanitize=thread -g)
add_link_options(-fsanitize=thread)
endif()
#-- find CGAL ---------------------------------------------
if( CGAL_USE_GMPXX )
add_definitions( "-DCGAL_USE_GMPXX" )
endif()
option( CGAL_USE_AUTOLINK "disable CGAL autolink" OFF )
if( ${CGAL_USE_AUTOLINK} )
add_definitions( "-DCGAL_NO_AUTOLINK" )
endif()
find_package( CGAL 5.6 COMPONENTS Core REQUIRED )
message( STATUS "CGAL ${CGAL_VERSION} found" )
set(CGAL_3RD_PARTY_LIBRARIES CGAL::CGAL CGAL::CGAL_Core)
include_directories( ${CMAKE_BINARY_DIR}/include )
#-- BOOST --------------------------------------------------
option( Boost_USE_AUTO_LINK "boost use autolink" OFF )
set(Boost_USE_DEBUG_RUNTIME OFF)
# set(Boost_USE_STATIC_LIBS OFF)
option( Boost_USE_DEBUG_RUNTIME "Use Boost debug runtime" OFF )
if( NOT ${Boost_USE_AUTO_LINK} )
add_definitions( "-DBOOST_ALL_NO_LIB" )
endif()
option( Boost_USE_STATIC_LIBS "boost use dynamic libraries" OFF )
if( Boost_USE_STATIC_LIBS )
message( STATUS "Boost_USE_STATIC_LIBS=ON" )
add_definitions( "-DBOOST_THREAD_USE_LIB" )
else()
message( STATUS "Boost_USE_STATIC_LIBS=OFF" )
# add_definitions( "-DBOOST_TEST_DYN_LINK" )
add_definitions( "-DBOOST_ALL_DYN_LINK" )
endif()
option( Boost_USE_MULTITHREAD "boost use multithread libraries" ON )
if( ${Boost_USE_MULTITHREAD} )
message( STATUS "Boost_USE_MULTITHREAD=ON" )
else()
message( STATUS "Boost_USE_MULTITHREAD=OFF" )
endif()
#-- minimalist build allowed with boost version 1.69 or newer
set( SFCGAL_Boost_COMPONENTS thread serialization )
#-- program_options
if ( SFCGAL_BUILD_TESTS OR SFCGAL_BUILD_EXAMPLES OR SFCGAL_BUILD_OSG )
set( SFCGAL_Boost_COMPONENTS chrono unit_test_framework filesystem program_options timer ${SFCGAL_Boost_COMPONENTS} )
endif()
find_package( Boost 1.69.0 COMPONENTS ${SFCGAL_Boost_COMPONENTS} REQUIRED )
if((${Boost_MAJOR_VERSION} EQUAL 1) AND (${Boost_MINOR_VERSION} EQUAL 58))
message( STATUS "Defining BOOST_VARIANT_USE_RELAXED_GET_BY_DEFAULT" )
add_definitions( "-DBOOST_VARIANT_USE_RELAXED_GET_BY_DEFAULT" )
endif()
if( SFCGAL_USE_STATIC_LIBS )
add_definitions( "-DSFCGAL_USE_STATIC_LIBS" )
if (NOT MSVC)
add_definitions( "-fPIC" )
endif()
endif()
#-- OpenScenegraph -----------------------------------------
if ( SFCGAL_WITH_OSG )
find_package( OpenSceneGraph COMPONENTS osgDB osgUtil )
if( ${OPENSCENEGRAPH_FOUND} )
message( STATUS "OPENSCENEGRAPH_INCLUDE_DIRS = ${OPENSCENEGRAPH_INCLUDE_DIRS}" )
message( STATUS "OPENSCENEGRAPH_LIBRARIES = ${OPENSCENEGRAPH_LIBRARIES}" )
include_directories( SYSTEM ${OPENSCENEGRAPH_INCLUDE_DIRS} )
endif()
endif()
#-- note that SYSTEM turns -I/path to -isystem and avoid warnings in CGAL and Boost
include_directories( SYSTEM
${CGAL_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS}
)
link_directories(
${CGAL_LIBRARY_DIRS}
${Boost_LIBRARY_DIRS}
)
#-- Coverage ---------------------------------------------------------------------
option( SFCGAL_COVERAGE "Generate code coverage report" OFF)
if( SFCGAL_COVERAGE )
include(CodeCoverage)
append_coverage_compiler_flags()
set(COVERAGE_EXCLUDES
'${PROJECT_SOURCE_DIR}/CGAL/*'
'${PROJECT_SOURCE_DIR}/test/*')
setup_target_for_coverage_gcovr_xml(
NAME sfcgal_coverage # New target name
EXECUTABLE ctest -j ${PROCESSOR_COUNT} -R unit-test
DEPENDENCIES SFCGAL unit-test-SFCGAL
)
endif()
#-- Warnings, frounding-math and gprof ------------------------------------------
option( SFCGAL_WARNING_AS_ERROR "fail the build on warnings" OFF )
option( SFCGAL_BUILD_WITH_GPROF "build with gprof" OFF )
if(MSVC)
# Force to always compile with W4
if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
endif()
elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
# Update if necessary
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-long-long -pedantic -Wpointer-arith -Wcast-align -Wcast-qual -Wno-overloaded-virtual -Wformat=2 -Winit-self -Wmissing-include-dirs -Wwrite-strings -Wno-error=undef")#-Wfloat-equal -Wconversion -Wshadow
if( SFCGAL_WARNING_AS_ERROR )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wno-error=format")
endif()
# Allows profiling with gprof
if(SFCGAL_BUILD_WITH_GPROF)
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "-pg")
endif()
endif()
if(NOT DEFINED CMAKE_INSTALL_LIBDIR)
set(_LIBDIR_DEFAULT "lib")
# Override this default 'lib' with 'lib64' iff:
# - we are on Linux system but NOT cross-compiling
# - we are NOT on debian
# - we are on a 64 bits system
# reason is: amd64 ABI: http://www.x86-64.org/documentation/abi.pdf
# Note that the future of multi-arch handling may be even
# more complicated than that: http://wiki.debian.org/Multiarch
if(CMAKE_SYSTEM_NAME MATCHES "Linux"
AND NOT CMAKE_CROSSCOMPILING
AND NOT EXISTS "/etc/debian_version")
if(NOT DEFINED CMAKE_SIZEOF_VOID_P)
message(AUTHOR_WARNING
"Unable to determine default CMAKE_INSTALL_LIBDIR directory because no target architecture is known. "
"Please enable at least one language before including GNUInstallDirs.")
else()
if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
set(_LIBDIR_DEFAULT "lib64")
endif()
endif()
endif()
set(CMAKE_INSTALL_LIBDIR "${_LIBDIR_DEFAULT}" CACHE PATH "object code libraries (${_LIBDIR_DEFAULT})")
endif()
if(NOT DEFINED CMAKE_INSTALL_FULL_LIBDIR)
set(CMAKE_INSTALL_FULL_LIBDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
endif()
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_FULL_LIBDIR}")
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
#SET(CMAKE_MACOSX_RPATH ON)
#-- generate library headers
configure_file( ${CMAKE_SOURCE_DIR}/src/config.h.cmake include/SFCGAL/config.h )
configure_file( ${CMAKE_SOURCE_DIR}/src/version.h.cmake include/SFCGAL/version.h )
enable_testing()
#note : not available on windows without export/import
OPTION( SFCGAL_USE_STATIC_LIBS "define if SFCGAL is build as a static library" OFF )
#-- build the library
add_subdirectory( src )
#-- build test (todo only if boost use dyn link)
add_subdirectory( test )
#-- build examples
if( SFCGAL_BUILD_EXAMPLES )
add_subdirectory( example )
endif()
#-- doxygen documentation (allows make doc when doxygen is found)
if( SFCGAL_BUILD_DOC )
add_subdirectory( doc )
endif()
#-- install directories
install(DIRECTORY ${CMAKE_BINARY_DIR}/include DESTINATION .)
#-- sfcgal-config
if ( "${CMAKE_BUILD_TYPE}" STREQUAL "Debug" )
set( SFCGAL_LIB_NAME "SFCGAL${CMAKE_DEBUG_POSTFIX}" )
else()
set( SFCGAL_LIB_NAME "SFCGAL" )
endif()
if ( UNIX )
include(GNUInstallDirs)
endif()
#set( SFCGAL_LIB_NAME ${${CMAKE_BUILD_TYPE}
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/sfcgal-config.in ${CMAKE_CURRENT_BINARY_DIR}/sfcgal-config @ONLY)
install( PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/sfcgal-config DESTINATION bin )
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/sfcgal.pc.in ${CMAKE_CURRENT_BINARY_DIR}/sfcgal.pc @ONLY)
install( FILES ${CMAKE_CURRENT_BINARY_DIR}/sfcgal.pc DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
set(SFCGAL_INCLUDE_DIR "${CMAKE_INSTALL_INCLUDEDIR}")
set(SFCGAL_LIBRARY_DIR "${CMAKE_INSTALL_LIBDIR}")
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/SFCGALConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/SFCGALConfig.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/SFCGAL"
PATH_VARS SFCGAL_INCLUDE_DIR SFCGAL_LIBRARY_DIR
)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/SFCGALConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/SFCGALConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/SFCGALConfigVersion.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/SFCGAL"
)
install(TARGETS SFCGAL
EXPORT SFCGALTargets
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
install(EXPORT SFCGALTargets
FILE SFCGALTargets.cmake
NAMESPACE SFCGAL::
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/SFCGAL")
|