CMakeLists.txt 7.2 KB
Newer Older
1
cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR)
2

Jan Möbius's avatar
Jan Möbius committed
3
4
5
6
7

# Set and enforce C++-11 flags
set( CMAKE_CXX_STANDARD_REQUIRED TRUE )
set( CMAKE_CXX_STANDARD 11 )

Jan Möbius's avatar
Jan Möbius committed
8
9
enable_testing()

10
11
12
13
# Only set project name if OpenMesh is built as stand-alone library
if("${PROJECT_NAME}" STREQUAL "")
    project (OpenMesh)
endif()
14

15
16
17
18
19
20
21
22
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
	if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "6.0" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "4.9" OR CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL "4.9")
		message(WARNING "Your version of GCC contains an optimizer bug. Please verify that you do not use -O3!")
		string(REPLACE "-O3" "-O2" CMAKE_CXX_FLAGS_RELEASE_NEW "${CMAKE_CXX_FLAGS_RELEASE}")
		set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE_NEW}" CACHE STRING "" FORCE)
	endif()
endif()

Jan Möbius's avatar
Typo    
Jan Möbius committed
23
24
25
26
27
if ( WIN32 )
  # This is the base directory for windows library search used in the finders we ship.
  set(CMAKE_WINDOWS_LIBS_DIR "c:/libs" CACHE STRING "Default Library search dir on windows." )
endif()

28
29
30
31
32
if (NOT WIN32 AND NOT CMAKE_BUILD_TYPE)
  message(STATUS "No build type selected, default to Release")
  set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
endif()

33
# add our macro directory to cmake search path
34
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
35
set (CMAKE_DEBUG_POSTFIX "d")
36
37
38
39
40
41

# include our cmake files
include (ACGCommon)

acg_get_version ()

42
43
44
45
46
47

# Disable package building when built as an external library
if(${PROJECT_NAME} MATCHES "OpenMesh")
    include(OpenMeshPackage)
endif()

48
include (ACGOutput)
Jan Möbius's avatar
Jan Möbius committed
49
include(ACGQt)
50

Matthias Möller's avatar
Matthias Möller committed
51
52
53
54
# ========================================================================
# Definitions
# ========================================================================

55
56
57
if (WIN32)
  add_definitions(
      -D_USE_MATH_DEFINES -DNOMINMAX
58
      -D_CRT_SECURE_NO_WARNINGS
59
60
61
  )
endif ()

Matthias Möller's avatar
Matthias Möller committed
62
63
64
65
set(NO_DECREMENT_DEPRECATED_WARNINGS OFF CACHE BOOL "Disables all deprecated warnings warning about decrement operations on normal circulators.")
if(NO_DECREMENT_DEPRECATED_WARNINGS)
  add_definitions( -DNO_DECREMENT_DEPRECATED_WARNINGS )
endif()
66
67
68
69
70
71
72

# ========================================================================
# Windows build style control
# ========================================================================

if ( WIN32 )
  if ( NOT DEFINED OPENMESH_BUILD_SHARED )
73
    set( OPENMESH_BUILD_SHARED false CACHE BOOL "Build as shared library(DLL)?" )
74
75
76
  endif()
endif()

Jan Möbius's avatar
Jan Möbius committed
77
78
79
# ========================================================================
# Add bundle targets here
# ========================================================================
80
81
82
83
if ( NOT DEFINED BUILD_APPS )
  set( BUILD_APPS true CACHE BOOL "Enable or disable building of apps" )
endif()

84
# Only call fixbundle, when we are building OpenMesh standalone
85
if( (${PROJECT_NAME} MATCHES "OpenMesh") AND BUILD_APPS )
86
87
88
89
90
91
92
93
94

  if (WIN32)
    if ( NOT "${CMAKE_GENERATOR}" MATCHES "MinGW Makefiles" AND BUILD_APPS )
      add_custom_target (fixbundle ALL
        COMMAND ${CMAKE_COMMAND} -P "${CMAKE_BINARY_DIR}/fixbundle.win.cmake" )
    endif()
  endif()

  if (APPLE)
95
    add_custom_target (fixbundle ALL
96
97
      COMMAND ${CMAKE_COMMAND} -P "${CMAKE_BINARY_DIR}/fixbundle.cmake"
    )
98
  endif()
Jan Möbius's avatar
Jan Möbius committed
99

100
endif() # project OpenMesh
Jan Möbius's avatar
Jan Möbius committed
101
102
103
104
105

# ========================================================================
# Call the subdirectories with there projects
# ========================================================================

106
107
108
add_subdirectory (src/OpenMesh/Core)
add_subdirectory (src/OpenMesh/Tools)
add_subdirectory (src/OpenMesh/Apps)
109

110
111
112
113
114
115
set(OPENMESH_BENCHMARK_DIR CACHE PATH "Source path of benchmark (https://github.com/google/benchmark).")
if (OPENMESH_BENCHMARK_DIR)
	add_subdirectory(${OPENMESH_BENCHMARK_DIR} benchmark)
	add_subdirectory(src/Benchmark)
