2020-06-13 16:19:27 +03:00
|
|
|
#
|
2023-03-09 14:21:49 +03:00
|
|
|
# A function used by the CMake build system for the Fast Light Tool Kit (FLTK).
|
|
|
|
# Originally written by Michael Surette
|
2020-06-13 16:19:27 +03:00
|
|
|
#
|
2024-02-07 20:30:11 +03:00
|
|
|
# Copyright 1998-2024 by Bill Spitzak and others.
|
2020-06-13 16:19:27 +03:00
|
|
|
#
|
|
|
|
# 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
|
|
|
|
#
|
|
|
|
|
2020-07-20 12:02:01 +03:00
|
|
|
################################################################################
|
2020-06-13 16:19:27 +03:00
|
|
|
#
|
2024-02-07 20:30:11 +03:00
|
|
|
# function fl_create_example - Create a test/demo (example) program
|
2020-06-13 16:19:27 +03:00
|
|
|
#
|
|
|
|
# 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'
|
2024-02-07 20:30:11 +03:00
|
|
|
# - .plist file(macOS), e.g. 'editor.plist'
|
|
|
|
# - .icns file(macOS Icon), e.g. 'checkers.icns'
|
|
|
|
# - .rc file(Windows resource file, e.g. icon definition)
|
2020-07-20 12:02:01 +03:00
|
|
|
#
|
2020-06-13 16:19:27 +03:00
|
|
|
# Order of sources doesn't matter, multiple .cxx and .fl files are
|
2020-07-20 12:02:01 +03:00
|
|
|
# supported, but only one .plist and one .icns file.
|
|
|
|
#
|
|
|
|
# File name (type), e.g. '.icns' matters, it is parsed internally:
|
|
|
|
# File types .fl, .plist, and .icns are treated specifically,
|
|
|
|
# all other file types are added to the target's source files.
|
|
|
|
#
|
|
|
|
# macOS specific .icns and .plist files are ignored on other platforms.
|
2021-05-13 17:16:50 +03:00
|
|
|
# These files must reside in the subdirectory 'mac-resources'.
|
2020-06-13 16:19:27 +03:00
|
|
|
#
|
|
|
|
# - LIBRARIES:
|
2024-02-07 20:30:11 +03:00
|
|
|
# List of libraries (CMake target names), separated by ';'. Must be
|
|
|
|
# quoted if more than one library is required, e.g. "fltk::gl;fltk::images"
|
2020-06-13 16:19:27 +03:00
|
|
|
#
|
2020-07-20 12:02:01 +03:00
|
|
|
################################################################################
|
2020-06-13 16:19:27 +03:00
|
|
|
|
2024-02-13 16:47:28 +03:00
|
|
|
function(fl_create_example NAME SOURCES LIBRARIES)
|
2020-06-13 16:19:27 +03:00
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
set(srcs) # source files
|
|
|
|
set(flsrcs) # fluid source (.fl) files
|
|
|
|
set(TARGET_NAME ${NAME}) # CMake target name
|
|
|
|
set(ICON_NAME) # macOS icon (max. one)
|
|
|
|
set(PLIST) # macOS .plist file(max. one)
|
|
|
|
set(ICON_PATH) # macOS icon resource path
|
2020-06-13 16:19:27 +03:00
|
|
|
|
2020-07-23 03:07:43 +03:00
|
|
|
# create macOS bundle? 0 = no, 1 = yes
|
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
if(APPLE AND NOT FLTK_BACKEND_X11)
|
|
|
|
set(MAC_BUNDLE 1)
|
|
|
|
else()
|
|
|
|
set(MAC_BUNDLE 0)
|
|
|
|
endif()
|
2020-06-13 16:19:27 +03:00
|
|
|
|
|
|
|
# filter input files for different handling (fluid, icon, plist, source)
|
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
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)
|
2020-06-13 16:19:27 +03:00
|
|
|
|
2020-07-20 12:02:01 +03:00
|
|
|
# generate source files from .fl files, add output to sources
|
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
if(flsrcs)
|
|
|
|
if(NOT FLTK_FLUID_EXECUTABLE)
|
2022-11-13 22:16:54 +03:00
|
|
|
message(STATUS "Example app \"${NAME}\" will not be built. FLUID executable not found.")
|
|
|
|
return ()
|
2024-02-07 20:30:11 +03:00
|
|
|
endif()
|
2020-06-13 16:19:27 +03:00
|
|
|
FLTK_RUN_FLUID (FLUID_SOURCES "${flsrcs}")
|
2024-02-07 20:30:11 +03:00
|
|
|
list(APPEND srcs ${FLUID_SOURCES})
|
|
|
|
unset(FLUID_SOURCES)
|
|
|
|
endif(flsrcs)
|
2020-06-13 16:19:27 +03:00
|
|
|
|
2020-07-20 12:02:01 +03:00
|
|
|
# set macOS (icon) resource path if applicable
|
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
if(MAC_BUNDLE AND ICON_NAME)
|
|
|
|
set(ICON_PATH "${CMAKE_CURRENT_SOURCE_DIR}/mac-resources/${ICON_NAME}")
|
|
|
|
endif(MAC_BUNDLE AND ICON_NAME)
|
2020-07-23 03:07:43 +03:00
|
|
|
|
|
|
|
##############################################################################
|
2020-07-20 12:02:01 +03:00
|
|
|
# add executable target and set properties (all platforms)
|
2020-07-23 03:07:43 +03:00
|
|
|
##############################################################################
|
2020-07-20 12:02:01 +03:00
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
if(MAC_BUNDLE)
|
2020-08-26 13:44:40 +03:00
|
|
|
add_executable (${TARGET_NAME} MACOSX_BUNDLE ${srcs} ${ICON_PATH})
|
2024-02-07 20:30:11 +03:00
|
|
|
else()
|
2021-05-13 17:16:50 +03:00
|
|
|
add_executable (${TARGET_NAME} WIN32 ${srcs})
|
2024-02-07 20:30:11 +03:00
|
|
|
endif(MAC_BUNDLE)
|
2020-08-26 13:44:40 +03:00
|
|
|
|
2020-07-20 12:02:01 +03:00
|
|
|
set_target_properties (${TARGET_NAME} PROPERTIES OUTPUT_NAME ${NAME})
|
2024-02-07 20:30:11 +03:00
|
|
|
target_link_libraries (${TARGET_NAME} PRIVATE ${LIBRARIES})
|
2020-07-20 12:02:01 +03:00
|
|
|
|
2023-12-21 21:13:49 +03:00
|
|
|
# make sure we're "exporting" global symbols like 'fl_disable_wayland',
|
|
|
|
# see also README.Wayland.txt and CMake policy CMP0065.
|
|
|
|
|
|
|
|
set_target_properties (${TARGET_NAME} PROPERTIES ENABLE_EXPORTS TRUE)
|
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
### *FIXME* Remove the entire 'if' block below when verified:
|
|
|
|
|
|
|
|
if(0) # This should no longer be necessary (implied by linking the libs)
|
|
|
|
|
|
|
|
# we must link all programs with Cairo if option CAIROEXT is enabled
|
|
|
|
if(FLTK_HAVE_CAIROEXT)
|
|
|
|
target_link_libraries(${TARGET_NAME} PRIVATE ${PKG_CAIRO_LIBRARIES})
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(FLTK_HAVE_CAIRO AND PKG_CAIRO_LIBRARY_DIRS)
|
|
|
|
target_link_directories(${TARGET_NAME} PRIVATE ${PKG_CAIRO_LIBRARY_DIRS})
|
|
|
|
endif()
|
2021-12-19 00:42:30 +03:00
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
endif() # This should no longer be necessary (implied by linking the libs)
|
2021-07-26 18:14:29 +03:00
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
# Search the current binary directory for header files created by CMake
|
|
|
|
# or fluid and the source folder for other headers included by test programs
|
2021-02-28 16:56:19 +03:00
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
target_include_directories(${TARGET_NAME} PRIVATE
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}
|
|
|
|
)
|
|
|
|
|
|
|
|
if(MAC_BUNDLE)
|
|
|
|
if(PLIST)
|
|
|
|
set_target_properties(${TARGET_NAME} PROPERTIES MACOSX_BUNDLE_INFO_PLIST
|
2021-05-13 17:16:50 +03:00
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/mac-resources/${PLIST}")
|
|
|
|
endif()
|
2020-06-13 16:19:27 +03:00
|
|
|
|
2023-02-02 22:54:19 +03:00
|
|
|
string(REPLACE "_" "-" FLTK_BUNDLE_ID "org.fltk.${TARGET_NAME}")
|
2024-02-07 20:30:11 +03:00
|
|
|
set_target_properties(${TARGET_NAME} PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "${TARGET_NAME}")
|
|
|
|
set_target_properties(${TARGET_NAME} PROPERTIES MACOSX_BUNDLE_GUI_IDENTIFIER "${FLTK_BUNDLE_ID}")
|
|
|
|
set_target_properties(${TARGET_NAME} PROPERTIES XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "${FLTK_BUNDLE_ID}")
|
2021-05-13 17:16:50 +03:00
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
if(ICON_NAME)
|
|
|
|
set_target_properties(${TARGET_NAME} PROPERTIES MACOSX_BUNDLE_ICON_FILE ${ICON_NAME})
|
|
|
|
set_target_properties(${TARGET_NAME} PROPERTIES RESOURCE ${ICON_PATH})
|
|
|
|
endif()
|
|
|
|
endif()
|
2020-06-13 16:19:27 +03:00
|
|
|
|
2020-08-18 17:23:25 +03:00
|
|
|
##############################################################################
|
|
|
|
# Copy macOS "bundle wrapper" (shell script) to target directory.
|
|
|
|
# The "custom command" will be executed "POST_BUILD".
|
|
|
|
##############################################################################
|
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
if(MAC_BUNDLE)
|
|
|
|
set(WRAPPER "${EXECUTABLE_OUTPUT_PATH}/${CMAKE_CFG_INTDIR}/${TARGET_NAME}")
|
2021-05-13 17:16:50 +03:00
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
add_custom_command(
|
2020-08-18 17:23:25 +03:00
|
|
|
TARGET ${TARGET_NAME} POST_BUILD
|
2021-05-13 17:16:50 +03:00
|
|
|
COMMAND cp ${FLTK_SOURCE_DIR}/CMake/macOS-bundle-wrapper.in ${WRAPPER}
|
2020-08-18 17:23:25 +03:00
|
|
|
COMMAND chmod u+x,g+x,o+x ${WRAPPER}
|
|
|
|
BYPRODUCTS ${WRAPPER}
|
|
|
|
# COMMENT "Creating macOS bundle wrapper script ${WRAPPER}"
|
|
|
|
VERBATIM
|
|
|
|
)
|
2024-02-07 20:30:11 +03:00
|
|
|
unset(WRAPPER)
|
|
|
|
endif(MAC_BUNDLE)
|
2020-08-18 17:23:25 +03:00
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
##############################################################################
|
|
|
|
# MSVC: Add fltk-shared (DLL) path to Environment 'PATH' for debugging
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
if(MSVC AND TARGET fltk-shared)
|
|
|
|
set(DllDir "$<SHELL_PATH:$<TARGET_FILE_DIR:fltk-shared>>")
|
2023-11-25 21:10:00 +03:00
|
|
|
set_target_properties(${TARGET_NAME} PROPERTIES
|
|
|
|
VS_DEBUGGER_ENVIRONMENT "PATH=${DllDir};$ENV{PATH}"
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2024-02-13 16:47:28 +03:00
|
|
|
endfunction()
|