24.09., 9:00 - 11:00: Due to updates GitLab will be unavailable for some minutes between 09:00 and 11:00.

commonconf.cmake 12 KB
Newer Older
schultezub's avatar
schultezub committed
1
IF(NOT CommonconfProcessed)
schultezub's avatar
schultezub committed
2

schultezub's avatar
schultezub committed
3
SET(CampvisHome ${CMAKE_CURRENT_SOURCE_DIR})
4
SET(CampvisBinaryDir ${CMAKE_BINARY_DIR})
5 6
MESSAGE(STATUS "CAMPVis Source Directory: ${CampvisHome}")
MESSAGE(STATUS "CAMPVis Binary Directory: ${CampvisBinaryDir}")
schultezub's avatar
schultezub committed
7 8

# include macros
schultezub's avatar
schultezub committed
9
INCLUDE(${CampvisHome}/cmake/macros.cmake)
schultezub's avatar
schultezub committed
10

11 12 13 14 15 16 17 18 19 20 21 22 23 24
# include packaging helper scripts
INCLUDE(GenerateExportHeader)
INCLUDE(CMakePackageConfigHelpers)

# guard against in-source builds
IF(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
	MESSAGE(FATAL_ERROR "In-source builds are strongly discouraged and therefore not allowed.")
ENDIF()

# guard against static builds
IF(NOT BUILD_SHARED_LIBS)
    MESSAGE(WARNING "Building static CAMPVis libraries is not officially supported and therefore strongly discouraged. Consider setting BUILD_SHARED_LIBS to ON unless you know what you're doing")
ENDIF()

schultezub's avatar
schultezub committed
25 26
# detect compiler and architecture
IF(${CMAKE_GENERATOR} STREQUAL "Visual Studio 9 2008")
schultezub's avatar
schultezub committed
27 28
    SET(CAMPVIS_MSVC2008 TRUE)
    SET(CAMPVIS_WIN32 TRUE)
schultezub's avatar
schultezub committed
29 30
    MESSAGE(STATUS "Visual Studio 2008 build (32 Bit)")
ELSEIF(${CMAKE_GENERATOR} STREQUAL "Visual Studio 9 2008 Win64")
schultezub's avatar
schultezub committed
31 32
    SET(CAMPVIS_MSVC2008 TRUE)
    SET(CAMPVIS_WIN64 TRUE)
schultezub's avatar
schultezub committed
33
    MESSAGE(STATUS "Visual Studio 2008 Build (64 Bit)")
34
ELSEIF(${CMAKE_GENERATOR} STREQUAL "Visual Studio 10" OR ${CMAKE_GENERATOR} STREQUAL "Visual Studio 10 2010")
schultezub's avatar
schultezub committed
35 36
    SET(CAMPVIS_MSVC2010 TRUE)
    SET(CAMPVIS_WIN32 TRUE)
schultezub's avatar
schultezub committed
37
    MESSAGE(STATUS "Visual Studio 2010 Build (32 Bit)")
38
ELSEIF(${CMAKE_GENERATOR} STREQUAL "Visual Studio 10 Win64" OR ${CMAKE_GENERATOR} STREQUAL "Visual Studio 10 2010 Win64")
schultezub's avatar
schultezub committed
39 40
    SET(CAMPVIS_MSVC2010 TRUE)
    SET(CAMPVIS_WIN64 TRUE)
schultezub's avatar
schultezub committed
41
    MESSAGE(STATUS "Visual Studio 2010 Build (64 Bit)")
42
ELSEIF(${CMAKE_GENERATOR} STREQUAL "Visual Studio 11" OR ${CMAKE_GENERATOR} STREQUAL "Visual Studio 11 2012")
schultezub's avatar
schultezub committed
43 44
    SET(CAMPVIS_MSVC11 TRUE)
    SET(CAMPVIS_WIN32 TRUE)
45
    MESSAGE("Visual Studio 11 Build (32 Bit)")
46
ELSEIF(${CMAKE_GENERATOR} STREQUAL "Visual Studio 11 Win64" OR ${CMAKE_GENERATOR} STREQUAL "Visual Studio 11 2012 Win64")
schultezub's avatar
schultezub committed
47 48
    SET(CAMPVIS_MSVC11 TRUE)
    SET(CAMPVIS_WIN64 TRUE)
49
    MESSAGE("Visual Studio 11 Build (64 Bit)")
50
ELSEIF(${CMAKE_GENERATOR} STREQUAL "Visual Studio 12" OR ${CMAKE_GENERATOR} STREQUAL "Visual Studio 12 2013")
51 52 53
    SET(CAMPVIS_MSVC12 TRUE)
    SET(CAMPVIS_WIN32 TRUE)
    MESSAGE("Visual Studio 12 Build (32 Bit)")
54
ELSEIF(${CMAKE_GENERATOR} STREQUAL "Visual Studio 12 Win64" OR ${CMAKE_GENERATOR} STREQUAL "Visual Studio 12 2013 Win64")
55 56 57
    SET(CAMPVIS_MSVC12 TRUE)
    SET(CAMPVIS_WIN64 TRUE)
    MESSAGE("Visual Studio 12 Build (64 Bit)")
58 59 60
ELSEIF(${CMAKE_GENERATOR} STREQUAL "Visual Studio 14 Win64" OR ${CMAKE_GENERATOR} STREQUAL "Visual Studio 14 2015 Win64")
    SET(CAMPVIS_MSVC14 TRUE)
    SET(CAMPVIS_WIN64 TRUE)
61 62 63 64 65
    MESSAGE("Visual Studio 14 Build (64 Bit)")
ELSEIF(${CMAKE_GENERATOR} STREQUAL "Visual Studio 15 Win64" OR ${CMAKE_GENERATOR} STREQUAL "Visual Studio 15 2017 Win64")
    SET(CAMPVIS_MSVC15 TRUE)
    SET(CAMPVIS_WIN64 TRUE)
    MESSAGE("Visual Studio 15 Build (64 Bit)")
schultezub's avatar
schultezub committed
66
ELSEIF(${CMAKE_GENERATOR} MATCHES "NMake") 
schultezub's avatar
schultezub committed
67
    SET(CAMPVIS_NMAKE TRUE)
68 69 70 71 72 73 74 75

    # NMake-based builds may very well use a Visual Studio compiler
    IF(MSVC90)
        SET(CAMPVIS_MSVC2008 TRUE)
    ELSEIF(MSVC10)
        SET(CAMPVIS_MSVC2010 TRUE)
    ELSEIF(MSVC11)
        SET(CAMPVIS_MSVC11 TRUE)
76 77
    ELSEIF(MSVC12)
        SET(CAMPVIS_MSVC12 TRUE)
78 79
	ELSEIF(MSVC14)
        SET(CAMPVIS_MSVC14 TRUE)
80 81
    ENDIF(MSVC90)

schultezub's avatar
schultezub committed
82
    IF(CMAKE_CL_64)
schultezub's avatar
schultezub committed
83
        SET(CAMPVIS_WIN64 TRUE)
schultezub's avatar
schultezub committed
84 85
        MESSAGE(STATUS "NMake 64 Bit Build")
    ELSE(CMAKE_CL_64)
schultezub's avatar
schultezub committed
86
        SET(CAMPVIS_WIN32 TRUE)
schultezub's avatar
schultezub committed
87 88 89
        MESSAGE(STATUS "NMake 32 Bit Build")            
    ENDIF(CMAKE_CL_64)    
ELSEIF(${CMAKE_GENERATOR} MATCHES "MinGW")
schultezub's avatar
schultezub committed
90 91
    SET(CAMPVIS_MINGW TRUE)
    SET(CAMPVIS_WIN32 TRUE)
schultezub's avatar
schultezub committed
92 93
    MESSAGE("MinGW 32 Bit Build (not actively supported)")
ELSEIF(${CMAKE_GENERATOR} MATCHES "Unix")
schultezub's avatar
schultezub committed
94
    SET(CAMPVIS_UNIX TRUE)
schultezub's avatar
schultezub committed
95 96 97 98 99 100 101
    MESSAGE(STATUS "Unix Build")
ELSE()
    MESSAGE(WARNING "Unsupported or unknown generator: ${CMAKE_GENERATOR}")
ENDIF()


# set binary output path
schultezub's avatar
schultezub committed
102 103 104
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
schultezub's avatar
schultezub committed
105

106 107 108 109 110
# set install directories
SET(CampvisIncludeInstallDir "include")
SET(CampvisLibInstallDir "lib")


schultezub's avatar
schultezub committed
111
# common include directories
schultezub's avatar
schultezub committed
112 113
LIST(APPEND CampvisGlobalIncludeDirs "${CampvisHome}/ext")
LIST(APPEND CampvisGlobalIncludeDirs ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) 
schultezub's avatar
schultezub committed
114

115 116
LIST(APPEND CampvisGlobalDefinitions "-DCAMPVIS_SOURCE_DIR=\"${CampvisHome}\"")

schultezub's avatar
schultezub committed
117 118
# platform-dependent configuration
IF(WIN32)
schultezub's avatar
schultezub committed
119
    LIST(APPEND CampvisGlobalDefinitions "-DNOMINMAX" "-D_CRT_SECURE_NO_DEPRECATE")
schultezub's avatar
schultezub committed
120 121

    # Disable warnings for Microsoft compiler:
122
    # C4251  class needs to have dll interface (used for std classes)
schultezub's avatar
schultezub committed
123 124 125 126
    # C4290: C++ exception specification ignored except to indicate a function is
    #        not __declspec(nothrow)
    # C4390: ';' : empty controlled statement found; is this the intent?
    #        occurs when OpenGL error logging macros are disabled
127 128 129
    # C4503: The decorated name was longer than the compiler limit (4096), and was truncated.
    #        Occurs in AutoEvaluatePipeline due to some nested nested map-iterator-map. Could
    #        not be deactivated locally...
130 131
    # C4068: Unknown Pragma since we use some GCC pragmas in the code.
    LIST(APPEND CampvisGlobalDefinitions /wd4251 /wd4290 /wd4390 /wd4503 /wd4068)
schultezub's avatar
schultezub committed
132 133
    
    # enable parallel builds in Visual Studio
schultezub's avatar
schultezub committed
134
    LIST(APPEND CampvisGlobalDefinitions /MP)
schultezub's avatar
schultezub committed
135 136

    # prevent error: number of sections exceeded object file format limit
schultezub's avatar
schultezub committed
137
    LIST(APPEND CampvisGlobalDefinitions /bigobj)
schultezub's avatar
schultezub committed
138 139 140 141 142
    
    # allows 32 Bit builds to use more than 2GB RAM (VC++ only)
    SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /LARGEADDRESSAWARE")
    SET(CMAKE_EXE_LINKER_FLAGS    "${CMAKE_EXE_LINKER_FLAGS} /LARGEADDRESSAWARE")

143
    IF(BUILD_SHARED_LIBS)
schultezub's avatar
schultezub committed
144
        # Linking against Windows DLLs requires explicit instantiation of templates
schultezub's avatar
schultezub committed
145
        LIST(APPEND CampvisGlobalDefinitions "-DDLL_TEMPLATE_INST")
146
        LIST(APPEND CampvisGlobalDefinitions "-DCAMPVIS_DYNAMIC_LIBS")
schultezub's avatar
schultezub committed
147

schultezub's avatar
schultezub committed
148
        IF(NOT CAMPVIS_GENERATE_MANIFEST)
schultezub's avatar
schultezub committed
149 150 151 152
            # Do not embed manifest into binaries in debug mode (slows down incremental linking)
            SET(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} /MANIFEST:NO")
            SET(CMAKE_EXE_LINKER_FLAGS_DEBUG    "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /MANIFEST:NO")
        ENDIF()
153 154 155 156
        
        # For Windows targets, we have to build campvis-modules and some other libs as static library, 
        # since we did not define the __declspec exports here.
        SET(CampvisSharedStaticModulesFix "STATIC")
schultezub's avatar
schultezub committed
157 158 159
    ENDIF()

    # enable/disable incremental linking in debug builds
schultezub's avatar
schultezub committed
160
    If(CAMPVIS_INCREMENTAL_LINKING)
schultezub's avatar
schultezub committed
161 162 163 164 165 166 167
        SET(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} /INCREMENTAL")
        SET(CMAKE_EXE_LINKER_FLAGS_DEBUG    "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /INCREMENTAL")
    ELSE()
        SET(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} /INCREMENTAL:NO")
        SET(CMAKE_EXE_LINKER_FLAGS_DEBUG    "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /INCREMENTAL:NO")
    ENDIF()
    
schultezub's avatar
schultezub committed
168
    LIST(APPEND CampvisGlobalExternalLibs netapi32 version)
169 170 171 172 173 174 175 176 177

    # Append the name of the current build type to the path of the CMake output directory so that
    # NMake places all build artifacts in the same directories as Visual Studio. This makes NMake
    # builds compatible with our macro that copies external DLLs into the build directory.
    IF(CAMPVIS_NMAKE)
        SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_BUILD_TYPE}")
        SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_BUILD_TYPE}")
        SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/${CMAKE_BUILD_TYPE}")
    ENDIF(CAMPVIS_NMAKE)
