1 cmake_minimum_required (VERSION 2.8)
5 include (FindPkgConfig)
6 include (CheckCCompilerFlag)
7 include (CheckSymbolExists)
9 find_package (OpenGL REQUIRED)
10 find_package (GLUT REQUIRED)
13 find_library (GLEW_glew_LIBRARY GLEW
17 find_path (GLEW_INCLUDE_DIR GL/glew.h
21 if (PKG_CONFIG_FOUND AND NOT WIN32)
22 pkg_check_modules (GLEW REQUIRED glew>=1.5.4)
23 pkg_check_modules (EGL egl)
24 pkg_check_modules (GLESV1 glesv1_cm)
25 pkg_check_modules (GLESV2 glesv2)
26 pkg_check_modules (VG vg)
27 pkg_check_modules (OSMESA osmesa)
30 # Check for FreeGLUT 2.6 or later
31 set (CMAKE_REQUIRED_INCLUDES "${GLUT_INCLUDE_DIR}")
32 set (CMAKE_REQUIRED_LIBRARIES "${GLUT_glut_LIBRARY}")
33 check_symbol_exists ("glutInitContextProfile" "GL/glut.h;GL/freeglut.h" HAVE_FREEGLUT)
35 add_definitions (-DHAVE_FREEGLUT)
42 # On Mac OS X, GLX is provided as a separate OpenGL implementation, different
43 # from the standard OpenGL framework which provides support for GLUT and native
44 # Mac OS X applications.
47 find_path (X11_GL_INCLUDE_PATH GL/glx.h ${X11_INC_SEARCH_PATH})
48 if (NOT X11_GL_INCLUDE_PATH)
49 message (WARNING "Could not find GL/glx.h")
51 endif (NOT X11_GL_INCLUDE_PATH)
52 set (X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_GL_INCLUDE_PATH})
54 find_library (X11_GL_LIB GL ${X11_LIB_SEARCH_PATH})
56 message (WARNING "Could not find libGL.dylib")
58 endif (NOT X11_GL_LIB)
60 find_library (X11_GLU_LIB GLU ${X11_LIB_SEARCH_PATH})
62 message (WARNING "Could not find libGLU.dylib")
64 endif (NOT X11_GLU_LIB)
66 set (X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${OPENGL_INCLUDE_DIR})
67 set (X11_GL_LIB ${OPENGL_gl_LIBRARY})
68 set (X11_GLU_LIB ${OPENGL_glu_LIBRARY})
72 if (CMAKE_COMPILER_IS_GNUCC)
76 -Wmissing-declarations
78 #-Wold-style-definition
79 #-Wdeclaration-after-statement
81 set (CMAKE_C_FLAGS "-Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Wbad-function-cast ${CMAKE_CXX_FLAGS}")
85 # Nobody likes to include windows.h:
86 # - Microsoft's GL/gl.h header depends on windows.h but doesn't include it;
87 # - GLEW temporarily defines the necessary defines but undefines them later
88 # - certain GLUT distributions don't include it;
89 # - most of our programs are meant to be portable so don't include it.
91 # We could try to replicate the windows.h definitions required by
92 # GL/gl.h, but the build time savings don't compensate the constant
93 # headaches that brings, so instead we force windows.h to be included
96 add_definitions (-FIwindows.h)
98 add_definitions (--include windows.h)
101 # Don't define min/max macros
102 add_definitions (-DNOMINMAX)
104 # MSVC & MinGW only define & use APIENTRY
105 add_definitions (-DGLAPIENTRY=__stdcall)
107 link_libraries (winmm)
111 message (WARNING "MSVC builds are unmainted. MinGW-w64 is recommended.")
113 # Enable math constants defines
114 add_definitions (-D_USE_MATH_DEFINES)
116 # Silence several MSVC pedantic warnings
117 add_definitions (-D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS)
118 add_definitions (-D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS)
119 add_definitions (-wd4018) # signed/unsigned mismatch
120 add_definitions (-wd4244) # conversion' conversion from 'type1' to 'type2', possible loss of data
121 add_definitions (-wd4305) # truncation from 'type1' to 'type2'
124 # http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_build_my_MSVC_application_with_a_static_runtime.3F
126 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
127 CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO
129 if (${flag_var} MATCHES "/MD")
130 string (REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
132 endforeach (flag_var)
136 # Avoid depending on MinGW runtime DLLs
137 check_c_compiler_flag (-static-libgcc HAVE_STATIC_LIBGCC_FLAG)
138 if (HAVE_STATIC_LIBGCC_FLAG)
139 set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc")
140 set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libgcc")
141 set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -static-libgcc")
143 check_c_compiler_flag (-static-libstdc++ HAVE_STATIC_LIBSTDCXX_FLAG)
144 if (HAVE_STATIC_LIBSTDCXX_FLAG)
145 set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++")
146 set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libstdc++")
147 set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -static-libstdc++")
152 # Silence deprecated function warnings (we rely on GLUT which is now
153 # declared as deprecated)
154 add_definitions (-Wno-deprecated-declarations)
157 add_definitions(-DDEMOS_DATA_DIR=\"../data/\")
159 if (BUILD_SHARED_LIBS AND NOT DEFINED LIBDIR)
161 endif (BUILD_SHARED_LIBS AND NOT DEFINED LIBDIR)
163 add_subdirectory (src)
166 install (FILES index.html DESTINATION doc)
168 set (CPACK_PACKAGE_NAME "mesa-demos")
169 set (CPACK_PACKAGE_VERSION_MAJOR "8")
170 set (CPACK_PACKAGE_VERSION_MINOR "4")
171 set (CPACK_PACKAGE_VERSION_PATCH "0")
174 set (CPACK_GENERATOR "ZIP")
176 set (CPACK_GENERATOR "DragNDrop")
177 set (CPACK_DMG_FORMAT "UDBZ")
179 set (CPACK_GENERATOR "TBZ2")