HelperMacros.cmake revision c43e8c459ef8a48adf6b336c1a8a13cfe0415065
7765ee8964c8ffd7faee9baa0412abeb1ef5b0a4Nick# A macro to replace slashes and spaces in a string with underscores
7765ee8964c8ffd7faee9baa0412abeb1ef5b0a4Nickmacro(SANITIZE_PATH _string_var)
7765ee8964c8ffd7faee9baa0412abeb1ef5b0a4Nick string(REGEX REPLACE "[\\/ ]+" "_" ${_string_var} ${${_string_var}})
7765ee8964c8ffd7faee9baa0412abeb1ef5b0a4Nickmacro(inkscape_source_group
7765ee8964c8ffd7faee9baa0412abeb1ef5b0a4Nick # Group by location on disk
7765ee8964c8ffd7faee9baa0412abeb1ef5b0a4Nick source_group("Source Files" FILES CMakeLists.txt)
7765ee8964c8ffd7faee9baa0412abeb1ef5b0a4Nick foreach(_SRC ${sources})
7765ee8964c8ffd7faee9baa0412abeb1ef5b0a4Nick get_filename_component(_SRC_EXT ${_SRC} EXT)
7765ee8964c8ffd7faee9baa0412abeb1ef5b0a4Nick if((${_SRC_EXT} MATCHES ".h") OR (${_SRC_EXT} MATCHES ".hpp"))
7765ee8964c8ffd7faee9baa0412abeb1ef5b0a4Nick source_group("Header Files" FILES ${_SRC})
7765ee8964c8ffd7faee9baa0412abeb1ef5b0a4Nick source_group("Source Files" FILES ${_SRC})
7765ee8964c8ffd7faee9baa0412abeb1ef5b0a4Nick endforeach()
7765ee8964c8ffd7faee9baa0412abeb1ef5b0a4Nick unset(_SRC)
7765ee8964c8ffd7faee9baa0412abeb1ef5b0a4Nick unset(_SRC_EXT)
7765ee8964c8ffd7faee9baa0412abeb1ef5b0a4Nick# only MSVC uses SOURCE_GROUP
7765ee8964c8ffd7faee9baa0412abeb1ef5b0a4Nickmacro(add_inkscape_lib
7765ee8964c8ffd7faee9baa0412abeb1ef5b0a4Nick add_library(${name} ${sources})
7765ee8964c8ffd7faee9baa0412abeb1ef5b0a4Nick # works fine without having the includes
7765ee8964c8ffd7faee9baa0412abeb1ef5b0a4Nick # listed is helpful for IDE's (QtCreator/MSVC)
7765ee8964c8ffd7faee9baa0412abeb1ef5b0a4Nick inkscape_source_group("${sources}")
7765ee8964c8ffd7faee9baa0412abeb1ef5b0a4Nick# A macro to append to the global source property
7765ee8964c8ffd7faee9baa0412abeb1ef5b0a4Nickset_property(GLOBAL PROPERTY inkscape_global_SRC "")
7765ee8964c8ffd7faee9baa0412abeb1ef5b0a4Nickmacro (add_inkscape_source
7765ee8964c8ffd7faee9baa0412abeb1ef5b0a4Nick foreach(_SRC ${ARGV})
7765ee8964c8ffd7faee9baa0412abeb1ef5b0a4Nick get_filename_component(_ABS_SRC ${_SRC} ABSOLUTE)
7765ee8964c8ffd7faee9baa0412abeb1ef5b0a4Nick set_property(GLOBAL APPEND PROPERTY inkscape_global_SRC ${_ABS_SRC})
7765ee8964c8ffd7faee9baa0412abeb1ef5b0a4Nick endforeach()
7765ee8964c8ffd7faee9baa0412abeb1ef5b0a4Nick unset(_SRC)
7765ee8964c8ffd7faee9baa0412abeb1ef5b0a4Nick unset(_ABS_SRC)
7765ee8964c8ffd7faee9baa0412abeb1ef5b0a4Nick# A macro to append to the global source property
7765ee8964c8ffd7faee9baa0412abeb1ef5b0a4Nickmacro (add_inkscape_library
7765ee8964c8ffd7faee9baa0412abeb1ef5b0a4Nick foreach(_SRC ${ARGV})
7765ee8964c8ffd7faee9baa0412abeb1ef5b0a4Nick get_filename_component(_ABS_SRC ${_SRC} ABSOLUTE)
7765ee8964c8ffd7faee9baa0412abeb1ef5b0a4Nick set_property(GLOBAL APPEND PROPERTY inkscape_global_SRC ${_ABS_SRC})
7765ee8964c8ffd7faee9baa0412abeb1ef5b0a4Nick endforeach()
7765ee8964c8ffd7faee9baa0412abeb1ef5b0a4Nick unset(_SRC)
7765ee8964c8ffd7faee9baa0412abeb1ef5b0a4Nick unset(_ABS_SRC)
c43e8c459ef8a48adf6b336c1a8a13cfe0415065Campbell Bartonmacro(INKSCAPE_PKG_CONFIG_FIND PREFIX MODNAME VERSION PATH_NAME PATH_SUFFIXE LIB_NAME)
c43e8c459ef8a48adf6b336c1a8a13cfe0415065Campbell Barton pkg_check_modules(_${PREFIX} ${MODNAME}${VERSION})
c43e8c459ef8a48adf6b336c1a8a13cfe0415065Campbell Barton else(VERSION)
c43e8c459ef8a48adf6b336c1a8a13cfe0415065Campbell Barton pkg_check_modules(_${PREFIX} ${MODNAME})
c43e8c459ef8a48adf6b336c1a8a13cfe0415065Campbell Barton endif(VERSION)
c43e8c459ef8a48adf6b336c1a8a13cfe0415065Campbell Barton find_path(${PREFIX}_INCLUDE_DIR
c43e8c459ef8a48adf6b336c1a8a13cfe0415065Campbell Barton ${_${PREFIX}_INCLUDEDIR}
c43e8c459ef8a48adf6b336c1a8a13cfe0415065Campbell Barton $ENV{DEVLIBS_PATH}//include//
c43e8c459ef8a48adf6b336c1a8a13cfe0415065Campbell Barton PATH_SUFFIXES
c43e8c459ef8a48adf6b336c1a8a13cfe0415065Campbell Barton ${PATH_SUFFIXE}
c43e8c459ef8a48adf6b336c1a8a13cfe0415065Campbell Barton find_library(${PREFIX}_LIBRARY
c43e8c459ef8a48adf6b336c1a8a13cfe0415065Campbell Barton ${_${PREFIX}_LIBDIR}
c43e8c459ef8a48adf6b336c1a8a13cfe0415065Campbell Barton if (${PREFIX}_LIBRARY)
c43e8c459ef8a48adf6b336c1a8a13cfe0415065Campbell Barton set(${PREFIX}_FOUND TRUE)
c43e8c459ef8a48adf6b336c1a8a13cfe0415065Campbell Barton set(${PREFIX}_VERSION ${_${PREFIX}_VERSION})
c43e8c459ef8a48adf6b336c1a8a13cfe0415065Campbell Barton endif (${PREFIX}_LIBRARY)
c43e8c459ef8a48adf6b336c1a8a13cfe0415065Campbell Barton set(${PREFIX}_INCLUDE_DIRS
c43e8c459ef8a48adf6b336c1a8a13cfe0415065Campbell Barton ${${PREFIX}_INCLUDE_DIR}
c43e8c459ef8a48adf6b336c1a8a13cfe0415065Campbell Barton if (${PREFIX}_FOUND)
c43e8c459ef8a48adf6b336c1a8a13cfe0415065Campbell Barton set(${PREFIX}_LIBRARIES
c43e8c459ef8a48adf6b336c1a8a13cfe0415065Campbell Barton ${${PREFIX}_LIBRARIES}
c43e8c459ef8a48adf6b336c1a8a13cfe0415065Campbell Barton ${${PREFIX}_LIBRARY}
c43e8c459ef8a48adf6b336c1a8a13cfe0415065Campbell Barton endif (${PREFIX}_FOUND)
c43e8c459ef8a48adf6b336c1a8a13cfe0415065Campbell Barton if (${PREFIX}_INCLUDE_DIRS AND ${PREFIX}_LIBRARIES)
c43e8c459ef8a48adf6b336c1a8a13cfe0415065Campbell Barton set(${PREFIX}_FOUND TRUE)
c43e8c459ef8a48adf6b336c1a8a13cfe0415065Campbell Barton endif (${PREFIX}_INCLUDE_DIRS AND ${PREFIX}_LIBRARIES)
c43e8c459ef8a48adf6b336c1a8a13cfe0415065Campbell Barton if (${PREFIX}_FOUND)
c43e8c459ef8a48adf6b336c1a8a13cfe0415065Campbell Barton if (NOT ${PREFIX}_FIND_QUIETLY)
c43e8c459ef8a48adf6b336c1a8a13cfe0415065Campbell Barton message(STATUS "Found ${MODNAME}: ${${PREFIX}_LIBRARIES}")
c43e8c459ef8a48adf6b336c1a8a13cfe0415065Campbell Barton endif (NOT ${PREFIX}_FIND_QUIETLY)
c43e8c459ef8a48adf6b336c1a8a13cfe0415065Campbell Barton else (${PREFIX}_FOUND)
c43e8c459ef8a48adf6b336c1a8a13cfe0415065Campbell Barton if (${PREFIX}_FIND_REQUIRED)
c43e8c459ef8a48adf6b336c1a8a13cfe0415065Campbell Barton message(FATAL_ERROR "Could not find ${MODNAME}")
c43e8c459ef8a48adf6b336c1a8a13cfe0415065Campbell Barton endif (${PREFIX}_FIND_REQUIRED)
c43e8c459ef8a48adf6b336c1a8a13cfe0415065Campbell Barton endif (${PREFIX}_FOUND)
c43e8c459ef8a48adf6b336c1a8a13cfe0415065Campbell Barton # show the <PREFIX>_INCLUDE_DIRS and <PREFIX>_LIBRARIES variables only in the advanced view
c43e8c459ef8a48adf6b336c1a8a13cfe0415065Campbell Barton mark_as_advanced(${PREFIX}_INCLUDE_DIRS ${PREFIX}_LIBRARIES)