178
    
schultezub's avatar
schultezub committed
179
ELSEIF(UNIX)
180
    LIST(APPEND CampvisGlobalDefinitions "-DUNIX")
Jakob Weiss's avatar
Jakob Weiss committed
181
    LIST(APPEND CampvisGlobalDefinitions "-Wall -Wno-unused-local-typedefs -Wno-unused-variable -Wno-unknown-pragmas -Wno-overloaded-virtual")
182
    LIST(APPEND CampvisGlobalDefinitions "-D__STDC_CONSTANT_MACROS")
183 184 185
    
    # dangerous!
    LIST(APPEND CampvisGlobalDefinitions "-Wno-deprecated-declarations")
186
    
187
    LIST(APPEND CampvisGlobalExternalLibs "pthread")
Christian Schulte zu Berge's avatar
Christian Schulte zu Berge committed
188
ELSE()
schultezub's avatar
schultezub committed
189 190
ENDIF(WIN32)

191 192 193 194 195
IF(CMAKE_COMPILER_IS_GNUCXX)
    # enable C++11 support in GCC
    LIST(APPEND CMAKE_CXX_FLAGS "-std=c++11")
ENDIF()

196 197
# cgt configuration
LIST(APPEND CampvisGlobalDefinitions "-DCGT_WITHOUT_DEFINES") # don't use cgt's build system
schultezub's avatar
schultezub committed
198
IF(WIN32)
199
    SET(CGT_WITH_WMI TRUE)  #< enable Windows Management Instrumentation for hardware detection
