diff options
Diffstat (limited to 'CMake')
| -rw-r--r-- | CMake/FLTK-Functions.cmake | 79 | ||||
| -rw-r--r-- | CMake/FLTKConfig.cmake.in | 122 | ||||
| -rw-r--r-- | CMake/cmake_uninstall.cmake.in | 39 | ||||
| -rw-r--r-- | CMake/compatibility.cmake | 2 | ||||
| -rw-r--r-- | CMake/export.cmake | 138 | ||||
| -rw-r--r-- | CMake/fl_add_library.cmake | 259 | ||||
| -rw-r--r-- | CMake/fl_create_example.cmake | 181 | ||||
| -rw-r--r-- | CMake/fl_debug_pkg.cmake | 40 | ||||
| -rw-r--r-- | CMake/fl_debug_var.cmake | 101 | ||||
| -rw-r--r-- | CMake/install-symlinks.cmake.in | 4 | ||||
| -rw-r--r-- | CMake/install.cmake | 65 | ||||
| -rw-r--r-- | CMake/options.cmake | 1387 | ||||
| -rw-r--r-- | CMake/resources.cmake | 183 | ||||
| -rw-r--r-- | CMake/setup.cmake | 191 | ||||
| -rw-r--r-- | CMake/variables.cmake | 244 |
15 files changed, 1728 insertions, 1307 deletions
diff --git a/CMake/FLTK-Functions.cmake b/CMake/FLTK-Functions.cmake index 009653721..a8d339fac 100644 --- a/CMake/FLTK-Functions.cmake +++ b/CMake/FLTK-Functions.cmake @@ -1,8 +1,8 @@ # # FLTK-Functions.cmake -# Written by Michael Surette +# Originally written by Michael Surette # -# Copyright 1998-2021 by Bill Spitzak and others. +# Copyright 1998-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 @@ -15,22 +15,37 @@ # https://www.fltk.org/bugs.php # -####################################################################### +################################################################################ # functions used by the build system and exported for the end-user -####################################################################### +################################################################################ -# USAGE: FLTK_RUN_FLUID TARGET_NAME "FLUID_SOURCE [.. FLUID_SOURCE]" +################################################################################ +# +# fltk_run_fluid: Run fluid to compile fluid (.fl) files +# +# Usage: fltk_run_fluid(SOURCES "FLUID_SOURCE [.. FLUID_SOURCE]") +# +# Input: The CMake variable "FL_FILES" must contain a list of input +# file names. Only names ending in ".fl" are considered and +# compiled to their ".cxx" and ".h" files which are stored +# in the current build directory. +# +# Output: "SOURCES" is used as a CMake variable name that is assigned the +# names of the compiled ".cxx" files as a ";" separated list in the +# parent scope (the caller's scope). +# +################################################################################ -function (FLTK_RUN_FLUID TARGET SOURCES) +function(fltk_run_fluid SOURCES FL_FILES) - if (NOT FLTK_FLUID_EXECUTABLE) - message (WARNING "Not building ${SOURCES}. FLUID executable not found.") - return () - endif (NOT FLTK_FLUID_EXECUTABLE) + if(NOT FLTK_FLUID_EXECUTABLE) + message(WARNING "Not building ${FL_FILES}. FLUID executable not found.") + return() + endif() - set (CXX_FILES) - foreach (src ${SOURCES}) - if ("${src}" MATCHES "\\.fl$") + set(CXX_FILES) + foreach(src ${FL_FILES}) + if("${src}" MATCHES "\\.fl$") string(REGEX REPLACE "(.*).fl" \\1 basename ${src}) add_custom_command( OUTPUT "${basename}.cxx" "${basename}.h" @@ -38,21 +53,33 @@ function (FLTK_RUN_FLUID TARGET SOURCES) DEPENDS ${src} MAIN_DEPENDENCY ${src} ) - list (APPEND CXX_FILES "${basename}.cxx") - endif ("${src}" MATCHES "\\.fl$") - endforeach () - set (${TARGET} ${CXX_FILES} PARENT_SCOPE) + list(APPEND CXX_FILES "${basename}.cxx") + endif() + endforeach() + set(${SOURCES} ${CXX_FILES} PARENT_SCOPE) -endfunction (FLTK_RUN_FLUID TARGET SOURCES) +endfunction(fltk_run_fluid SOURCES FL_FILES) -####################################################################### -# sets the bundle icon for OSX bundles +################################################################################ +# +# fltk_set_bundle_icon: Set the bundle icon for macOS bundles +# +# This function sets macOS specific target properties. These properties are +# ignored on other platforms. +# +# Usage: fltk_set_bundle_icon(TARGET ICON_PATH) +# +# TARGET must be a valid CMake target that has been created before this +# function is called. It must not be an alias name. +# +################################################################################ -function (FLTK_SET_BUNDLE_ICON TARGET ICON_PATH) - get_filename_component (ICON_NAME "${ICON_PATH}" NAME) - set_target_properties ("${TARGET}" PROPERTIES - MACOSX_BUNDLE_ICON_FILE "${ICON_NAME}" - RESOURCE "${ICON_PATH}" +function(fltk_set_bundle_icon TARGET ICON_PATH) + get_filename_component(ICON_NAME "${ICON_PATH}" NAME) + set_target_properties(${TARGET} + PROPERTIES + MACOSX_BUNDLE_ICON_FILE "${ICON_NAME}" + RESOURCE "${ICON_PATH}" ) -endfunction (FLTK_SET_BUNDLE_ICON TARGET ICON_PATH) +endfunction(fltk_set_bundle_icon TARGET ICON_PATH) diff --git a/CMake/FLTKConfig.cmake.in b/CMake/FLTKConfig.cmake.in index e647e6453..23f784698 100644 --- a/CMake/FLTKConfig.cmake.in +++ b/CMake/FLTKConfig.cmake.in @@ -8,7 +8,7 @@ # # FLTK_VERSION - FLTK version string ("x.y.z") # FLTK_INCLUDE_DIRS - FLTK include directories -# FLTK_LIBRARIES - list of FLTK libraries built (not yet implemented) +# FLTK_LIBRARIES - list of built FLTK libraries # FLTK_FLUID_EXECUTABLE - needed by the function FLTK_RUN_FLUID # (or the deprecated fltk_wrap_ui() CMake command) # @@ -21,28 +21,118 @@ # changed in future versions. This includes the list of defined variables # above that may be changed if necessary. # +# Note: FLTK 1.4.0 introduced "Modern CMake", therefore usage of most if not +# all of the variables mentioned above is no longer needed in user projects. +# Please use the CMake target names fltk::fltk, fltk::images, etc. instead. +# Please see README.CMake.txt for mor info on how to do this. +# + +# Optional: Create backwards compatible aliases for libraries and fluid. +# This is enabled in FLTK 1.4.0 to simplify migration of user projects +# from "classic" (1.3.x) to "modern" CMake and will likely be removed +# in a later FLTK version (maybe 1.4.x, x>2, or 1.5.0). + +set(FLTK_CREATE_COMPATIBILITY_ALIASES TRUE) + +set(FLTK_VERSION @FLTK_VERSION@) -set (FLTK_VERSION @FLTK_VERSION@) +include(${CMAKE_CURRENT_LIST_DIR}/FLTK-Targets.cmake) -include (${CMAKE_CURRENT_LIST_DIR}/FLTK-Targets.cmake) +set(FLTK_INCLUDE_DIRS "@INCLUDE_DIRS@") +set(FLTK_LIBRARIES "@FLTK_LIBRARIES@") -set (FLTK_INCLUDE_DIRS "@INCLUDE_DIRS@") +# For compatibility with CMake's FindFLTK.cmake: -# for compatibility with CMake's FindFLTK.cmake +set(FLTK_INCLUDE_DIR "${FLTK_INCLUDE_DIRS}") -set (FLTK_INCLUDE_DIR "${FLTK_INCLUDE_DIRS}") +if(CMAKE_CROSSCOMPILING) -if (CMAKE_CROSSCOMPILING) - find_file(FLUID_PATH + # Find a fluid executable on the build host to be able to build fluid programs + + find_program(FLTK_FLUID_HOST NAMES fluid fluid.exe PATHS ENV PATH + NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH ) - add_executable(fluid IMPORTED) - set_target_properties(fluid - PROPERTIES IMPORTED_LOCATION ${FLUID_PATH} - ) - set (FLTK_FLUID_EXECUTABLE ${FLUID_PATH}) -else () - set (FLTK_FLUID_EXECUTABLE fluid) -endif (CMAKE_CROSSCOMPILING) + + if(FLTK_FLUID_HOST) + + if(0) # Experimental: currently not used + # Import a special 'fluid' target called 'fluid-host' (fltk::fluid-host) + # Note: this is "the same as" the CMake variable FLTK_FLUID_EXECUTABLE + add_executable(fluid-host IMPORTED) + set_target_properties(fluid-host + PROPERTIES IMPORTED_LOCATION ${FLTK_FLUID_HOST} + ) + add_executable(fltk::fluid-host ALIAS fluid-host) + set(FLTK_FLUID_EXECUTABLE fltk::fluid-host) + + else() + + set(FLTK_FLUID_EXECUTABLE "${FLTK_FLUID_HOST}") + + endif() + + else() # fluid not found on build host + + message(STATUS "FLTKConfig.cmake (cross-compiling): fluid not found on the build host") + # note: this assigns "FLTK_FLUID_HOST-NOTFOUND" and running fluid will fail + set(FLTK_FLUID_EXECUTABLE "${FLTK_FLUID_HOST}") + + endif() + +else(CMAKE_CROSSCOMPILING) + + if(FLTK_CREATE_COMPATIBILITY_ALIASES) + + function(_fltk_make_alias target from) + if(TARGET ${from} AND NOT TARGET ${target}) + # message(STATUS "FLTKConfig.cmake - create alias: ${target} from ${from}") + get_target_property(ttype ${from} TYPE) + if(ttype STREQUAL "EXECUTABLE") + add_executable(${target} ALIAS ${from}) + else() + add_library(${target} ALIAS ${from}) + endif() + endif() + endfunction(_fltk_make_alias target) + + if(NOT TARGET fltk::fltk) + message(FATAL "FLTKConfig.cmake: target fltk::fltk does not exist!") + endif() + + _fltk_make_alias(fltk fltk::fltk) + _fltk_make_alias(fltk-shared fltk::fltk-shared) + + _fltk_make_alias(fluid fltk::fluid) + _fltk_make_alias(fluid-cmd fltk::fluid-cmd) + + _fltk_make_alias(fltk-options fltk::options) + _fltk_make_alias(fltk-options-cmd fltk::options-cmd) + + foreach(target cairo forms gl images jpeg png z) + _fltk_make_alias(fltk_${target} fltk::${target}) + _fltk_make_alias(fltk_${target}-shared fltk::${target}-shared) + endforeach() + + endif() # Create aliases ... + + # set FLTK_FLUID_EXECUTABLE: try to use the fltk::target name if it + # exists and fall back to 'fluid-cmd' or 'fluid' if not. This will + # eventually call the build host's fluid if found in the users's PATH + + if(TARGET fltk::fluid-cmd) # Windows only + set(FLTK_FLUID_EXECUTABLE fltk::fluid-cmd) + elseif(TARGET fltk::fluid) + set(FLTK_FLUID_EXECUTABLE fltk::fluid) + elseif(WIN32) + set(FLTK_FLUID_EXECUTABLE fluid-cmd) + else() + set(FLTK_FLUID_EXECUTABLE fluid) + endif() + +endif(CMAKE_CROSSCOMPILING) + +# Debug: should be commented out +# message(STATUS "FLTKConfig.cmake: FLTK_FLUID_EXECUTABLE = '${FLTK_FLUID_EXECUTABLE}'") diff --git a/CMake/cmake_uninstall.cmake.in b/CMake/cmake_uninstall.cmake.in index b2547ecf2..efd90e47f 100644 --- a/CMake/cmake_uninstall.cmake.in +++ b/CMake/cmake_uninstall.cmake.in @@ -1,8 +1,9 @@ # # Support file to uninstall the FLTK project using CMake +# # Originally written by Michael Surette # -# Copyright 1998-2023 by Bill Spitzak and others. +# Copyright 1998-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 @@ -15,13 +16,13 @@ # https://www.fltk.org/bugs.php # -if (NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") +if(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") message(FATAL_ERROR "Cannot find install manifest: \"@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt\"") -endif () +endif() -file (READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files) -string (REGEX REPLACE "\n" ";" files "${files}") +file(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files) +string(REGEX REPLACE "\n" ";" files "${files}") # Note 1: 'cmake -E remove [-f]' is deprecated since CMake 3.17 and the docs # state: "The implementation was buggy and always returned 0. It cannot be @@ -30,13 +31,13 @@ string (REGEX REPLACE "\n" ";" files "${files}") # Note 3: # Remove this distinction if: cmake_minimum_required(VERSION 3.17) or higher. -if (CMAKE_VERSION VERSION_LESS 3.17) - set (rm_cmd remove) -else () - set (rm_cmd rm) -endif () +if(CMAKE_VERSION VERSION_LESS 3.17) + set(rm_cmd remove) +else() + set(rm_cmd rm) +endif() -foreach (file ${files}) +foreach(file ${files}) message(STATUS "Uninstalling \"$ENV{DESTDIR}${file}\"") execute_process( COMMAND "${CMAKE_COMMAND}" -E ${rm_cmd} -f "$ENV{DESTDIR}${file}" @@ -45,12 +46,12 @@ foreach (file ${files}) RESULT_VARIABLE rm_retval ) - if (NOT "${rm_retval}" STREQUAL 0) - message (STATUS "Error removing \"$ENV{DESTDIR}${file}\"") - message (STATUS " Status = '${rm_retval}'") - message (STATUS " Output = '${rm_out}'") - message (STATUS " Error = '${rm_err}'") - message (FATAL_ERROR "Exiting with fatal error.") - endif () + if(NOT "${rm_retval}" STREQUAL 0) + message(STATUS "Error removing \"$ENV{DESTDIR}${file}\"") + message(STATUS " Status = '${rm_retval}'") + message(STATUS " Output = '${rm_out}'") + message(STATUS " Error = '${rm_err}'") + message(FATAL_ERROR "Exiting - uninstall may be incomplete.") + endif() -endforeach (file) +endforeach(file) diff --git a/CMake/compatibility.cmake b/CMake/compatibility.cmake index 233b4001f..ba48d80e9 100644 --- a/CMake/compatibility.cmake +++ b/CMake/compatibility.cmake @@ -62,7 +62,7 @@ # # Example: # -# fl_target_link_directories (fluid PRIVATE "${PKG_CAIRO_LIBRARY_DIRS}") +# fl_target_link_directories(fluid PRIVATE "${PKG_CAIRO_LIBRARY_DIRS}") # # In this example 'PKG_CAIRO_LIBRARY_DIRS' is platform dependent and # can be an empty list. diff --git a/CMake/export.cmake b/CMake/export.cmake index 63502a4d9..a466e37ae 100644 --- a/CMake/export.cmake +++ b/CMake/export.cmake @@ -1,8 +1,9 @@ # # Export CMake file to build the FLTK project using CMake (www.cmake.org) +# # Originally written by Michael Surette # -# Copyright 1998-2022 by Bill Spitzak and others. +# Copyright 1998-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 @@ -21,42 +22,65 @@ # Set the fluid executable path used to create .cxx/.h from .fl files -if (FLTK_BUILD_FLUID AND NOT CMAKE_CROSSCOMPILING) - # use the fluid executable we build - if (WIN32) - set (FLTK_FLUID_EXECUTABLE fluid-cmd) - set (FLUID_EXPORT fluid fluid-cmd) # export fluid and fluid-cmd - else () - set (FLTK_FLUID_EXECUTABLE fluid) - set (FLUID_EXPORT fluid) # export fluid - endif () -else () - # find a fluid executable on the host system - find_file(FLUID_PATH +if(FLTK_BUILD_FLUID AND NOT CMAKE_CROSSCOMPILING) + # Use the fluid executable we build using its namespaced target name + if(WIN32) + set(FLTK_FLUID_EXECUTABLE fltk::fluid-cmd) + set(FLUID_EXPORT fluid fluid-cmd) # export fluid and fluid-cmd + else() + set(FLTK_FLUID_EXECUTABLE fltk::fluid) + set(FLUID_EXPORT fluid) # export fluid + endif() +else() + # We don't build fluid /or/ we are cross-compiling (or both): + # we need to find a fluid executable on the build host. + # The search is restricted to the user's PATH (environment). + find_program(FLTK_FLUID_HOST NAMES fluid fluid.exe PATHS ENV PATH + NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH ) - set (FLTK_FLUID_EXECUTABLE ${FLUID_PATH}) - set (FLUID_EXPORT "") # don't export fluid -endif (FLTK_BUILD_FLUID AND NOT CMAKE_CROSSCOMPILING) + if(NOT FLTK_FLUID_HOST) + message(STATUS "Warning: fluid not found on the build system!") + endif() + # Note: this *may* assign "FLTK_FLUID_HOST-NOTFOUND" + set(FLTK_FLUID_EXECUTABLE "${FLTK_FLUID_HOST}") + set(FLUID_EXPORT "") # don't export fluid +endif(FLTK_BUILD_FLUID AND NOT CMAKE_CROSSCOMPILING) + +if(0) # Debug + message(STATUS "##############################################################") + message(STATUS "[export.cmake] INFO: Did we find fluid?") + fl_debug_var(FLTK_FLUID_HOST) + fl_debug_var(FLTK_FLUID_EXECUTABLE) + fl_debug_var(FLTK_BUILD_FLUID) + fl_debug_var(CMAKE_CROSSCOMPILING) + message(STATUS "##############################################################") +endif() # generate FLTK-Targets.cmake for build directory use -export (TARGETS ${FLUID_EXPORT} ${FLTK_LIBRARIES} FILE ${CMAKE_CURRENT_BINARY_DIR}/FLTK-Targets.cmake) +export(TARGETS + ${FLUID_EXPORT} ${FLTK_LIBRARIES} + FILE + ${CMAKE_CURRENT_BINARY_DIR}/FLTK-Targets.cmake + NAMESPACE + fltk::) # generate FLTK-Functions.cmake for build directory use -configure_file ( +configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/CMake/FLTK-Functions.cmake ${CMAKE_CURRENT_BINARY_DIR}/FLTK-Functions.cmake COPYONLY ) # generate FLTKConfig.cmake for build directory use -set (INCLUDE_DIRS "${FLTK_INCLUDE_DIRS}") -if (FLTK_HAVE_CAIRO) - list (APPEND INCLUDE_DIRS ${PKG_CAIRO_INCLUDE_DIRS}) -endif () -set (CONFIG_PATH ${CMAKE_CURRENT_BINARY_DIR}) +set(INCLUDE_DIRS "${FLTK_INCLUDE_DIRS}") +if(FLTK_HAVE_CAIRO OR FLTK_USE_CAIRO) + list(APPEND INCLUDE_DIRS ${PKG_CAIRO_INCLUDE_DIRS}) +endif() +list(REMOVE_DUPLICATES INCLUDE_DIRS) +set(CONFIG_PATH ${CMAKE_CURRENT_BINARY_DIR}) configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/CMake/FLTKConfig.cmake.in @@ -65,14 +89,14 @@ configure_file( ) # generate fltk-config for build directory use -set (prefix ${CMAKE_CURRENT_BINARY_DIR}) -set (exec_prefix "\${prefix}") -set (includedir "${CMAKE_CURRENT_SOURCE_DIR}") -set (BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}") -set (libdir "\${exec_prefix}/lib") -set (srcdir ".") +set(prefix ${CMAKE_CURRENT_BINARY_DIR}) +set(exec_prefix "\${prefix}") +set(includedir "${CMAKE_CURRENT_SOURCE_DIR}") +set(BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}") +set(libdir "\${exec_prefix}/lib") +set(srcdir ".") -set (LIBNAME "${libdir}/libfltk.a") +set(LIBNAME "${libdir}/libfltk.a") configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/fltk-config.in" @@ -80,38 +104,38 @@ configure_file( @ONLY ) -# Set execute permissions on fltk-config in build dir -# Note: file(CHMOD) available since CMake 3.19, +# Set execute permissions on fltk-config in the build directory. +# Note: file(CHMOD) is available since CMake 3.19, # use fallback before CMake 3.19 -if (CMAKE_VERSION VERSION_LESS 3.19) - if (UNIX OR MSYS OR MINGW) +if(CMAKE_VERSION VERSION_LESS 3.19) + if(UNIX OR MSYS OR MINGW) execute_process(COMMAND chmod 755 fltk-config WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") - endif () -else (CMAKE_VERSION VERSION_LESS 3.19) - file (CHMOD "${CMAKE_CURRENT_BINARY_DIR}/fltk-config" + endif() +else(CMAKE_VERSION VERSION_LESS 3.19) + file(CHMOD "${CMAKE_CURRENT_BINARY_DIR}/fltk-config" PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) -endif (CMAKE_VERSION VERSION_LESS 3.19) +endif(CMAKE_VERSION VERSION_LESS 3.19) # prepare some variables for config.h -if (IS_ABSOLUTE "${FLTK_DATADIR}") - set (PREFIX_DATA "${FLTK_DATADIR}/fltk") -else (IS_ABSOLUTE "${FLTK_DATADIR}") - set (PREFIX_DATA "${CMAKE_INSTALL_PREFIX}/${FLTK_DATADIR}/fltk") -endif (IS_ABSOLUTE "${FLTK_DATADIR}") +if(IS_ABSOLUTE "${FLTK_DATADIR}") + set(PREFIX_DATA "${FLTK_DATADIR}/fltk") +else(IS_ABSOLUTE "${FLTK_DATADIR}") + set(PREFIX_DATA "${CMAKE_INSTALL_PREFIX}/${FLTK_DATADIR}/fltk") +endif(IS_ABSOLUTE "${FLTK_DATADIR}") -if (IS_ABSOLUTE "${FLTK_DOCDIR}") - set (PREFIX_DOC "${FLTK_DOCDIR}/fltk") -else (IS_ABSOLUTE "${FLTK_DOCDIR}") - set (PREFIX_DOC "${CMAKE_INSTALL_PREFIX}/${FLTK_DOCDIR}/fltk") -endif (IS_ABSOLUTE "${FLTK_DOCDIR}") +if(IS_ABSOLUTE "${FLTK_DOCDIR}") + set(PREFIX_DOC "${FLTK_DOCDIR}/fltk") +else(IS_ABSOLUTE "${FLTK_DOCDIR}") + set(PREFIX_DOC "${CMAKE_INSTALL_PREFIX}/${FLTK_DOCDIR}/fltk") +endif(IS_ABSOLUTE "${FLTK_DOCDIR}") -set (CONFIG_H_IN configh.cmake.in) -set (CONFIG_H config.h) +set(CONFIG_H_IN configh.cmake.in) +set(CONFIG_H config.h) # generate config.h @@ -121,15 +145,15 @@ configure_file( @ONLY ) -if (OPTION_CREATE_LINKS) +if(FLTK_INSTALL_LINKS) # Set PREFIX_INCLUDE to the proper value. - if (IS_ABSOLUTE ${FLTK_INCLUDEDIR}) - set (PREFIX_INCLUDE ${FLTK_INCLUDEDIR}) - else () - set (PREFIX_INCLUDE "${CMAKE_INSTALL_PREFIX}/${FLTK_INCLUDEDIR}") - endif (IS_ABSOLUTE ${FLTK_INCLUDEDIR}) + if(IS_ABSOLUTE ${FLTK_INCLUDEDIR}) + set(PREFIX_INCLUDE ${FLTK_INCLUDEDIR}) + else() + set(PREFIX_INCLUDE "${CMAKE_INSTALL_PREFIX}/${FLTK_INCLUDEDIR}") + endif(IS_ABSOLUTE ${FLTK_INCLUDEDIR}) configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/CMake/install-symlinks.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/install-symlinks.cmake" @ONLY) -endif (OPTION_CREATE_LINKS) +endif(FLTK_INSTALL_LINKS) diff --git a/CMake/fl_add_library.cmake b/CMake/fl_add_library.cmake index ee7956560..a64f998d7 100644 --- a/CMake/fl_add_library.cmake +++ b/CMake/fl_add_library.cmake @@ -1,8 +1,8 @@ # # Macro used by the CMake build system for the Fast Light Tool Kit (FLTK). -# Written by Michael Surette +# Originally written by Michael Surette # -# Copyright 1998-2020 by Bill Spitzak and others. +# Copyright 1998-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 @@ -16,108 +16,239 @@ # ####################################################################### -# FL_ADD_LIBRARY - add a static or shared library to the build +# fl_add_library - add a static or shared library to the build +#====================================================================== +# +# Input: +# +# LIBNAME: name of the library, including 'fltk_' prefix if applicable. +# +# LIBTYPE: either "STATIC" or "SHARED" +# +# SOURCES: Files needed to build the library +# +# Output: +# +# FLTK_LIBRARIES or FLTK_LIBRARIES_SHARED (in parent scope) +# +# This function adds the given library to the build, adds it to +# either FLTK_LIBRARIES or FLTK_LIBRARIES_SHARED, respectively, +# and "exports" the modified variable to the parent scope. +# +# For each library an alias is defined (see comment below). +# ####################################################################### -macro (FL_ADD_LIBRARY LIBNAME LIBTYPE LIBFILES) +function (fl_add_library LIBNAME LIBTYPE SOURCES) + + # message(STATUS "Building library **************** ${LIBNAME} ${LIBTYPE}") + + set(suffix "") + if(LIBTYPE STREQUAL "SHARED") + set(suffix "-shared") + endif() - if (${LIBTYPE} STREQUAL "SHARED") - set (TARGET_NAME ${LIBNAME}_SHARED) - else () - set (TARGET_NAME ${LIBNAME}) - endif (${LIBTYPE} STREQUAL "SHARED") + set(TARGET_NAME ${LIBNAME}${suffix}) - if (MSVC) - set (OUTPUT_NAME_DEBUG "${LIBNAME}d") - set (OUTPUT_NAME_RELEASE "${LIBNAME}") - else () - set (OUTPUT_NAME_DEBUG "${LIBNAME}") - set (OUTPUT_NAME_RELEASE "${LIBNAME}") - endif (MSVC) + ## Strip 'fltk_' from target name (if it exists in the name) + ## and use the result as EXPORT_NAME property. This makes it + ## easy to export library targets fltk::fltk and fltk::images + ## rather than fltk::fltk_images. - add_library(${TARGET_NAME} ${LIBTYPE} ${LIBFILES}) + string(REPLACE "fltk_" "" EXPORT_NAME ${TARGET_NAME}) + + if(MSVC) + set(OUTPUT_NAME_DEBUG "${LIBNAME}d") + else() + set(OUTPUT_NAME_DEBUG "${LIBNAME}") + endif(MSVC) + + set(OUTPUT_NAME_RELEASE "${LIBNAME}") + + add_library(${TARGET_NAME} ${LIBTYPE} ${SOURCES}) + + # Create an alias 'fltk::alias_name' for the library + # where 'alias_name' is the library name without the prefix 'fltk_' + # + # e.g. 'fltk' -> 'fltk::fltk' + # and 'fltk-shared' -> 'fltk::fltk-shared' + # but 'fltk_images' -> 'fltk::images' + # and 'fltk_images-shared' -> 'fltk::images-shared' + + if(NOT (LIBNAME STREQUAL "fltk")) + string(REPLACE "fltk_" "" alias_name ${LIBNAME}) + else() + set(alias_name ${LIBNAME}) + endif() + set(alias_name "fltk::${alias_name}${suffix}") + + add_library (${alias_name} ALIAS ${TARGET_NAME}) + + if(0) + fl_debug_var(TARGET_NAME) + fl_debug_var(LIBTYPE) + fl_debug_var(alias_name) + # fl_debug_var(SOURCES) + endif() # Target properties for all libraries # Set 'PRIVATE' target compile definitions for the library # so they are not inherited by consumers - target_compile_definitions(${TARGET_NAME} - PRIVATE "FL_LIBRARY") + target_compile_definitions (${TARGET_NAME} PRIVATE "FL_LIBRARY") + + # Set PUBLIC include and linker directories + + if(0) # DEBUG + message(STATUS "fl_add_library and alias : fltk::${alias_name} ALIAS ${TARGET_NAME}") + fl_debug_var(TARGET_NAME) + fl_debug_var(FLTK_INCLUDE_DIRS) + fl_debug_var(CMAKE_CURRENT_BINARY_DIR) + fl_debug_var(CMAKE_CURRENT_SOURCE_DIR) + fl_debug_var(FLTK_BUILD_INCLUDE_DIRECTORIES) + endif() + + # Special handling for the core 'fltk' library, + # no matter if it's SHARED or STATIC + # FIXME: maybe this should be in src/CMakeLists.txt (?) - # additional target properties for static libraries + if(LIBNAME STREQUAL "fltk") - if (${LIBTYPE} STREQUAL "STATIC") + target_include_directories(${TARGET_NAME} PUBLIC + $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/..> + $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..> + $<INSTALL_INTERFACE:include> + ) + + ### FIXME: why does the simplified else() block not work? + ### Needs investigation, using 'if(1)' for now... + + if(1) + + foreach(dir ${FLTK_BUILD_INCLUDE_DIRECTORIES}) + target_include_directories(${TARGET_NAME} PRIVATE + $<BUILD_INTERFACE:${dir}> + ) + endforeach() + + else() + + ### This generates a wrong string in property INTERFACE_INCLUDE_DIRECTORIES: + ### ... $<INSTALL_INTERFACE:include>;/git/fltk/modern-cmake/src/$<BUILD_INTERFACE:/usr/include/freetype2; ... + ### ... --- OK ---------------------^^^^^^^ WRONG ^^^^^^^^^^^^^^-------- would be OK -------------------- ... + ### End of string: ';/usr/include/libpng16' (WRONG: missing '>') + ### I don't see anything wrong with this statement though but + ### maybe I'm missing something. Albrecht, Jan 22 2024 + + target_include_directories(${TARGET_NAME} PRIVATE + $<BUILD_INTERFACE:${FLTK_BUILD_INCLUDE_DIRECTORIES}> + ) + fl_debug_target(${TARGET_NAME}) + + endif() + + target_link_directories(${TARGET_NAME} PUBLIC + $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/../lib> + $<INSTALL_INTERFACE:lib> + ) + + if(APPLE AND NOT FLTK_BACKEND_X11) + target_link_libraries(${TARGET_NAME} PUBLIC "-framework Cocoa") + endif() + + # we must link fltk with cairo if Cairo or Wayland is enabled (or both) + if(FLTK_HAVE_CAIRO OR FLTK_USE_CAIRO) + target_include_directories(${TARGET_NAME} PUBLIC ${PKG_CAIRO_INCLUDE_DIRS}) + target_link_directories(${TARGET_NAME} PUBLIC ${PKG_CAIRO_LIBRARY_DIRS}) + endif() + + endif(LIBNAME STREQUAL "fltk") + + # Set additional target properties for static libraries + + if(LIBTYPE STREQUAL "STATIC") set_target_properties(${TARGET_NAME} PROPERTIES OUTPUT_NAME ${LIBNAME} OUTPUT_NAME_DEBUG ${OUTPUT_NAME_DEBUG} OUTPUT_NAME_RELEASE ${OUTPUT_NAME_RELEASE} + EXPORT_NAME ${EXPORT_NAME} ) - endif (${LIBTYPE} STREQUAL "STATIC") + endif(LIBTYPE STREQUAL "STATIC") - # additional target properties for shared (dynamic) libraries (DLL's) + # Set additional target properties for shared (dynamic) libraries (DLL's) - if (${LIBTYPE} STREQUAL "SHARED") - set_target_properties(${TARGET_NAME} - PROPERTIES + if(LIBTYPE STREQUAL "SHARED") + set_target_properties(${TARGET_NAME} PROPERTIES VERSION ${FLTK_VERSION} SOVERSION ${FLTK_VERSION_MAJOR}.${FLTK_VERSION_MINOR} OUTPUT_NAME ${LIBNAME} OUTPUT_NAME_DEBUG ${OUTPUT_NAME_DEBUG} OUTPUT_NAME_RELEASE ${OUTPUT_NAME_RELEASE} + EXPORT_NAME ${EXPORT_NAME} ) - # MSVC only: - if (MSVC) - set_target_properties(${TARGET_NAME} - PROPERTIES - OUTPUT_NAME lib${LIBNAME} - OUTPUT_NAME_DEBUG lib${OUTPUT_NAME_DEBUG} - OUTPUT_NAME_RELEASE lib${OUTPUT_NAME_RELEASE} - # PREFIX "lib" # for MSVC static/shared coexistence *DOES NOT WORK* + # Visual Studio only: + if(MSVC) + set_target_properties(${TARGET_NAME} PROPERTIES + OUTPUT_NAME ${LIBNAME}_dll + OUTPUT_NAME_DEBUG ${LIBNAME}_dlld + OUTPUT_NAME_RELEASE ${LIBNAME}_dll ) - endif (MSVC) - endif (${LIBTYPE} STREQUAL "SHARED") + target_compile_definitions (${TARGET_NAME} PRIVATE FL_DLL) + endif(MSVC) + endif(LIBTYPE STREQUAL "SHARED") # Debug library output names (optional) - set (DEBUG_ONAME 0) + set(DEBUG_ONAME 0) - if (DEBUG_ONAME) + if(DEBUG_ONAME) get_target_property (XX_NAME ${TARGET_NAME} NAME) get_target_property (XX_ONAME ${TARGET_NAME} OUTPUT_NAME) get_target_property (XX_ONAME_DEBUG ${TARGET_NAME} OUTPUT_NAME_DEBUG) get_target_property (XX_ONAME_RELEASE ${TARGET_NAME} OUTPUT_NAME_RELEASE) - - fl_debug_var (TARGET_NAME) - fl_debug_var (XX_NAME) - fl_debug_var (XX_ONAME) - fl_debug_var (XX_ONAME_DEBUG) - fl_debug_var (XX_ONAME_RELEASE) - message (STATUS "---") - endif (DEBUG_ONAME) - - if (MSVC) - if (OPTION_LARGE_FILE) - set_target_properties(${TARGET_NAME} - PROPERTIES + get_target_property (XX_EXPORT_NAME ${TARGET_NAME} EXPORT_NAME) + + message(STATUS "--- DEBUG_ONAME ---") + fl_debug_var(TARGET_NAME) + fl_debug_var(XX_NAME) + fl_debug_var(XX_ONAME) + fl_debug_var(XX_ONAME_DEBUG) + fl_debug_var(XX_ONAME_RELEASE) + fl_debug_var(XX_EXPORT_NAME) + message(STATUS "--- /DEBUG_ONAME ---") + endif(DEBUG_ONAME) + + if(MSVC) + if(FLTK_OPTION_LARGE_FILE) + fl_debug_var(FLTK_OPTION_LARGE_FILE) + fl_debug_var(TARGET_NAME) + set_target_properties(${TARGET_NAME} PROPERTIES LINK_FLAGS /LARGEADDRESSAWARE ) - endif (OPTION_LARGE_FILE) + endif(FLTK_OPTION_LARGE_FILE) + endif(MSVC) - if (${LIBTYPE} STREQUAL "SHARED") - target_compile_definitions(${TARGET_NAME} - PRIVATE "FL_DLL") - endif () - endif (MSVC) - - install (TARGETS ${TARGET_NAME} - EXPORT FLTK-Targets + install(TARGETS ${TARGET_NAME} EXPORT FLTK-Targets RUNTIME DESTINATION ${FLTK_BINDIR} LIBRARY DESTINATION ${FLTK_LIBDIR} ARCHIVE DESTINATION ${FLTK_LIBDIR} ) - list (APPEND FLTK_LIBRARIES "${TARGET_NAME}") - set (FLTK_LIBRARIES ${FLTK_LIBRARIES} PARENT_SCOPE) - -endmacro (FL_ADD_LIBRARY LIBNAME LIBTYPE LIBFILES) + if(LIBTYPE STREQUAL "SHARED") + list(APPEND FLTK_LIBRARIES_SHARED "${TARGET_NAME}") + set(FLTK_LIBRARIES_SHARED "${FLTK_LIBRARIES_SHARED}" PARENT_SCOPE) + else() + list(APPEND FLTK_LIBRARIES "${TARGET_NAME}") + set(FLTK_LIBRARIES "${FLTK_LIBRARIES}" PARENT_SCOPE) + endif() + + if(0) + fl_debug_var(fl_add_library_DEBUG) + fl_debug_var(FLTK_LIBRARIES) + fl_debug_var(FLTK_LIBRARIES_SHARED) + fl_debug_var(fl_add_library_END) + message("") + endif() + +endfunction (fl_add_library LIBNAME LIBTYPE SOURCES) diff --git a/CMake/fl_create_example.cmake b/CMake/fl_create_example.cmake index be1b27608..7e930ee9b 100644 --- a/CMake/fl_create_example.cmake +++ b/CMake/fl_create_example.cmake @@ -2,7 +2,7 @@ # A function used by the CMake build system for the Fast Light Tool Kit (FLTK). # Originally written by Michael Surette # -# Copyright 1998-2023 by Bill Spitzak and others. +# Copyright 1998-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 @@ -17,7 +17,7 @@ ################################################################################ # -# function CREATE_EXAMPLE - Create a test/demo (example) program +# function fl_create_example - Create a test/demo (example) program # # Input: # @@ -27,9 +27,9 @@ # Sources can be: # - .c/.cxx files, e.g. 'hello.cxx' # - .fl (fluid) files, e.g. 'radio.fl' -# - .plist file (macOS), e.g. 'editor.plist' -# - .icns file (macOS Icon), e.g. 'checkers.icns' -# - .rc file (Windows resource file, e.g. icon definition) +# - .plist file(macOS), e.g. 'editor.plist' +# - .icns file(macOS Icon), e.g. 'checkers.icns' +# - .rc file(Windows resource file, e.g. icon definition) # # Order of sources doesn't matter, multiple .cxx and .fl files are # supported, but only one .plist and one .icns file. @@ -42,127 +42,127 @@ # These files must reside in the subdirectory 'mac-resources'. # # - LIBRARIES: -# List of libraries (CMake target names), separated by ';'. Needs -# quotes if more than one library is required, e.g. "fltk_gl;fltk" -# -# CREATE_EXAMPLE can have an optional fourth argument with a list of options -# - these options are currently not used +# List of libraries (CMake target names), separated by ';'. Must be +# quoted if more than one library is required, e.g. "fltk::gl;fltk::images" # ################################################################################ -function (CREATE_EXAMPLE NAME SOURCES LIBRARIES) +function (fl_create_example NAME SOURCES LIBRARIES) - 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 + 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 # create macOS bundle? 0 = no, 1 = yes - if (APPLE AND (NOT OPTION_APPLE_X11)) - set (MAC_BUNDLE 1) - else () - set (MAC_BUNDLE 0) - endif (APPLE AND (NOT OPTION_APPLE_X11)) - - # rename target name "help" (reserved since CMake 2.8.12) - # 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") + if(APPLE AND NOT FLTK_BACKEND_X11) + set(MAC_BUNDLE 1) + else() + set(MAC_BUNDLE 0) + endif() # 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) + 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) # generate source files from .fl files, add output to sources - if (flsrcs) - if (NOT FLTK_FLUID_EXECUTABLE) + if(flsrcs) + if(NOT FLTK_FLUID_EXECUTABLE) message(STATUS "Example app \"${NAME}\" will not be built. FLUID executable not found.") return () - endif () + endif() FLTK_RUN_FLUID (FLUID_SOURCES "${flsrcs}") - list (APPEND srcs ${FLUID_SOURCES}) - unset (FLUID_SOURCES) - endif (flsrcs) + list(APPEND srcs ${FLUID_SOURCES}) + unset(FLUID_SOURCES) + endif(flsrcs) # set macOS (icon) resource path if applicable - if (MAC_BUNDLE AND ICON_NAME) - set (ICON_PATH "${CMAKE_CURRENT_SOURCE_DIR}/mac-resources/${ICON_NAME}") - endif (MAC_BUNDLE AND ICON_NAME) + if(MAC_BUNDLE AND ICON_NAME) + set(ICON_PATH "${CMAKE_CURRENT_SOURCE_DIR}/mac-resources/${ICON_NAME}") + endif(MAC_BUNDLE AND ICON_NAME) ############################################################################## # add executable target and set properties (all platforms) ############################################################################## - if (MAC_BUNDLE) + if(MAC_BUNDLE) add_executable (${TARGET_NAME} MACOSX_BUNDLE ${srcs} ${ICON_PATH}) - else () + else() add_executable (${TARGET_NAME} WIN32 ${srcs}) - endif (MAC_BUNDLE) + endif(MAC_BUNDLE) set_target_properties (${TARGET_NAME} PROPERTIES OUTPUT_NAME ${NAME}) - target_link_libraries (${TARGET_NAME} ${LIBRARIES}) + target_link_libraries (${TARGET_NAME} PRIVATE ${LIBRARIES}) # 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) - # we must link all programs with cairo if option CAIROEXT is enabled - if (FLTK_HAVE_CAIROEXT) - target_link_libraries (${TARGET_NAME} ${PKG_CAIRO_LIBRARIES}) - endif () + ### *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() - if (FLTK_HAVE_CAIRO AND PKG_CAIRO_LIBRARY_DIRS) - target_link_directories (${TARGET_NAME} PUBLIC ${PKG_CAIRO_LIBRARY_DIRS}) - endif () + endif() # This should no longer be necessary (implied by linking the libs) - if (USE_GDIPLUS) # can only be true on Windows - target_link_libraries (${TARGET_NAME} gdiplus) - endif () + # Search the current binary directory for header files created by CMake + # or fluid and the source folder for other headers included by test programs - if (MAC_BUNDLE) - if (PLIST) - set_target_properties (${TARGET_NAME} PROPERTIES MACOSX_BUNDLE_INFO_PLIST + 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 "${CMAKE_CURRENT_SOURCE_DIR}/mac-resources/${PLIST}") endif() string(REPLACE "_" "-" FLTK_BUNDLE_ID "org.fltk.${TARGET_NAME}") - 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}") + 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}") - 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 () + 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() ############################################################################## # Copy macOS "bundle wrapper" (shell script) to target directory. # The "custom command" will be executed "POST_BUILD". ############################################################################## - if (MAC_BUNDLE) - set (WRAPPER "${EXECUTABLE_OUTPUT_PATH}/${CMAKE_CFG_INTDIR}/${TARGET_NAME}") + if(MAC_BUNDLE) + set(WRAPPER "${EXECUTABLE_OUTPUT_PATH}/${CMAKE_CFG_INTDIR}/${TARGET_NAME}") - add_custom_command ( + add_custom_command( TARGET ${TARGET_NAME} POST_BUILD COMMAND cp ${FLTK_SOURCE_DIR}/CMake/macOS-bundle-wrapper.in ${WRAPPER} COMMAND chmod u+x,g+x,o+x ${WRAPPER} @@ -170,29 +170,18 @@ function (CREATE_EXAMPLE NAME SOURCES LIBRARIES) # COMMENT "Creating macOS bundle wrapper script ${WRAPPER}" VERBATIM ) - unset (WRAPPER) - endif (MAC_BUNDLE) + unset(WRAPPER) + endif(MAC_BUNDLE) - if (MSVC AND TARGET fltk_SHARED) - set (DllDir "$<SHELL_PATH:$<TARGET_FILE_DIR:fltk_SHARED>>") - ## fl_debug_var (DllDir) + ############################################################################## + # 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>>") set_target_properties(${TARGET_NAME} PROPERTIES VS_DEBUGGER_ENVIRONMENT "PATH=${DllDir};$ENV{PATH}" ) endif() - ###################################################################### - # Parse optional fourth argument, see description above. - ###################################################################### - - # code left commented out as an example - - # *unused* # if (${ARGC} GREATER 3) - # *unused* # foreach (OPTION ${ARGV3}) - # *unused* # if (${OPTION} STREQUAL "xxx") - # *unused* # # do something ... - # *unused* # endif () - # *unused* # endforeach () - # *unused* # endif () - endfunction () diff --git a/CMake/fl_debug_pkg.cmake b/CMake/fl_debug_pkg.cmake index 56df4ca37..1eebb63a6 100644 --- a/CMake/fl_debug_pkg.cmake +++ b/CMake/fl_debug_pkg.cmake @@ -41,29 +41,29 @@ macro (fl_debug_pkg PREFIX NAME) message("") message(STATUS "Results of pkg_check_modules(${PREFIX}, ${NAME}):") - fl_debug_var (${PREFIX}_FOUND) - if (${PREFIX}_FOUND) + fl_debug_var(${PREFIX}_FOUND) + if(${PREFIX}_FOUND) - fl_debug_var (${PREFIX}_INCLUDE_DIRS) - fl_debug_var (${PREFIX}_CFLAGS) - fl_debug_var (${PREFIX}_LIBRARIES) - fl_debug_var (${PREFIX}_LINK_LIBRARIES) - fl_debug_var (${PREFIX}_LIBRARY_DIRS) - fl_debug_var (${PREFIX}_LDFLAGS) - fl_debug_var (${PREFIX}_LDFLAGS_OTHER) - fl_debug_var (${PREFIX}_CFLAGS_OTHER) + fl_debug_var(${PREFIX}_INCLUDE_DIRS) + fl_debug_var(${PREFIX}_CFLAGS) + fl_debug_var(${PREFIX}_LIBRARIES) + fl_debug_var(${PREFIX}_LINK_LIBRARIES) + fl_debug_var(${PREFIX}_LIBRARY_DIRS) + fl_debug_var(${PREFIX}_LDFLAGS) + fl_debug_var(${PREFIX}_LDFLAGS_OTHER) + fl_debug_var(${PREFIX}_CFLAGS_OTHER) - fl_debug_var (${PREFIX}_STATIC_INCLUDE_DIRS) - fl_debug_var (${PREFIX}_STATIC_CFLAGS) - fl_debug_var (${PREFIX}_STATIC_LIBRARIES) - fl_debug_var (${PREFIX}_STATIC_LINK_LIBRARIES) - fl_debug_var (${PREFIX}_STATIC_LIBRARY_DIRS) + fl_debug_var(${PREFIX}_STATIC_INCLUDE_DIRS) + fl_debug_var(${PREFIX}_STATIC_CFLAGS) + fl_debug_var(${PREFIX}_STATIC_LIBRARIES) + fl_debug_var(${PREFIX}_STATIC_LINK_LIBRARIES) + fl_debug_var(${PREFIX}_STATIC_LIBRARY_DIRS) - fl_debug_var (${PREFIX}_VERSION) - fl_debug_var (${PREFIX}_PREFIX) - fl_debug_var (${PREFIX}_INCLUDEDIR) - fl_debug_var (${PREFIX}_LIBDIR) + fl_debug_var(${PREFIX}_VERSION) + fl_debug_var(${PREFIX}_PREFIX) + fl_debug_var(${PREFIX}_INCLUDEDIR) + fl_debug_var(${PREFIX}_LIBDIR) - endif () + endif() message("") endmacro (fl_debug_pkg) diff --git a/CMake/fl_debug_var.cmake b/CMake/fl_debug_var.cmake index 5717704a3..08f91bf1d 100644 --- a/CMake/fl_debug_var.cmake +++ b/CMake/fl_debug_var.cmake @@ -1,7 +1,7 @@ # -# Macro used by the CMake build system for the Fast Light Tool Kit (FLTK). +# Function used by the CMake build system for the Fast Light Tool Kit (FLTK). # -# Copyright 1998-2022 by Bill Spitzak and others. +# Copyright 1998-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 @@ -15,10 +15,42 @@ # ####################################################################### -# fl_debug_var - a macro to output debugging info +# fl_expand_name - a function to expand a variable name with spaces ####################################################################### # -# This macro displays the name and value of a CMake variable. +# This function returns a string comprising of the given name and +# enough spaces to have at least the given minimal length (min_len). +# Currently min_len must not be greater than 50. +# +# If the string is already at least min_len it is not changed, +# otherwise the string is returned to the given variable (out) +# in the parent scope. +# +# Syntax: +# fl_expand_name (out in min_len) +# +# Example: +# fl_expand_name (var WIN32 30) +# fl_expand_name (var UNIX 40) +# +####################################################################### + +function (fl_expand_name out in min_len) + string(LENGTH "${in}" len) + if(len LESS min_len) + set(spaces " ") + set(temp "${in}") + set(temp "${in}${spaces}${spaces}") + string(SUBSTRING "${temp}" 0 ${min_len} temp) + set(${out} "${temp}" PARENT_SCOPE) + endif() +endfunction (fl_expand_name) + +####################################################################### +# fl_debug_var - a function to output debugging info +####################################################################### +# +# This function displays the name and value of a CMake variable. # The variable name is expanded with spaces to be (at least) # <min_len> (currently 30) characters wide for better readability. # VARNAME must be a string literal, e.g. WIN32 or "WIN32". @@ -32,15 +64,52 @@ # ####################################################################### -macro (fl_debug_var name) - set (min_len 32) - set (var "${name}") - string(LENGTH "${var}" len) - while (len LESS min_len) - # add one space until min_len is reached - # ** string(APPEND var " ") # requires CMake 3.4.x (otherwise loop...) - set (var "${var} ") - string(LENGTH "${var}" len) - endwhile (len LESS min_len) - message (STATUS "${var} = '${${name}}'") -endmacro (fl_debug_var) +function (fl_debug_var name) + set(var "${name}") + fl_expand_name(var "${name}" 40) + message(STATUS "${var} = '${${name}}'") +endfunction (fl_debug_var) + + +####################################################################### +# fl_debug_target - a function to output info about a target +####################################################################### +# +# This function displays properties of a CMake target. +# +# Currently there's a fixed number of properties. +# +# Syntax: +# fl_debug_target(target) +# +# Example: +# fl_debug_target(fltk) +# fl_debug_target(fluid) +# fl_debug_target(fltk_image) +# fl_debug_target(fltk::forms) +# +####################################################################### + +function (fl_debug_target name) + message(STATUS "+++ fl_debug_target (${name})") + set(var "${name}") + fl_expand_name(var "${name}" 40) + if(TARGET ${name}) + message(STATUS "${var} = <target>") + foreach(prop + ALIASED_TARGET + INTERFACE_INCLUDE_DIRECTORIES + INTERFACE_LINK_DIRECTORIES + INTERFACE_LINK_LIBRARIES) + get_target_property (${prop} ${name} ${prop}) + if(NOT ${prop}) + set(${prop} "") + endif() + fl_debug_var(${prop}) + endforeach() + else() + message(STATUS "${var} = <not a target>") + endif() + message(STATUS "") + +endfunction (fl_debug_target) diff --git a/CMake/install-symlinks.cmake.in b/CMake/install-symlinks.cmake.in index b338163f1..595ed7fb2 100644 --- a/CMake/install-symlinks.cmake.in +++ b/CMake/install-symlinks.cmake.in @@ -22,7 +22,7 @@ if (NOT EXISTS $ENV{DESTDIR}@PREFIX_INCLUDE@/Fl) endif (NOT EXISTS $ENV{DESTDIR}@PREFIX_INCLUDE@/Fl) file (GLOB FLTK_HEADER_FILES $ENV{DESTDIR}@PREFIX_INCLUDE@/FL/*.H) -foreach (file ${FLTK_HEADER_FILES}) +foreach(file ${FLTK_HEADER_FILES}) GET_FILENAME_COMPONENT(nameWE ${file} NAME_WE) if (NOT EXISTS $ENV{DESTDIR}@PREFIX_INCLUDE@/FL/${nameWE}.h) EXECUTE_PROCESS( @@ -30,4 +30,4 @@ foreach (file ${FLTK_HEADER_FILES}) WORKING_DIRECTORY $ENV{DESTDIR}@PREFIX_INCLUDE@/FL ) endif (NOT EXISTS $ENV{DESTDIR}@PREFIX_INCLUDE@/FL/${nameWE}.h) -endforeach (file) +endforeach(file) diff --git a/CMake/install.cmake b/CMake/install.cmake index ea36ab301..651d8a0f1 100644 --- a/CMake/install.cmake +++ b/CMake/install.cmake @@ -2,7 +2,7 @@ # Installation support for building the FLTK project using CMake (www.cmake.org) # Originally written by Michael Surette # -# Copyright 1998-2022 by Bill Spitzak and others. +# Copyright 1998-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 @@ -25,11 +25,11 @@ configure_file( "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" @ONLY ) -add_custom_target (uninstall +add_custom_target(uninstall "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" ) -install (DIRECTORY +install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/FL DESTINATION ${FLTK_INCLUDEDIR} USE_SOURCE_PERMISSIONS FILES_MATCHING @@ -37,28 +37,29 @@ install (DIRECTORY PATTERN "fl_config.h" EXCLUDE ) -install (DIRECTORY +install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/FL DESTINATION ${FLTK_INCLUDEDIR} USE_SOURCE_PERMISSIONS FILES_MATCHING PATTERN "*.[hH]" ) -if (OPTION_CREATE_LINKS) - install (SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/install-symlinks.cmake) -endif (OPTION_CREATE_LINKS) +if(FLTK_INSTALL_LINKS) + install(SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/install-symlinks.cmake) +endif(FLTK_INSTALL_LINKS) # generate FLTKConfig.cmake for installed directory use -set (INCLUDE_DIRS ${CMAKE_INSTALL_PREFIX}/include) -if (FLTK_HAVE_CAIRO) - list (APPEND INCLUDE_DIRS ${PKG_CAIRO_INCLUDE_DIRS}) -endif () +set(INCLUDE_DIRS ${CMAKE_INSTALL_PREFIX}/include) +if(FLTK_HAVE_CAIRO) + list(APPEND INCLUDE_DIRS ${PKG_CAIRO_INCLUDE_DIRS}) +endif() -set (CONFIG_PATH ${CMAKE_INSTALL_PREFIX}/${FLTK_CONFIG_PATH}) +set(CONFIG_PATH ${CMAKE_INSTALL_PREFIX}/${FLTK_CONFIG_PATH}) -install (EXPORT FLTK-Targets +install(EXPORT FLTK-Targets DESTINATION ${FLTK_CONFIG_PATH} FILE FLTK-Targets.cmake + NAMESPACE fltk:: ) configure_file( @@ -67,26 +68,26 @@ configure_file( @ONLY ) -install (FILES +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/etc/FLTKConfig.cmake DESTINATION ${FLTK_CONFIG_PATH} ) -install (FILES +install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/CMake/FLTK-Functions.cmake DESTINATION ${FLTK_CONFIG_PATH} ) # Generate fltk-config -set (prefix ${CMAKE_INSTALL_PREFIX}) -set (exec_prefix "\${prefix}") -set (includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}") -set (BINARY_DIR) -set (libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}") -set (srcdir ".") +set(prefix ${CMAKE_INSTALL_PREFIX}) +set(exec_prefix "\${prefix}") +set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}") +set(BINARY_DIR) +set(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}") +set(srcdir ".") -set (LIBNAME "${libdir}/libfltk.a") +set(LIBNAME "${libdir}/libfltk.a") configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/fltk-config.in" @@ -95,14 +96,14 @@ configure_file( ) # Install fltk-config -# Note: no need to set execute perms, install (PROGRAMS) does this +# Note: no need to set execute perms, install(PROGRAMS) does this -install (PROGRAMS +install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/bin/fltk-config DESTINATION ${FLTK_BINDIR} ) -if (UNIX OR MSYS OR MINGW) +if(UNIX OR MSYS OR MINGW) macro(INSTALL_MAN FILE LEVEL) install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/documentation/src/${FILE}.man @@ -111,20 +112,20 @@ if (UNIX OR MSYS OR MINGW) ) endmacro (INSTALL_MAN FILE LEVEL) - if (FLTK_BUILD_FLUID) + if(FLTK_BUILD_FLUID) INSTALL_MAN (fluid 1) - endif (FLTK_BUILD_FLUID) - if (FLTK_BUILD_FLTK_OPTIONS) + endif(FLTK_BUILD_FLUID) + if(FLTK_BUILD_FLTK_OPTIONS) INSTALL_MAN (fltk-options 1) - endif (FLTK_BUILD_FLTK_OPTIONS) + endif(FLTK_BUILD_FLTK_OPTIONS) INSTALL_MAN (fltk-config 1) INSTALL_MAN (fltk 3) - if (FLTK_BUILD_TEST AND FLTK_BUILD_FLUID) + if(FLTK_BUILD_TEST AND FLTK_BUILD_FLUID) # Don't (!) install man pages of games (GitHub issue #23) # INSTALL_MAN (blocks 6) # INSTALL_MAN (checkers 6) # INSTALL_MAN (sudoku 6) - endif () + endif() -endif (UNIX OR MSYS OR MINGW) +endif(UNIX OR MSYS OR MINGW) diff --git a/CMake/options.cmake b/CMake/options.cmake index 0a774b09b..2d0522ed1 100644 --- a/CMake/options.cmake +++ b/CMake/options.cmake @@ -2,7 +2,7 @@ # Main CMakeLists.txt to build the FLTK project using CMake (www.cmake.org) # Originally written by Michael Surette # -# Copyright 1998-2023 by Bill Spitzak and others. +# Copyright 1998-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 @@ -37,7 +37,7 @@ # bundled libraries (png, jpeg, zlib) *must* appear before any other # include_directories() statements that might introduce conflicts. # Currently 'resources.cmake' is included before this file and thus -# 'include_directories (${FREETYPE_PATH})' is executed before this +# 'include_directories(${FREETYPE_PATH})' is executed before this # file but this doesn't matter. # # This *MUST* be fixed using target_include_directories() as @@ -47,36 +47,37 @@ # ####################################################################### -set (DEBUG_OPTIONS_CMAKE 0) -if (DEBUG_OPTIONS_CMAKE) - message (STATUS "[** options.cmake **]") - fl_debug_var (WIN32) - fl_debug_var (FLTK_LDLIBS) -endif (DEBUG_OPTIONS_CMAKE) +set(DEBUG_OPTIONS_CMAKE 0) +if(DEBUG_OPTIONS_CMAKE) + message(STATUS "[** options.cmake **]") + fl_debug_var(WIN32) + fl_debug_var(FLTK_LDLIBS) +endif(DEBUG_OPTIONS_CMAKE) ####################################################################### # options ####################################################################### -set (OPTION_OPTIM "" +set(FLTK_OPTION_OPTIM "" CACHE STRING "custom optimization flags" ) -add_definitions (${OPTION_OPTIM}) +# *FIXME* add_definitions() +add_definitions(${FLTK_OPTION_OPTIM}) ####################################################################### -set (OPTION_ARCHFLAGS "" +set(FLTK_ARCHFLAGS "" CACHE STRING "custom architecture flags" ) -add_definitions (${OPTION_ARCHFLAGS}) +# *FIXME* add_definitions() +add_definitions(${FLTK_ARCHFLAGS}) ####################################################################### -set (OPTION_ABI_VERSION "" +set(FLTK_ABI_VERSION "" CACHE STRING "FLTK ABI Version FL_ABI_VERSION: 1xxyy for 1.x.y (xx,yy with leading zero)" ) -set (FL_ABI_VERSION ${OPTION_ABI_VERSION}) - +set(FL_ABI_VERSION ${FLTK_ABI_VERSION}) ####################################################################### # Select MSVC (Visual Studio) Runtime: DLL (/MDx) or static (/MTx) @@ -86,508 +87,549 @@ set (FL_ABI_VERSION ${OPTION_ABI_VERSION}) # CMake variable - but this version does the latter. ####################################################################### -if (MSVC) - option (FLTK_MSVC_RUNTIME_DLL "use MSVC Runtime-DLL (/MDx)" ON) - if (FLTK_MSVC_RUNTIME_DLL) - set (CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL") - else () - set (CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>") - endif () -endif (MSVC) +if(MSVC) + option(FLTK_MSVC_RUNTIME_DLL "use MSVC Runtime-DLL (/MDx)" ON) + if(FLTK_MSVC_RUNTIME_DLL) + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL") + else() + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>") + endif() +endif(MSVC) ####################################################################### -# Bundled Library Options -####################################################################### - -option (OPTION_USE_SYSTEM_ZLIB "use system zlib" ON) -if (APPLE) - option (OPTION_USE_SYSTEM_LIBJPEG "use system libjpeg" OFF) - option (OPTION_USE_SYSTEM_LIBPNG "use system libpng" OFF) -else () - option (OPTION_USE_SYSTEM_LIBJPEG "use system libjpeg" ON) - option (OPTION_USE_SYSTEM_LIBPNG "use system libpng" ON) -endif () +if(APPLE) + option(FLTK_BACKEND_X11 "use X11" OFF) + if(CMAKE_OSX_SYSROOT) + list(APPEND FLTK_CFLAGS "-isysroot ${CMAKE_OSX_SYSROOT}") + endif(CMAKE_OSX_SYSROOT) +elseif(UNIX) + option(FLTK_BACKEND_X11 "use X11" ON) +endif(APPLE) ####################################################################### -# Make sure that png and zlib are either system or local for compatibility +# Bundled Library Options ####################################################################### -if (OPTION_USE_SYSTEM_ZLIB) - find_package (ZLIB) -endif () +if(WIN32 OR (APPLE AND NOT FLTK_BACKEND_X11)) + option(FLTK_USE_SYSTEM_LIBJPEG "use system libjpeg" OFF) + option(FLTK_USE_SYSTEM_LIBPNG "use system libpng" OFF) + option(FLTK_USE_SYSTEM_ZLIB "use system zlib" OFF) +else() + option(FLTK_USE_SYSTEM_LIBJPEG "use system libjpeg" ON) + option(FLTK_USE_SYSTEM_LIBPNG "use system libpng" ON) + option(FLTK_USE_SYSTEM_ZLIB "use system zlib" ON) +endif() + +# Set default values of internal build options -if (OPTION_USE_SYSTEM_LIBPNG) - find_package (PNG) -endif () +set(FLTK_USE_BUNDLED_JPEG FALSE) +set(FLTK_USE_BUNDLED_PNG FALSE) +set(FLTK_USE_BUNDLED_ZLIB FALSE) -# If we use the system zlib, we must also use the system png zlib and vice versa -# If either of them is not available, we fall back to using both local libraries -if (OPTION_USE_SYSTEM_LIBPNG AND NOT (OPTION_USE_SYSTEM_ZLIB AND ZLIB_FOUND)) - set (PNG_FOUND FALSE) - set (OPTION_USE_SYSTEM_LIBPNG OFF) - message (STATUS "Local z lib selected: overriding png lib to local for compatibility.\n") -endif () -if (OPTION_USE_SYSTEM_ZLIB AND NOT (OPTION_USE_SYSTEM_LIBPNG AND PNG_FOUND)) - set (ZLIB_FOUND FALSE) - set (OPTION_USE_SYSTEM_ZLIB OFF) - message (STATUS "Local png lib selected: overriding z lib to local for compatibility.\n") -endif () +# Collect libraries to build fltk_images (starting empty) + +set(FLTK_IMAGE_LIBRARIES "") ####################################################################### -# Bundled Compression Library : zlib +# Ensure that png and zlib are both system or both local for compatibility ####################################################################### -if (OPTION_USE_SYSTEM_ZLIB AND ZLIB_FOUND) - set (FLTK_USE_BUILTIN_ZLIB FALSE) - set (FLTK_ZLIB_LIBRARIES ${ZLIB_LIBRARIES}) - include_directories (${ZLIB_INCLUDE_DIRS}) +if(FLTK_USE_SYSTEM_ZLIB) + find_package(ZLIB) + if(NOT ZLIB_FOUND) + set(FLTK_USE_BUNDLED_ZLIB TRUE) + endif() else() - if (OPTION_USE_SYSTEM_ZLIB) - message (STATUS "cannot find system zlib library - using built-in\n") - endif () + set(FLTK_USE_BUNDLED_ZLIB TRUE) +endif() + +if(FLTK_USE_SYSTEM_LIBPNG AND NOT FLTK_USE_BUNDLED_ZLIB) + find_package(PNG) + if(NOT PNG_FOUND) + set(FLTK_USE_BUNDLED_PNG TRUE) + set(FLTK_USE_BUNDLED_ZLIB TRUE) + endif() +else() + set(FLTK_USE_BUNDLED_PNG TRUE) + set(FLTK_USE_BUNDLED_ZLIB TRUE) +endif() + +# Issue warnings if we deviate from the user's choice - add_subdirectory (zlib) - set (FLTK_USE_BUILTIN_ZLIB TRUE) - set (FLTK_ZLIB_LIBRARIES fltk_z) - set (ZLIB_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/zlib) - include_directories (${CMAKE_CURRENT_SOURCE_DIR}/zlib) -endif () +if(FLTK_USE_SYSTEM_LIBPNG AND FLTK_USE_BUNDLED_PNG) + message(STATUS "System PNG or ZLIB not usable, falling back to local PNG for compatibility.") +endif() -set (HAVE_LIBZ 1) +if(FLTK_USE_SYSTEM_ZLIB AND FLTK_USE_BUNDLED_ZLIB) + message(STATUS "System PNG or ZLIB not usable, falling back to local ZLIB for compatibility.") +endif() ####################################################################### -# Bundled Image Library : libjpeg +# Bundled Compression Library : zlib ####################################################################### -if (OPTION_USE_SYSTEM_LIBJPEG) - find_package (JPEG) -endif () +if(FLTK_USE_BUNDLED_ZLIB) + + add_subdirectory(zlib) -if (OPTION_USE_SYSTEM_LIBJPEG AND JPEG_FOUND) - set (FLTK_USE_BUILTIN_JPEG FALSE) - set (FLTK_JPEG_LIBRARIES ${JPEG_LIBRARIES}) - include_directories (${JPEG_INCLUDE_DIR}) -else () - if (OPTION_USE_SYSTEM_LIBJPEG) - message (STATUS "cannot find system jpeg library - using built-in\n") - endif () + set(ZLIB_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/zlib) - add_subdirectory (jpeg) - set (FLTK_USE_BUILTIN_JPEG TRUE) - set (FLTK_JPEG_LIBRARIES fltk_jpeg) - include_directories (${CMAKE_CURRENT_SOURCE_DIR}/jpeg) -endif () + # FIXME - include_directories() + include_directories(${ZLIB_INCLUDE_DIR}) -set (HAVE_LIBJPEG 1) +endif() + +set(HAVE_LIBZ 1) ####################################################################### # Bundled Image Library : libpng ####################################################################### -if (OPTION_USE_SYSTEM_LIBPNG AND PNG_FOUND) +if(FLTK_USE_BUNDLED_PNG) + + add_subdirectory(png) + set(FLTK_PNG_LIBRARIES fltk::png) + list(APPEND FLTK_IMAGE_LIBRARIES fltk::png) + + # Definitions for 'config.h' - do we still need this? + # See also png/CMakeLists.txt (target_compile_definitions). + # Note: config.h is generated by either configure or CMake, + # hence we should support it in 1.4.0 (may be changed in 1.5.0) + + set(HAVE_PNG_H 1) + set(HAVE_PNG_GET_VALID 1) + set(HAVE_PNG_SET_TRNS_TO_ALPHA 1) + + # *FIXME* include_directories() + include_directories(${FLTK_SOURCE_DIR}/png) - set (FLTK_USE_BUILTIN_PNG FALSE) - set (FLTK_PNG_LIBRARIES ${PNG_LIBRARIES}) - include_directories (${PNG_INCLUDE_DIRS}) - add_definitions (${PNG_DEFINITIONS}) +else() # use system libpng and zlib - set (_INCLUDE_SAVED ${CMAKE_REQUIRED_INCLUDES}) - list (APPEND CMAKE_REQUIRED_INCLUDES ${PNG_INCLUDE_DIRS}) + set(FLTK_PNG_LIBRARIES ${PNG_LIBRARIES}) + list(APPEND FLTK_IMAGE_LIBRARIES ${PNG_LIBRARIES}) + + # *FIXME* include_directories() + include_directories(${PNG_INCLUDE_DIRS}) + + set(_INCLUDE_SAVED ${CMAKE_REQUIRED_INCLUDES}) + list(APPEND CMAKE_REQUIRED_INCLUDES ${PNG_INCLUDE_DIRS}) # Note: we do not check for <libpng/png.h> explicitly. # This is assumed to exist if we have PNG_FOUND and don't find <png.h> # FIXME - Force search by unsetting the chache variable. Maybe use # FIXME - another cache variable to check for option changes? + # unset(HAVE_PNG_H CACHE) # force search + + check_include_file(png.h HAVE_PNG_H) + mark_as_advanced(HAVE_PNG_H) + + set(CMAKE_REQUIRED_INCLUDES ${_INCLUDE_SAVED}) + unset(_INCLUDE_SAVED) + +endif() + +set(HAVE_LIBPNG 1) + +####################################################################### +# Bundled Image Library : libjpeg +####################################################################### - unset (HAVE_PNG_H CACHE) # force search - check_include_file (png.h HAVE_PNG_H) - mark_as_advanced (HAVE_PNG_H) +if(FLTK_USE_SYSTEM_LIBJPEG) + find_package(JPEG) + if(NOT JPEG_FOUND) + set(FLTK_USE_BUNDLED_JPEG TRUE) + message(STATUS "cannot find system jpeg library - using built-in") + endif() +else() + set(FLTK_USE_BUNDLED_JPEG TRUE) +endif() + +if(FLTK_USE_BUNDLED_JPEG) - set (CMAKE_REQUIRED_INCLUDES ${_INCLUDE_SAVED}) - unset (_INCLUDE_SAVED) + add_subdirectory(jpeg) + set(FLTK_JPEG_LIBRARIES fltk::jpeg) + # list(APPEND FLTK_IMAGE_LIBRARIES fltk::jpeg) -else () + # *FIXME* include_directories + include_directories(${FLTK_SOURCE_DIR}/jpeg) - if (OPTION_USE_SYSTEM_LIBPNG) - message (STATUS "cannot find system png library - using built-in\n") - endif () +else() - add_subdirectory (png) - set (FLTK_USE_BUILTIN_PNG TRUE) - set (FLTK_PNG_LIBRARIES fltk_png) - set (HAVE_PNG_H 1) - set (HAVE_PNG_GET_VALID 1) - set (HAVE_PNG_SET_TRNS_TO_ALPHA 1) - include_directories (${CMAKE_CURRENT_SOURCE_DIR}/png) -endif () + set(FLTK_JPEG_LIBRARIES ${JPEG_LIBRARIES}) + list(APPEND FLTK_IMAGE_LIBRARIES ${JPEG_LIBRARIES}) -set (HAVE_LIBPNG 1) +endif() + +set(HAVE_LIBJPEG 1) ####################################################################### -if (UNIX) - option (OPTION_CREATE_LINKS "create backwards compatibility links" OFF) - list (APPEND FLTK_LDLIBS -lm) - if (NOT APPLE) - option (OPTION_USE_WAYLAND "support both Wayland and X11 backends" ON) - endif (NOT APPLE) - if (OPTION_USE_WAYLAND) + +if(UNIX) + option(FLTK_INSTALL_LINKS "create backwards compatibility links" OFF) + list(APPEND FLTK_LDLIBS -lm) + if(NOT APPLE) + option(FLTK_BACKEND_WAYLAND "support the Wayland backend" ON) + endif(NOT APPLE) + if(FLTK_BACKEND_WAYLAND) pkg_check_modules(WLDCLIENT wayland-client>=1.18) pkg_check_modules(WLDCURSOR wayland-cursor) pkg_check_modules(WLDPROTO wayland-protocols>=1.15) pkg_check_modules(XKBCOMMON xkbcommon) - if (NOT(WLDCLIENT_FOUND AND WLDCURSOR_FOUND AND WLDPROTO_FOUND AND XKBCOMMON_FOUND)) - message (STATUS "Not all software modules 'wayland-client>=1.18 wayland-cursor wayland-protocols>=1.15 xkbcommon' are present") - message (STATUS "Consequently, OPTION_USE_WAYLAND is set to OFF.") - unset (OPTION_USE_WAYLAND CACHE) - set (OPTION_USE_WAYLAND 0) - endif (NOT(WLDCLIENT_FOUND AND WLDCURSOR_FOUND AND WLDPROTO_FOUND AND XKBCOMMON_FOUND)) - endif (OPTION_USE_WAYLAND) - - if (OPTION_USE_WAYLAND) - option (OPTION_WAYLAND_ONLY "support Wayland backend only" OFF) - set (FLTK_USE_WAYLAND 1) - if (NOT OPTION_WAYLAND_ONLY) - include (FindX11) - endif (NOT OPTION_WAYLAND_ONLY) - if (X11_FOUND) - set (FLTK_USE_X11 1) # to build a hybrid Wayland/X11 library - else () - set (FLTK_USE_X11 0) # to build a Wayland-only library - endif (X11_FOUND) - unset (OPTION_USE_CAIRO CACHE) - set (OPTION_USE_CAIRO TRUE CACHE BOOL "all drawing to X11 windows uses Cairo") - option (OPTION_USE_SYSTEM_LIBDECOR "use libdecor from the system" ON) - unset (OPTION_USE_XRENDER CACHE) - unset (OPTION_USE_XINERAMA CACHE) - unset (OPTION_USE_XFT CACHE) - unset (OPTION_USE_XCURSOR CACHE) - unset (OPTION_USE_XFIXES CACHE) - if (X11_FOUND) - if (NOT X11_Xfixes_FOUND) + if(NOT(WLDCLIENT_FOUND AND WLDCURSOR_FOUND AND WLDPROTO_FOUND AND XKBCOMMON_FOUND)) + message(STATUS "Not all software modules 'wayland-client>=1.18 wayland-cursor wayland-protocols>=1.15 xkbcommon' are present") + message(STATUS "Consequently, FLTK_BACKEND_WAYLAND is set to OFF.") + unset(FLTK_BACKEND_WAYLAND CACHE) + set(FLTK_BACKEND_WAYLAND 0) + endif(NOT(WLDCLIENT_FOUND AND WLDCURSOR_FOUND AND WLDPROTO_FOUND AND XKBCOMMON_FOUND)) + endif(FLTK_BACKEND_WAYLAND) + + if(FLTK_BACKEND_WAYLAND) + set(FLTK_USE_WAYLAND 1) + if(FLTK_BACKEND_X11) + include(FindX11) + endif() + if(X11_FOUND) + set(FLTK_USE_X11 1) # to build a hybrid Wayland/X11 library + else() + set(FLTK_USE_X11 0) # to build a Wayland-only library + endif(X11_FOUND) + unset(FLTK_GRAPHICS_CAIRO CACHE) + set(FLTK_GRAPHICS_CAIRO TRUE CACHE BOOL "all drawing to X11 windows uses Cairo") + option(FLTK_USE_SYSTEM_LIBDECOR "use libdecor from the system" ON) + set(USE_SYSTEM_LIBDECOR 1) + unset(FLTK_USE_XRENDER CACHE) + unset(FLTK_USE_XINERAMA CACHE) + unset(FLTK_USE_XFT CACHE) + unset(FLTK_USE_XCURSOR CACHE) + unset(FLTK_USE_XFIXES CACHE) + if(X11_FOUND) + if(NOT X11_Xfixes_FOUND) message(WARNING "Install development headers for libXfixes (e.g., libxfixes-dev)") endif() - set (HAVE_XFIXES 1) - if (NOT X11_Xrender_FOUND) + set(HAVE_XFIXES 1) + if(NOT X11_Xrender_FOUND) message(WARNING "Install development headers for libXrender (e.g., libxrender-dev)") endif() - set (HAVE_XRENDER 1) - if (NOT X11_Xft_FOUND) + set(HAVE_XRENDER 1) + if(NOT X11_Xft_FOUND) message(WARNING "Install development headers for libXft (e.g., libxft-dev)") endif() - set (USE_XFT 1) - if (NOT X11_Xcursor_FOUND) + set(USE_XFT 1) + if(NOT X11_Xcursor_FOUND) message(WARNING "Install development headers for libXcursor (e.g., libxcursor-dev)") endif() - set (HAVE_XCURSOR 1) - if (NOT X11_Xinerama_FOUND) + set(HAVE_XCURSOR 1) + if(NOT X11_Xinerama_FOUND) message(WARNING "Install development headers for libXinerama (e.g., libxinerama-dev)") endif() - set (HAVE_XINERAMA 1) - if (NOT (X11_Xfixes_FOUND AND X11_Xrender_FOUND AND X11_Xft_FOUND AND X11_Xcursor_FOUND + set(HAVE_XINERAMA 1) + if(NOT (X11_Xfixes_FOUND AND X11_Xrender_FOUND AND X11_Xft_FOUND AND X11_Xcursor_FOUND AND X11_Xinerama_FOUND)) - message (FATAL_ERROR "*** Terminating: one or more required software package(s) missing.") - endif () - endif (X11_FOUND) - unset (OPTION_USE_PANGO CACHE) - set (OPTION_USE_PANGO TRUE CACHE BOOL "use lib Pango") - if (OPTION_USE_SYSTEM_LIBDECOR) - pkg_check_modules(SYSTEM_LIBDECOR libdecor-0>=0.2.0) - if (NOT SYSTEM_LIBDECOR_FOUND) - set (OPTION_USE_SYSTEM_LIBDECOR OFF) - else () + message(FATAL_ERROR "*** Terminating: one or more required software package(s) missing.") + endif() + endif(X11_FOUND) + unset(FLTK_USE_PANGO CACHE) + set(FLTK_USE_PANGO TRUE CACHE BOOL "use lib Pango") + if(FLTK_USE_SYSTEM_LIBDECOR) + pkg_check_modules(SYSTEM_LIBDECOR libdecor-0>=0.2.0 QUIET) + if(NOT SYSTEM_LIBDECOR_FOUND) + message(STATUS "Warning: system libdecor doesn't satisfy version >= 0.2.0,") + message(STATUS " using bundled libdecor library instead.") + set(USE_SYSTEM_LIBDECOR 0) + else() pkg_get_variable(LIBDECOR_LIBDIR libdecor-0 libdir) - set (LIBDECOR_PLUGIN_DIR ${LIBDECOR_LIBDIR}/libdecor/plugins-1) - if (EXISTS ${LIBDECOR_PLUGIN_DIR} AND IS_DIRECTORY ${LIBDECOR_PLUGIN_DIR}) - set (LIBDECOR_PLUGIN_DIR "\"${LIBDECOR_PLUGIN_DIR}\"" ) - else () - set (OPTION_USE_SYSTEM_LIBDECOR OFF) - endif () - endif (NOT SYSTEM_LIBDECOR_FOUND) - endif (OPTION_USE_SYSTEM_LIBDECOR) - - if (OPTION_USE_SYSTEM_LIBDECOR) - set (OPTION_ALLOW_GTK_PLUGIN ON) - else () - option (OPTION_ALLOW_GTK_PLUGIN "Allow to use libdecor's GTK plugin" ON) - endif (OPTION_USE_SYSTEM_LIBDECOR) - - if (${CMAKE_HOST_SYSTEM_NAME} STREQUAL "FreeBSD") - CHECK_INCLUDE_FILE (linux/input.h LINUX_INPUT_H) - if (NOT LINUX_INPUT_H) - message (FATAL_ERROR "Required include file 'linux/input.h' is missing. Please install package 'evdev-proto'") - endif (NOT LINUX_INPUT_H) - endif (${CMAKE_HOST_SYSTEM_NAME} STREQUAL "FreeBSD") - - endif (OPTION_USE_WAYLAND) -endif (UNIX) - -if (WIN32) - option (OPTION_USE_GDIPLUS "use GDI+ when possible for antialiased graphics" ON) - if (OPTION_USE_GDIPLUS) - set (USE_GDIPLUS TRUE) - if (NOT MSVC) - list (APPEND FLTK_LDLIBS "-lgdiplus") - endif (NOT MSVC) - endif (OPTION_USE_GDIPLUS) -endif (WIN32) - -####################################################################### -if (APPLE) - option (OPTION_APPLE_X11 "use X11" OFF) - if (CMAKE_OSX_SYSROOT) - list (APPEND FLTK_CFLAGS "-isysroot ${CMAKE_OSX_SYSROOT}") - endif (CMAKE_OSX_SYSROOT) -endif (APPLE) - -####################################################################### -option (OPTION_USE_STD "allow FLTK to use some std:: features" OFF) -if (OPTION_USE_STD) - set (FLTK_USE_STD 1) -else () - set (FLTK_USE_STD 0) -endif () + set(LIBDECOR_PLUGIN_DIR ${LIBDECOR_LIBDIR}/libdecor/plugins-1) + if(EXISTS ${LIBDECOR_PLUGIN_DIR} AND IS_DIRECTORY ${LIBDECOR_PLUGIN_DIR}) + set(LIBDECOR_PLUGIN_DIR "\"${LIBDECOR_PLUGIN_DIR}\"" ) + else() + set(USE_SYSTEM_LIBDECOR 0) + endif() + endif(NOT SYSTEM_LIBDECOR_FOUND) + endif(FLTK_USE_SYSTEM_LIBDECOR) + + if(USE_SYSTEM_LIBDECOR) + set(FLTK_USE_LIBDECOR_GTK ON) + else() + option(FLTK_USE_LIBDECOR_GTK "Allow to use libdecor's GTK plugin" ON) + endif(USE_SYSTEM_LIBDECOR) + + if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "FreeBSD") + check_include_file(linux/input.h LINUX_INPUT_H) + if(NOT LINUX_INPUT_H) + message(FATAL_ERROR "Required include file 'linux/input.h' is missing. Please install package 'evdev-proto'") + endif(NOT LINUX_INPUT_H) + endif(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "FreeBSD") + + endif(FLTK_BACKEND_WAYLAND) +endif(UNIX) + +if(WIN32) + option(FLTK_GRAPHICS_GDIPLUS "use GDI+ when possible for antialiased graphics" ON) + if(FLTK_GRAPHICS_GDIPLUS) + set(USE_GDIPLUS TRUE) + if(NOT MSVC) + list(APPEND FLTK_LDLIBS "-lgdiplus") + endif(NOT MSVC) + endif(FLTK_GRAPHICS_GDIPLUS) +endif(WIN32) + +####################################################################### +option(FLTK_OPTION_STD "allow FLTK to use some std:: features" OFF) +if(FLTK_OPTION_STD) + set(FLTK_USE_STD 1) +else() + set(FLTK_USE_STD 0) +endif() ####################################################################### # find X11 libraries and headers -set (PATH_TO_XLIBS) -if ((NOT APPLE OR OPTION_APPLE_X11) AND NOT WIN32 AND NOT OPTION_USE_WAYLAND) - include (FindX11) - if (X11_FOUND) - set (FLTK_USE_X11 1) - list (APPEND FLTK_LDLIBS -lX11) - if (X11_Xext_FOUND) - list (APPEND FLTK_LDLIBS -lXext) - endif (X11_Xext_FOUND) - get_filename_component (PATH_TO_XLIBS ${X11_X11_LIB} PATH) - endif (X11_FOUND) -endif ((NOT APPLE OR OPTION_APPLE_X11) AND NOT WIN32 AND NOT OPTION_USE_WAYLAND) - -if (OPTION_APPLE_X11) - if (NOT(${CMAKE_SYSTEM_VERSION} VERSION_LESS 17.0.0)) # a.k.a. macOS version ≥ 10.13 - list (APPEND FLTK_CFLAGS "-D_LIBCPP_HAS_THREAD_API_PTHREAD") - endif (NOT(${CMAKE_SYSTEM_VERSION} VERSION_LESS 17.0.0)) - include_directories (AFTER SYSTEM /opt/X11/include/freetype2) - include_directories (AFTER SYSTEM /opt/X11/include) # for Xft.h - if (PATH_TO_XLIBS) - set (LDFLAGS "-L${PATH_TO_XLIBS} ${LDFLAGS}") - endif (PATH_TO_XLIBS) - if (X11_INCLUDE_DIR) - set (TEMP_INCLUDE_DIR ${X11_INCLUDE_DIR}) - list (TRANSFORM TEMP_INCLUDE_DIR PREPEND "-I") - list (APPEND FLTK_CFLAGS "${TEMP_INCLUDE_DIR}") - endif (X11_INCLUDE_DIR) -endif (OPTION_APPLE_X11) - -####################################################################### -option (OPTION_USE_POLL "use poll if available" OFF) -mark_as_advanced (OPTION_USE_POLL) - -if (OPTION_USE_POLL) +set(PATH_TO_XLIBS) +if((NOT APPLE OR FLTK_BACKEND_X11) AND NOT WIN32 AND NOT FLTK_BACKEND_WAYLAND) + include(FindX11) + if(X11_FOUND) + set(FLTK_USE_X11 1) + list(APPEND FLTK_LDLIBS -lX11) + if(X11_Xext_FOUND) + list(APPEND FLTK_LDLIBS -lXext) + endif(X11_Xext_FOUND) + get_filename_component(PATH_TO_XLIBS ${X11_X11_LIB} PATH) + endif(X11_FOUND) +endif() + +if(FLTK_BACKEND_X11) + if(NOT(${CMAKE_SYSTEM_VERSION} VERSION_LESS 17.0.0)) # a.k.a. macOS version ≥ 10.13 + list(APPEND FLTK_CFLAGS "-D_LIBCPP_HAS_THREAD_API_PTHREAD") + endif(NOT(${CMAKE_SYSTEM_VERSION} VERSION_LESS 17.0.0)) + # FIXME: include_directories(!) + # FIXME: how can we implement "AFTER SYSTEM" ? + include_directories(AFTER SYSTEM /opt/X11/include/freetype2) + include_directories(AFTER SYSTEM /opt/X11/include) # for Xft.h + if(PATH_TO_XLIBS) + set(LDFLAGS "-L${PATH_TO_XLIBS} ${LDFLAGS}") + endif(PATH_TO_XLIBS) + if(X11_INCLUDE_DIR) + set(TEMP_INCLUDE_DIR ${X11_INCLUDE_DIR}) + list(TRANSFORM TEMP_INCLUDE_DIR PREPEND "-I") + list(APPEND FLTK_CFLAGS "${TEMP_INCLUDE_DIR}") + endif(X11_INCLUDE_DIR) +endif(FLTK_BACKEND_X11) + +####################################################################### +option(FLTK_USE_POLL "use poll if available" OFF) +mark_as_advanced(FLTK_USE_POLL) + +if(FLTK_USE_POLL) CHECK_FUNCTION_EXISTS(poll USE_POLL) -endif (OPTION_USE_POLL) +endif(FLTK_USE_POLL) ####################################################################### -option (OPTION_BUILD_SHARED_LIBS - "Build shared libraries (in addition to static libraries)" +option(FLTK_BUILD_SHARED_LIBS + "Build shared libraries in addition to static libraries" OFF ) ####################################################################### -option (OPTION_PRINT_SUPPORT "allow print support" ON) -option (OPTION_FILESYSTEM_SUPPORT "allow file system support" ON) +option(FLTK_OPTION_PRINT_SUPPORT "allow print support" ON) +option(FLTK_OPTION_FILESYSTEM_SUPPORT "allow file system support" ON) -option (FLTK_BUILD_FORMS "Build forms compatibility library" ON) -option (FLTK_BUILD_FLUID "Build FLUID" ON) -option (FLTK_BUILD_FLTK_OPTIONS "Build fltk-options" ON) -option (FLTK_BUILD_TEST "Build test/demo programs" ON) -option (FLTK_BUILD_EXAMPLES "Build example programs" OFF) +option(FLTK_BUILD_FORMS "Build forms compatibility library" ON) +option(FLTK_BUILD_FLUID "Build FLUID" ON) +option(FLTK_BUILD_FLTK_OPTIONS "Build fltk-options" ON) +option(FLTK_BUILD_EXAMPLES "Build example programs" OFF) -if (FLTK_BUILD_FORMS) - set (FLTK_HAVE_FORMS 1) -else () - set (FLTK_HAVE_FORMS 0) -endif () +if(FLTK_IS_TOPLEVEL) + option(FLTK_BUILD_TEST "Build test/demo programs" ON) +else() + option(FLTK_BUILD_TEST "Build test/demo programs" OFF) +endif() -if (DEFINED OPTION_BUILD_EXAMPLES) - message (WARNING - "'OPTION_BUILD_EXAMPLES' is obsolete, please use 'FLTK_BUILD_TEST' instead.") - message (STATUS - "To remove this warning, please delete 'OPTION_BUILD_EXAMPLES' from the CMake cache") -endif (DEFINED OPTION_BUILD_EXAMPLES) +if(FLTK_BUILD_FORMS) + set(FLTK_HAVE_FORMS 1) +else() + set(FLTK_HAVE_FORMS 0) +endif() ####################################################################### -if (DOXYGEN_FOUND) - option (OPTION_BUILD_HTML_DOCUMENTATION "build html docs" ON) - option (OPTION_INSTALL_HTML_DOCUMENTATION "install html docs" OFF) +if(DOXYGEN_FOUND) + option(FLTK_BUILD_HTML_DOCS "build html docs" ON) + option(FLTK_INSTALL_HTML_DOCS "install html docs" OFF) - option (OPTION_INCLUDE_DRIVER_DOCUMENTATION "include driver (developer) docs" OFF) - mark_as_advanced (OPTION_INCLUDE_DRIVER_DOCUMENTATION) + option(FLTK_INCLUDE_DRIVER_DOCS "include driver (developer) docs" OFF) + mark_as_advanced(FLTK_INCLUDE_DRIVER_DOCS) - if (LATEX_FOUND) - option (OPTION_BUILD_PDF_DOCUMENTATION "build pdf docs" ON) - option (OPTION_INSTALL_PDF_DOCUMENTATION "install pdf docs" OFF) - endif (LATEX_FOUND) -endif (DOXYGEN_FOUND) + if(LATEX_FOUND) + option(FLTK_BUILD_PDF_DOCS "build pdf docs" ON) + option(FLTK_INSTALL_PDF_DOCS "install pdf docs" OFF) + endif(LATEX_FOUND) +endif(DOXYGEN_FOUND) -if (OPTION_BUILD_HTML_DOCUMENTATION OR OPTION_BUILD_PDF_DOCUMENTATION) - add_subdirectory (documentation) -endif (OPTION_BUILD_HTML_DOCUMENTATION OR OPTION_BUILD_PDF_DOCUMENTATION) +if(FLTK_BUILD_HTML_DOCS OR FLTK_BUILD_PDF_DOCS) + add_subdirectory(documentation) +endif(FLTK_BUILD_HTML_DOCS OR FLTK_BUILD_PDF_DOCS) ####################################################################### # Include optional Cairo support ####################################################################### -option (OPTION_CAIRO "add support for Fl_Cairo_Window" OFF) -option (OPTION_CAIROEXT +option(FLTK_OPTION_CAIRO_WINDOW "add support for Fl_Cairo_Window" OFF) +option(FLTK_OPTION_CAIRO_EXT "use FLTK code instrumentation for Cairo extended use" OFF ) -set (FLTK_HAVE_CAIRO 0) -set (FLTK_HAVE_CAIROEXT 0) +set(FLTK_HAVE_CAIRO 0) +set(FLTK_HAVE_CAIROEXT 0) -if (OPTION_CAIRO OR OPTION_CAIROEXT) - pkg_search_module (PKG_CAIRO cairo) +if(FLTK_OPTION_CAIRO_WINDOW OR FLTK_OPTION_CAIRO_EXT) + pkg_search_module(PKG_CAIRO cairo) - # fl_debug_var (PKG_CAIRO_FOUND) + if(PKG_CAIRO_FOUND) + set(FLTK_HAVE_CAIRO 1) + if(FLTK_OPTION_CAIRO_EXT) + set(FLTK_HAVE_CAIROEXT 1) + endif(FLTK_OPTION_CAIRO_EXT) - if (PKG_CAIRO_FOUND) - set (FLTK_HAVE_CAIRO 1) - if (OPTION_CAIROEXT) - set (FLTK_HAVE_CAIROEXT 1) - endif (OPTION_CAIROEXT) - - ### FIXME ### - include_directories (${PKG_CAIRO_INCLUDE_DIRS}) + list(APPEND FLTK_BUILD_INCLUDE_DIRECTORIES ${PKG_CAIRO_INCLUDE_DIRS}) # Cairo libs and flags for fltk-config # Hint: use either PKG_CAIRO_* or PKG_CAIRO_STATIC_* variables to - # create the list of libraries used to link programs with cairo + # create the list of libraries used to link programs with Cairo # by running fltk-config --use-cairo --compile ... - # Currently we're using the non-STATIC variables to link cairo shared. + # Currently we're using the non-STATIC variables to link Cairo shared. - set (CAIROLIBS) - foreach (lib ${PKG_CAIRO_LIBRARIES}) - list (APPEND CAIROLIBS "-l${lib}") + set(CAIROLIBS) + foreach(lib ${PKG_CAIRO_LIBRARIES}) + list(APPEND CAIROLIBS "-l${lib}") endforeach() - string (REPLACE ";" " " CAIROLIBS "${CAIROLIBS}") - string (REPLACE ";" " " CAIROFLAGS "${PKG_CAIRO_CFLAGS}") + string(REPLACE ";" " " CAIROLIBS "${CAIROLIBS}") + string(REPLACE ";" " " CAIROFLAGS "${PKG_CAIRO_CFLAGS}") - else (PKG_CAIRO_FOUND) + else(PKG_CAIRO_FOUND) - if (NOT MSVC) - message (STATUS "*** Cairo was requested but not found - please check your cairo installation") - message (STATUS "*** or disable options OPTION_CAIRO and OPTION_CAIRO_EXT.") - message (FATAL_ERROR "*** Terminating: missing Cairo libs or headers.") - endif () + if(NOT MSVC) + message(STATUS "*** Cairo was requested but not found - please check your Cairo installation") + message(STATUS "*** or disable options FLTK_OPTION_CAIRO_WINDOW and FLTK_OPTION_CAIRO_EXT.") + message(FATAL_ERROR "*** Terminating: missing Cairo libs or headers.") + endif() # Tweak Cairo includes / libs / paths for Visual Studio (TEMPORARY solution). # Todo: find a better way to set the required variables and flags! # AlbrechtS 03/2023 - message (STATUS "--- Cairo not found: trying to find Cairo for MSVC ...") + message(STATUS "--- Cairo not found: trying to find Cairo for MSVC ...") - if (NOT FLTK_CAIRO_DIR) - message (STATUS "--- Please set FLTK_CAIRO_DIR to point at the Cairo installation folder ...") - message (STATUS " ... with files 'include/cairo.h' and 'lib/x64/cairo.lib'") - message (STATUS "--- Example: cmake -DFLTK_CAIRO_DIR=\"C:/cairo-windows\" ...") - message (STATUS "--- Note: this will be changed in the future; currently only 64-bit supported") - message (FATAL_ERROR "*** Terminating: missing Cairo libs or headers.") - endif () + if(NOT FLTK_CAIRO_DIR) + message(STATUS "--- Please set FLTK_CAIRO_DIR to point at the Cairo installation folder ...") + message(STATUS " ... with files 'include/cairo.h' and 'lib/x64/cairo.lib'") + message(STATUS "--- Example: cmake -DFLTK_CAIRO_DIR=\"C:/cairo-windows\" ...") + message(STATUS "--- Note: this will be changed in the future; currently only 64-bit supported") + message(FATAL_ERROR "*** Terminating: missing Cairo libs or headers.") + endif() - set (CAIROLIBS "-lcairo") # should be correct: needs cairo.lib + set(CAIROLIBS "-lcairo") # should be correct: needs cairo.lib # simulate results of 'pkg_search_module (PKG_CAIRO cairo)' and more (above) # these variables will be used later - set (PKG_CAIRO_LIBRARIES "cairo") - set (PKG_CAIRO_INCLUDE_DIRS "${FLTK_CAIRO_DIR}/include") - set (PKG_CAIRO_LIBRARY_DIRS "${FLTK_CAIRO_DIR}/lib/x64/") + set(PKG_CAIRO_LIBRARIES "cairo") + set(PKG_CAIRO_INCLUDE_DIRS "${FLTK_CAIRO_DIR}/include") + set(PKG_CAIRO_LIBRARY_DIRS "${FLTK_CAIRO_DIR}/lib/x64/") ### FIXME ### - include_directories (${PKG_CAIRO_INCLUDE_DIRS}) - - set (FLTK_HAVE_CAIRO 1) - if (OPTION_CAIROEXT) - set (FLTK_HAVE_CAIROEXT 1) - endif (OPTION_CAIROEXT) - - endif (PKG_CAIRO_FOUND) - - if (0) # 1 = DEBUG, 0 = no output - message (STATUS "--- options.cmake: Cairo related variables ---") - if (MSVC) - fl_debug_var (FLTK_CAIRO_DIR) - endif (MSVC) - fl_debug_var (PKG_CAIRO_INCLUDE_DIRS) - fl_debug_var (PKG_CAIRO_CFLAGS) - fl_debug_var (PKG_CAIRO_LIBRARIES) - fl_debug_var (PKG_CAIRO_LIBRARY_DIRS) - fl_debug_var (PKG_CAIRO_STATIC_INCLUDE_DIRS) - fl_debug_var (PKG_CAIRO_STATIC_CFLAGS) - fl_debug_var (PKG_CAIRO_STATIC_LIBRARIES) - fl_debug_var (PKG_CAIRO_STATIC_LIBRARY_DIRS) - message (STATUS "--- fltk-config/Cairo variables ---") - fl_debug_var (FLTK_LDLIBS) - fl_debug_var (CAIROFLAGS) - fl_debug_var (CAIROLIBS) - message (STATUS "--- End of Cairo related variables ---") + include_directories(${PKG_CAIRO_INCLUDE_DIRS}) + + set(FLTK_HAVE_CAIRO 1) + if(FLTK_OPTION_CAIRO_EXT) + set(FLTK_HAVE_CAIROEXT 1) + endif(FLTK_OPTION_CAIRO_EXT) + + endif(PKG_CAIRO_FOUND) + + if(0) # 1 = DEBUG, 0 = no output + message(STATUS "--- options.cmake: Cairo related variables ---") + if(MSVC) + fl_debug_var(FLTK_CAIRO_DIR) + endif(MSVC) + # fl_debug_pkg(PKG_CAIRO cairo) + fl_debug_var(PKG_CAIRO_INCLUDE_DIRS) + fl_debug_var(PKG_CAIRO_CFLAGS) + fl_debug_var(PKG_CAIRO_LIBRARIES) + fl_debug_var(PKG_CAIRO_LIBRARY_DIRS) + fl_debug_var(PKG_CAIRO_STATIC_INCLUDE_DIRS) + fl_debug_var(PKG_CAIRO_STATIC_CFLAGS) + fl_debug_var(PKG_CAIRO_STATIC_LIBRARIES) + fl_debug_var(PKG_CAIRO_STATIC_LIBRARY_DIRS) + message(STATUS "--- fltk-config/Cairo variables ---") + fl_debug_var(FLTK_LDLIBS) + fl_debug_var(CAIROFLAGS) + fl_debug_var(CAIROLIBS) + message(STATUS "--- End of Cairo related variables ---") endif() # 1 = DEBUG, ... -endif (OPTION_CAIRO OR OPTION_CAIROEXT) +endif(FLTK_OPTION_CAIRO_WINDOW OR FLTK_OPTION_CAIRO_EXT) ####################################################################### -option (OPTION_USE_SVG "read/write SVG files" ON) -if (OPTION_USE_SVG) - set (FLTK_USE_SVG 1) -endif (OPTION_USE_SVG) +option(FLTK_OPTION_SVG "read/write SVG image files" ON) + +if(FLTK_OPTION_SVG) + set(FLTK_USE_SVG 1) +else() + set(FLTK_USE_SVG 0) +endif(FLTK_OPTION_SVG) ####################################################################### -set (HAVE_GL LIB_GL OR LIB_MesaGL) -if (HAVE_GL) - option (OPTION_USE_GL "use OpenGL" ON) -endif (HAVE_GL) +# FIXME: GL libs have already been searched in resources.cmake + +set(HAVE_GL LIB_GL OR LIB_MesaGL) +set(FLTK_USE_GL FALSE) -if (OPTION_USE_GL) - if (OPTION_USE_WAYLAND) +if(HAVE_GL) + option(FLTK_BUILD_GL "use OpenGL and build fltk_gl library" ON) + if (FLTK_BUILD_GL) + set(FLTK_USE_GL TRUE) + endif() +endif() + +if(FLTK_BUILD_GL) + if(FLTK_BACKEND_WAYLAND) pkg_check_modules(WLD_EGL wayland-egl) pkg_check_modules(PKG_EGL egl) pkg_check_modules(PKG_GL gl) - if (NOT (WLD_EGL_FOUND AND PKG_EGL_FOUND AND PKG_GL_FOUND)) - message (STATUS "Modules 'wayland-egl, egl, and gl' are required to build for the Wayland backend.") - message (FATAL_ERROR "*** Aborting ***") - endif (NOT (WLD_EGL_FOUND AND PKG_EGL_FOUND AND PKG_GL_FOUND)) - endif (OPTION_USE_WAYLAND) - if (OPTION_APPLE_X11) - set (OPENGL_FOUND TRUE) + if(NOT (WLD_EGL_FOUND AND PKG_EGL_FOUND AND PKG_GL_FOUND)) + message(STATUS "Modules 'wayland-egl, egl, and gl' are required to build for the Wayland backend.") + message(FATAL_ERROR "*** Aborting ***") + endif(NOT (WLD_EGL_FOUND AND PKG_EGL_FOUND AND PKG_GL_FOUND)) + endif(FLTK_BACKEND_WAYLAND) + if(FLTK_BACKEND_X11) + set(OPENGL_FOUND TRUE) find_library(OPENGL_LIB GL) - get_filename_component (PATH_TO_GLLIB ${OPENGL_LIB} DIRECTORY) + get_filename_component(PATH_TO_GLLIB ${OPENGL_LIB} DIRECTORY) # with GL, must use XQuartz libX11 else "Insufficient GL support" - set (OPENGL_LIBRARIES -L${PATH_TO_GLLIB} -lX11 -lGLU -lGL) + set(OPENGL_LIBRARIES -L${PATH_TO_GLLIB} -lX11 -lGLU -lGL) unset(HAVE_GL_GLU_H CACHE) - find_file (HAVE_GL_GLU_H GL/glu.h PATHS ${X11_INCLUDE_DIR}) + find_file(HAVE_GL_GLU_H GL/glu.h PATHS ${X11_INCLUDE_DIR}) else() find_package(OpenGL) - if (APPLE) - set (HAVE_GL_GLU_H ${HAVE_OPENGL_GLU_H}) - endif (APPLE) - endif (OPTION_APPLE_X11) -else () - set (OPENGL_FOUND FALSE) - set (HAVE_GL FALSE) - set (HAVE_GL_GLU_H FALSE) - set (HAVE_GLXGETPROCADDRESSARB FALSE) -endif (OPTION_USE_GL) - -if (OPENGL_FOUND) - set (CMAKE_REQUIRED_INCLUDES ${OPENGL_INCLUDE_DIR}/GL) + if(APPLE) + set(HAVE_GL_GLU_H ${HAVE_OPENGL_GLU_H}) + endif(APPLE) + endif(FLTK_BACKEND_X11) +else() + set(OPENGL_FOUND FALSE) + set(HAVE_GL FALSE) + set(HAVE_GL_GLU_H FALSE) + set(HAVE_GLXGETPROCADDRESSARB FALSE) +endif(FLTK_BUILD_GL) + +if(OPENGL_FOUND) + set(CMAKE_REQUIRED_INCLUDES ${OPENGL_INCLUDE_DIR}/GL) # Set GLLIBS (used in fltk-config). # We should probably deduct this from OPENGL_LIBRARIES but it turned @@ -595,38 +637,38 @@ if (OPENGL_FOUND) # syntax depending on the platform (and maybe also CMake version). # Hence we use the following code... - if (WIN32) - set (GLLIBS "-lglu32 -lopengl32") - elseif (APPLE AND NOT OPTION_APPLE_X11) - set (GLLIBS "-framework OpenGL") - elseif (OPTION_USE_WAYLAND) - set (GLLIBS "-lwayland-egl -lEGL -lGLU -lGL") - else () - set (GLLIBS "-lGLU -lGL") - endif (WIN32) + if(WIN32) + set(GLLIBS "-lglu32 -lopengl32") + elseif(APPLE AND NOT FLTK_BACKEND_X11) + set(GLLIBS "-framework OpenGL") + elseif(FLTK_BACKEND_WAYLAND) + set(GLLIBS "-lwayland-egl -lEGL -lGLU -lGL") + else() + set(GLLIBS "-lGLU -lGL") + endif(WIN32) # check if function glXGetProcAddressARB exists - set (TEMP_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}) - set (CMAKE_REQUIRED_LIBRARIES ${OPENGL_LIBRARIES}) - CHECK_FUNCTION_EXISTS (glXGetProcAddressARB HAVE_GLXGETPROCADDRESSARB) - set (CMAKE_REQUIRED_LIBRARIES ${TEMP_REQUIRED_LIBRARIES}) - unset (TEMP_REQUIRED_LIBRARIES) + set(TEMP_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}) + set(CMAKE_REQUIRED_LIBRARIES ${OPENGL_LIBRARIES}) + check_function_exists(glXGetProcAddressARB HAVE_GLXGETPROCADDRESSARB) + set(CMAKE_REQUIRED_LIBRARIES ${TEMP_REQUIRED_LIBRARIES}) + unset(TEMP_REQUIRED_LIBRARIES) - set (FLTK_GL_FOUND TRUE) -else () - set (FLTK_GL_FOUND FALSE) - set (GLLIBS) -endif (OPENGL_FOUND) + set(FLTK_GL_FOUND TRUE) +else() + set(FLTK_GL_FOUND FALSE) + set(GLLIBS) +endif(OPENGL_FOUND) ####################################################################### -option (OPTION_LARGE_FILE "enable large file support" ON) +option(FLTK_OPTION_LARGE_FILE "enable large file support" ON) -if (OPTION_LARGE_FILE) - if (NOT MSVC) - add_definitions (-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64) - list (APPEND FLTK_CFLAGS -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64) - endif (NOT MSVC) -endif (OPTION_LARGE_FILE) +if(FLTK_OPTION_LARGE_FILE) + if(NOT MSVC) + add_definitions(-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64) + list(APPEND FLTK_CFLAGS -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64) + endif(NOT MSVC) +endif(FLTK_OPTION_LARGE_FILE) ####################################################################### # Create an option whether we want to check for pthreads. @@ -636,221 +678,222 @@ endif (OPTION_LARGE_FILE) # Note: HAVE_PTHREAD_H has already been determined in resources.cmake # before this file is included (or set to 0 for WIN32). -if (WIN32 AND NOT CYGWIN) - # set (HAVE_PTHREAD_H 0) # (see resources.cmake) - set (OPTION_USE_THREADS FALSE) -else () - option (OPTION_USE_THREADS "use multi-threading with pthreads" ON) -endif (WIN32 AND NOT CYGWIN) +if(WIN32 AND NOT CYGWIN) + # set(HAVE_PTHREAD_H 0) # (see resources.cmake) + set(FLTK_USE_PTHREADS FALSE) +else() + option(FLTK_USE_PTHREADS "use multi-threading with pthreads" ON) +endif(WIN32 AND NOT CYGWIN) # initialize more variables -set (USE_THREADS 0) -set (HAVE_PTHREAD 0) -set (FLTK_PTHREADS_FOUND FALSE) - -if (OPTION_USE_THREADS) - - include (FindThreads) - - if (CMAKE_HAVE_THREADS_LIBRARY) - add_definitions ("-D_THREAD_SAFE -D_REENTRANT") - set (USE_THREADS 1) - set (FLTK_THREADS_FOUND TRUE) - endif (CMAKE_HAVE_THREADS_LIBRARY) - - if (CMAKE_USE_PTHREADS_INIT AND NOT WIN32) - set (HAVE_PTHREAD 1) - if (NOT APPLE) - set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pthread") - endif (NOT APPLE) - list (APPEND FLTK_LDLIBS -lpthread) - list (APPEND FLTK_CFLAGS -D_THREAD_SAFE -D_REENTRANT) - set (FLTK_PTHREADS_FOUND TRUE) +set(USE_THREADS 0) +set(HAVE_PTHREAD 0) +set(FLTK_PTHREADS_FOUND FALSE) + +if(FLTK_USE_PTHREADS) + + include(FindThreads) + + if(CMAKE_HAVE_THREADS_LIBRARY) + add_definitions("-D_THREAD_SAFE -D_REENTRANT") + set(USE_THREADS 1) + set(FLTK_THREADS_FOUND TRUE) + endif(CMAKE_HAVE_THREADS_LIBRARY) + + if(CMAKE_USE_PTHREADS_INIT AND NOT WIN32) + set(HAVE_PTHREAD 1) + if(NOT APPLE) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pthread") + endif(NOT APPLE) + list(APPEND FLTK_LDLIBS -lpthread) + list(APPEND FLTK_CFLAGS -D_THREAD_SAFE -D_REENTRANT) + set(FLTK_PTHREADS_FOUND TRUE) else() - set (HAVE_PTHREAD 0) - set (HAVE_PTHREAD_H 0) - set (FLTK_PTHREADS_FOUND FALSE) - endif (CMAKE_USE_PTHREADS_INIT AND NOT WIN32) + set(HAVE_PTHREAD 0) + set(HAVE_PTHREAD_H 0) + set(FLTK_PTHREADS_FOUND FALSE) + endif(CMAKE_USE_PTHREADS_INIT AND NOT WIN32) -else (OPTION_USE_THREADS) +else(FLTK_USE_PTHREADS) - set (HAVE_PTHREAD_H 0) + set(HAVE_PTHREAD_H 0) -endif (OPTION_USE_THREADS) +endif(FLTK_USE_PTHREADS) -set (debug_threads 0) # set to 1 to show debug info -if (debug_threads) - message ("") - message (STATUS "options.cmake: set debug_threads to 0 to disable the following info:") - fl_debug_var(OPTION_USE_THREADS) +set(debug_threads 0) # set to 1 to show debug info +if(debug_threads) + message("") + message(STATUS "options.cmake: set debug_threads to 0 to disable the following info:") + fl_debug_var(FLTK_USE_PTHREADS) fl_debug_var(HAVE_PTHREAD) fl_debug_var(HAVE_PTHREAD_H) fl_debug_var(FLTK_THREADS_FOUND) fl_debug_var(CMAKE_EXE_LINKER_FLAGS) - message (STATUS "options.cmake: end of debug_threads info.") -endif (debug_threads) -unset (debug_threads) + message(STATUS "options.cmake: end of debug_threads info.") +endif(debug_threads) +unset(debug_threads) ####################################################################### -if (X11_Xinerama_FOUND) - option (OPTION_USE_XINERAMA "use lib Xinerama" ON) -endif (X11_Xinerama_FOUND) - -if (OPTION_USE_XINERAMA) - set (HAVE_XINERAMA ${X11_Xinerama_FOUND}) - include_directories (${X11_Xinerama_INCLUDE_PATH}) - list (APPEND FLTK_LDLIBS -lXinerama) - set (FLTK_XINERAMA_FOUND TRUE) +if(X11_Xinerama_FOUND) + option(FLTK_USE_XINERAMA "use lib Xinerama" ON) +endif(X11_Xinerama_FOUND) + +if(FLTK_USE_XINERAMA) + set(HAVE_XINERAMA ${X11_Xinerama_FOUND}) + list(APPEND FLTK_BUILD_INCLUDE_DIRECTORIES ${X11_Xinerama_INCLUDE_PATH}) + list(APPEND FLTK_LDLIBS -lXinerama) + set(FLTK_XINERAMA_FOUND TRUE) else() - set (FLTK_XINERAMA_FOUND FALSE) -endif (OPTION_USE_XINERAMA) + set(FLTK_XINERAMA_FOUND FALSE) +endif(FLTK_USE_XINERAMA) ####################################################################### -if (X11_Xfixes_FOUND) - option (OPTION_USE_XFIXES "use lib Xfixes" ON) -endif (X11_Xfixes_FOUND) - -if (OPTION_USE_XFIXES) - set (HAVE_XFIXES ${X11_Xfixes_FOUND}) - include_directories (${X11_Xfixes_INCLUDE_PATH}) - list (APPEND FLTK_LDLIBS -lXfixes) - set (FLTK_XFIXES_FOUND TRUE) +if(X11_Xfixes_FOUND) + option(FLTK_USE_XFIXES "use lib Xfixes" ON) +endif(X11_Xfixes_FOUND) + +if(FLTK_USE_XFIXES) + set(HAVE_XFIXES ${X11_Xfixes_FOUND}) + list(APPEND FLTK_BUILD_INCLUDE_DIRECTORIES ${X11_Xfixes_INCLUDE_PATH}) + list(APPEND FLTK_LDLIBS -lXfixes) + set(FLTK_XFIXES_FOUND TRUE) else() - set (FLTK_XFIXES_FOUND FALSE) -endif (OPTION_USE_XFIXES) + set(FLTK_XFIXES_FOUND FALSE) +endif(FLTK_USE_XFIXES) ####################################################################### -if (X11_Xcursor_FOUND) - option (OPTION_USE_XCURSOR "use lib Xcursor" ON) -endif (X11_Xcursor_FOUND) - -if (OPTION_USE_XCURSOR) - set (HAVE_XCURSOR ${X11_Xcursor_FOUND}) - include_directories (${X11_Xcursor_INCLUDE_PATH}) - list (APPEND FLTK_LDLIBS -lXcursor) - set (FLTK_XCURSOR_FOUND TRUE) +if(X11_Xcursor_FOUND) + option(FLTK_USE_XCURSOR "use lib Xcursor" ON) +endif(X11_Xcursor_FOUND) + +if(FLTK_USE_XCURSOR) + set(HAVE_XCURSOR ${X11_Xcursor_FOUND}) + list(APPEND FLTK_BUILD_INCLUDE_DIRECTORIES ${X11_Xcursor_INCLUDE_PATH}) + list(APPEND FLTK_LDLIBS -lXcursor) + set(FLTK_XCURSOR_FOUND TRUE) else() - set (FLTK_XCURSOR_FOUND FALSE) -endif (OPTION_USE_XCURSOR) + set(FLTK_XCURSOR_FOUND FALSE) +endif(FLTK_USE_XCURSOR) ####################################################################### -if (X11_Xft_FOUND) - option (OPTION_USE_XFT "use lib Xft" ON) - option (OPTION_USE_PANGO "use lib Pango" OFF) - if (NOT OPTION_USE_WAYLAND) - option (OPTION_USE_CAIRO "all drawing to X11 windows uses Cairo" OFF) - endif (NOT OPTION_USE_WAYLAND) -endif (X11_Xft_FOUND) +if(X11_Xft_FOUND) + option(FLTK_USE_XFT "use lib Xft" ON) + option(FLTK_USE_PANGO "use lib Pango" OFF) + if(NOT FLTK_BACKEND_WAYLAND) + option(FLTK_GRAPHICS_CAIRO "all drawing to X11 windows uses Cairo" OFF) + endif(NOT FLTK_BACKEND_WAYLAND) +endif(X11_Xft_FOUND) # test option compatibility: Cairo for Xlib requires Pango -if (OPTION_USE_CAIRO) - unset (OPTION_USE_PANGO CACHE) - set (OPTION_USE_PANGO TRUE CACHE BOOL "use lib Pango") -endif (OPTION_USE_CAIRO) - -if (OPTION_USE_PANGO OR OPTION_USE_CAIRO) - if (OPTION_USE_WAYLAND OR OPTION_APPLE_X11) - set (USE_PANGOXFT false) - else () - set (USE_PANGOXFT true) - endif (OPTION_USE_WAYLAND OR OPTION_APPLE_X11) -endif (OPTION_USE_PANGO OR OPTION_USE_CAIRO) +if(FLTK_GRAPHICS_CAIRO) + unset(FLTK_USE_PANGO CACHE) + set(FLTK_USE_PANGO TRUE CACHE BOOL "use lib Pango") +endif(FLTK_GRAPHICS_CAIRO) + +if(FLTK_USE_PANGO OR FLTK_GRAPHICS_CAIRO) + if(FLTK_BACKEND_WAYLAND OR FLTK_BACKEND_X11) + set(USE_PANGOXFT false) + else() + set(USE_PANGOXFT true) + endif() +endif() # test option compatibility: Pango requires Xft -if (USE_PANGOXFT) - if (NOT X11_Xft_FOUND) - message (STATUS "Pango requires Xft but Xft library or headers could not be found.") - message (STATUS "Please install Xft development files and try again or disable OPTION_USE_PANGO.") - message (FATAL_ERROR "*** Aborting ***") - else () - if (NOT OPTION_USE_XFT) - message (STATUS "Pango requires Xft but usage of Xft was disabled.") - message (STATUS "Please enable OPTION_USE_XFT and try again or disable OPTION_USE_PANGO.") - message (FATAL_ERROR "*** Aborting ***") - endif (NOT OPTION_USE_XFT) - endif (NOT X11_Xft_FOUND) -endif (USE_PANGOXFT) - -####################################################################### -if ((X11_Xft_FOUND OR NOT USE_PANGOXFT) AND OPTION_USE_PANGO) +if(USE_PANGOXFT) + if(NOT X11_Xft_FOUND) + message(STATUS "Pango requires Xft but Xft library or headers could not be found.") + message(STATUS "Please install Xft development files and try again or disable FLTK_USE_PANGO.") + message(FATAL_ERROR "*** Aborting ***") + else() + if(NOT FLTK_USE_XFT) + message(STATUS "Pango requires Xft but usage of Xft was disabled.") + message(STATUS "Please enable FLTK_USE_XFT and try again or disable FLTK_USE_PANGO.") + message(FATAL_ERROR "*** Aborting ***") + endif(NOT FLTK_USE_XFT) + endif(NOT X11_Xft_FOUND) +endif(USE_PANGOXFT) + +####################################################################### +if((X11_Xft_FOUND OR NOT USE_PANGOXFT) AND FLTK_USE_PANGO) pkg_check_modules(CAIRO cairo) - if (USE_PANGOXFT) + if(USE_PANGOXFT) pkg_check_modules(PANGOXFT pangoxft) - endif (USE_PANGOXFT) + endif(USE_PANGOXFT) pkg_check_modules(PANGOCAIRO pangocairo) - if ((PANGOXFT_FOUND OR NOT USE_PANGOXFT) AND PANGOCAIRO_FOUND AND CAIRO_FOUND) - if (USE_PANGOXFT) - include_directories (${PANGOXFT_INCLUDE_DIRS}) - else () - include_directories (${PANGOCAIRO_INCLUDE_DIRS}) - endif (USE_PANGOXFT) - include_directories (${CAIRO_INCLUDE_DIRS}) - - find_library (HAVE_LIB_PANGO pango-1.0 ${CMAKE_LIBRARY_PATH}) - if (USE_PANGOXFT) - find_library (HAVE_LIB_PANGOXFT pangoxft-1.0 ${CMAKE_LIBRARY_PATH}) - endif (USE_PANGOXFT) - find_library (HAVE_LIB_PANGOCAIRO pangocairo-1.0 ${CMAKE_LIBRARY_PATH}) - find_library (HAVE_LIB_CAIRO cairo ${CMAKE_LIBRARY_PATH}) - find_library (HAVE_LIB_GOBJECT gobject-2.0 ${CMAKE_LIBRARY_PATH}) - - mark_as_advanced (HAVE_LIB_PANGO) - if (USE_PANGOXFT) - mark_as_advanced (HAVE_LIB_PANGOXFT) - endif (USE_PANGOXFT) - mark_as_advanced (HAVE_LIB_PANGOCAIRO) - mark_as_advanced (HAVE_LIB_CAIRO) - mark_as_advanced (HAVE_LIB_GOBJECT) - - set (USE_PANGO TRUE) + if((PANGOXFT_FOUND OR NOT USE_PANGOXFT) AND PANGOCAIRO_FOUND AND CAIRO_FOUND) + if(USE_PANGOXFT) + list(APPEND FLTK_BUILD_INCLUDE_DIRECTORIES ${PANGOXFT_INCLUDE_DIRS}) + else() + list(APPEND FLTK_BUILD_INCLUDE_DIRECTORIES ${PANGOCAIRO_INCLUDE_DIRS}) + endif(USE_PANGOXFT) + list(APPEND FLTK_BUILD_INCLUDE_DIRECTORIES ${CAIRO_INCLUDE_DIRS}) + + find_library(HAVE_LIB_PANGO pango-1.0 ${CMAKE_LIBRARY_PATH}) + mark_as_advanced(HAVE_LIB_PANGO) + + if(USE_PANGOXFT) + find_library(HAVE_LIB_PANGOXFT pangoxft-1.0 ${CMAKE_LIBRARY_PATH}) + mark_as_advanced(HAVE_LIB_PANGOXFT) + endif(USE_PANGOXFT) + + find_library(HAVE_LIB_PANGOCAIRO pangocairo-1.0 ${CMAKE_LIBRARY_PATH}) + mark_as_advanced(HAVE_LIB_PANGOCAIRO) + + find_library(HAVE_LIB_CAIRO cairo ${CMAKE_LIBRARY_PATH}) + mark_as_advanced(HAVE_LIB_CAIRO) + + find_library(HAVE_LIB_GOBJECT gobject-2.0 ${CMAKE_LIBRARY_PATH}) + mark_as_advanced(HAVE_LIB_GOBJECT) + + set(USE_PANGO TRUE) # add required libraries to fltk-config ... - if (USE_PANGOXFT) - list (APPEND FLTK_LDLIBS ${PANGOXFT_LDFLAGS}) - endif (USE_PANGOXFT) - list (APPEND FLTK_LDLIBS ${PANGOCAIRO_LDFLAGS}) - list (APPEND FLTK_LDLIBS ${CAIRO_LDFLAGS}) + if(USE_PANGOXFT) + list(APPEND FLTK_LDLIBS ${PANGOXFT_LDFLAGS}) + endif(USE_PANGOXFT) + list(APPEND FLTK_LDLIBS ${PANGOCAIRO_LDFLAGS}) + list(APPEND FLTK_LDLIBS ${CAIRO_LDFLAGS}) # *FIXME* Libraries should not be added explicitly if possible - if (OPTION_USE_WAYLAND) - list (APPEND FLTK_LDLIBS -lgtk-3 -lgdk-3 -lgio-2.0) - if (NOT OPTION_WAYLAND_ONLY) - list (APPEND FLTK_LDLIBS -lX11) - endif (NOT OPTION_WAYLAND_ONLY) - endif (OPTION_USE_WAYLAND) - - if (APPLE) + if(FLTK_BACKEND_WAYLAND) + list(APPEND FLTK_LDLIBS -lgtk-3 -lgdk-3 -lgio-2.0) + if(FLTK_BACKEND_X11) + list(APPEND FLTK_LDLIBS -lX11) + endif() + endif() + + if(APPLE) get_filename_component(PANGO_L_PATH ${HAVE_LIB_PANGO} PATH) - set (LDFLAGS "${LDFLAGS} -L${PANGO_L_PATH}") - endif (APPLE) + set(LDFLAGS "${LDFLAGS} -L${PANGO_L_PATH}") + endif(APPLE) - else () + else() # this covers Debian, Ubuntu, FreeBSD, NetBSD, Darwin - if (APPLE AND OPTION_APPLE_X11) + if(APPLE AND FLTK_BACKEND_X11) find_file(FINK_PREFIX NAMES /opt/sw /sw) - list (APPEND CMAKE_INCLUDE_PATH ${FINK_PREFIX}/include) - include_directories (${FINK_PREFIX}/include/cairo) - list (APPEND CMAKE_LIBRARY_PATH ${FINK_PREFIX}/lib) - endif (APPLE AND OPTION_APPLE_X11) + list(APPEND CMAKE_INCLUDE_PATH ${FINK_PREFIX}/include) + list(APPEND FLTK_BUILD_INCLUDE_DIRECTORIES ${FINK_PREFIX}/include/cairo) + list(APPEND CMAKE_LIBRARY_PATH ${FINK_PREFIX}/lib) + endif(APPLE AND FLTK_BACKEND_X11) find_file(HAVE_PANGO_H pango-1.0/pango/pango.h ${CMAKE_INCLUDE_PATH}) find_file(HAVE_PANGOXFT_H pango-1.0/pango/pangoxft.h ${CMAKE_INCLUDE_PATH}) - if (HAVE_PANGO_H AND HAVE_PANGOXFT_H) + if(HAVE_PANGO_H AND HAVE_PANGOXFT_H) find_library(HAVE_LIB_PANGO pango-1.0 ${CMAKE_LIBRARY_PATH}) find_library(HAVE_LIB_PANGOXFT pangoxft-1.0 ${CMAKE_LIBRARY_PATH}) - if (APPLE) - set (HAVE_LIB_GOBJECT TRUE) + if(APPLE) + set(HAVE_LIB_GOBJECT TRUE) else() find_library(HAVE_LIB_GOBJECT gobject-2.0 ${CMAKE_LIBRARY_PATH}) - endif (APPLE) - endif (HAVE_PANGO_H AND HAVE_PANGOXFT_H) + endif(APPLE) + endif(HAVE_PANGO_H AND HAVE_PANGOXFT_H) - if (HAVE_LIB_PANGO AND HAVE_LIB_PANGOXFT AND HAVE_LIB_GOBJECT) - set (USE_PANGO TRUE) + if(HAVE_LIB_PANGO AND HAVE_LIB_PANGOXFT AND HAVE_LIB_GOBJECT) + set(USE_PANGO TRUE) # remove last 3 components of HAVE_PANGO_H and put in PANGO_H_PREFIX get_filename_component(PANGO_H_PREFIX ${HAVE_PANGO_H} PATH) get_filename_component(PANGO_H_PREFIX ${PANGO_H_PREFIX} PATH) @@ -861,122 +904,136 @@ if ((X11_Xft_FOUND OR NOT USE_PANGOXFT) AND OPTION_USE_PANGO) find_path(GLIB_H_PATH glib.h PATHS ${PANGO_H_PREFIX}/glib-2.0 ${PANGO_H_PREFIX}/glib/glib-2.0) - include_directories (${PANGO_H_PREFIX}/pango-1.0 ${GLIB_H_PATH} ${PANGOLIB_DIR}/glib-2.0/include) + list(APPEND FLTK_BUILD_INCLUDE_DIRECTORIES ${PANGO_H_PREFIX}/pango-1.0 ${GLIB_H_PATH} ${PANGOLIB_DIR}/glib-2.0/include) # *FIXME* Libraries should not be added explicitly if possible - list (APPEND FLTK_LDLIBS -lpango-1.0 -lpangoxft-1.0 -lgobject-2.0) + list(APPEND FLTK_LDLIBS -lpango-1.0 -lpangoxft-1.0 -lgobject-2.0) - endif (HAVE_LIB_PANGO AND HAVE_LIB_PANGOXFT AND HAVE_LIB_GOBJECT) - endif ((PANGOXFT_FOUND OR NOT USE_PANGOXFT) AND PANGOCAIRO_FOUND AND CAIRO_FOUND) + endif(HAVE_LIB_PANGO AND HAVE_LIB_PANGOXFT AND HAVE_LIB_GOBJECT) + endif((PANGOXFT_FOUND OR NOT USE_PANGOXFT) AND PANGOCAIRO_FOUND AND CAIRO_FOUND) - if (USE_PANGO AND (OPTION_USE_CAIRO OR OPTION_USE_WAYLAND)) - set (FLTK_USE_CAIRO 1) - # fl_debug_var (FLTK_USE_CAIRO) - endif (USE_PANGO AND (OPTION_USE_CAIRO OR OPTION_USE_WAYLAND)) + if(USE_PANGO AND (FLTK_GRAPHICS_CAIRO OR FLTK_BACKEND_WAYLAND)) + set(FLTK_USE_CAIRO 1) + # fl_debug_var(FLTK_USE_CAIRO) + endif() -endif ((X11_Xft_FOUND OR NOT USE_PANGOXFT) AND OPTION_USE_PANGO) +endif((X11_Xft_FOUND OR NOT USE_PANGOXFT) AND FLTK_USE_PANGO) -if (OPTION_USE_WAYLAND) +if(FLTK_BACKEND_WAYLAND) - # Note: Disable OPTION_ALLOW_GTK_PLUGIN to get cairo titlebars rather than GTK - if (OPTION_ALLOW_GTK_PLUGIN) + # Note: Disable FLTK_USE_LIBDECOR_GTK to get cairo titlebars rather than GTK + if(FLTK_USE_LIBDECOR_GTK) pkg_check_modules(GTK gtk+-3.0) - if (GTK_FOUND) - include_directories (${GTK_INCLUDE_DIRS}) - else () + if(GTK_FOUND) + list(APPEND FLTK_BUILD_INCLUDE_DIRECTORIES ${GTK_INCLUDE_DIRS}) + else() message(WARNING "Installation of the development files for the GTK library " "(e.g., libgtk-3-dev) is recommended when using the gnome desktop.") - endif (GTK_FOUND) - endif (OPTION_ALLOW_GTK_PLUGIN) + endif(GTK_FOUND) + endif(FLTK_USE_LIBDECOR_GTK) -endif (OPTION_USE_WAYLAND) +endif() -if (OPTION_USE_XFT) - set (USE_XFT X11_Xft_FOUND) - list (APPEND FLTK_LDLIBS -lXft) - set (FLTK_XFT_FOUND TRUE) - if (APPLE AND OPTION_APPLE_X11) +if(FLTK_USE_XFT) + set(USE_XFT X11_Xft_FOUND) + list(APPEND FLTK_LDLIBS -lXft) + set(FLTK_XFT_FOUND TRUE) + if(APPLE AND FLTK_BACKEND_X11) find_library(LIB_fontconfig fontconfig "/opt/X11/lib") - endif (APPLE AND OPTION_APPLE_X11) + endif() else() - set (FLTK_XFT_FOUND FALSE) -endif (OPTION_USE_XFT) + set(FLTK_XFT_FOUND FALSE) +endif(FLTK_USE_XFT) ####################################################################### -if (X11_Xrender_FOUND) - option (OPTION_USE_XRENDER "use lib Xrender" ON) -endif (X11_Xrender_FOUND) - -if (OPTION_USE_XRENDER) - set (HAVE_XRENDER ${X11_Xrender_FOUND}) - if (HAVE_XRENDER) - include_directories (${X11_Xrender_INCLUDE_PATH}) - list (APPEND FLTK_LDLIBS -lXrender) - set (FLTK_XRENDER_FOUND TRUE) +if(X11_Xrender_FOUND) + option(FLTK_USE_XRENDER "use lib Xrender" ON) +endif(X11_Xrender_FOUND) + +if(FLTK_USE_XRENDER) + set(HAVE_XRENDER ${X11_Xrender_FOUND}) + if(HAVE_XRENDER) + list(APPEND FLTK_BUILD_INCLUDE_DIRECTORIES ${X11_Xrender_INCLUDE_PATH}) + list(APPEND FLTK_LDLIBS -lXrender) + set(FLTK_XRENDER_FOUND TRUE) else(HAVE_XRENDER) - set (FLTK_XRENDER_FOUND FALSE) - endif (HAVE_XRENDER) -else(OPTION_USE_XRENDER) - set (FLTK_XRENDER_FOUND FALSE) -endif (OPTION_USE_XRENDER) + set(FLTK_XRENDER_FOUND FALSE) + endif(HAVE_XRENDER) +else(FLTK_USE_XRENDER) + set(FLTK_XRENDER_FOUND FALSE) +endif(FLTK_USE_XRENDER) ####################################################################### -set (FL_NO_PRINT_SUPPORT FALSE) -if (X11_FOUND AND NOT OPTION_PRINT_SUPPORT) - set (FL_NO_PRINT_SUPPORT TRUE) -endif (X11_FOUND AND NOT OPTION_PRINT_SUPPORT) +set(FL_NO_PRINT_SUPPORT FALSE) +if(X11_FOUND AND NOT FLTK_OPTION_PRINT_SUPPORT) + set(FL_NO_PRINT_SUPPORT TRUE) +endif(X11_FOUND AND NOT FLTK_OPTION_PRINT_SUPPORT) ####################################################################### ####################################################################### -set (FL_CFG_NO_FILESYSTEM_SUPPORT TRUE) -if (OPTION_FILESYSTEM_SUPPORT) - set (FL_CFG_NO_FILESYSTEM_SUPPORT FALSE) -endif (OPTION_FILESYSTEM_SUPPORT) +set(FL_CFG_NO_FILESYSTEM_SUPPORT TRUE) +if(FLTK_OPTION_FILESYSTEM_SUPPORT) + set(FL_CFG_NO_FILESYSTEM_SUPPORT FALSE) +endif(FLTK_OPTION_FILESYSTEM_SUPPORT) ####################################################################### ####################################################################### -option (OPTION_USE_KDIALOG "Fl_Native_File_Chooser may run kdialog" ON) -if (OPTION_USE_KDIALOG) - set (USE_KDIALOG 1) -else () - set (USE_KDIALOG 0) -endif (OPTION_USE_KDIALOG) +option(FLTK_USE_KDIALOG "Fl_Native_File_Chooser may run kdialog" ON) +if(FLTK_USE_KDIALOG) + set(USE_KDIALOG 1) +else() + set(USE_KDIALOG 0) +endif() ####################################################################### ####################################################################### -option (CMAKE_SUPPRESS_REGENERATION "suppress rules to re-run CMake on rebuild" OFF) -mark_as_advanced (CMAKE_SUPPRESS_REGENERATION) +option(CMAKE_SUPPRESS_REGENERATION "suppress rules to re-run CMake on rebuild" OFF) +mark_as_advanced(CMAKE_SUPPRESS_REGENERATION) + +####################################################################### +# Clean up ... + +# *** FIXME *** Do we need all these variables ? + +list(REMOVE_DUPLICATES FLTK_BUILD_INCLUDE_DIRECTORIES) +list(REMOVE_DUPLICATES FLTK_IMAGE_INCLUDE_DIRECTORIES) +list(REMOVE_DUPLICATES FLTK_IMAGE_LIBRARIES) ####################################################################### # Debugging ... -if (DEBUG_OPTIONS_CMAKE) - message (STATUS "") # empty line - fl_debug_var (WIN32) - fl_debug_var (LIBS) - fl_debug_var (GLLIBS) - fl_debug_var (FLTK_LDLIBS) - fl_debug_var (OPENGL_FOUND) - fl_debug_var (OPENGL_INCLUDE_DIR) - fl_debug_var (OPENGL_LIBRARIES) - fl_debug_var (CMAKE_MSVC_RUNTIME_LIBRARY) - message ("--- bundled libraries ---") - fl_debug_var (OPTION_USE_SYSTEM_LIBJPEG) - fl_debug_var (OPTION_USE_SYSTEM_LIBPNG) - fl_debug_var (OPTION_USE_SYSTEM_ZLIB) - fl_debug_var (FLTK_USE_BUILTIN_JPEG) - fl_debug_var (FLTK_USE_BUILTIN_PNG) - fl_debug_var (FLTK_USE_BUILTIN_ZLIB) - message ("--- X11 ---") - fl_debug_var (X11_FOUND) - fl_debug_var (X11_INCLUDE_DIR) - fl_debug_var (X11_LIBRARIES) - fl_debug_var (X11_X11_LIB) - fl_debug_var (X11_X11_INCLUDE_PATH) - fl_debug_var (X11_Xft_INCLUDE_PATH) - fl_debug_var (X11_Xft_LIB) - fl_debug_var (X11_Xft_FOUND) - fl_debug_var (PATH_TO_XLIBS) - message (STATUS "[** end of options.cmake **]") -endif (DEBUG_OPTIONS_CMAKE) -unset (DEBUG_OPTIONS_CMAKE) +if(DEBUG_OPTIONS_CMAKE) + message(STATUS "") # empty line + fl_debug_var(WIN32) + fl_debug_var(LIBS) + fl_debug_var(GLLIBS) + fl_debug_var(FLTK_LDLIBS) + fl_debug_var(OPENGL_FOUND) + fl_debug_var(OPENGL_INCLUDE_DIR) + fl_debug_var(OPENGL_LIBRARIES) + fl_debug_var(CMAKE_MSVC_RUNTIME_LIBRARY) + message("--- bundled libraries ---") + fl_debug_var(FLTK_USE_SYSTEM_LIBJPEG) + fl_debug_var(FLTK_USE_SYSTEM_LIBPNG) + fl_debug_var(FLTK_USE_SYSTEM_ZLIB) + fl_debug_var(FLTK_USE_BUNDLED_JPEG) + fl_debug_var(FLTK_USE_BUNDLED_PNG) + fl_debug_var(FLTK_USE_BUNDLED_ZLIB) + + message(STATUS "--- *FIXME* include directories ---") + fl_debug_var(FLTK_BUILD_INCLUDE_DIRECTORIES) + fl_debug_var(FLTK_IMAGE_INCLUDE_DIRECTORIES) + + message("--- X11 ---") + fl_debug_var(X11_FOUND) + fl_debug_var(X11_INCLUDE_DIR) + fl_debug_var(X11_LIBRARIES) + fl_debug_var(X11_X11_LIB) + fl_debug_var(X11_X11_INCLUDE_PATH) + fl_debug_var(X11_Xft_INCLUDE_PATH) + fl_debug_var(X11_Xft_LIB) + fl_debug_var(X11_Xft_FOUND) + fl_debug_var(PATH_TO_XLIBS) + message(STATUS "[** end of options.cmake **]") +endif(DEBUG_OPTIONS_CMAKE) +unset(DEBUG_OPTIONS_CMAKE) diff --git a/CMake/resources.cmake b/CMake/resources.cmake index aa17f73b3..7ee2c665d 100644 --- a/CMake/resources.cmake +++ b/CMake/resources.cmake @@ -1,8 +1,8 @@ # # Resource definitions to build the FLTK project using CMake (www.cmake.org) -# Written by Michael Surette +# Originally written by Michael Surette # -# Copyright 1998-2021 by Bill Spitzak and others. +# Copyright 1998-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 @@ -24,34 +24,37 @@ # and the result of the search is logged with fl_debug_var(). # This is useful for debugging. -set (CMAKE_REQUIRED_QUIET 1) +set(CMAKE_REQUIRED_QUIET 1) -include (CheckIncludeFiles) +include(CheckIncludeFiles) macro (fl_find_header VAR HEADER) - check_include_files ("${HEADER}" ${VAR}) - if (NOT CMAKE_REQUIRED_QUIET) - fl_debug_var (${VAR}) - endif (NOT CMAKE_REQUIRED_QUIET) + check_include_files("${HEADER}" ${VAR}) + if(NOT CMAKE_REQUIRED_QUIET) + fl_debug_var(${VAR}) + endif(NOT CMAKE_REQUIRED_QUIET) endmacro (fl_find_header) ####################################################################### # Include FindPkgConfig for later use of pkg-config ####################################################################### -include (FindPkgConfig) +include(FindPkgConfig) -# fl_debug_var (PKG_CONFIG_FOUND) -# fl_debug_var (PKG_CONFIG_EXECUTABLE) -# fl_debug_var (PKG_CONFIG_VERSION_STRING) +# fl_debug_var(PKG_CONFIG_FOUND) +# fl_debug_var(PKG_CONFIG_EXECUTABLE) +# fl_debug_var(PKG_CONFIG_VERSION_STRING) ####################################################################### # Find header files... ####################################################################### -if (${CMAKE_HOST_SYSTEM_NAME} STREQUAL "FreeBSD") - list (APPEND CMAKE_REQUIRED_INCLUDES /usr/local/include) -endif (${CMAKE_HOST_SYSTEM_NAME} STREQUAL "FreeBSD") +if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "FreeBSD") + list(APPEND CMAKE_REQUIRED_INCLUDES /usr/local/include) +endif(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "FreeBSD") + +# fl_debug_var(CMAKE_HOST_SYSTEM_NAME) +# fl_debug_var(CMAKE_REQUIRED_INCLUDES) fl_find_header (HAVE_ALSA_ASOUNDLIB_H alsa/asoundlib.h) fl_find_header (HAVE_DLFCN_H dlfcn.h) @@ -65,23 +68,23 @@ fl_find_header (HAVE_SYS_STDTYPES_H sys/stdtypes.h) fl_find_header (HAVE_X11_XREGION_H "X11/Xlib.h;X11/Xregion.h") -if (WIN32 AND NOT CYGWIN) +if(WIN32 AND NOT CYGWIN) # we don't use pthreads on Windows (except for Cygwin, see options.cmake) - set (HAVE_PTHREAD_H 0) -else () + set(HAVE_PTHREAD_H 0) +else() fl_find_header (HAVE_PTHREAD_H pthread.h) -endif (WIN32 AND NOT CYGWIN) +endif(WIN32 AND NOT CYGWIN) # Do we have PTHREAD_MUTEX_RECURSIVE ? -if (HAVE_PTHREAD_H) +if(HAVE_PTHREAD_H) try_compile(HAVE_PTHREAD_MUTEX_RECURSIVE ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/CMake/pthread_mutex_recursive.c ) -else () - set (HAVE_PTHREAD_MUTEX_RECURSIVE 0) -endif () +else() + set(HAVE_PTHREAD_MUTEX_RECURSIVE 0) +endif() # Special case for Microsoft Visual Studio generator (MSVC): # @@ -94,19 +97,19 @@ endif () # # Note: these cache variables can only be seen in "advanced" mode. -if (MSVC) +if(MSVC) - if (NOT HAVE_GL_GLU_H) - message (STATUS "Info: Header file GL/glu.h was not found. Continuing...") - set (HAVE_GL_GLU_H 1) - endif (NOT HAVE_GL_GLU_H) + if(NOT HAVE_GL_GLU_H) + message(STATUS "Info: Header file GL/glu.h was not found. Continuing...") + set(HAVE_GL_GLU_H 1) + endif(NOT HAVE_GL_GLU_H) - if (NOT HAVE_LOCALE_H) - message (STATUS "Info: Header file locale.h was not found. Continuing...") - set (HAVE_LOCALE_H 1) - endif (NOT HAVE_LOCALE_H) + if(NOT HAVE_LOCALE_H) + message(STATUS "Info: Header file locale.h was not found. Continuing...") + set(HAVE_LOCALE_H 1) + endif(NOT HAVE_LOCALE_H) -endif (MSVC) +endif(MSVC) # Simulate the behavior of autoconf macro AC_HEADER_DIRENT, see: # https://www.gnu.org/software/autoconf/manual/autoconf-2.69/html_node/Particular-Headers.html @@ -118,15 +121,15 @@ endif (MSVC) fl_find_header (HAVE_DIRENT_H dirent.h) -if (NOT HAVE_DIRENT_H) +if(NOT HAVE_DIRENT_H) fl_find_header (HAVE_SYS_NDIR_H sys/ndir.h) - if (NOT HAVE_SYS_NDIR_H) + if(NOT HAVE_SYS_NDIR_H) fl_find_header (HAVE_SYS_DIR_H sys/dir.h) - if (NOT HAVE_SYS_DIR_H) + if(NOT HAVE_SYS_DIR_H) fl_find_header (HAVE_NDIR_H ndir.h) - endif (NOT HAVE_SYS_DIR_H) - endif (NOT HAVE_SYS_NDIR_H) -endif (NOT HAVE_DIRENT_H) + endif(NOT HAVE_SYS_DIR_H) + endif(NOT HAVE_SYS_NDIR_H) +endif(NOT HAVE_DIRENT_H) mark_as_advanced (HAVE_ALSA_ASOUNDLIB_H HAVE_DIRENT_H HAVE_DLFCN_H) mark_as_advanced (HAVE_GL_GLU_H) @@ -147,18 +150,18 @@ mark_as_advanced (HAVE_X11_XREGION_H) find_path (FREETYPE_PATH freetype.h PATH_SUFFIXES freetype2) find_path (FREETYPE_PATH freetype/freetype.h PATH_SUFFIXES freetype2) -if (FREETYPE_PATH) - include_directories (${FREETYPE_PATH}) -endif (FREETYPE_PATH) +if(FREETYPE_PATH) + list(APPEND FLTK_BUILD_INCLUDE_DIRECTORIES ${FREETYPE_PATH}) +endif(FREETYPE_PATH) mark_as_advanced (FREETYPE_PATH) ####################################################################### # libraries find_library (LIB_dl dl) -if ((NOT APPLE) OR OPTION_APPLE_X11) +if((NOT APPLE) OR FLTK_BACKEND_X11) find_library (LIB_fontconfig fontconfig) -endif ((NOT APPLE) OR OPTION_APPLE_X11) +endif((NOT APPLE) OR FLTK_BACKEND_X11) find_library (LIB_freetype freetype) find_library (LIB_GL GL) find_library (LIB_MesaGL MesaGL) @@ -173,40 +176,40 @@ mark_as_advanced (LIB_jpeg LIB_png LIB_zlib) ####################################################################### # functions -include (CheckFunctionExists) +include(CheckFunctionExists) # save CMAKE_REQUIRED_LIBRARIES (is this really necessary ?) -if (DEFINED CMAKE_REQUIRED_LIBRARIES) - set (SAVED_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}) -else (DEFINED CMAKE_REQUIRED_LIBRARIES) - unset (SAVED_REQUIRED_LIBRARIES) -endif (DEFINED CMAKE_REQUIRED_LIBRARIES) -set (CMAKE_REQUIRED_LIBRARIES) - -if (HAVE_DLFCN_H) - set (HAVE_DLFCN_H 1) -endif (HAVE_DLFCN_H) - -set (CMAKE_REQUIRED_LIBRARIES ${CMAKE_DL_LIBS}) +if(DEFINED CMAKE_REQUIRED_LIBRARIES) + set(SAVED_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}) +else(DEFINED CMAKE_REQUIRED_LIBRARIES) + unset(SAVED_REQUIRED_LIBRARIES) +endif(DEFINED CMAKE_REQUIRED_LIBRARIES) +set(CMAKE_REQUIRED_LIBRARIES) + +if(HAVE_DLFCN_H) + set(HAVE_DLFCN_H 1) +endif(HAVE_DLFCN_H) + +set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_DL_LIBS}) CHECK_FUNCTION_EXISTS (dlsym HAVE_DLSYM) -set (CMAKE_REQUIRED_LIBRARIES) +set(CMAKE_REQUIRED_LIBRARIES) CHECK_FUNCTION_EXISTS (localeconv HAVE_LOCALECONV) -if (LIB_png) - set (CMAKE_REQUIRED_LIBRARIES ${LIB_png}) +if(LIB_png) + set(CMAKE_REQUIRED_LIBRARIES ${LIB_png}) CHECK_FUNCTION_EXISTS (png_get_valid HAVE_PNG_GET_VALID) CHECK_FUNCTION_EXISTS (png_set_tRNS_to_alpha HAVE_PNG_SET_TRNS_TO_ALPHA) - set (CMAKE_REQUIRED_LIBRARIES) -endif (LIB_png) + set(CMAKE_REQUIRED_LIBRARIES) +endif(LIB_png) CHECK_FUNCTION_EXISTS (scandir HAVE_SCANDIR) CHECK_FUNCTION_EXISTS (snprintf HAVE_SNPRINTF) # not really true but we convert strcasecmp calls to _stricmp calls in flstring.h -if (MSVC) - set (HAVE_STRCASECMP 1) -endif (MSVC) +if(MSVC) + set(HAVE_STRCASECMP 1) +endif(MSVC) CHECK_FUNCTION_EXISTS (strcasecmp HAVE_STRCASECMP) @@ -214,30 +217,30 @@ CHECK_FUNCTION_EXISTS (strlcat HAVE_STRLCAT) CHECK_FUNCTION_EXISTS (strlcpy HAVE_STRLCPY) CHECK_FUNCTION_EXISTS (vsnprintf HAVE_VSNPRINTF) -if (HAVE_SCANDIR AND NOT HAVE_SCANDIR_POSIX) - set (MSG "POSIX compatible scandir") - message (STATUS "Looking for ${MSG}") +if(HAVE_SCANDIR AND NOT HAVE_SCANDIR_POSIX) + set(MSG "POSIX compatible scandir") + message(STATUS "Looking for ${MSG}") try_compile(V ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/CMake/posixScandir.cxx ) - if (V) - message (STATUS "${MSG} - found") - set (HAVE_SCANDIR_POSIX 1 CACHE INTERNAL "") + if(V) + message(STATUS "${MSG} - found") + set(HAVE_SCANDIR_POSIX 1 CACHE INTERNAL "") else() - message (STATUS "${MSG} - not found") - set (HAVE_SCANDIR_POSIX HAVE_SCANDIR_POSIX-NOTFOUND) - endif (V) -endif (HAVE_SCANDIR AND NOT HAVE_SCANDIR_POSIX) + message(STATUS "${MSG} - not found") + set(HAVE_SCANDIR_POSIX HAVE_SCANDIR_POSIX-NOTFOUND) + endif(V) +endif(HAVE_SCANDIR AND NOT HAVE_SCANDIR_POSIX) mark_as_advanced (HAVE_SCANDIR_POSIX) # restore CMAKE_REQUIRED_LIBRARIES (is this really necessary ?) -if (DEFINED SAVED_REQUIRED_LIBRARIES) - set (CMAKE_REQUIRED_LIBRARIES ${SAVED_REQUIRED_LIBRARIES}) - unset (SAVED_REQUIRED_LIBRARIES) +if(DEFINED SAVED_REQUIRED_LIBRARIES) + set(CMAKE_REQUIRED_LIBRARIES ${SAVED_REQUIRED_LIBRARIES}) + unset(SAVED_REQUIRED_LIBRARIES) else(DEFINED SAVED_REQUIRED_LIBRARIES) - unset (CMAKE_REQUIRED_LIBRARIES) -endif (DEFINED SAVED_REQUIRED_LIBRARIES) + unset(CMAKE_REQUIRED_LIBRARIES) +endif(DEFINED SAVED_REQUIRED_LIBRARIES) ####################################################################### # packages @@ -250,18 +253,18 @@ find_package (Doxygen) # Note: we only check existence of `latex' (LATEX_COMPILER), hence # building the pdf docs may still fail because of other missing tools. -set (LATEX_FOUND) -if (DOXYGEN_FOUND) +set(LATEX_FOUND) +if(DOXYGEN_FOUND) find_package (LATEX) - if (LATEX_COMPILER AND NOT LATEX_FOUND) - set (LATEX_FOUND YES) - endif (LATEX_COMPILER AND NOT LATEX_FOUND) -endif (DOXYGEN_FOUND) + if(LATEX_COMPILER AND NOT LATEX_FOUND) + set(LATEX_FOUND YES) + endif(LATEX_COMPILER AND NOT LATEX_FOUND) +endif(DOXYGEN_FOUND) -# message ("Doxygen found : ${DOXYGEN_FOUND}") -# message ("LaTex found : ${LATEX_FOUND}") -# message ("LaTex Compiler : ${LATEX_COMPILER}") +# message("Doxygen found : ${DOXYGEN_FOUND}") +# message("LaTex found : ${LATEX_FOUND}") +# message("LaTex Compiler : ${LATEX_COMPILER}") # Cleanup: unset local variables -unset (CMAKE_REQUIRED_QUIET) +unset(CMAKE_REQUIRED_QUIET) diff --git a/CMake/setup.cmake b/CMake/setup.cmake index 7dd91ebd4..b663813be 100644 --- a/CMake/setup.cmake +++ b/CMake/setup.cmake @@ -2,7 +2,7 @@ # CMakeLists.txt to build the FLTK project using CMake (www.cmake.org) # Originally written by Michael Surette # -# Copyright 1998-2023 by Bill Spitzak and others. +# Copyright 1998-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 @@ -19,107 +19,132 @@ # basic setup ####################################################################### -set (EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/bin) -set (LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/lib) -set (ARCHIVE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/lib) +set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/bin) +set(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/lib) +set(ARCHIVE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/lib) # Search for modules in the FLTK source dir first -set (CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake") - -set (FLTK_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) -include_directories (${FLTK_INCLUDE_DIRS}) - -# Remember root of FLTK source directory in case we're in a subdirectory. -# Used for instance to find the source directory for doxygen docs -set (FLTK_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) +set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake") # Setup install locations (requires CMake 2.8.4) include(GNUInstallDirs) -set (FLTK_BINDIR ${CMAKE_INSTALL_BINDIR} CACHE PATH +set(FLTK_BINDIR ${CMAKE_INSTALL_BINDIR} CACHE PATH "Binary install path relative to CMAKE_INSTALL_PREFIX unless set to an absolute path.") -set (FLTK_LIBDIR ${CMAKE_INSTALL_LIBDIR} CACHE PATH +set(FLTK_LIBDIR ${CMAKE_INSTALL_LIBDIR} CACHE PATH "Library install path relative to CMAKE_INSTALL_PREFIX unless set to an absolute path.") -set (FLTK_INCLUDEDIR ${CMAKE_INSTALL_INCLUDEDIR} CACHE PATH +set(FLTK_INCLUDEDIR ${CMAKE_INSTALL_INCLUDEDIR} CACHE PATH "Public header install path relative to CMAKE_INSTALL_PREFIX unless set to an absolute path.") -set (FLTK_DATADIR ${CMAKE_INSTALL_DATADIR} CACHE PATH +set(FLTK_DATADIR ${CMAKE_INSTALL_DATADIR} CACHE PATH "Non-arch data install path relative to CMAKE_INSTALL_PREFIX unless set to an absolute path.") -set (FLTK_MANDIR ${CMAKE_INSTALL_MANDIR} CACHE PATH +set(FLTK_MANDIR ${CMAKE_INSTALL_MANDIR} CACHE PATH "Manual install path relative to CMAKE_INSTALL_PREFIX unless set to an absolute path.") -set (FLTK_DOCDIR ${CMAKE_INSTALL_DATADIR}/doc CACHE PATH +set(FLTK_DOCDIR ${CMAKE_INSTALL_DATADIR}/doc CACHE PATH "Non-arch doc install path relative to CMAKE_INSTALL_PREFIX unless set to an absolute path.") ####################################################################### -# initialize internally used variables -# some of these variables are used to *append* other values later +# Initialize variables needed to collect include directories etc.. +# Some of these variables are used to *append* other values later ####################################################################### -set (FLTK_LDLIBS "") -set (FLTK_LIBRARIES "") -set (GLLIBS "") -set (IMAGELIBS "") -set (LDFLAGS "") -set (LIBS "") -set (LINK_LIBS "") -set (STATICIMAGELIBS "") +set(FLTK_BUILD_INCLUDE_DIRECTORIES "") +set(FLTK_IMAGE_INCLUDE_DIRECTORIES "") +set(FLTK_IMAGE_LIBRARIES "") +set(FLTK_IMAGE_LIBRARIES_SHARED "") + +set(FLTK_CFLAGS "") +set(FLTK_LIBRARIES "") +set(FLTK_LIBRARIES_SHARED "") + +# Remember root of FLTK source directory in case we're later in a subdirectory. +# Used for instance to find the source directory for doxygen docs + +set(FLTK_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) + +if(FLTK_SOURCE_DIR STREQUAL ${CMAKE_SOURCE_DIR}) + set(FLTK_IS_TOPLEVEL TRUE) +else() + set(FLTK_IS_TOPLEVEL FALSE) +endif() + +# Note: FLTK_INCLUDE_DIRS is used to export the required include directories +# in FLTKConfig.cmake etc. +# ### FIXME ### check if we really need this ... + +set(FLTK_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) + +# FLTK_BUILD_INCLUDE_DIRECTORIES is used to build the main FLTK lib + +set(FLTK_BUILD_INCLUDE_DIRECTORIES) + +# Some of these variables are used to *append* other values later + +set(FLTK_LDLIBS "") +set(FLTK_LIBRARIES "") +set(GLLIBS "") +set(IMAGELIBS "") +set(LDFLAGS "") +set(LIBS "") +set(LINK_LIBS "") +set(STATICIMAGELIBS "") ####################################################################### # platform dependent information ####################################################################### # set where config files go -if (WIN32 AND NOT CYGWIN) - set (FLTK_CONFIG_PATH CMake) -elseif (APPLE AND NOT OPTION_APPLE_X11) - set (FLTK_CONFIG_PATH FLTK.framework/Resources/CMake) -else () - set (FLTK_CONFIG_PATH ${FLTK_DATADIR}/fltk) -endif (WIN32 AND NOT CYGWIN) +if(WIN32 AND NOT CYGWIN) + set(FLTK_CONFIG_PATH CMake) +elseif(APPLE AND NOT FLTK_BACKEND_X11) + set(FLTK_CONFIG_PATH FLTK.framework/Resources/CMake) +else() + set(FLTK_CONFIG_PATH ${FLTK_DATADIR}/fltk) +endif(WIN32 AND NOT CYGWIN) include(TestBigEndian) TEST_BIG_ENDIAN(WORDS_BIGENDIAN) -if (CMAKE_GENERATOR MATCHES "Xcode") +if(CMAKE_GENERATOR MATCHES "Xcode") # Tell Xcode to regenerate scheme information automatically whenever the # CMake configuration changes without asking the user - set (CMAKE_XCODE_GENERATE_SCHEME 1) + set(CMAKE_XCODE_GENERATE_SCHEME 1) endif() -if (APPLE) - set (HAVE_STRCASECMP 1) - set (HAVE_DIRENT_H 1) - set (HAVE_SNPRINTF 1) - set (HAVE_VSNPRINTF 1) - set (HAVE_SCANDIR 1) - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated") - if (OPTION_APPLE_X11) - if (NOT(${CMAKE_SYSTEM_VERSION} VERSION_LESS 17.0.0)) # a.k.a. macOS version ≥ 10.13 - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_LIBCPP_HAS_THREAD_API_PTHREAD") - endif (NOT(${CMAKE_SYSTEM_VERSION} VERSION_LESS 17.0.0)) - else () - set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -framework Cocoa") - set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -framework Cocoa") - endif (OPTION_APPLE_X11) -endif (APPLE) - -if (WIN32) +if(APPLE) + set(HAVE_STRCASECMP 1) + set(HAVE_DIRENT_H 1) + set(HAVE_SNPRINTF 1) + set(HAVE_VSNPRINTF 1) + set(HAVE_SCANDIR 1) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated") + if(FLTK_BACKEND_X11) + if(NOT(${CMAKE_SYSTEM_VERSION} VERSION_LESS 17.0.0)) # a.k.a. macOS version ≥ 10.13 + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_LIBCPP_HAS_THREAD_API_PTHREAD") + endif(NOT(${CMAKE_SYSTEM_VERSION} VERSION_LESS 17.0.0)) + else() + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -framework Cocoa") + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -framework Cocoa") + endif(FLTK_BACKEND_X11) +endif(APPLE) + +if(WIN32) # we do no longer define WIN32 or _WIN32 (since FLTK 1.4.0) # ... but if we did, we'd define _WIN32 (since FLTK 1.4.0) # add_definitions (-D_WIN32) - if (MSVC) + if(MSVC) add_definitions (-DWIN32_LEAN_AND_MEAN) add_definitions (-D_CRT_SECURE_NO_WARNINGS) - if (NOT MSVC_VERSION VERSION_LESS 1900) # Visual Studio 2015 - add_compile_options (/utf-8) # equivalent to `/source-charset:utf-8 /execution-charset:utf-8` - endif () - set (BORDER_WIDTH 2) - endif (MSVC) - if (MINGW AND EXISTS /mingw) + if(NOT MSVC_VERSION VERSION_LESS 1900) # Visual Studio 2015 + add_compile_options (/utf-8) # equivalent to `/source-charset:utf-8 /execution-charset:utf-8` + endif() + set(BORDER_WIDTH 2) + endif(MSVC) + if(MINGW AND EXISTS /mingw) list(APPEND CMAKE_PREFIX_PATH /mingw) - endif (MINGW AND EXISTS /mingw) -endif (WIN32) + endif(MINGW AND EXISTS /mingw) +endif(WIN32) ####################################################################### # size of ints @@ -130,22 +155,22 @@ CHECK_TYPE_SIZE(int SIZEOF_INT) CHECK_TYPE_SIZE(long SIZEOF_LONG) CHECK_TYPE_SIZE("long long" HAVE_LONG_LONG) -if (${SIZEOF_SHORT} MATCHES "^2$") - set (U16 "unsigned short") -endif (${SIZEOF_SHORT} MATCHES "^2$") - -if (${SIZEOF_INT} MATCHES "^4$") - set (U32 "unsigned") -else () - if (${SIZEOF_LONG} MATCHES "^4$") - set (U32 "unsigned long") - endif (${SIZEOF_LONG} MATCHES "^4$") -endif (${SIZEOF_INT} MATCHES "^4$") - -if (${SIZEOF_INT} MATCHES "^8$") - set (U64 "unsigned") -else () - if (${SIZEOF_LONG} MATCHES "^8$") - set (U64 "unsigned long") - endif (${SIZEOF_LONG} MATCHES "^8$") -endif (${SIZEOF_INT} MATCHES "^8$") +if(${SIZEOF_SHORT} MATCHES "^2$") + set(U16 "unsigned short") +endif(${SIZEOF_SHORT} MATCHES "^2$") + +if(${SIZEOF_INT} MATCHES "^4$") + set(U32 "unsigned") +else() + if(${SIZEOF_LONG} MATCHES "^4$") + set(U32 "unsigned long") + endif(${SIZEOF_LONG} MATCHES "^4$") +endif(${SIZEOF_INT} MATCHES "^4$") + +if(${SIZEOF_INT} MATCHES "^8$") + set(U64 "unsigned") +else() + if(${SIZEOF_LONG} MATCHES "^8$") + set(U64 "unsigned long") + endif(${SIZEOF_LONG} MATCHES "^8$") +endif(${SIZEOF_INT} MATCHES "^8$") diff --git a/CMake/variables.cmake b/CMake/variables.cmake index 25bbefaeb..3d37aecad 100644 --- a/CMake/variables.cmake +++ b/CMake/variables.cmake @@ -1,8 +1,8 @@ # # This file sets variables for common use in export.cmake and install.cmake -# Written by Michael Surette +# Originally written by Michael Surette # -# Copyright 1998-2020 by Bill Spitzak and others. +# Copyright 1998-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 @@ -17,51 +17,52 @@ ####################################################################### -set (DEBUG_VARIABLES_CMAKE 0) -if (DEBUG_VARIABLES_CMAKE) - message (STATUS "[** variables.cmake **]") - fl_debug_var (HAVE_DLSYM) - fl_debug_var (CMAKE_DL_LIBS) - fl_debug_var (CMAKE_EXE_LINKER_FLAGS) - fl_debug_var (LDFLAGS) - fl_debug_var (LIBS) - fl_debug_var (GLLIBS) - fl_debug_var (IMAGELIBS) - fl_debug_var (STATICIMAGELIBS) - fl_debug_var (FLTK_LDLIBS) - fl_debug_var (LIB_jpeg) - fl_debug_var (LIB_png) - fl_debug_var (LIB_zlib) -endif (DEBUG_VARIABLES_CMAKE) +set(DEBUG_VARIABLES_CMAKE 0) +if(DEBUG_VARIABLES_CMAKE) + message(STATUS "[** variables.cmake **]") + fl_debug_var(HAVE_DLSYM) + fl_debug_var(CMAKE_DL_LIBS) + fl_debug_var(CMAKE_EXE_LINKER_FLAGS) + fl_debug_var(LDFLAGS) + fl_debug_var(LIBS) + fl_debug_var(GLLIBS) + fl_debug_var(IMAGELIBS) + fl_debug_var(STATICIMAGELIBS) + fl_debug_var(FLTK_LDLIBS) + fl_debug_var(LIB_jpeg) + fl_debug_var(LIB_png) + fl_debug_var(LIB_zlib) + fl_debug_var(FLTK_LIBRARIES) +endif(DEBUG_VARIABLES_CMAKE) ####################################################################### # add several libraries # FIXME: libraries may need reordering. # FIXME: check fontconfig conditions (only if Xft is used or ...) -if (WIN32) - list (APPEND FLTK_LDLIBS -lole32 -luuid -lcomctl32 -lws2_32) -elseif (APPLE AND NOT OPTION_APPLE_X11) - list (APPEND FLTK_LDLIBS "-framework Cocoa") -elseif (OPTION_USE_WAYLAND) - list (APPEND FLTK_LDLIBS "-lwayland-cursor -lwayland-client -lxkbcommon -ldbus-1") - if (OPTION_USE_SYSTEM_LIBDECOR) - list (APPEND FLTK_LDLIBS "-ldecor-0") - endif (OPTION_USE_SYSTEM_LIBDECOR) -else () - list (APPEND FLTK_LDLIBS -lm) -endif (WIN32) - -if (LIB_fontconfig) +if(WIN32) + list(APPEND FLTK_LDLIBS -lole32 -luuid -lcomctl32 -lws2_32) +elseif(APPLE AND NOT FLTK_BACKEND_X11) + list(APPEND FLTK_LDLIBS "-framework Cocoa") +elseif(FLTK_BACKEND_WAYLAND) + list(APPEND FLTK_LDLIBS "-lwayland-cursor -lwayland-client -lxkbcommon -ldbus-1") + if(USE_SYSTEM_LIBDECOR) + list(APPEND FLTK_LDLIBS "-ldecor-0") + endif(USE_SYSTEM_LIBDECOR) +else() + list(APPEND FLTK_LDLIBS -lm) +endif(WIN32) + +if(LIB_fontconfig) list(APPEND FLTK_LDLIBS -lfontconfig) -endif (LIB_fontconfig) +endif(LIB_fontconfig) # add "-ldl" or whatever is necessary according to CMake (CMAKE_DL_LIBS) -if (HAVE_DLSYM) - foreach (LIB ${CMAKE_DL_LIBS}) - list (APPEND FLTK_LDLIBS "-l${LIB}") - endforeach () -endif (HAVE_DLSYM) +if(HAVE_DLSYM) + foreach(LIB ${CMAKE_DL_LIBS}) + list(APPEND FLTK_LDLIBS "-l${LIB}") + endforeach() +endif(HAVE_DLSYM) ####################################################################### # Set variables for fltk-config (generated from fltk-config.in) @@ -75,90 +76,93 @@ endif (HAVE_DLSYM) # should be set here, whereas variables with different values should # be set in install.cmake or export.cmake, respectively. -if (WIN32) - set (LDFLAGS "${CMAKE_EXE_LINKER_FLAGS} -mwindows") -endif () - -set (IMAGELIBS) -set (STATICIMAGELIBS) - -if (FLTK_USE_BUILTIN_JPEG) - list (APPEND IMAGELIBS -lfltk_jpeg) - list (APPEND STATICIMAGELIBS \$libdir/libfltk_jpeg.a) -else () - if (LIB_jpeg) - list (APPEND IMAGELIBS -ljpeg) - list (APPEND STATICIMAGELIBS -ljpeg) - endif (LIB_jpeg) -endif (FLTK_USE_BUILTIN_JPEG) - -if (FLTK_USE_BUILTIN_PNG) - list (APPEND IMAGELIBS -lfltk_png) - list (APPEND STATICIMAGELIBS \$libdir/libfltk_png.a) -else () - if (LIB_png) - list (APPEND IMAGELIBS -lpng) - list (APPEND STATICIMAGELIBS -lpng) - endif (LIB_png) -endif (FLTK_USE_BUILTIN_PNG) - -if (FLTK_USE_BUILTIN_ZLIB) - list (APPEND IMAGELIBS -lfltk_z) - list (APPEND STATICIMAGELIBS \$libdir/libfltk_z.a) -else () - if (LIB_zlib) - list (APPEND IMAGELIBS -lz) - list (APPEND STATICIMAGELIBS -lz) - endif (LIB_zlib) -endif (FLTK_USE_BUILTIN_ZLIB) - -string (REPLACE ";" " " IMAGELIBS "${IMAGELIBS}") -string (REPLACE ";" " " STATICIMAGELIBS "${STATICIMAGELIBS}") +if(WIN32) + set(LDFLAGS "${CMAKE_EXE_LINKER_FLAGS} -mwindows") +endif() + +set(IMAGELIBS) +set(STATICIMAGELIBS) + +if(FLTK_USE_BUNDLED_JPEG) + list(APPEND IMAGELIBS -lfltk_jpeg) + list(APPEND STATICIMAGELIBS \$libdir/libfltk_jpeg.a) +else() + if(LIB_jpeg) + # fl_debug_var(LIB_jpeg) + list(APPEND IMAGELIBS ${LIB_jpeg}) + list(APPEND STATICIMAGELIBS ${LIB_jpeg}) + endif(LIB_jpeg) +endif(FLTK_USE_BUNDLED_JPEG) + +if(FLTK_USE_BUNDLED_PNG) + list(APPEND IMAGELIBS -lfltk_png) + list(APPEND STATICIMAGELIBS \$libdir/libfltk_png.a) +else() + if(LIB_png) + # fl_debug_var(LIB_png) + list(APPEND IMAGELIBS ${LIB_png}) + list(APPEND STATICIMAGELIBS ${LIB_png}) + endif(LIB_png) +endif(FLTK_USE_BUNDLED_PNG) + +if(FLTK_USE_BUNDLED_ZLIB) + list(APPEND IMAGELIBS -lfltk_z) + list(APPEND STATICIMAGELIBS \$libdir/libfltk_z.a) +else() + if(LIB_zlib) + list(APPEND IMAGELIBS ${LIB_zlib}) + list(APPEND STATICIMAGELIBS ${LIB_zlib}) + endif(LIB_zlib) +endif(FLTK_USE_BUNDLED_ZLIB) + +string(REPLACE ";" " " IMAGELIBS "${IMAGELIBS}") +string(REPLACE ";" " " STATICIMAGELIBS "${STATICIMAGELIBS}") ####################################################################### -set (CC ${CMAKE_C_COMPILER}) -set (CXX ${CMAKE_CXX_COMPILER}) +set(CC ${CMAKE_C_COMPILER}) +set(CXX ${CMAKE_CXX_COMPILER}) -set (ARCHFLAGS ${OPTION_ARCHFLAGS}) +set(ARCHFLAGS ${FLTK_ARCHFLAGS}) string(TOUPPER "${CMAKE_BUILD_TYPE}" BUILD_UPPER) -if (${BUILD_UPPER}) - set (CFLAGS "${CMAKE_C_FLAGS_${BUILD_UPPER}} ${CFLAGS}") -endif (${BUILD_UPPER}) - -set (CFLAGS "${OPTION_OPTIM} ${CMAKE_C_FLAGS} ${CFLAGS}") -foreach (arg ${FLTK_CFLAGS}) - set (CFLAGS "${CFLAGS} ${arg}") -endforeach (arg ${FLTK_CFLAGS}) - -set (CXXFLAGS "${CFLAGS}") - -foreach (arg ${FLTK_LDLIBS}) - set (LINK_LIBS "${LINK_LIBS} ${arg}") -endforeach (arg ${FLTK_LDLIBS}) - -set (LIBS "${LINK_LIBS}") - -if (${CMAKE_SYSTEM_NAME} STREQUAL "AIX") - set (SHAREDSUFFIX "_s") -else () - set (SHAREDSUFFIX "") -endif (${CMAKE_SYSTEM_NAME} STREQUAL "AIX") - -if (DEBUG_VARIABLES_CMAKE) - message (STATUS "") # empty line - fl_debug_var (HAVE_DLSYM) - fl_debug_var (CMAKE_DL_LIBS) - fl_debug_var (CMAKE_EXE_LINKER_FLAGS) - fl_debug_var (LDFLAGS) - fl_debug_var (LIBS) - fl_debug_var (GLLIBS) - fl_debug_var (IMAGELIBS) - fl_debug_var (STATICIMAGELIBS) - fl_debug_var (FLTK_LDLIBS) - fl_debug_var (LIB_jpeg) - fl_debug_var (LIB_png) - fl_debug_var (LIB_zlib) - message (STATUS "[** end of variables.cmake **]") -endif (DEBUG_VARIABLES_CMAKE) -unset (DEBUG_VARIABLES_CMAKE) +if(${BUILD_UPPER}) + set(CFLAGS "${CMAKE_C_FLAGS_${BUILD_UPPER}} ${CFLAGS}") +endif(${BUILD_UPPER}) + +set(CFLAGS "${FLTK_OPTION_OPTIM} ${CMAKE_C_FLAGS} ${CFLAGS}") +foreach(arg ${FLTK_CFLAGS}) + set(CFLAGS "${CFLAGS} ${arg}") +endforeach(arg ${FLTK_CFLAGS}) + +set(CXXFLAGS "${CFLAGS}") + +foreach(arg ${FLTK_LDLIBS}) + set(LINK_LIBS "${LINK_LIBS} ${arg}") +endforeach(arg ${FLTK_LDLIBS}) + +set(LIBS "${LINK_LIBS}") + +if(${CMAKE_SYSTEM_NAME} STREQUAL "AIX") + set(SHAREDSUFFIX "_s") +else() + set(SHAREDSUFFIX "") +endif(${CMAKE_SYSTEM_NAME} STREQUAL "AIX") + +if(DEBUG_VARIABLES_CMAKE) + message(STATUS "") # empty line + fl_debug_var(HAVE_DLSYM) + fl_debug_var(CMAKE_DL_LIBS) + fl_debug_var(CMAKE_EXE_LINKER_FLAGS) + fl_debug_var(LDFLAGS) + fl_debug_var(LIBS) + fl_debug_var(GLLIBS) + fl_debug_var(IMAGELIBS) + fl_debug_var(STATICIMAGELIBS) + fl_debug_var(FLTK_LDLIBS) + fl_debug_var(LIB_jpeg) + fl_debug_var(LIB_png) + fl_debug_var(LIB_zlib) + fl_debug_var(FLTK_LIBRARIES) + message(STATUS "[** end of variables.cmake **]") +endif(DEBUG_VARIABLES_CMAKE) +unset(DEBUG_VARIABLES_CMAKE) |
