SET(INKSCAPE_SRC)

# A macro to replace slashes and spaces in a string with underscores
MACRO(SANITIZE_PATH _string_var)
  STRING(REGEX REPLACE "[\\/ ]+" "_" ${_string_var} ${${_string_var}})
ENDMACRO(SANITIZE_PATH _string_var)

# A macro to prepend a given string onto the beginning of each string in a list
MACRO(PREPEND _list _str)
  SET(_temp_list ${${_list}})
  SET(${_list})
  FOREACH(x ${_temp_list})
    SET(${_list} ${${_list}} ${_str}${x})
  ENDFOREACH(x)
ENDMACRO(PREPEND _list _str)

# All folder with CMakeLists.txt files (excluding internal libraries)
SET(srcfolders
algorithms
api
bind
debug
dialogs
display
dom
dom/io
dom/odf
dom/util
#dom/work
extension
#extension/dxf2svg
extension/implementation
extension/internal
extension/param
graphlayout
helper
inkjar
io
jabber_whiteboard
jabber_whiteboard/dialog
live_effects
live_effects/parameter
pedro
removeoverlap
svg
trace
trace/potrace
traits
ui/cache
ui
ui/dialog
ui/view
ui/widget
#utest
util
widgets
xml
)

# 1) include each list file
# 2) grab the variable inside 
# 3) prepend the full relative path to each file in list
# 4) append the list to INKSCAPE_SRC
FOREACH(dirlist ${srcfolders})
  SET(_temp_dirlist "${dirlist}")
  MESSAGE(STATUS "Processing ${CMAKE_CURRENT_SOURCE_DIR}/${dirlist}/CMakeLists.txt")
  INCLUDE(${CMAKE_CURRENT_SOURCE_DIR}/${dirlist}/CMakeLists.txt)
  SANITIZE_PATH(dirlist)
  PREPEND(${dirlist}_SRC "${_temp_dirlist}/")
  SET(INKSCAPE_SRC ${INKSCAPE_SRC} ${${dirlist}_SRC})
ENDFOREACH(dirlist)


# All directories containing lists files that describe building internal libraries
SET(libfolders
2geom
application
#dialogs
libavoid
libcola
libcroco
libgdl
libnr
libnrtype
libvpsc
livarot
)

FOREACH(dirlist ${libfolders})
  ADD_SUBDIRECTORY(${dirlist})
ENDFOREACH(dirlist)

IF(WIN32)
SET(ONLY_WIN
registrytool.cpp
registrytool.h
#deptool.cpp
winmain.cpp
)
ELSEIF(WIN32)
SET(ONLY_WIN)
ENDIF(WIN32)