schultezub's avatar
schultezub committed
200
ENDIF()
schultezub's avatar
schultezub committed
201
IF(CAMPVIS_DEBUG)
202
    LIST(APPEND CampvisGlobalDefinitions -DCGT_DEBUG -DCAMPVIS_DEBUG)
schultezub's avatar
schultezub committed
203 204 205
ENDIF()
 
# minimum Qt version
206
IF(CAMPVIS_BUILD_APPLICATION)
207 208 209 210 211 212 213
    SET(CampvisRequiredQtVersion "5.0")
    
    # Tell CMake to run moc when necessary:
    SET(CMAKE_AUTOMOC ON)
    # As moc files are generated in the binary dir, tell CMake to always look for includes there:
    SET(CMAKE_INCLUDE_CURRENT_DIR ON)
    
214
    FIND_PACKAGE(Qt5 COMPONENTS Widgets OpenGL REQUIRED)
215 216 217
    
    RESOLVE_QT5_DLL_LOCATIONS("Core;Gui;OpenGL;Widgets")

218
    SET(CGT_WITH_QT true)
219
ENDIF(CAMPVIS_BUILD_APPLICATION)
schultezub's avatar
schultezub committed
220 221 222 223


# detect libraries
MESSAGE(STATUS "--------------------------------------------------------------------------------")
schultezub's avatar
schultezub committed
224
MESSAGE(STATUS "Detecting Mandatory External Libraries:")
schultezub's avatar
schultezub committed
225

