diff options
Diffstat (limited to 'fltk-options')
| -rw-r--r-- | fltk-options/CMakeLists.txt | 124 | ||||
| -rw-r--r-- | fltk-options/fltk-options-shared.plist | 34 |
2 files changed, 110 insertions, 48 deletions
diff --git a/fltk-options/CMakeLists.txt b/fltk-options/CMakeLists.txt index 912832839..3f7b1436e 100644 --- a/fltk-options/CMakeLists.txt +++ b/fltk-options/CMakeLists.txt @@ -1,7 +1,7 @@ # # CMakeLists.txt to build fltk-options for the FLTK project using CMake (www.cmake.org) # -# Copyright 2023-2024 by Bill Spitzak and others. +# Copyright 2023-2025 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 @@ -15,46 +15,95 @@ # # Targets that will be built: fltk-options and fltk-options-cmd (Windows) -set(TARGETS fltk-options) +set(TARGETS "") if(APPLE AND NOT FLTK_BACKEND_X11) - - # macOS - + set(BACKEND_APPLE TRUE) set(ICON_NAME fltk-options.icns) set(ICON_PATH "${CMAKE_CURRENT_SOURCE_DIR}/icons/${ICON_NAME}") - add_executable(fltk-options MACOSX_BUNDLE fltk-options.cxx ${ICON_PATH}) + list(APPEND SOURCES ${ICON_PATH}) +else() + set(BACKEND_APPLE FALSE) + set(ICON_NAME "") + set(ICON_PATH "") +endif() - # create macOS bundle wrapper script +# 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. - set(WRAPPER "${EXECUTABLE_OUTPUT_PATH}/${CMAKE_CFG_INTDIR}/fltk-options") - add_custom_command( - TARGET fltk-options POST_BUILD - COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/../CMake/macOS-bundle-wrapper.in ${WRAPPER} - COMMAND chmod u+x,g+x,o+x ${WRAPPER} - BYPRODUCTS ${WRAPPER} - VERBATIM - ) - unset(WRAPPER) +macro(make_target TARGET GUI SOURCES LIBS EXPORT_NAME) -else() + if(ICON_PATH) + list(APPEND SOURCES ${ICON_PATH}) # macOS only + endif() - # Option WIN32 builds a Windows GUI program, ignored on other platforms - add_executable(fltk-options WIN32 fltk-options.cxx) + # message(STATUS "[fltk-options] make_target ${TARGET} ${GUI} ${SOURCES} ${LIBS} ${EXPORT_NAME}") -endif() + # Options WIN32 and MACOSX_BUNDLE build a Windows GUI program or macOS bundle, + # respectively. Both options are ignored on other platforms. -target_link_libraries(fltk-options PRIVATE fltk::fltk) -set_target_properties(fltk-options PROPERTIES EXPORT_NAME options) + 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) # Add the console app (Windows only) # This is done for all Windows targets, even if cross-compiling. if(WIN32) - list(APPEND TARGETS fltk-options-cmd) - add_executable(fltk-options-cmd fltk-options.cxx) - target_link_libraries(fltk-options-cmd PRIVATE fltk::fltk) - set_target_properties(fltk-options-cmd PROPERTIES EXPORT_NAME options-cmd) + 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) endif() # Create aliases for all executables, @@ -68,29 +117,8 @@ endforeach() # Install fltk-options GUI and commandline tool -if(APPLE AND NOT FLTK_BACKEND_X11) - - # On macOS, fltk-options will be installed twice: - # - The bundled version goes into the destination folder ${FLTK_BINDIR}. - # - The binary without bundle goes into ${FLTK_BINDIR} as well. - # These folders are relative to the install prefix, usually 'bin'. - # The command line tool is the same executable as the one included in the bundle. - # Note: - # Both the bundle and the commandline tool are currently installed side by side. - # This may be changed in the future. - - # set bundle properties - set_target_properties(fltk-options PROPERTIES MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/fltk-options.plist") - set_target_properties(fltk-options PROPERTIES MACOSX_BUNDLE_ICON_FILE ${ICON_NAME}) - set_target_properties(fltk-options PROPERTIES XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "org.fltk.fltk-options") - - # install command line tool - install(PROGRAMS $<TARGET_FILE:fltk-options> - DESTINATION ${FLTK_BINDIR}) - -endif(APPLE AND NOT FLTK_BACKEND_X11) - # Install the GUI and (on Windows only) the commandline tool 'fltk-options-cmd' +# message(STATUS "fltk-options: INSTALL TARGETS: ${TARGETS}") install(TARGETS ${TARGETS} EXPORT FLTK-Targets diff --git a/fltk-options/fltk-options-shared.plist b/fltk-options/fltk-options-shared.plist new file mode 100644 index 000000000..6c763f42e --- /dev/null +++ b/fltk-options/fltk-options-shared.plist @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> +<dict> + <key>CFBundleInfoDictionaryVersion</key> + <string>6.0</string> + <key>CFBundleExecutable</key> + <string>fltk-options-shared</string> + <key>CFBundleIdentifier</key> + <string>org.fltk.fltk-options</string> + <key>CFBundleVersion</key> + <string>1.5.0</string> + <key>CFBundleDevelopmentRegion</key> + <string>English</string> + <key>NSHumanReadableCopyright</key> + <string>Copyright 2023-2025 by Bill Spitzak and others</string> + <key>CFAppleHelpAnchor</key> + <string>help</string> + <key>CFBundleName</key> + <string>fltk-options</string> + <key>CFBundlePackageType</key> + <string>APPL</string> + <key>CFBundleSignature</key> + <string>FLOP</string> + <key>CFBundleIconFile</key> + <string>fltk-options.icns</string> + <key>CFBundleShortVersionString</key> + <string>1.5.0</string> + <key>CFBundleGetInfoString</key> + <string>1.5.0, Copyright 2023-2025 by Bill Spitzak and others</string> + <key>NSHighResolutionCapable</key> + <true/> +</dict> +</plist> |
