From fd5cd809356dc73d2ede5bb2f0db25098771cb8e Mon Sep 17 00:00:00 2001 From: Albrecht Schlosser Date: Wed, 7 Feb 2024 18:30:11 +0100 Subject: Introduce "Modern CMake" in FLTK This is a big commit and there are too many changes to list them all. The main changes are: - rename all CMake build options to 'FLTK_*' - export library targets with namespace (prefix) 'fltk::' - standardize shared library target names with suffix '-shared' - set public build properties on libraries for consumers - document library names and aliases in README.CMake.txt - document changes in "Migrating Code from FLTK 1.3 to 1.4" - partial backwards compatibility for old user projects Included but not directly related changes: - fix Windows (Visual Studio) DLL build - add CMake function fl_debug_target() to show target properties - don't build test programs if FLTK is a subproject - internal: reformat CMake code: remove space before '(' Thanks to Matthias and Manolo for their help, testing, and feeback. --- fltk-options/CMakeLists.txt | 106 ++++++++++++++++++++------------------------ 1 file changed, 47 insertions(+), 59 deletions(-) (limited to 'fltk-options') diff --git a/fltk-options/CMakeLists.txt b/fltk-options/CMakeLists.txt index 0d12e95f4..5ce9e40fb 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 by Bill Spitzak and others. +# Copyright 2023-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 @@ -14,71 +14,59 @@ # https://www.fltk.org/bugs.php # -set (CPPFILES - fltk-options.cxx -) +# Targets that will be built: fltk-options and fltk-options-cmd (Windows) +set(TARGETS fltk-options) -set (HEADERFILES -) - -set (FLTK_OPTIONS_TARGETS fltk-options) # fltk-options and optional fltk-options-cmd target -set (FLTK_OPTIONS_LIBS fltk) # libraries used to link fltk-options executables - -if (APPLE AND (NOT OPTION_APPLE_X11)) +if(APPLE AND NOT FLTK_BACKEND_X11) # macOS - set (ICON_NAME fltk-options.icns) - set (ICON_PATH "${CMAKE_CURRENT_SOURCE_DIR}/icons/${ICON_NAME}") - add_executable (fltk-options MACOSX_BUNDLE ${CPPFILES} ${HEADERFILES} ${ICON_PATH}) + 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}) # create macOS bundle wrapper script - set (WRAPPER "${EXECUTABLE_OUTPUT_PATH}/${CMAKE_CFG_INTDIR}/fltk-options") - add_custom_command ( + 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) - -else () - - # option WIN32 builds a Windows GUI program, ignored on other platforms - add_executable (fltk-options WIN32 ${CPPFILES} ${HEADERFILES}) + unset(WRAPPER) -endif () - -# we must link fltk-optons with cairo if option CAIRO is enabled -if (FLTK_HAVE_CAIRO) - target_link_directories (fltk-options PRIVATE ${PKG_CAIRO_LIBRARY_DIRS}) -endif (FLTK_HAVE_CAIRO) +else() -if (USE_GDIPLUS) # can only be true on Windows - list (APPEND FLTK_OPTIONS_LIBS gdiplus) -endif (USE_GDIPLUS) + # Option WIN32 builds a Windows GUI program, ignored on other platforms + add_executable(fltk-options WIN32 fltk-options.cxx) -target_link_libraries (fltk-options ${FLTK_OPTIONS_LIBS}) +endif() +target_link_libraries(fltk-options PRIVATE fltk::fltk) -# Add fltk-options-cmd console app (Windows only) for editing FLTK options. +# Add the console app (Windows only) # This is done for all Windows targets, even if cross-compiling. -if (WIN32) - list (APPEND FLTK_OPTIONS_TARGETS fltk-options-cmd) - add_executable (fltk-options-cmd ${CPPFILES} ${HEADERFILES}) - target_link_libraries (fltk-options-cmd ${FLTK_OPTIONS_LIBS}) - if (FLTK_HAVE_CAIRO) - target_link_directories (fltk-options-cmd PRIVATE ${PKG_CAIRO_LIBRARY_DIRS}) - endif (FLTK_HAVE_CAIRO) -endif () +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) +endif() + +# Create aliases for all executables, +# replacing 'fltk-options' with 'fltk::options' +foreach(tgt ${TARGETS}) + string(REPLACE "fltk-options" "fltk::options" alias ${tgt}) + add_executable(${alias} ALIAS ${tgt}) + unset(alias) +endforeach() -# install fltk-options GUI and commandline tool +# Install fltk-options GUI and commandline tool -if (APPLE AND (NOT OPTION_APPLE_X11)) +if(APPLE AND NOT FLTK_BACKEND_X11) # On macOS, fltk-options must be installed twice. The bundled version of # fltk-options needs to go into the /Applications folder to make it visible @@ -90,49 +78,49 @@ if (APPLE AND (NOT OPTION_APPLE_X11)) # one included in the bundle. # create bundle - 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") + 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") # The line below would wrongly install /Applications/fltk-options.icns - # ## set_target_properties (fltk-options PROPERTIES RESOURCE ${ICON_PATH}) + # ## set_target_properties(fltk-options PROPERTIES RESOURCE ${ICON_PATH}) # install fltk-options GUI and commandline tools - #install (TARGETS fltk-options DESTINATION "/Applications") + # install(TARGETS fltk-options DESTINATION "/Applications") # install command line tool - install (PROGRAMS $ DESTINATION ${FLTK_BINDIR}) + install(PROGRAMS $ DESTINATION ${FLTK_BINDIR}) else() # install fltk-options GUI and optional commandline tool 'fltk-options-cmd' # (only on Windows) - install (TARGETS ${FLTK_OPTIONS_TARGETS} + install(TARGETS ${TARGETS} EXPORT FLTK-Targets RUNTIME DESTINATION ${FLTK_BINDIR} LIBRARY DESTINATION ${FLTK_LIBDIR} ARCHIVE DESTINATION ${FLTK_LIBDIR} ) - endif (APPLE AND (NOT OPTION_APPLE_X11)) +endif(APPLE AND NOT FLTK_BACKEND_X11) -# install desktop files +# Install desktop files -if (UNIX) - install (FILES fltk-options.desktop +if(UNIX) + install(FILES fltk-options.desktop DESTINATION ${FLTK_DATADIR}/applications ) - # Install mime-type file (x-fltk-options.desktop method is deprecated) - install (FILES fltk-options.xml + # Install mime-type file(x-fltk-options.desktop method is deprecated) + install(FILES fltk-options.xml DESTINATION ${FLTK_DATADIR}/mime/packages ) # Install desktop icons - foreach (icon 32 48 64 128) - install (FILES icons/fltk-options-${icon}.png + foreach(icon 32 48 64 128) + install(FILES icons/fltk-options-${icon}.png DESTINATION ${FLTK_DATADIR}/icons/hicolor/${icon}x${icon}/apps RENAME fltk-options.png ) endforeach() -endif (UNIX) +endif(UNIX) -- cgit v1.2.3