schultezub's avatar
schultezub committed
226
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CampvisHome}/cmake")
schultezub's avatar
schultezub committed
227 228 229 230 231

# OpenGL
FIND_PACKAGE(OpenGL REQUIRED)
IF(OPENGL_FOUND)
    MESSAGE(STATUS "* Found OpenGL")
schultezub's avatar
schultezub committed
232 233
    LIST(APPEND CampvisGlobalIncludeDirs ${OPENGL_INCLUDE_DIR})
    LIST(APPEND CampvisGlobalExternalLibs ${OPENGL_LIBRARIES})
schultezub's avatar
schultezub committed
234 235 236 237 238 239 240 241
ELSE(OPENGL_FOUND)
    MESSAGE(FATAL_ERROR "OpenGL not found!")
ENDIF(OPENGL_FOUND)
    
# GLEW
FIND_PACKAGE(Glew REQUIRED)
IF(GLEW_FOUND)
    MESSAGE(STATUS "* Found GLEW")
schultezub's avatar
schultezub committed
242 243 244 245 246 247
    LIST(APPEND CampvisGlobalDefinitions ${GLEW_DEFINITIONS})
    LIST(APPEND CampvisGlobalIncludeDirs ${GLEW_INCLUDE_DIR})
    LIST(APPEND CampvisGlobalExternalLibs ${GLEW_LIBRARY})
    LIST(APPEND CampvisExternalDllsDebug ${GLEW_DLL_DEBUG})
    LIST(APPEND CampvisExternalDllsRelease ${GLEW_DLL_RELEASE})
    LIST(APPEND CampvisExternalLicenseFiles ${GLEW_LICENSE_FILE})
