summaryrefslogtreecommitdiff
path: root/CMake/fl_create_example.cmake
diff options
context:
space:
mode:
authorAlbrecht Schlosser <albrechts.fltk@online.de>2020-06-13 15:19:27 +0200
committerAlbrecht Schlosser <albrechts.fltk@online.de>2020-07-15 00:34:53 +0200
commit720b84ef9d086245f5119d143202a2661a78ca53 (patch)
tree26bcd11ffa797c3c01917507e9204fbc9f9b45aa /CMake/fl_create_example.cmake
parent54425030774eb04b29c749ffa85d224c8bbfcc34 (diff)
CMake: refactor and reformat CMake files
- raise minimum CMake version from 2.6.3 to 3.2.3 (Jun 01, 2015) - indent all CMake files according to the CMP (2 col.) - refactor FLTK version number definitions and usage - unify CMake and autoconf/configure variable names: - FL_VERSION -> FLTK_VERSION - FL_MAJOR_VERSION -> FLTK_VERSION_MAJOR - etc. for _MINOR_ and _PATCH_, respectively - note: this does not affect FL_VERSION etc. in source code - generate "export headers" for all libraries (experimental: OFF) - port some forgotten goodies from branch-1.3 to master - merge and improve macro 'create_example' (WIP) - remove "temporary" options and code for older CMake versions - include and use 'GenerateExportHeader' (experimental, WIP: OFF) - note: created header files are not yet used - build only *one* DLL with Visual Studio (tested, works) - similar to the bundled IDE projects in 1.3.x - add some dynamically linked test/demo programs ('*-shared') if shared libraries are built (WIP) - split 'macros.cmake': use one file per macro
Diffstat (limited to 'CMake/fl_create_example.cmake')
-rw-r--r--CMake/fl_create_example.cmake145
1 files changed, 145 insertions, 0 deletions
diff --git a/CMake/fl_create_example.cmake b/CMake/fl_create_example.cmake
new file mode 100644
index 000000000..6fa14c4e9
--- /dev/null
+++ b/CMake/fl_create_example.cmake
@@ -0,0 +1,145 @@
+#
+# A macro used by the CMake build system for the Fast Light Tool Kit (FLTK).
+# Written by Michael Surette
+#
+# Copyright 1998-2020 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
+#
+
+#######################################################################
+#
+# macro CREATE_EXAMPLE - Create a test/demo program
+#
+# Input:
+#
+# - NAME: program name, e.g. 'hello'
+#
+# - SOURCES: list of source files, separated by ';' (needs quotes)
+# Sources can be:
+# - .c/.cxx files, e.g. 'hello.cxx'
+# - .fl (fluid) files, e.g. 'radio.fl'
+# - .plist file (macOS), e.g. 'editor-Info.plist'
+# - .icns file (macOS Icon), e.g. 'checkers.icns'
+# File name (type), e.g. '.icns' matters, it is parsed internally.
+# Order of sources doesn't matter, multiple .cxx and .fl files are
+# supported, but only one .plist and .icns file.
+# macOS specific files are ignored on other platforms.
+#
+# - LIBRARIES:
+# List of libraries (CMake target names), separated by ';'. Needs
+# quotes if more than one library is needed, e.g. "fltk_gl;fltk"
+#
+# CREATE_EXAMPLE can have an optional fourth argument with a list of options
+# - the option ANDROID_OK is set if CREATE_EXAMPLE creates code for Android
+# builds in addition to the native build
+#
+#######################################################################
+
+macro (CREATE_EXAMPLE NAME SOURCES LIBRARIES)
+
+ set (srcs) # source files
+ set (flsrcs) # fluid source (.fl) files
+ set (TARGET_NAME ${NAME}) # CMake target name
+ set (FLUID_SOURCES) # generated sources
+ set (ICON_NAME) # macOS icon (max. one)
+ set (PLIST) # macOS .plist file (max. one)
+ set (RESOURCE_PATH) # macOS resource path
+
+ # rename target name "help" (reserved since CMake 2.8.12 and later)
+ # FIXME: not necessary in FLTK 1.4 but left for compatibility (06/2020)
+
+ if (${TARGET_NAME} STREQUAL "help")
+ set (TARGET_NAME "test_help")
+ endif (${TARGET_NAME} STREQUAL "help")
+
+ # filter input files for different handling (fluid, icon, plist, source)
+
+ foreach (src ${SOURCES})
+ if ("${src}" MATCHES "\\.fl$")
+ list (APPEND flsrcs ${src})
+ elseif ("${src}" MATCHES "\\.icns$")
+ set (ICON_NAME "${src}")
+ elseif ("${src}" MATCHES "\\.plist$")
+ set (PLIST "${src}")
+ else ()
+ list (APPEND srcs ${src})
+ endif ("${src}" MATCHES "\\.fl$")
+ endforeach (src)
+
+ if (flsrcs)
+ FLTK_RUN_FLUID (FLUID_SOURCES "${flsrcs}")
+ endif (flsrcs)
+
+ ## FIXME ## #############################################################
+ ## FIXME ## The macOS specific code needs reorganization/simplification
+ ## FIXME ## -- Albrecht (06/2020)
+ ## FIXME ## =============================================================
+ ## FIXME ## Use "new" function `FLTK_SET_BUNDLE_ICON()` (?)
+ ## FIXME ## -- see CMake/FLTK-Functions.cmake (may need some tweaks)
+ ## FIXME ## -- ported from FLTK 1.3 (06/2020)
+ ## FIXME ## #############################################################
+
+ if (APPLE AND (NOT OPTION_APPLE_X11) AND (NOT OPTION_APPLE_SDL))
+
+ ## -- Code from FLTK 1.3 for reference (variable names adjusted):
+ ## add_executable (${TARGET_NAME} MACOSX_BUNDLE ${srcs} ${FLUID_SOURCES} ${ICON_NAME})
+ ## if (ICON_NAME)
+ ## FLTK_SET_BUNDLE_ICON (${TARGET_NAME} ${ICON_NAME})
+ ## endif ()
+ ## -- End of code from FLTK 1.3
+
+ if (ICON_NAME)
+ set (RESOURCE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/${TARGET_NAME}.app/Contents/Resources/${ICON_NAME}")
+ elseif (${TARGET_NAME} STREQUAL "demo")
+ set (RESOURCE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/demo.menu")
+ endif (ICON_NAME)
+
+ if (RESOURCE_PATH)
+ add_executable (${TARGET_NAME} MACOSX_BUNDLE ${srcs} ${FLUID_SOURCES} ${RESOURCE_PATH})
+ if (${TARGET_NAME} STREQUAL "demo")
+ target_compile_definitions (demo PUBLIC USING_XCODE)
+ endif (${TARGET_NAME} STREQUAL "demo")
+ else ()
+ add_executable (${TARGET_NAME} MACOSX_BUNDLE ${srcs} ${FLUID_SOURCES})
+ endif (RESOURCE_PATH)
+ else ()
+ add_executable (${TARGET_NAME} WIN32 ${srcs} ${FLUID_SOURCES})
+ endif (APPLE AND (NOT OPTION_APPLE_X11) AND (NOT OPTION_APPLE_SDL))
+
+ set_target_properties (${TARGET_NAME}
+ PROPERTIES OUTPUT_NAME ${NAME}
+ )
+
+ if (APPLE AND RESOURCE_PATH)
+ if (ICON_NAME)
+ set_target_properties (${TARGET_NAME} PROPERTIES MACOSX_BUNDLE_ICON_FILE ${ICON_NAME})
+ endif (ICON_NAME)
+ set_target_properties (${TARGET_NAME} PROPERTIES RESOURCE ${RESOURCE_PATH})
+ endif (APPLE AND RESOURCE_PATH)
+
+ if (APPLE AND (NOT OPTION_APPLE_X11) AND (NOT OPTION_APPLE_SDL) AND PLIST)
+ set_target_properties (${TARGET_NAME} PROPERTIES MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/${PLIST}")
+ endif (APPLE AND (NOT OPTION_APPLE_X11) AND (NOT OPTION_APPLE_SDL) AND PLIST)
+
+ target_link_libraries (${TARGET_NAME} ${LIBRARIES})
+
+ # Parse optional fourth argument 'ANDROID_OK', see description above.
+
+ if (${ARGC} GREATER 3)
+ foreach (OPTION ${ARGV3})
+ if (${OPTION} STREQUAL ANDROID_OK AND OPTION_CREATE_ANDROID_STUDIO_IDE)
+ CREATE_ANDROID_IDE_FOR_TEST (${NAME} ${SOURCES} ${LIBRARIES})
+ endif ()
+ endforeach ()
+ endif ()
+
+endmacro (CREATE_EXAMPLE NAME SOURCES LIBRARIES)