2023-01-21 16:14:41 +00:00
|
|
|
#
|
|
|
|
|
# CMakeLists.txt to build fltk-options for the FLTK project using CMake (www.cmake.org)
|
|
|
|
|
#
|
2026-02-07 19:08:23 +00:00
|
|
|
# Copyright 2023-2026 by Bill Spitzak and others.
|
2023-01-21 16:14:41 +00: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
|
|
|
|
|
#
|
|
|
|
|
|
2024-02-07 17:30:11 +00:00
|
|
|
# Targets that will be built: fltk-options and fltk-options-cmd (Windows)
|
2025-04-17 16:23:55 +00:00
|
|
|
set(TARGETS "")
|
2023-01-21 16:14:41 +00:00
|
|
|
|
2024-02-07 17:30:11 +00:00
|
|
|
if(APPLE AND NOT FLTK_BACKEND_X11)
|
2025-04-17 16:23:55 +00:00
|
|
|
set(BACKEND_APPLE TRUE)
|
2024-02-07 17:30:11 +00:00
|
|
|
set(ICON_NAME fltk-options.icns)
|
|
|
|
|
set(ICON_PATH "${CMAKE_CURRENT_SOURCE_DIR}/icons/${ICON_NAME}")
|
2025-04-17 16:23:55 +00:00
|
|
|
list(APPEND SOURCES ${ICON_PATH})
|
|
|
|
|
else()
|
|
|
|
|
set(BACKEND_APPLE FALSE)
|
|
|
|
|
set(ICON_NAME "")
|
|
|
|
|
set(ICON_PATH "")
|
|
|
|
|
endif()
|
2023-01-21 16:14:41 +00:00
|
|
|
|
2025-04-17 16:23:55 +00:00
|
|
|
# This macro is used to avoid duplicate code to create executable programs.
|
|
|
|
|
# This must be a macro because it changes at least one global variable: TARGETS.
|
|
|
|
|
# This macro also uses some (local) variables defined above.
|
|
|
|
|
# In the future this might be converted to a function to avoid side effects.
|
2023-01-21 16:14:41 +00:00
|
|
|
|
2025-04-17 16:23:55 +00:00
|
|
|
macro(make_target TARGET GUI SOURCES LIBS EXPORT_NAME)
|
2023-01-21 16:14:41 +00:00
|
|
|
|
2025-04-17 16:23:55 +00:00
|
|
|
if(ICON_PATH)
|
|
|
|
|
list(APPEND SOURCES ${ICON_PATH}) # macOS only
|
|
|
|
|
endif()
|
2023-01-21 16:14:41 +00:00
|
|
|
|
2025-04-17 16:23:55 +00:00
|
|
|
# message(STATUS "[fltk-options] make_target ${TARGET} ${GUI} ${SOURCES} ${LIBS} ${EXPORT_NAME}")
|
2023-01-21 16:14:41 +00:00
|
|
|
|
2025-04-17 16:23:55 +00:00
|
|
|
# Options WIN32 and MACOSX_BUNDLE build a Windows GUI program or macOS bundle,
|
|
|
|
|
# respectively. Both options are ignored on other platforms.
|
2023-01-21 16:14:41 +00:00
|
|
|
|
2025-04-17 16:23:55 +00:00
|
|
|
if(${GUI})
|
|
|
|
|
add_executable(${TARGET} WIN32 MACOSX_BUNDLE ${SOURCES})
|
|
|
|
|
else()
|
|
|
|
|
add_executable(${TARGET} ${SOURCES})
|
|
|
|
|
endif(${GUI})
|
|
|
|
|
|
|
|
|
|
list(APPEND TARGETS ${TARGET})
|
|
|
|
|
|
|
|
|
|
if(BACKEND_APPLE)
|
|
|
|
|
|
|
|
|
|
# set bundle properties
|
|
|
|
|
set_target_properties(${TARGET} PROPERTIES MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/${TARGET}.plist")
|
|
|
|
|
set_target_properties(${TARGET} PROPERTIES MACOSX_BUNDLE_ICON_FILE ${ICON_NAME})
|
|
|
|
|
set_target_properties(${TARGET} PROPERTIES XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "org.fltk.${TARGET}")
|
|
|
|
|
|
|
|
|
|
# install command line tool
|
|
|
|
|
install(PROGRAMS $<TARGET_FILE:${TARGET}>
|
|
|
|
|
DESTINATION ${FLTK_BINDIR})
|
|
|
|
|
|
|
|
|
|
# create macOS bundle wrapper script
|
|
|
|
|
|
|
|
|
|
set(WRAPPER "${EXECUTABLE_OUTPUT_PATH}/${CMAKE_CFG_INTDIR}/${TARGET}")
|
|
|
|
|
add_custom_command(
|
|
|
|
|
TARGET ${TARGET} POST_BUILD
|
|
|
|
|
COMMAND cp ${FLTK_SOURCE_DIR}/CMake/macOS-bundle-wrapper.in ${WRAPPER}
|
|
|
|
|
COMMAND chmod u+x,g+x,o+x ${WRAPPER}
|
|
|
|
|
BYPRODUCTS ${WRAPPER}
|
|
|
|
|
VERBATIM
|
|
|
|
|
)
|
|
|
|
|
unset(WRAPPER)
|
|
|
|
|
|
|
|
|
|
endif(BACKEND_APPLE)
|
|
|
|
|
|
|
|
|
|
target_link_libraries(${TARGET} PRIVATE ${LIBS})
|
|
|
|
|
set_target_properties(${TARGET} PROPERTIES EXPORT_NAME ${EXPORT_NAME})
|
|
|
|
|
|
|
|
|
|
endmacro(make_target TARGET GUI LIBS EXPORT_NAME)
|
|
|
|
|
|
|
|
|
|
set(SOURCES fltk-options.cxx)
|
|
|
|
|
|
|
|
|
|
make_target(fltk-options TRUE "${SOURCES}" fltk::fltk options)
|
2023-01-21 16:14:41 +00:00
|
|
|
|
2024-02-07 17:30:11 +00:00
|
|
|
# Add the console app (Windows only)
|
2023-01-21 16:14:41 +00:00
|
|
|
# This is done for all Windows targets, even if cross-compiling.
|
|
|
|
|
|
2024-02-07 17:30:11 +00:00
|
|
|
if(WIN32)
|
2025-04-17 16:23:55 +00:00
|
|
|
make_target(fltk-options-cmd FALSE "${SOURCES}" fltk::fltk options-cmd)
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
# Add the "shared" executable (linked against the shared FLTK libs).
|
|
|
|
|
# Note 1: only the GUI version is built as "shared" executable.
|
|
|
|
|
# Note 2: For MSVC we need the special object library 'call_main'.
|
|
|
|
|
|
|
|
|
|
if(FLTK_BUILD_SHARED_LIBS)
|
|
|
|
|
if(MSVC)
|
|
|
|
|
set(libs fltk::fltk-shared call_main)
|
|
|
|
|
else()
|
|
|
|
|
set(libs fltk::fltk-shared)
|
|
|
|
|
endif()
|
|
|
|
|
make_target(fltk-options-shared TRUE "${SOURCES}" "${libs}" options-shared)
|
2024-02-07 17:30:11 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
# Create aliases for all executables,
|
|
|
|
|
# replacing 'fltk-options' with 'fltk::options'
|
2023-01-21 16:14:41 +00:00
|
|
|
|
2024-02-07 17:30:11 +00:00
|
|
|
foreach(tgt ${TARGETS})
|
|
|
|
|
string(REPLACE "fltk-options" "fltk::options" alias ${tgt})
|
|
|
|
|
add_executable(${alias} ALIAS ${tgt})
|
|
|
|
|
unset(alias)
|
|
|
|
|
endforeach()
|
2023-01-21 16:14:41 +00:00
|
|
|
|
2024-02-07 17:30:11 +00:00
|
|
|
# Install fltk-options GUI and commandline tool
|
2023-01-21 16:14:41 +00:00
|
|
|
|
2024-02-14 16:06:10 +00:00
|
|
|
# Install the GUI and (on Windows only) the commandline tool 'fltk-options-cmd'
|
2025-04-17 16:23:55 +00:00
|
|
|
# message(STATUS "fltk-options: INSTALL TARGETS: ${TARGETS}")
|
2023-01-21 16:14:41 +00:00
|
|
|
|
2026-02-07 19:08:23 +00:00
|
|
|
# note: do NOT "export" fltk-options - this could break CMake config files
|
2024-02-14 16:06:10 +00:00
|
|
|
install(TARGETS ${TARGETS}
|
|
|
|
|
RUNTIME DESTINATION ${FLTK_BINDIR}
|
|
|
|
|
LIBRARY DESTINATION ${FLTK_LIBDIR}
|
|
|
|
|
ARCHIVE DESTINATION ${FLTK_LIBDIR}
|
|
|
|
|
BUNDLE DESTINATION ${FLTK_BINDIR} # macOS: bundles
|
|
|
|
|
)
|
2023-01-21 16:14:41 +00:00
|
|
|
|
2024-02-07 17:30:11 +00:00
|
|
|
# Install desktop files
|
2023-01-21 16:14:41 +00:00
|
|
|
|
2024-02-07 17:30:11 +00:00
|
|
|
if(UNIX)
|
|
|
|
|
install(FILES fltk-options.desktop
|
2023-01-21 16:14:41 +00:00
|
|
|
DESTINATION ${FLTK_DATADIR}/applications
|
|
|
|
|
)
|
2024-02-07 17:30:11 +00:00
|
|
|
# Install mime-type file(x-fltk-options.desktop method is deprecated)
|
|
|
|
|
install(FILES fltk-options.xml
|
2023-01-21 16:14:41 +00:00
|
|
|
DESTINATION ${FLTK_DATADIR}/mime/packages
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Install desktop icons
|
2024-02-07 17:30:11 +00:00
|
|
|
foreach(icon 32 48 64 128)
|
|
|
|
|
install(FILES icons/fltk-options-${icon}.png
|
2023-01-21 16:14:41 +00:00
|
|
|
DESTINATION ${FLTK_DATADIR}/icons/hicolor/${icon}x${icon}/apps
|
|
|
|
|
RENAME fltk-options.png
|
|
|
|
|
)
|
|
|
|
|
endforeach()
|
2024-02-07 17:30:11 +00:00
|
|
|
endif(UNIX)
|