SET(INKSCAPE_SRC
${INKSCAPE_SRC}
approx-equal.h
arc-context.cpp
arc-context.h
attributes.cpp
attributes.h
attributes-test.h
axis-manip.cpp
axis-manip.h
bad-uri-exception.h
box3d-context.cpp
box3d-context.h
box3d.cpp
box3d.h
box3d-side.cpp
box3d-side.h
brokenimage.xpm
color.cpp
color.h
color-profile.cpp
color-profile-fns.h
color-profile.h
color-profile-test.h
color-rgba.h
composite-undo-stack-observer.cpp
composite-undo-stack-observer.h
conditions.cpp
conditions.h
conn-avoid-ref.cpp
conn-avoid-ref.h
connection-pool.h
connector-context.cpp
connector-context.h
console-output-undo-observer.cpp
console-output-undo-observer.h
context-fns.cpp
context-fns.h
decimal-round.h
deptool.cpp
desktop-affine.cpp
desktop-affine.h
desktop.cpp
desktop-events.cpp
desktop-events.h
desktop.h
desktop-handles.cpp
desktop-handles.h
desktop-style.cpp
desktop-style.h
device-manager.cpp
device-manager.h
dir-util.cpp
dir-util.h
dir-util-test.h
document.cpp
document.h
document-private.h
document-subset.cpp
document-subset.h
document-undo.cpp
doxygen-main.cpp
draw-anchor.cpp
draw-anchor.h
draw-context.cpp
draw-context.h
dropper-context.cpp
dropper-context.h
dyna-draw-context.cpp
dyna-draw-context.h
ege-adjustment-action.cpp
ege-adjustment-action.h
ege-color-prof-tracker.cpp
ege-color-prof-tracker.h
ege-output-action.cpp
ege-output-action.h
ege-select-one-action.cpp
ege-select-one-action.h
enums.h
eraser-context.cpp
eraser-context.h
event-context.cpp
event-context.h
event.h
event-log.cpp
event-log.h
extension
extract-uri.cpp
extract-uri.h
extract-uri-test.h
file.cpp
file.h
fill-or-stroke.h
filter-chemistry.cpp
filter-chemistry.h
filter-enums.cpp
filter-enums.h
fixes.cpp
flood-context.cpp
flood-context.h
fontsize-expansion.cpp
fontsize-expansion.h
forward.h
gc-alloc.h
gc-anchored.cpp
gc-anchored.h
gc-core.h
gc.cpp
gc-finalized.cpp
gc-finalized.h
gc-managed.h
gc-soft-ptr.h
gradient-chemistry.cpp
gradient-chemistry.h
gradient-context.cpp
gradient-context.h
gradient-drag.cpp
gradient-drag.h
guide-snapper.cpp
guide-snapper.h
help.cpp
helper-fns.h
help.h
icon-size.h
ige-mac-menu.c
ige-mac-menu.h
ink-action.cpp
ink-action.h
inkscape.cpp
inkscape.h
inkscape-private.h
inkscape.rc
inkscape-stock.cpp
inkscape-stock.h
inkscape_version.h.mingw
interface.cpp
interface.h
isinf.h
isnan.h
isnormal.h
jabber_whiteboard
knot.cpp
knot-enums.h
knot.h
knotholder.cpp
knot-holder-entity.h
knotholder.h
layer-fns.cpp
layer-fns.h
layer-manager.cpp
layer-manager.h
line-geometry.cpp
line-geometry.h
line-snapper.cpp
line-snapper.h
macros.h
main-cmdlineact.cpp
main-cmdlineact.h
main.cpp
marker.cpp
marker.h
media.cpp
media.h
memeq.h
menus-skeleton.h
message-context.cpp
message-context.h
message.h
message-stack.cpp
message-stack.h
mod360.cpp
mod360.h
mod360-test.h
modifier-fns.h
MultiPrinter.h
node-context.cpp
node-context.h
nodepath.cpp
nodepath.h
number-opt-number.h
object-edit.cpp
object-edit.h
object-hierarchy.cpp
object-hierarchy.h
object-snapper.cpp
object-snapper.h
path-chemistry.cpp
path-chemistry.h
path-prefix.h
pencil-context.cpp
pencil-context.h
pen-context.cpp
pen-context.h
persp3d.cpp
persp3d.h
persp3d-reference.cpp
persp3d-reference.h
perspective-line.cpp
perspective-line.h
plugin.def
preferences.cpp
preferences.h
preferences-skeleton.h
prefix.cpp
prefix.h
prefs-utils.cpp
prefs-utils.h
print.cpp
print.h
profile-manager.cpp
profile-manager.h
proj_pt.cpp
proj_pt.h
PylogFormatter.h
rect-context.cpp
rect-context.h
remove-last.h
require-config.h
round.h
round-test.h
rubberband.cpp
rubberband.h
satisfied-guide-cns.cpp
satisfied-guide-cns.h
selcue.cpp
selcue.h
select-context.cpp
select-context.h
selection-chemistry.cpp
selection-chemistry.h
selection.cpp
selection-describer.cpp
selection-describer.h
selection.h
selfname.tpl
seltrans.cpp
seltrans.h
seltrans-handles.cpp
seltrans-handles.h
shape-editor.cpp
shape-editor.h
shortcuts.cpp
shortcuts.h
snap.cpp
snap.h
snapped-line.cpp
snapped-line.h
snapped-point.cpp
snapped-point.h
snapper.cpp
snapper.h
sp-anchor.cpp
sp-anchor.h
sp-animation.cpp
sp-animation.h
sp-clippath.cpp
sp-clippath.h
sp-conn-end.cpp
sp-conn-end.h
sp-conn-end-pair.cpp
sp-conn-end-pair.h
sp-cursor.cpp
sp-cursor.h
sp-defs.cpp
sp-defs.h
sp-ellipse.cpp
sp-ellipse.h
sp-feblend.cpp
sp-feblend-fns.h
sp-feblend.h
sp-fecolormatrix.cpp
sp-fecolormatrix-fns.h
sp-fecolormatrix.h
sp-fecomponenttransfer.cpp
sp-fecomponenttransfer-fns.h
sp-fecomponenttransfer-funcnode.cpp
sp-fecomponenttransfer-funcnode.h
sp-fecomponenttransfer.h
sp-fecomposite.cpp
sp-fecomposite-fns.h
sp-fecomposite.h
sp-feconvolvematrix.cpp
sp-feconvolvematrix-fns.h
sp-feconvolvematrix.h
sp-fediffuselighting.cpp
sp-fediffuselighting-fns.h
sp-fediffuselighting.h
sp-fedisplacementmap.cpp
sp-fedisplacementmap-fns.h
sp-fedisplacementmap.h
sp-fedistantlight.cpp
sp-fedistantlight.h
sp-feflood.cpp
sp-feflood-fns.h
sp-feflood.h
sp-feimage.cpp
sp-feimage-fns.h
sp-feimage.h
sp-femerge.cpp
sp-femerge-fns.h
sp-femerge.h
sp-femergenode.cpp
sp-femergenode.h
sp-femorphology.cpp
sp-femorphology-fns.h
sp-femorphology.h
sp-feoffset.cpp
sp-feoffset-fns.h
sp-feoffset.h
sp-fepointlight.cpp
sp-fepointlight.h
sp-fespecularlighting.cpp
sp-fespecularlighting-fns.h
sp-fespecularlighting.h
sp-fespotlight.cpp
sp-fespotlight.h
sp-fetile.cpp
sp-fetile-fns.h
sp-fetile.h
sp-feturbulence.cpp
sp-feturbulence-fns.h
sp-feturbulence.h
sp-filter.cpp
sp-filter-fns.h
sp-filter.h
sp-filter-primitive.cpp
sp-filter-primitive.h
sp-filter-reference.cpp
sp-filter-reference.h
sp-filter-units.h
sp-flowdiv.cpp
sp-flowdiv.h
sp-flowregion.cpp
sp-flowregion.h
sp-flowtext.cpp
sp-flowtext.h
sp-font.cpp
sp-font.h
sp-gaussian-blur.cpp
sp-gaussian-blur-fns.h
sp-gaussian-blur.h
sp-glyph.cpp
sp-glyph.h
sp-gradient.cpp
sp-gradient-fns.h
sp-gradient.h
sp-gradient-reference.cpp
sp-gradient-reference.h
sp-gradient-spread.h
sp-gradient-test.h
sp-gradient-units.h
sp-gradient-vector.h
sp-guide-attachment.h
sp-guide-constraint.h
sp-guide.cpp
sp-guide.h
sp-image.cpp
sp-image.h
spiral-context.cpp
spiral-context.h
sp-item.cpp
sp-item-group.cpp
sp-item-group.h
sp-item.h
sp-item-notify-moveto.cpp
sp-item-notify-moveto.h
sp-item-rm-unsatisfied-cns.cpp
sp-item-rm-unsatisfied-cns.h
sp-item-transform.cpp
sp-item-transform.h
sp-item-update-cns.cpp
sp-item-update-cns.h
sp-linear-gradient-fns.h
sp-linear-gradient.h
sp-line.cpp
sp-line.h
splivarot.cpp
splivarot.h
sp-lpe-item.cpp
sp-lpe-item.h
sp-marker-loc.h
sp-mask.cpp
sp-mask.h
sp-metadata.cpp
sp-metadata.h
sp-metric.h
sp-metrics.cpp
sp-metrics.h
sp-missing-glyph.cpp
sp-missing-glyph.h
sp-namedview.cpp
sp-namedview.h
sp-object.cpp
sp-object-group.cpp
sp-object-group.h
sp-object.h
sp-object-repr.cpp
sp-object-repr.h
sp-offset.cpp
sp-offset.h
sp-paint-server.cpp
sp-paint-server.h
sp-path.cpp
sp-path.h
sp-pattern.cpp
sp-pattern.h
sp-polygon.cpp
sp-polygon.h
sp-polyline.cpp
sp-polyline.h
sp-radial-gradient-fns.h
sp-radial-gradient.h
sp-rect.cpp
sp-rect.h
sp-root.cpp
sp-root.h
sp-shape.cpp
sp-shape.h
sp-skeleton.cpp
sp-skeleton.h
sp-spiral.cpp
sp-spiral.h
sp-star.cpp
sp-star.h
sp-stop-fns.h
sp-stop.h
sp-string.cpp
sp-string.h
sp-style-elem.cpp
sp-style-elem.h
sp-style-elem-test.h
sp-switch.cpp
sp-switch.h
sp-symbol.cpp
sp-symbol.h
sp-text.cpp
sp-text.h
sp-textpath.h
sp-tref.cpp
sp-tref.h
sp-tref-reference.cpp
sp-tref-reference.h
sp-tspan.cpp
sp-tspan.h
sp-use.cpp
sp-use.h
sp-use-reference.cpp
sp-use-reference.h
star-context.cpp
star-context.h
streams-gzip.cpp
streams-gzip.h
streams-handles.cpp
streams-handles.h
streams-jar.cpp
streams-jar.h
streams-zlib.cpp
streams-zlib.h
streq.h
strneq.h
style.cpp
style.h
style-test.cpp
style-test.h
svg-profile.h
svg-view.cpp
svg-view.h
svg-view-widget.cpp
svg-view-widget.h
syseq.h
test-helpers.h
text-chemistry.cpp
text-chemistry.h
text-context.cpp
text-context.h
text-editing.cpp
text-editing.h
text-tag-attributes.h
tools-switch.cpp
tools-switch.h
transf_mat_3x4.cpp
transf_mat_3x4.h
TRPIFormatter.h
tweak-context.cpp
tweak-context.h
undo-stack-observer.h
unit-constants.h
uri.cpp
uri.h
uri-references.cpp
uri-references.h
vanishing-point.cpp
vanishing-point.h
verbs.cpp
verbs.h
verbs-test.h
version.cpp
version.h
zoom-context.cpp
zoom-context.h
${ONLY_WIN}

)

# make executable for INKSCAPE
ADD_EXECUTABLE(inkscape ${INKSCAPE_SRC})
TARGET_LINK_LIBRARIES(inkscape
	"${INKSCAPE_LINK_FLAGS}" 2geom avoid cola croco gdl nr nrtype vpsc livarot
)

# make executable for INKVIEW
ADD_EXECUTABLE(inkview inkview.cpp)
TARGET_LINK_LIBRARIES(inkview
	"${INKSCAPE_LINK_FLAGS}" 2geom avoid cola croco gdl nr nrtype vpsc livarot
)
#INSTALL(TARGETS INKSCAPE
#  RUNTIME DESTINATION bin
#  LIBRARY DESTINATION lib
#  ARCHIVE DESTINATION lib
#)

#FILE(GLOB files "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
#INSTALL(FILES ${files} DESTINATION include/INKSCAPE/INKSCAPE)

#CONFIGURE_FILE( ${CMAKE_SOURCE_DIR}/INKSCAPE.pc.in
#                ${CMAKE_BINARY_DIR}/INKSCAPE.pc @ONLY IMMEDIATE )
#INSTALL(FILES "${CMAKE_BINARY_DIR}/INKSCAPE.pc" DESTINATION lib/pkgconfig)
