summaryrefslogtreecommitdiff
path: root/examples/CMakeLists.txt
blob: a8dfa970f9dacc4fb87be97587b6ce962eb80fbf (plain)
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
#
# CMakeLists.txt used to build example apps by the CMake build system
#
# Copyright 2020-2024 by Bill Spitzak and others.
#
# This library is free software. Distribution and use rights are outlined in
# the file "COPYING" which should have been included with this file.  If this
# file is missing or damaged, see the license at:
#
#     https://www.fltk.org/COPYING.php
#
# Please see the following page on how to report bugs and issues:
#
#     https://www.fltk.org/bugs.php
#
################################################################################

include(../CMake/fl_create_example.cmake)
include(../CMake/FLTK-Functions.cmake)

set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/../bin/examples)
file(MAKE_DIRECTORY ${EXECUTABLE_OUTPUT_PATH})

################################################################################

# create separate lists of all source (.cxx) files
# depending on the required FLTK and system libraries

############################################################
# simple examples w/o extra libs
############################################################

set(SIMPLE_SOURCES
  browser-simple
  callbacks
  chart-simple
  draggable-group
  grid-simple
  howto-add_fd-and-popen
  howto-browser-with-icons
  howto-drag-and-drop
  howto-draw-an-x
  howto-flex-simple
  howto-menu-with-images
  howto-parse-args
  howto-remap-numpad-keyboard-keys
  howto-text-over-image-button
  menubar-add
  nativefilechooser-simple
  nativefilechooser-simple-app
  progress-simple
  shapedwindow
  simple-terminal
  table-as-container
  table-simple
  table-sort
  table-spreadsheet
  table-spreadsheet-with-keyboard-nav
  table-with-keynav
  table-with-right-column-stretch-fit
  table-with-right-click-menu
  tabs-simple
  textdisplay-with-colors
  texteditor-simple
  texteditor-with-dynamic-colors
  tree-as-container
  tree-custom-draw-items
  tree-custom-sort
  tree-of-tables
  tree-simple
  wizard-simple
)

############################################################
# simple FLUID examples w/o extra libs
############################################################

set(FLUID_SOURCES
  fluid-callback
)

############################################################
# examples requiring fltk::images
############################################################

set(IMAGE_SOURCES
  animgifimage
  animgifimage-play
  animgifimage-resize
  animgifimage-simple
  howto-simple-svg
)

############################################################
# examples requiring cairo
############################################################

set(CAIRO_SOURCES
  cairo-draw-x
)

############################################################
# examples requiring OpenGL3 + GLEW
############################################################

set(OPENGL_SOURCES
  OpenGL3-glut-test
  OpenGL3test
)

############################################################
# create simple example programs
############################################################

foreach(src ${SIMPLE_SOURCES})
  fl_create_example(${src} ${src}.cxx fltk::fltk)
endforeach(src)

############################################################
# create FLUID example programs
############################################################

foreach(src ${FLUID_SOURCES})
  fl_create_example(${src} ${src}.fl fltk::fltk)
endforeach(src)

############################################################
# create example programs with fltk_images library
############################################################

foreach(src ${IMAGE_SOURCES})
  fl_create_example(${src} ${src}.cxx "fltk::images")
endforeach(src)

############################################################
# create example programs requiring cairo
############################################################

foreach(src ${CAIRO_SOURCES})
  fl_create_example(${src} ${src}.cxx fltk::fltk)
endforeach(src)

############################################################
# create example programs with OpenGL3 + GLEW
############################################################
#
# Note 1: macOS (Quartz) does not need GLEW, it's included in OpenGL
# Note 2: find_package(GLEW) finds either shared or static libs or both.
# Note 3: on Windows we set the variable GLEW_USE_STATIC_LIBS=TRUE because
#         we *want* to find static libs but we *can* also use shared libs.
# Note 4: FindGLEW.cmake changed the library suffixes for MinGW in CMake 3.28.0,
#         obviously "assuming" that ".lib" is Visual Studio only. There have been
#         discussions about finding the "wrong" libraries since CMake 3.25 or so.
#         Therefore the static lib "glew32s.lib" is not found if CMake 3.28 or
#         higher is used (current version, as of this writing: 3.29.3). However,
#         this assumption is probably not true for a pure C library (glew32s).
#         This library *is* found and works well with CMake 3.15.0 - 3.27.9.
#         Users may need to copy or rename "glew32s.lib" to "glew32s.a"
#         if CMake 3.28 or higher is used.
#         Albrecht-S, May 13, 2024

if(OPENGL_FOUND)
  if(WIN32)
    set(GLEW_USE_STATIC_LIBS TRUE)
  endif()
  set(_glew_lib GLEW::glew)
  set(_glew_static FALSE)
  if(APPLE AND NOT FLTK_BACKEND_X11) # macOS Quartz
    set(_glew_lib)
    set(GLEW_FOUND TRUE)
  else()
    # set(GLEW_VERBOSE TRUE) # make `find_package(GLEW)` verbose
    set(_CMAKE_PREFIX_PATH_SAVED ${CMAKE_PREFIX_PATH})
    set(CMAKE_PREFIX_PATH ${FLTK_GLEW_DIR} ${CMAKE_PREFIX_PATH})
    find_package(GLEW MODULE)
    set(CMAKE_PREFIX_PATH ${_CMAKE_PREFIX_PATH_SAVED})
    unset(_CMAKE_PREFIX_PATH_SAVED)
    # Did we find the static lib? If yes, use it
    if(TARGET GLEW::glew_s)
      set(_glew_lib GLEW::glew_s)
      set(_glew_static TRUE)
    endif()
  endif()

  if(0) # Debug
    fl_debug_var(OPENGL_FOUND)
    fl_debug_var(GLEW_FOUND)
    fl_debug_var(GLEW_DIR)
    fl_debug_var(_glew_lib)
    fl_debug_target(GLEW::glew)
    fl_debug_target(GLEW::glew_s)
    fl_debug_target(GLEW::GLEW)
  endif() # /Debug

endif(OPENGL_FOUND)

if(OPENGL_FOUND AND (TARGET "${_glew_lib}" OR APPLE))

  # GLEW was found, create the OpenGL3 targets:

  foreach(tgt ${OPENGL_SOURCES})
    fl_create_example(${tgt} ${tgt}.cxx "fltk::gl;${_glew_lib}")
    set_property(TARGET ${tgt} PROPERTY CXX_STANDARD 11)
    set_property(TARGET ${tgt} PROPERTY CXX_STANDARD_REQUIRED TRUE)
    # define preprocessor macro GLEW_STATIC only if we link to the static lib
    if(_glew_static)
      target_compile_definitions(${tgt} PRIVATE "GLEW_STATIC")
    endif()
  endforeach(tgt)

else()

  message(STATUS
    "OpenGL or GLEW not present: OpenGL3 example programs will not be built.")
  fl_debug_var(OPENGL_FOUND)
  fl_debug_var(GLEW_FOUND)
  message("")

endif() # (OPENGL_FOUND AND TARGET "${_glew_lib}")