endif()

116
# Do not build unit tests when build as external library
117
if(${PROJECT_NAME} MATCHES "OpenMesh")
118
    add_subdirectory (src/Unittests)
119
120
121
122
123
else()
	# If built as a dependent project simulate effects of
	# successful finder run:
	set (OPENMESH_FOUND true PARENT_SCOPE)
	set (OPENMESH_LIBRARIES OpenMeshCore OpenMeshTools PARENT_SCOPE)
124
	set (OPENMESH_INCLUDE_DIR  "${CMAKE_CURRENT_SOURCE_DIR}/src" PARENT_SCOPE)
125
126
127
128
129
130
131
132
133
	set (OPENMESH_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src" PARENT_SCOPE)

	# Also define variables provided by the old legacy finder.
	set (OPENMESH_CORE_LIBRARY OpenMeshCore PARENT_SCOPE)
	set (OPENMESH_TOOLS_LIBRARY OpenMeshTools PARENT_SCOPE)
	set (OPENMESH_TOOLS_LIBRARY OpenMeshTools PARENT_SCOPE)
	set (OPENMESH_LIBRARY OpenMeshCore OpenMeshTools PARENT_SCOPE)
	get_target_property(_OPENMESH_LIBRARY_DIR OpenMeshCore LIBRARY_OUTPUT_DIRECTORY)
	set (OPENMESH_LIBRARY_DIR "${_OPENMESH_LIBRARY_DIR}" CACHE PATH "The directory where the OpenMesh libraries can be found.")
134
endif()
135

Jan Möbius's avatar
Jan Möbius committed
136
if ( NOT DEFINED OPENMESH_DOCS )
137
  set( OPENMESH_DOCS true CACHE BOOL "Enable or disable building of documentation" )
Jan Möbius's avatar
Jan Möbius committed
138
139
140
141
142
endif()

if (OPENMESH_DOCS)
  add_subdirectory (Doc)
endif()
143
144

# ========================================================================
Jan Möbius's avatar
Jan Möbius committed
145
# Bundle generation (Targets exist, now configure them)
146
147
# ========================================================================

148
149
# Only call fixbundle, when we are building OpenMesh standalone
if(${PROJECT_NAME} MATCHES "OpenMesh")
150

151
152
153
154
  if (WIN32 AND  BUILD_APPS )
    # prepare bundle generation cmake file and add a build target for it
    configure_file ("${CMAKE_SOURCE_DIR}/cmake/fixbundle.cmake.win.in"
       "${CMAKE_BINARY_DIR}/fixbundle.win.cmake" @ONLY IMMEDIATE)
155

156
157
158
159
160
161
    if ( NOT "${CMAKE_GENERATOR}" MATCHES "MinGW Makefiles" )
      # let bundle generation depend on all targets
      add_dependencies (fixbundle QtViewer DecimaterGui)
    endif()
 
  endif()
162
163
164
 
  # On apple we do a fixbundle, which is only necessary for the apps and not for the libs
  if (APPLE AND BUILD_APPS)
165
166
167
    # prepare bundle generation cmake file and add a build target for it
    configure_file ("${CMAKE_SOURCE_DIR}/cmake/fixbundle.cmake.in"
       "${CMAKE_BINARY_DIR}/fixbundle.cmake" @ONLY IMMEDIATE)
168

169
170
171
172
173
174
    # let bundle generation depend on all targets
    add_dependencies (fixbundle DecimaterGui ProgViewer QtViewer SubdividerGui) 

    # Required for Snow leopard, and the latest qt. Then the resources have to be copied
    if ( EXISTS "/opt/local/libexec/qt4-mac/lib/QtGui.framework/Versions/4/Resources/qt_menu.nib" )
        add_custom_command(TARGET OpenMesh POST_BUILD
175
176
           COMMAND ${CMAKE_COMMAND} -E copy_directory "/opt/local/libexec/qt4-mac/lib/QtGui.framework/Versions/4/Resources/qt_menu.nib" 
                                                      "${CMAKE_BINARY_DIR}/Build/Libraries/qt_menu.nib" )
177
178
179
180
    endif ()
  endif ()

endif()
181
182
183

# ========================================================================

Jan Möbius's avatar
Jan Möbius committed
184
185
186
187
188
189
190
# Generate openmesh.pc file

set(DEST_DIR "${CMAKE_INSTALL_PREFIX}")
set(PRIVATE_LIBS "-lOpenMeshCore -lOpenMeshTools")

configure_file("openmesh.pc.in" "${CMAKE_CURRENT_BINARY_DIR}/openmesh.pc" @ONLY)

191
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/openmesh.pc DESTINATION libdata/pkgconfig)
Jan Möbius's avatar
Jan Möbius committed
192
193
194
195
196
197

# generate target file

install(EXPORT OpenMeshConfig DESTINATION share/OpenMesh/cmake)

export(TARGETS OpenMeshCore OpenMeshTools FILE OpenMeshConfig.cmake)
198
199
200

# display results
acg_print_configure_header (OPENMESH "OpenMesh")