[CMake] Fix library name (Debug mode), add fluid dependencies.

The library name in Debug mode must only be 'libname'd.a if the build
is with MSVC; all other builds never appended the 'd' suffix to the name.
This is also documented (see lib/README).

Fluid did not regenerate the .cxx and .h files if the .fl file was changed.
The DEPENDS keyword adds the necessary dependency.
The MAIN_DEPENDENCY keyword "also suggests to Visual Studio generators
where to hang the custom command" according to CMake docs.

Ported from branch-1.3, svn r11430.


git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11431 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Albrecht Schlosser 2016-03-26 14:33:20 +00:00
parent ff0ec68023
commit e86e4a6ab0

View File

@ -4,7 +4,7 @@
# macros.cmake defines macros used by the build system # macros.cmake defines macros used by the build system
# Written by Michael Surette # 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 # 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 # the file "COPYING" which should have been included with this file. If this
@ -22,151 +22,159 @@
####################################################################### #######################################################################
macro(FL_ADD_LIBRARY LIBNAME LIBTYPE LIBFILES) macro(FL_ADD_LIBRARY LIBNAME LIBTYPE LIBFILES)
if(${LIBTYPE} STREQUAL "SHARED") if (${LIBTYPE} STREQUAL "SHARED")
set(LIBRARY_NAME ${LIBNAME}_SHARED) set (LIBRARY_NAME ${LIBNAME}_SHARED)
else() else ()
set(LIBRARY_NAME ${LIBNAME}) set (LIBRARY_NAME ${LIBNAME})
endif(${LIBTYPE} STREQUAL "SHARED") endif (${LIBTYPE} STREQUAL "SHARED")
if (MSVC)
set (LIBNAME_DEBUG "${LIBNAME}d")
else ()
set (LIBNAME_DEBUG "${LIBNAME}")
endif (MSVC)
add_library(${LIBRARY_NAME} ${LIBTYPE} ${LIBFILES}) add_library(${LIBRARY_NAME} ${LIBTYPE} ${LIBFILES})
set_target_properties(${LIBRARY_NAME} set_target_properties(${LIBRARY_NAME}
PROPERTIES PROPERTIES
OUTPUT_NAME ${LIBNAME} OUTPUT_NAME ${LIBNAME}
DEBUG_OUTPUT_NAME "${LIBNAME}d" DEBUG_OUTPUT_NAME "${LIBNAME_DEBUG}"
CLEAN_DIRECT_OUTPUT TRUE CLEAN_DIRECT_OUTPUT TRUE
COMPILE_DEFINITIONS "FL_LIBRARY" COMPILE_DEFINITIONS "FL_LIBRARY"
) )
if(${LIBTYPE} STREQUAL "SHARED") if (${LIBTYPE} STREQUAL "SHARED")
set_target_properties(${LIBRARY_NAME} set_target_properties(${LIBRARY_NAME}
PROPERTIES PROPERTIES
VERSION ${FLTK_VERSION_FULL} VERSION ${FLTK_VERSION_FULL}
SOVERSION ${FLTK_VERSION_MAJOR}.${FLTK_VERSION_MINOR} SOVERSION ${FLTK_VERSION_MAJOR}.${FLTK_VERSION_MINOR}
PREFIX "lib" # for MSVC static/shared coexistence PREFIX "lib" # for MSVC static/shared coexistence
) )
endif(${LIBTYPE} STREQUAL "SHARED") endif (${LIBTYPE} STREQUAL "SHARED")
if(MSVC) if (MSVC)
if(OPTION_LARGE_FILE) if (OPTION_LARGE_FILE)
set_target_properties(${LIBNAME} set_target_properties(${LIBNAME}
PROPERTIES PROPERTIES
LINK_FLAGS /LARGEADDRESSAWARE LINK_FLAGS /LARGEADDRESSAWARE
) )
endif(OPTION_LARGE_FILE) endif (OPTION_LARGE_FILE)
if(${LIBTYPE} STREQUAL "SHARED") if (${LIBTYPE} STREQUAL "SHARED")
set_target_properties(${LIBRARY_NAME} set_target_properties(${LIBRARY_NAME}
PROPERTIES PROPERTIES
COMPILE_DEFINITIONS "FL_DLL" COMPILE_DEFINITIONS "FL_DLL"
) )
endif(${LIBTYPE} STREQUAL "SHARED") endif (${LIBTYPE} STREQUAL "SHARED")
endif(MSVC) endif (MSVC)
install(TARGETS ${LIBRARY_NAME} install(TARGETS ${LIBRARY_NAME}
EXPORT FLTK-Targets EXPORT FLTK-Targets
RUNTIME DESTINATION ${FLTK_BINDIR} RUNTIME DESTINATION ${FLTK_BINDIR}
LIBRARY DESTINATION ${FLTK_LIBDIR} LIBRARY DESTINATION ${FLTK_LIBDIR}
ARCHIVE DESTINATION ${FLTK_LIBDIR} ARCHIVE DESTINATION ${FLTK_LIBDIR}
) )
list(APPEND FLTK_LIBRARIES "${LIBRARY_NAME}") list(APPEND FLTK_LIBRARIES "${LIBRARY_NAME}")
set(FLTK_LIBRARIES ${FLTK_LIBRARIES} PARENT_SCOPE) set (FLTK_LIBRARIES ${FLTK_LIBRARIES} PARENT_SCOPE)
endmacro(FL_ADD_LIBRARY LIBNAME LIBTYPE LIBFILES) endmacro(FL_ADD_LIBRARY LIBNAME LIBTYPE LIBFILES)
####################################################################### #######################################################################
# USAGE: FLTK_RUN_FLUID TARGET_NAME "FLUID_SOURCE [.. FLUID_SOURCE]" # USAGE: FLTK_RUN_FLUID TARGET_NAME "FLUID_SOURCE [.. FLUID_SOURCE]"
function(FLTK_RUN_FLUID TARGET SOURCES) function(FLTK_RUN_FLUID TARGET SOURCES)
set(CXX_FILES) set (CXX_FILES)
foreach(src ${SOURCES}) foreach(src ${SOURCES})
if("${src}" MATCHES "\\.fl$") if ("${src}" MATCHES "\\.fl$")
string(REGEX REPLACE "(.*).fl" \\1 basename ${src}) string(REGEX REPLACE "(.*).fl" \\1 basename ${src})
add_custom_command( add_custom_command(
OUTPUT "${basename}.cxx" "${basename}.h" OUTPUT "${basename}.cxx" "${basename}.h"
COMMAND fluid -c ${CMAKE_CURRENT_SOURCE_DIR}/${src} COMMAND fluid -c ${CMAKE_CURRENT_SOURCE_DIR}/${src}
DEPENDS ${src}
MAIN_DEPENDENCY ${src}
) )
list(APPEND CXX_FILES "${basename}.cxx") list(APPEND CXX_FILES "${basename}.cxx")
endif("${src}" MATCHES "\\.fl$") endif ("${src}" MATCHES "\\.fl$")
set(${TARGET} ${CXX_FILES} PARENT_SCOPE) set (${TARGET} ${CXX_FILES} PARENT_SCOPE)
endforeach(src) endforeach(src)
endfunction(FLTK_RUN_FLUID TARGET SOURCES) endfunction(FLTK_RUN_FLUID TARGET SOURCES)
####################################################################### #######################################################################
macro(CREATE_EXAMPLE NAME SOURCES LIBRARIES) macro(CREATE_EXAMPLE NAME SOURCES LIBRARIES)
set(srcs) # source files set (srcs) # source files
set(flsrcs) # fluid source files set (flsrcs) # fluid source files
set(tname ${NAME}) # target name set (tname ${NAME}) # target name
set(oname ${NAME}) # output (executable) name set (oname ${NAME}) # output (executable) name
# rename reserved target name "help" (CMake 2.8.12 and later) # rename reserved target name "help" (CMake 2.8.12 and later)
if(${tname} MATCHES "^help$") if (${tname} MATCHES "^help$")
set(tname "test_help") set (tname "test_help")
endif(${tname} MATCHES "^help$") endif (${tname} MATCHES "^help$")
foreach(src ${SOURCES}) foreach(src ${SOURCES})
if("${src}" MATCHES "\\.fl$") if ("${src}" MATCHES "\\.fl$")
list(APPEND flsrcs ${src}) list(APPEND flsrcs ${src})
else() else ()
list(APPEND srcs ${src}) list(APPEND srcs ${src})
endif("${src}" MATCHES "\\.fl$") endif ("${src}" MATCHES "\\.fl$")
endforeach(src) endforeach(src)
set(FLUID_SOURCES) set (FLUID_SOURCES)
if(flsrcs) if (flsrcs)
FLTK_RUN_FLUID(FLUID_SOURCES "${flsrcs}") FLTK_RUN_FLUID(FLUID_SOURCES "${flsrcs}")
endif(flsrcs) endif (flsrcs)
if(APPLE AND (NOT OPTION_APPLE_X11) AND (NOT OPTION_APPLE_SDL)) if (APPLE AND (NOT OPTION_APPLE_X11) AND (NOT OPTION_APPLE_SDL))
unset(RESOURCE_PATH) unset (RESOURCE_PATH)
if(${tname} STREQUAL "blocks" OR ${tname} STREQUAL "checkers" OR ${tname} STREQUAL "sudoku") if (${tname} STREQUAL "blocks" OR ${tname} STREQUAL "checkers" OR ${tname} STREQUAL "sudoku")
set( ICON_NAME ${tname}.icns ) set (ICON_NAME ${tname}.icns)
set( RESOURCE_PATH "${PROJECT_SOURCE_DIR}/test/${tname}.app/Contents/Resources/${ICON_NAME}" ) set (RESOURCE_PATH "${PROJECT_SOURCE_DIR}/test/${tname}.app/Contents/Resources/${ICON_NAME}")
elseif(${tname} STREQUAL "demo") elseif (${tname} STREQUAL "demo")
set( RESOURCE_PATH "${PROJECT_SOURCE_DIR}/test/demo.menu" ) set (RESOURCE_PATH "${PROJECT_SOURCE_DIR}/test/demo.menu")
endif(${tname} STREQUAL "blocks" OR ${tname} STREQUAL "checkers" OR ${tname} STREQUAL "sudoku") endif (${tname} STREQUAL "blocks" OR ${tname} STREQUAL "checkers" OR ${tname} STREQUAL "sudoku")
if(DEFINED RESOURCE_PATH) if (DEFINED RESOURCE_PATH)
add_executable(${tname} MACOSX_BUNDLE ${srcs} ${FLUID_SOURCES} ${RESOURCE_PATH}) add_executable(${tname} MACOSX_BUNDLE ${srcs} ${FLUID_SOURCES} ${RESOURCE_PATH})
if(${tname} STREQUAL "demo") if (${tname} STREQUAL "demo")
target_compile_definitions(demo PUBLIC USING_XCODE) target_compile_definitions(demo PUBLIC USING_XCODE)
endif(${tname} STREQUAL "demo") endif (${tname} STREQUAL "demo")
else() else ()
add_executable(${tname} MACOSX_BUNDLE ${srcs} ${FLUID_SOURCES}) add_executable(${tname} MACOSX_BUNDLE ${srcs} ${FLUID_SOURCES})
endif(DEFINED RESOURCE_PATH) endif (DEFINED RESOURCE_PATH)
else() else ()
add_executable(${tname} WIN32 ${srcs} ${FLUID_SOURCES}) add_executable(${tname} WIN32 ${srcs} ${FLUID_SOURCES})
endif(APPLE AND (NOT OPTION_APPLE_X11) AND (NOT OPTION_APPLE_SDL)) endif (APPLE AND (NOT OPTION_APPLE_X11) AND (NOT OPTION_APPLE_SDL))
set_target_properties(${tname} set_target_properties(${tname}
PROPERTIES OUTPUT_NAME ${oname} PROPERTIES OUTPUT_NAME ${oname}
) )
if(APPLE AND DEFINED RESOURCE_PATH) if (APPLE AND DEFINED RESOURCE_PATH)
if(NOT ${tname} STREQUAL "demo") if (NOT ${tname} STREQUAL "demo")
set_target_properties(${tname} PROPERTIES MACOSX_BUNDLE_ICON_FILE ${ICON_NAME}) set_target_properties(${tname} PROPERTIES MACOSX_BUNDLE_ICON_FILE ${ICON_NAME})
endif(NOT ${tname} STREQUAL "demo") endif (NOT ${tname} STREQUAL "demo")
set_target_properties(${tname} PROPERTIES RESOURCE ${RESOURCE_PATH}) set_target_properties(${tname} PROPERTIES RESOURCE ${RESOURCE_PATH})
endif(APPLE AND DEFINED RESOURCE_PATH) endif (APPLE AND DEFINED RESOURCE_PATH)
if(APPLE AND (NOT OPTION_APPLE_X11) AND (NOT OPTION_APPLE_SDL) AND ${tname} STREQUAL "editor") if (APPLE AND (NOT OPTION_APPLE_X11) AND (NOT OPTION_APPLE_SDL) AND ${tname} STREQUAL "editor")
set_target_properties("editor" PROPERTIES MACOSX_BUNDLE_INFO_PLIST "${PROJECT_SOURCE_DIR}/test/editor-Info.plist" ) set_target_properties("editor" PROPERTIES MACOSX_BUNDLE_INFO_PLIST "${PROJECT_SOURCE_DIR}/test/editor-Info.plist" )
endif(APPLE AND (NOT OPTION_APPLE_X11) AND (NOT OPTION_APPLE_SDL) AND ${tname} STREQUAL "editor") endif(APPLE AND (NOT OPTION_APPLE_X11) AND (NOT OPTION_APPLE_SDL) AND ${tname} STREQUAL "editor")
target_link_libraries(${tname} ${LIBRARIES}) target_link_libraries(${tname} ${LIBRARIES})
# link in optional libraries # link in optional libraries
if(USE_XFT) if (USE_XFT)
target_link_libraries(${tname} ${X11_Xft_LIB}) target_link_libraries(${tname} ${X11_Xft_LIB})
endif(USE_XFT) endif (USE_XFT)
if(HAVE_XINERAMA) if (HAVE_XINERAMA)
target_link_libraries(${tname} ${X11_Xinerama_LIB}) target_link_libraries(${tname} ${X11_Xinerama_LIB})
endif(HAVE_XINERAMA) endif (HAVE_XINERAMA)
if(HAVE_XRENDER) if (HAVE_XRENDER)
target_link_libraries(${tname} ${X11_Xrender_LIB}) target_link_libraries(${tname} ${X11_Xrender_LIB})
endif(HAVE_XRENDER) endif (HAVE_XRENDER)
if (OPTION_APPLE_SDL) if (OPTION_APPLE_SDL)
target_link_libraries(${tname} ${SDL2_LIBRARY}) target_link_libraries(${tname} ${SDL2_LIBRARY})