[CMake] Improve Mac OS X bundle generation and more (STR #3299).

Remove example specific tests from macro CREATE_EXAMPLE, add
function to set bundle icon, simplify some CMake setup code,
deprecate usage of UseFLTK.CMake.

Todo: Fix documentation.


git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@11742 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Albrecht Schlosser
2016-05-16 14:43:37 +00:00
parent d6906ffb16
commit c092b92938
9 changed files with 169 additions and 101 deletions
+53
View File
@@ -0,0 +1,53 @@
#
# "$Id$"
#
# FLTK-Functions.cmake
# Written by Michael Surette
#
# Copyright 1998-2016 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
# file is missing or damaged, see the license at:
#
# http://www.fltk.org/COPYING.php
#
# Please report all bugs and problems on the following page:
#
# http://www.fltk.org/str.php
#
#######################################################################
# functions used by the build system and exported for the end-user
#######################################################################
# USAGE: FLTK_RUN_FLUID TARGET_NAME "FLUID_SOURCE [.. FLUID_SOURCE]"
function(FLTK_RUN_FLUID TARGET SOURCES)
set (CXX_FILES)
foreach(src ${SOURCES})
if ("${src}" MATCHES "\\.fl$")
string(REGEX REPLACE "(.*).fl" \\1 basename ${src})
add_custom_command(
OUTPUT "${basename}.cxx" "${basename}.h"
COMMAND "${FLTK_FLUID_EXECUTABLE}" -c ${CMAKE_CURRENT_SOURCE_DIR}/${src}
DEPENDS ${src}
MAIN_DEPENDENCY ${src}
)
list(APPEND CXX_FILES "${basename}.cxx")
endif ("${src}" MATCHES "\\.fl$")
set (${TARGET} ${CXX_FILES} PARENT_SCOPE)
endforeach(src)
endfunction(FLTK_RUN_FLUID TARGET SOURCES)
#######################################################################
# sets the bundle icon for OSX bundles
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)
#
# End of "$Id$".
#
+33 -6
View File
@@ -1,12 +1,20 @@
#
# "$Id$"
#
# FLTKConfig.cmake - FLTK CMake configuration file for external projects.
#
# This file is generated by CMake and used to load FLTK's settings for an external project.
# It defines the following variables
# FLTK_INCLUDE_DIRS - FLTK include directories
# FLTK_LIBRARIES - list of FLTK libraries built
# FLTK_FLUID_EXECUTABLE needed by fltk_wrap_ui()
# FLTK_USE_FILE - sets things up to use FLTK
# This file is generated by CMake and used to load FLTK's settings for
# an external project.
#
# It defines the following variables:
#
# FLTK_INCLUDE_DIRS - FLTK include directories
# FLTK_LIBRARIES - list of FLTK libraries built (not yet implemented)
# FLTK_FLUID_EXECUTABLE - needed by the function FLTK_RUN_FLUID
# (or the deprecated fltk_wrap_ui() CMake command)
#
# FLTK_USE_FILE - sets things up to use FLTK (deprecated since FLTK 1.3.4)
# - will be removed in FLTK 1.4.0
set(FLTK_VERSION @FLTK_VERSION_FULL@)
@@ -14,3 +22,22 @@ include(${CMAKE_CURRENT_LIST_DIR}/FLTK-Targets.cmake)
set(FLTK_INCLUDE_DIRS "@INCLUDE_DIRS@")
set(FLTK_USE_FILE ${CMAKE_CURRENT_LIST_DIR}/UseFLTK.cmake)
if(CMAKE_CROSSCOMPILING)
find_file(FLUID_PATH
NAMES fluid fluid.exe
PATHS ENV 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)
#
# End of "$Id$".
#
+11 -16
View File
@@ -1,25 +1,20 @@
#
# "$Id$"
#
# UseFLTK.CMake - FLTK CMake environment configuration file for external projects.
#
# This file is generated by CMake and used to set FLTK's environment for an external project.
# This file is deprecated and will be removed in FLTK 1.4
#
# automatically generated - do not edit
#
include_directories("@INCLUDE_DIRS@")
if(CMAKE_CROSSCOMPILING)
find_file(FLUID_PATH
NAMES fluid fluid.exe
PATHS ENV 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)
message(STATUS "* Notice: UseFLTK.CMake is deprecated and will be removed in FLTK 1.4")
message(STATUS "* Please use 'include_directories(\${FLTK_INCLUDE_DIRS})' or")
message(STATUS "* 'target_include_directories(<target> PUBLIC|PRIVATE \${FLTK_INCLUDE_DIRS})'")
message(STATUS "* instead of 'include(\${FLTK_USE_FILE})'.")
set(FLTK_WRAP_UI TRUE)
#
# End of "$Id$".
#
+8 -1
View File
@@ -4,7 +4,7 @@
# Main CMakeLists.txt to build the FLTK project using CMake (www.cmake.org)
# Written by Michael Surette
#
# Copyright 1998-2015 by Bill Spitzak and others.
# Copyright 1998-2016 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
@@ -44,6 +44,13 @@ add_subdirectory(src)
# generate FLTK-Targets.cmake for build directory use
export(TARGETS ${FLUID} ${FLTK_LIBRARIES} FILE ${CMAKE_BINARY_DIR}/FLTK-Targets.cmake)
# generate FLTK-Functions.cmake for build directory use
configure_file(
${FLTK_SOURCE_DIR}/CMake/FLTK-Functions.cmake
${FLTK_BINARY_DIR}/FLTK-Functions.cmake
COPYONLY
)
# generate FLTKConfig.cmake for build directory use
set(INCLUDE_DIRS "${FLTK_INCLUDE_DIRS}")
set(CONFIG_PATH ${FLTK_BINARY_DIR})
+5 -3
View File
@@ -4,7 +4,7 @@
# Main CMakeLists.txt to build the FLTK project using CMake (www.cmake.org)
# Written by Michael Surette
#
# Copyright 1998-2015 by Bill Spitzak and others.
# Copyright 1998-2016 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
@@ -60,8 +60,10 @@ configure_file(
@ONLY
)
install(FILES ${FLTK_BINARY_DIR}/etc/FLTKConfig.cmake
DESTINATION ${FLTK_CONFIG_PATH}
install(FILES
${FLTK_BINARY_DIR}/etc/FLTKConfig.cmake
${FLTK_SOURCE_DIR}/CMake/FLTK-Functions.cmake
DESTINATION ${FLTK_CONFIG_PATH}
)
configure_file(
+17 -51
View File
@@ -1,7 +1,7 @@
#
# "$Id$"
#
# macros.cmake defines macros used by the build system
# macros.cmake
# Written by Michael Surette
#
# Copyright 1998-2016 by Bill Spitzak and others.
@@ -82,32 +82,13 @@ macro(FL_ADD_LIBRARY LIBNAME LIBTYPE LIBFILES)
endmacro(FL_ADD_LIBRARY LIBNAME LIBTYPE LIBFILES)
#######################################################################
# USAGE: FLTK_RUN_FLUID TARGET_NAME "FLUID_SOURCE [.. FLUID_SOURCE]"
function(FLTK_RUN_FLUID TARGET SOURCES)
set (CXX_FILES)
foreach(src ${SOURCES})
if ("${src}" MATCHES "\\.fl$")
string(REGEX REPLACE "(.*).fl" \\1 basename ${src})
add_custom_command(
OUTPUT "${basename}.cxx" "${basename}.h"
COMMAND fluid -c ${CMAKE_CURRENT_SOURCE_DIR}/${src}
DEPENDS ${src}
MAIN_DEPENDENCY ${src}
)
list(APPEND CXX_FILES "${basename}.cxx")
endif ("${src}" MATCHES "\\.fl$")
set (${TARGET} ${CXX_FILES} PARENT_SCOPE)
endforeach(src)
endfunction(FLTK_RUN_FLUID TARGET SOURCES)
#######################################################################
macro(CREATE_EXAMPLE NAME SOURCES LIBRARIES)
function(CREATE_EXAMPLE NAME SOURCES LIBRARIES)
set (srcs) # source files
set (flsrcs) # fluid source files
set (icns) # mac icons
set (tname ${NAME}) # target name
set (oname ${NAME}) # output (executable) name
# rename reserved target name "help" (CMake 2.8.12 and later)
if (${tname} MATCHES "^help$")
@@ -117,6 +98,8 @@ macro(CREATE_EXAMPLE NAME SOURCES LIBRARIES)
foreach(src ${SOURCES})
if ("${src}" MATCHES "\\.fl$")
list(APPEND flsrcs ${src})
elseif ("${src}" MATCHES "\\.icns$")
set(icns "${src}")
else ()
list(APPEND srcs ${src})
endif ("${src}" MATCHES "\\.fl$")
@@ -124,45 +107,28 @@ macro(CREATE_EXAMPLE NAME SOURCES LIBRARIES)
set (FLUID_SOURCES)
if (flsrcs)
FLTK_RUN_FLUID(FLUID_SOURCES "${flsrcs}")
FLTK_RUN_FLUID(FLUID_SOURCES "${flsrcs}")
endif (flsrcs)
if (APPLE AND NOT OPTION_APPLE_X11)
unset (RESOURCE_PATH)
if (${tname} STREQUAL "blocks" OR ${tname} STREQUAL "checkers" OR ${tname} STREQUAL "sudoku")
set (ICON_NAME ${tname}.icns)
set (RESOURCE_PATH "${PROJECT_SOURCE_DIR}/test/${tname}.app/Contents/Resources/${ICON_NAME}")
elseif (${tname} STREQUAL "demo")
set (RESOURCE_PATH "${PROJECT_SOURCE_DIR}/test/demo.menu")
endif (${tname} STREQUAL "blocks" OR ${tname} STREQUAL "checkers" OR ${tname} STREQUAL "sudoku")
if (DEFINED RESOURCE_PATH)
add_executable(${tname} MACOSX_BUNDLE ${srcs} ${FLUID_SOURCES} ${RESOURCE_PATH})
if (${tname} STREQUAL "demo")
target_compile_definitions(demo PUBLIC USING_XCODE)
endif (${tname} STREQUAL "demo")
else ()
add_executable(${tname} MACOSX_BUNDLE ${srcs} ${FLUID_SOURCES})
endif (DEFINED RESOURCE_PATH)
add_executable(${tname} MACOSX_BUNDLE ${srcs} ${FLUID_SOURCES} ${icns})
if (icns)
FLTK_SET_BUNDLE_ICON(${tname} ${icns})
endif (icns)
else ()
add_executable(${tname} WIN32 ${srcs} ${FLUID_SOURCES})
add_executable(${tname} WIN32 ${srcs} ${FLUID_SOURCES})
endif (APPLE AND NOT OPTION_APPLE_X11)
set_target_properties(${tname}
PROPERTIES OUTPUT_NAME ${oname}
PROPERTIES OUTPUT_NAME ${NAME}
)
if (APPLE AND DEFINED RESOURCE_PATH)
if (NOT ${tname} STREQUAL "demo")
set_target_properties(${tname} PROPERTIES MACOSX_BUNDLE_ICON_FILE ${ICON_NAME})
endif (NOT ${tname} STREQUAL "demo")
set_target_properties(${tname} PROPERTIES RESOURCE ${RESOURCE_PATH})
endif (APPLE AND DEFINED RESOURCE_PATH)
if (APPLE AND (NOT OPTION_APPLE_X11) AND ${tname} STREQUAL "editor")
set_target_properties("editor" PROPERTIES MACOSX_BUNDLE_INFO_PLIST "${PROJECT_SOURCE_DIR}/ide/Xcode4/plists/editor-Info.plist")
endif (APPLE AND (NOT OPTION_APPLE_X11) AND ${tname} STREQUAL "editor")
target_link_libraries(${tname} ${LIBRARIES})
endmacro(CREATE_EXAMPLE NAME SOURCES LIBRARIES)
endfunction(CREATE_EXAMPLE NAME SOURCES LIBRARIES)
#######################################################################
#
# End of "$Id$".
#
+3 -2
View File
@@ -4,7 +4,7 @@
# Main CMakeLists.txt to build the FLTK project using CMake (www.cmake.org)
# Written by Michael Surette
#
# Copyright 1998-2014 by Bill Spitzak and others.
# Copyright 1998-2016 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,8 +25,9 @@ project(FLTK)
cmake_minimum_required(VERSION 2.6.3)
#######################################################################
# define some macros
# define some functions and macros
#######################################################################
include(CMake/FLTK-Functions.cmake)
include(CMake/macros.cmake)
#######################################################################
+8 -18
View File
@@ -3,7 +3,7 @@
#
# CMakeLists.txt to build fluid for the FLTK project using CMake (www.cmake.org)
#
# Copyright 1998-2015 by Bill Spitzak and others.
# Copyright 1998-2016 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
@@ -39,31 +39,21 @@ set(CPPFILES
)
if(APPLE AND NOT OPTION_APPLE_X11)
set( ICON_NAME fluid.icns )
set( ICON_PATH "${PROJECT_SOURCE_DIR}/fluid/Fluid.app/Contents/Resources/${ICON_NAME}" )
add_executable(fluid MACOSX_BUNDLE ${CPPFILES} ${ICON_PATH})
set(FLUID_ICON "${CMAKE_CURRENT_SOURCE_DIR}/Fluid.app/Contents/Resources/fluid.icns")
add_executable(fluid MACOSX_BUNDLE ${CPPFILES} "${FLUID_ICON}")
FLTK_SET_BUNDLE_ICON(fluid "${FLUID_ICON}")
else()
add_executable(fluid ${CPPFILES})
add_executable(fluid WIN32 ${CPPFILES})
endif(APPLE AND NOT OPTION_APPLE_X11)
target_link_libraries(fluid fltk fltk_images fltk_forms)
# install fluid
if(APPLE AND NOT OPTION_APPLE_X11)
# create bundle
set_target_properties(fluid PROPERTIES MACOSX_BUNDLE_ICON_FILE ${ICON_NAME})
set_target_properties(fluid PROPERTIES RESOURCE ${ICON_PATH})
# install
install(TARGETS fluid DESTINATION ${FLTK_BINDIR})
else()
install(TARGETS fluid
install(TARGETS fluid
EXPORT FLTK-Targets
RUNTIME DESTINATION ${FLTK_BINDIR}
LIBRARY DESTINATION ${FLTK_LIBDIR}
ARCHIVE DESTINATION ${FLTK_LIBDIR}
)
endif(APPLE AND NOT OPTION_APPLE_X11)
DESTINATION ${FLTK_BINDIR}
)
# install desktop files
+31 -4
View File
@@ -16,27 +16,46 @@ include_directories(
${CMAKE_CURRENT_BINARY_DIR}
)
#######################################################################
if (APPLE AND NOT OPTION_APPLE_X11)
add_definitions(-DUSING_XCODE)
endif(APPLE AND NOT OPTION_APPLE_X11)
#######################################################################
CREATE_EXAMPLE(adjuster adjuster.cxx fltk)
CREATE_EXAMPLE(arc arc.cxx fltk)
CREATE_EXAMPLE(animated animated.cxx fltk)
CREATE_EXAMPLE(ask ask.cxx fltk)
CREATE_EXAMPLE(bitmap bitmap.cxx fltk)
CREATE_EXAMPLE(blocks blocks.cxx "fltk;${AUDIOLIBS}")
set(BLOCKS_ICON "${CMAKE_CURRENT_SOURCE_DIR}/blocks.app/Contents/Resources/blocks.icns")
CREATE_EXAMPLE(blocks "blocks.cxx;${BLOCKS_ICON}" "fltk;${AUDIOLIBS}")
CREATE_EXAMPLE(boxtype boxtype.cxx fltk)
CREATE_EXAMPLE(browser browser.cxx fltk)
CREATE_EXAMPLE(button button.cxx fltk)
CREATE_EXAMPLE(buttons buttons.cxx fltk)
CREATE_EXAMPLE(checkers checkers.cxx fltk)
set(CHECKERS_ICON "${CMAKE_CURRENT_SOURCE_DIR}/checkers.app/Contents/Resources/checkers.icns")
CREATE_EXAMPLE(checkers "checkers.cxx;${CHECKERS_ICON}" fltk)
CREATE_EXAMPLE(clock clock.cxx fltk)
CREATE_EXAMPLE(colbrowser colbrowser.cxx "fltk;fltk_forms")
CREATE_EXAMPLE(color_chooser color_chooser.cxx fltk)
CREATE_EXAMPLE(cursor cursor.cxx fltk)
CREATE_EXAMPLE(curve curve.cxx fltk)
CREATE_EXAMPLE(demo demo.cxx fltk)
CREATE_EXAMPLE(demo "demo.cxx;demo.menu" fltk)
set_source_files_properties(demo.menu PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
CREATE_EXAMPLE(device device.cxx fltk)
CREATE_EXAMPLE(doublebuffer doublebuffer.cxx fltk)
CREATE_EXAMPLE(editor editor.cxx fltk)
set_target_properties(editor PROPERTIES
MACOSX_BUNDLE_INFO_PLIST "${PROJECT_SOURCE_DIR}/ide/Xcode4/plists/editor-Info.plist"
)
CREATE_EXAMPLE(fast_slow fast_slow.fl fltk)
CREATE_EXAMPLE(file_chooser file_chooser.cxx "fltk;fltk_images")
CREATE_EXAMPLE(fonts fonts.cxx fltk)
@@ -72,7 +91,10 @@ CREATE_EXAMPLE(resizebox resizebox.cxx fltk)
CREATE_EXAMPLE(rotated_text rotated_text.cxx fltk)
CREATE_EXAMPLE(scroll scroll.cxx fltk)
CREATE_EXAMPLE(subwindow subwindow.cxx fltk)
CREATE_EXAMPLE(sudoku sudoku.cxx "fltk;fltk_images;${AUDIOLIBS}")
set(SUDOKU_ICON "${CMAKE_CURRENT_SOURCE_DIR}/sudoku.app/Contents/Resources/sudoku.icns")
CREATE_EXAMPLE(sudoku "sudoku.cxx;${SUDOKU_ICON}" "fltk;fltk_images;${AUDIOLIBS}")
CREATE_EXAMPLE(symbols symbols.cxx fltk)
CREATE_EXAMPLE(tabs tabs.fl fltk)
CREATE_EXAMPLE(table table.cxx fltk)
@@ -127,3 +149,8 @@ configure_file(rgb.txt ${TESTFILE_PATH} COPYONLY)
configure_file(help-test.html ${TESTFILE_PATH} COPYONLY)
configure_file(browser.cxx ${TESTFILE_PATH} COPYONLY)
configure_file(editor.cxx ${TESTFILE_PATH} COPYONLY)
if(APPLE AND NOT OPTION_APPLE_X11)
configure_file(browser.cxx "${TESTFILE_PATH}/browser.app/Contents/Resources/browser.cxx" COPYONLY)
configure_file(rgb.txt ${TESTFILE_PATH}/colbrowser.app/Contents/Resources/rgb.txt COPYONLY)
configure_file(help-test.html ${TESTFILE_PATH}/help.app/Contents/Resources/help-test.html COPYONLY)
endif(APPLE AND NOT OPTION_APPLE_X11)