schultezub's avatar
schultezub committed
248 249 250 251
ELSE(GLEW_FOUND)
    MESSAGE(FATAL_ERROR "GLEW not found!")
ENDIF(GLEW_FOUND)

schultezub's avatar
schultezub committed
252
# TBB
Jakob Weiss's avatar
Jakob Weiss committed
253 254 255 256 257 258 259 260 261 262
find_package(TBB QUIET)
if(NOT TBB_FOUND)
    find_package(TBB_ COMPONENTS tbb tbbmalloc)#cmake/FindTBB_.cmake)
endif(NOT TBB_FOUND)

if(NOT TBB_FOUND)
    message(FATAL_ERROR "TBB not found!")
endif(NOT TBB_FOUND)

IF(TARGET TBB::tbb)
schultezub's avatar
schultezub committed
263
    MESSAGE(STATUS "* Found TBB")
264 265 266
    #LIST(APPEND CampvisGlobalDefinitions ${TBB_DEFINITIONS})
    #LIST(APPEND CampvisGlobalIncludeDirs ${TBB_INCLUDE_DIR})
    LIST(APPEND CampvisGlobalExternalLibs TBB::tbb TBB::tbbmalloc)
267 268
    LIST(APPEND CampvisExternalDllsDebug ${TBB_DLL_DEBUG} ${TBB_MALLOC_DLL_DEBUG})
    LIST(APPEND CampvisExternalDllsRelease ${TBB_DLL_RELEASE} ${TBB_MALLOC_DLL_RELEASE})
269 270 271 272
    if(WIN32 AND NOT TBB_DLL_DEBUG)
        message(WARNING "TBB DLL Paths could not resolved. Please copy TBB dlls manually to output directory. (VCPKG takes care of that for you if you use it..)")
    endif()
    #LIST(APPEND CampvisExternalLicenseFiles ${TBB_LICENSE_FILE})
273 274
    # unfortunately, the new TBB API does no longer allow copying of mutexes, hence we need to set a fallback define
    LIST(APPEND CampvisGlobalDefinitions "-DTBB_DEPRECATED_MUTEX_COPYING")
Jakob Weiss's avatar
Jakob Weiss committed
275 276 277 278 279
elseif(TBB_LIBRARIES)
    LIST(APPEND CampvisGlobalDefinitions ${TBB_DEFINITIONS})
    LIST(APPEND CampvisGlobalExternalLibs ${TBB_LIBRARIES})
    LIST(APPEND CampvisGlobalDefinitions "-DTBB_DEPRECATED_MUTEX_COPYING")
ENDIF(TARGET TBB::tbb)
schultezub's avatar
schultezub committed
280

schultezub's avatar
schultezub committed
281 282 283 284 285 286 287 288
# Eigen
IF(EXISTS "${CampvisHome}/ext/eigen/Eigen/Eigen")
    MESSAGE(STATUS "* Found Eigen")
    LIST(APPEND CampvisGlobalIncludeDirs "${CampvisHome}/ext/eigen")
    LIST(APPEND CampvisGlobalDefinitions -DEIGEN_PERMANENTLY_DISABLE_STUPID_WARNINGS)
ELSE()
    MESSAGE(WARNING "Did not find Eigen - Eigen library must be placed in ext/eigen/!")
ENDIF()
schultezub's avatar
schultezub committed
289
SET(CommonconfProcessed TRUE)
290

schultezub's avatar
schultezub committed
291
ENDIF(NOT CommonconfProcessed)