File: CMakeLists.txt

package info (click to toggle)
scribus 1.4.8+dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • size: 244,532 kB
  • sloc: cpp: 274,439; xml: 12,534; python: 3,448; ansic: 3,438; makefile: 1,201; perl: 95; sh: 41
file content (1023 lines) | stat: -rw-r--r-- 35,052 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
##############################################################################################################
########## CMake Setup                                                                              ##########

#Set our CMake minimum version
#Require 2.4.2 for Qt finding
#Require 2.4.3 for moc change detection and rpath updates for custom cairo install
#its not likely 2.4.x will work any more
CMAKE_MINIMUM_REQUIRED(VERSION 2.6.0 FATAL_ERROR)

#IF(WIN32)
#  IF (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} LESS 2.6)
#    MESSAGE(FATAL_ERROR "Windows builds require CMake 2.6")
#  ENDIF (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} LESS 2.6)
#ENDIF(WIN32)

#Pretty colors
SET(CMAKE_COLOR_MAKEFILE ON)
#Dont force verbose
SET(CMAKE_VERBOSE_MAKEFILE OFF)
#Include current dir
SET(CMAKE_INCLUDE_CURRENT_DIR TRUE)

#RPATH setup - more below too
IF (WANT_NORPATH OR WANT_DISTROBUILD)
    SET(CMAKE_SKIP_RPATH TRUE)
ELSE (WANT_NORPATH OR WANT_DISTROBUILD)
    SET(CMAKE_SKIP_BUILD_RPATH TRUE)
    SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
    SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
    SET(CMAKE_SKIP_RULE_DEPENDENCY TRUE)
ENDIF (WANT_NORPATH OR WANT_DISTROBUILD)

INCLUDE(CheckIncludeFile)
INCLUDE(CheckCCompilerFlag)
INCLUDE(CheckCXXCompilerFlag)
INCLUDE(CheckTypeSize)
INCLUDE(TestBigEndian)
INCLUDE(GNUInstallDirs)

#Set the custom CMake module directory where our include/lib finders are
SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules")

##############################################################################################################
########## toplevel compiler flags                                                                  ##########

# CHECK_C_COMPILER_FLAG(" ${CMAKE_SHARED_LIBRARY_C_FLAGS}" C_HAVE_PIC)
# CHECK_CXX_COMPILER_FLAG(" ${CMAKE_SHARED_LIBRARY_C_FLAGS}" CXX_HAVE_PIC)
# IF (CXX_HAVE_PIC AND C_HAVE_PIC)
#     SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_SHARED_LIBRARY_C_FLAGS}")
#     SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_SHARED_LIBRARY_C_FLAGS}")
# ELSE (CXX_HAVE_PIC AND C_HAVE_PIC)
#     MESSAGE(FATAL_ERROR "Shared library support is missing")
# ENDIF (CXX_HAVE_PIC AND C_HAVE_PIC)

# SET(CMAKE_SHARED_MODULE_LINK_FLAGS "${CMAKE_SHARED_MODULE_LINK_FLAGS} -export-dynamic")
# SET(CMAKE_SHARED_MODULE_LINK_CXX_FLAGS "${CMAKE_SHARED_MODULE_LINK_CXX_FLAGS} -export-dynamic")
# SET(CMAKE_SHARED_LIBRARY_C_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS} -export-dynamic")
# SET(CMAKE_SHARED_LIBRARY_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS} -export-dynamic")
# MESSAGE(STATUS ${CMAKE_SHARED_MODULE_LINK_FLAGS})
# MESSAGE(STATUS ${CMAKE_SHARED_MODULE_LINK_CXX_FLAGS})
# MESSAGE(STATUS ${CMAKE_SHARED_LIBRARY_C_FLAGS})
# MESSAGE(STATUS ${CMAKE_SHARED_LIBRARY_CXX_FLAGS})
# MESSAGE(STATUS ${CMAKE_CXX_CREATE_SHARED_MODULE})
# MESSAGE(STATUS ${CMAKE_CXX_CREATE_SHARED_LIBRARY})

#IMPORT FROM COMMANDLINE
# SET with cmake -DWANT_CAIRO=1, etc
# MESSAGE(STATUS ${WANT_CAIRO})
# MESSAGE(STATUS ${WANT_LIBART})
# MESSAGE(STATUS ${WANT_DEBUG})

# SET(WANT_CAIRO 0)
# SET(WANT_LIBART 1)

#Project Setup
PROJECT(scribus)
#Set our version values
#Final version is ${VERSION} = ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}.${VERSION_SUFFIX}
#where VERSION_SUFFIX is of the form "", "svn" or "Nsvn" (N being the minor patch level)
SET (VERSION_MAJOR "1")
SET (VERSION_MINOR "4")
SET (VERSION_PATCH "8")
SET (VERSION_SUFFIX "")
SET (VERSION ${VERSION_MAJOR})
IF (VERSION_MINOR GREATER -1)
  SET (VERSION ${VERSION}.${VERSION_MINOR})
ENDIF (VERSION_MINOR GREATER -1)
IF (VERSION_PATCH GREATER -1)
  SET (VERSION ${VERSION}.${VERSION_PATCH})
ENDIF (VERSION_PATCH GREATER -1)
IF (VERSION_SUFFIX)
  SET (VERSION ${VERSION}.${VERSION_SUFFIX})
ENDIF (VERSION_SUFFIX)
MESSAGE(STATUS "Scribus ${VERSION} will be built to install into ${CMAKE_INSTALL_PREFIX}")

#Set the permissions to be used when installing plugins
SET(PLUGIN_PERMISSIONS WORLD_EXECUTE GROUP_EXECUTE OWNER_EXECUTE WORLD_READ GROUP_READ OWNER_READ OWNER_WRITE)

#Our main directory is scribus
SET(MAIN_DIR_NAME "scribus")

##############################################################################################################
########## check for the CPU we build for                                                           ##########

EXECUTE_PROCESS(
    COMMAND ${CMAKE_C_COMPILER} -dumpmachine
    OUTPUT_VARIABLE MACHINE
    OUTPUT_STRIP_TRAILING_WHITESPACE
)

MESSAGE(STATUS  "Machine: ${MACHINE}, void pointer size: ${CMAKE_SIZEOF_VOID_P}")
STRING(REGEX MATCH "(i[0-9]86-*)|(athlon-*)|(pentium-*)" _machine_x86 "${MACHINE}")
IF (_machine_x86)
    MESSAGE(STATUS "Found target X86")
    SET(ARCH_X86 1)
ENDIF (_machine_x86)

STRING(REGEX MATCH "(x86_64-*)|(X86_64-*)|(AMD64-*)|(amd64-*)" _machine_x86_64 "${MACHINE}")
IF (_machine_x86_64)
    MESSAGE(STATUS "Found target X86_64")
    SET(ARCH_X86_64 1)
ENDIF (_machine_x86_64)

IF (APPLE AND CMAKE_SIZEOF_VOID_P EQUAL 8 AND (ARCH_X86 EQUAL 1 OR ARCH_X86_64 EQUAL 1))
	STRING(REGEX REPLACE ".*-darwin([0-9]+).*" "\\1" _apple_ver "${MACHINE}")
	IF (_apple_ver EQUAL "14")
		MESSAGE(STATUS "Found OSX Yosemite Target: Apple, 64 bit, X86")
		SET(APPLE_10_10_X 1 CACHE TYPE BOOL)
	ENDIF (_apple_ver EQUAL "14")
	IF (_apple_ver EQUAL "13")
		MESSAGE(STATUS "Found OSX Mavericks Target: Apple, 64 bit, X86")
		SET(APPLE_10_9_X 1 CACHE TYPE BOOL)
	ENDIF (_apple_ver EQUAL "13")
	IF (_apple_ver EQUAL "12")
		MESSAGE(STATUS "Found OSX Mountain Lion Target: Apple, 64 bit, X86")
		SET(APPLE_10_8_X 1 CACHE TYPE BOOL)
	ENDIF (_apple_ver EQUAL "12")
	IF (_apple_ver EQUAL "11")
		MESSAGE(STATUS "Found OSX Lion Target: Apple, 64 bit, X86")
		SET(APPLE_10_7_X 1 CACHE TYPE BOOL)
	ENDIF (_apple_ver EQUAL "11")
	IF (_apple_ver EQUAL "10")
		MESSAGE(STATUS "Found OSX Snow Leopard Target: Apple, 64 bit, X86")
		SET(APPLE_10_6_X 1 CACHE TYPE BOOL)
	ENDIF (_apple_ver EQUAL "10")
	IF (_apple_ver EQUAL "9")
		MESSAGE(STATUS "Found OSX Leopard Target: Apple, 32 bit, X86")
		SET(APPLE_10_5_X 1 CACHE TYPE BOOL)
	ENDIF (_apple_ver EQUAL "9")
	UNSET(ARCH_X86)
ENDIF (APPLE AND CMAKE_SIZEOF_VOID_P EQUAL 8 AND (ARCH_X86 EQUAL 1 OR ARCH_X86_64 EQUAL 1))

STRING(REGEX MATCH "(sparc64-*)|(SPARC64-*)" _machine_sparc_64 "${MACHINE}")
IF (_machine_sparc_64)
    MESSAGE(STATUS "Found target SPARC 64")
    SET(ARCH_SPARC_64 1)
ENDIF (_machine_sparc_64)

STRING(REGEX MATCH "(mips64-*)|(MIPS64-*)" _machine_mips_64 "${MACHINE}")
IF (_machine_mips_64)
    MESSAGE(STATUS "Found target MIPS 64")
    SET(ARCH_MIPS_64 1)
ENDIF (_machine_mips_64)

STRING(REGEX MATCH "(mips-*)|(MIPS-*)" _machine_mips "${MACHINE}")
IF (_machine_mips)
    MESSAGE(STATUS "Found target MIPS")
    SET(ARCH_MIPS 1)
ENDIF (_machine_mips)

STRING(REGEX MATCH "(hppa-*)" _machine_hppa "${MACHINE}")
IF (_machine_hppa)
    MESSAGE(STATUS "Found target HPPA")
    SET(ARCH_HPPA 1)
ENDIF (_machine_hppa)

STRING(REGEX MATCH "(ppc-*)|(powerpc-*)" _machine_ppc "${MACHINE}")
IF (_machine_ppc)
    MESSAGE(STATUS "Found target PPC")
    SET(ARCH_PPC 1)
ENDIF (_machine_ppc)

STRING(REGEX MATCH "(ppc64-*)|(PPC64-*)|(powerpc64-*)" _machine_ppc_64 "${MACHINE}")
IF (_machine_ppc_64)
    MESSAGE(STATUS "Found target PPC64")
    SET(ARCH_PPC_64 1)
ENDIF (_machine_ppc_64)

STRING(REGEX MATCH "(sparc-*)" _machine_sparc "${MACHINE}")
IF (_machine_sparc)
    MESSAGE(STATUS "Found target Sparc")
    SET(ARCH_SPARC 1)
ENDIF (_machine_sparc)

STRING(REGEX MATCH "(sparcv9-*)" _machine_sparcv9 "${MACHINE}")
IF (_machine_sparcv9)
    MESSAGE(STATUS "Found target Sparc v9")
    SET(ARCH_SPARCV9 1)
ENDIF (_machine_sparcv9)

STRING(REGEX MATCH "(sparc64-*)" _machine_sparc64 "${MACHINE}")
IF (_machine_sparc64)
    MESSAGE(STATUS "Found target Sparc64")
    SET(ARCH_SPARC64 1)
    SET(ARCH64BIT 1)
ENDIF (_machine_sparc64)

#convert any 64 bit build into generic 64 tag for below
IF (ARCH_X86_64 OR ARCH_SPARC_64 OR ARCH_MIPS_64 OR ARCH_PPC_64) 
  SET(ARCH64BIT 1)
ENDIF (ARCH_X86_64 OR ARCH_SPARC_64 OR ARCH_MIPS_64 OR ARCH_PPC_64) 

MESSAGE(STATUS "Building for target ${MACHINE}")

##############################################################################################################
########## Versioning Setup                                                                         ##########

#On Apple, we ignore the versioning tag so all items are "scribus" not "scribus-version"
IF (NOT BUILD_OSX_BUNDLE)
  SET(BUILD_OSX_BUNDLE ${APPLE} CACHE TYPE BOOL)
ENDIF (NOT BUILD_OSX_BUNDLE)

#Simplify future conditionals for Apple
IF (APPLE AND BUILD_OSX_BUNDLE)
  SET(APPLEBUNDLE TRUE CACHE TYPE BOOL)
ENDIF (APPLE AND BUILD_OSX_BUNDLE)

#Announce we cached a version request before, overridden below for OSX
IF(TAG_VERSION)
  IF (NOT APPLEBUNDLE)
    MESSAGE(STATUS "Previously selected version tag: ${TAG_VERSION}")
  ENDIF (NOT APPLEBUNDLE)
  SET(WANT_VERSIONING 1)
  SET(CACHED_VERSIONING 1)
ENDIF(TAG_VERSION)

#Remove version tags on OSX so our bundle is Scribus.app
IF (APPLEBUNDLE)
  IF (WANT_VERSIONING OR CACHED_VERSIONING)
    MESSAGE(STATUS "Ignoring version tag on OSX when building bundle")
    SET(WANT_VERSIONING 0)
    SET(CACHED_VERSIONING 0)
  ENDIF (WANT_VERSIONING OR CACHED_VERSIONING)
ENDIF (APPLEBUNDLE)

#Store our version string if require
IF (WANT_VERSIONING AND NOT CACHED_VERSIONING)
  IF (NOT CUSTOM_VERSIONTAG)
    SET(TAG_VERSION "-${VERSION}" CACHE TYPE STRING)
  ELSE (NOT CUSTOM_VERSIONTAG)
    SET(TAG_VERSION ${CUSTOM_VERSIONTAG} CACHE TYPE STRING)
  ENDIF (NOT CUSTOM_VERSIONTAG)
ENDIF (WANT_VERSIONING AND NOT CACHED_VERSIONING)

##############################################################################################################
########## Install/Directory Setup                                                                  ##########

IF (APPLEBUNDLE)
  IF ("${CMAKE_INSTALL_PREFIX}" MATCHES "[.]app/Contents/?$")
    # all ok
  ELSE ("${CMAKE_INSTALL_PREFIX}" MATCHES "[.]app/Contents/?$")
    IF ("${CMAKE_INSTALL_PREFIX}" MATCHES "[.]app/?$")
      # add "/Contents" subpath
      SET(CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/Contents")
    ELSE ("${CMAKE_INSTALL_PREFIX}" MATCHES "[.]app/?$")
      # no bundle name spcified, use appname and version
      SET(CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/Scribus${VERSION}.app/Contents")
    ENDIF ("${CMAKE_INSTALL_PREFIX}" MATCHES "[.]app/?$")
  ENDIF ("${CMAKE_INSTALL_PREFIX}" MATCHES "[.]app/Contents/?$")

  MESSAGE(STATUS "APPLEBUNDLE install prefix: ${CMAKE_INSTALL_PREFIX}")
ENDIF (APPLEBUNDLE)


#Setp all the directories we will use
#MAN
CMAKE_POLICY(SET CMP0005 OLD)
SET(MANDIR "${CMAKE_INSTALL_DATAROOTDIR}/man/")
IF(WANT_VERSIONING)
    SET(SHAREDIR "${CMAKE_INSTALL_DATAROOTDIR}/${MAIN_DIR_NAME}${TAG_VERSION}/")
ELSE(WANT_VERSIONING)
    SET(SHAREDIR "${CMAKE_INSTALL_DATAROOTDIR}/${MAIN_DIR_NAME}/")
ENDIF(WANT_VERSIONING)
IF(NOT IS_ABSOLUTE ${SHAREDIR})
    ADD_DEFINITIONS("-DSHAREDIR=\\\"${CMAKE_INSTALL_PREFIX}/${SHAREDIR}\\\"")
ELSE()
    ADD_DEFINITIONS("-DSHAREDIR=\\\"${SHAREDIR}\\\"")
ENDIF()

#SHARE - use the default on Apple as TAG_VERSION is empty
IF(WIN32 OR OS2)
  SET(DOCDIR "${CMAKE_INSTALL_DATAROOTDIR}/doc/")
ELSE (WIN32 OR OS2)
  IF(TAG_VERSION OR BUILD_OSX_BUNDLE)
    SET(DOCDIR "${CMAKE_INSTALL_DATAROOTDIR}/doc/${MAIN_DIR_NAME}${TAG_VERSION}/")
  ELSE(TAG_VERSION OR BUILD_OSX_BUNDLE)
        IF(NOT WANT_VERSIONING)
            SET(DOCDIR "${CMAKE_INSTALL_DATAROOTDIR}/doc/${MAIN_DIR_NAME}/")
        ELSE(NOT WANT_VERSIONING)
            SET(DOCDIR "${CMAKE_INSTALL_DATAROOTDIR}/doc/${MAIN_DIR_NAME}-${VERSION}/")
        ENDIF(NOT WANT_VERSIONING)
  ENDIF (TAG_VERSION OR BUILD_OSX_BUNDLE)
ENDIF (WIN32 OR OS2)
IF(NOT IS_ABSOLUTE ${DOCDIR})
    ADD_DEFINITIONS("-DDOCDIR=\\\"${CMAKE_INSTALL_PREFIX}/${DOCDIR}\\\"")
ELSE()
    ADD_DEFINITIONS("-DDOCDIR=\\\"${DOCDIR}\\\"")
ENDIF()

#ICON
IF(WIN32)
  SET(ICONDIR "${CMAKE_INSTALL_DATAROOTDIR}/icons/")
ELSE(WIN32)
  SET(ICONDIR "${CMAKE_INSTALL_DATAROOTDIR}/${MAIN_DIR_NAME}${TAG_VERSION}/icons/")
ENDIF(WIN32)
IF(NOT IS_ABSOLUTE ${ICONDIR})
    ADD_DEFINITIONS("-DICONDIR=\\\"${CMAKE_INSTALL_PREFIX}/${ICONDIR}\\\"")
ELSE()
    ADD_DEFINITIONS("-DICONDIR=\\\"${ICONDIR}\\\"")
ENDIF()

#SAMPLES
SET(SAMPLESDIR "${CMAKE_INSTALL_DATAROOTDIR}/${MAIN_DIR_NAME}${TAG_VERSION}/samples/")
IF(NOT IS_ABSOLUTE ${SAMPLESDIR})
    ADD_DEFINITIONS("-DSAMPLESDIR=\\\"${CMAKE_INSTALL_PREFIX}/${SAMPLESDIR}\\\"")
ELSE()
    ADD_DEFINITIONS("-DSAMPLESDIR=\\\"${SAMPLESDIR}\\\"")
ENDIF()

#SCRIPTS
SET(SCRIPTSDIR "${CMAKE_INSTALL_DATAROOTDIR}/${MAIN_DIR_NAME}${TAG_VERSION}/scripts/")
IF(NOT IS_ABSOLUTE ${SCRIPTSDIR})
    ADD_DEFINITIONS("-DSCRIPTSDIR=\\\"${CMAKE_INSTALL_PREFIX}/${SCRIPTSDIR}\\\"")
ELSE()
    ADD_DEFINITIONS("-DSCRIPTSDIR=\\\"${SCRIPTSDIR}\\\"")
ENDIF()

#TEMPLATES
IF(WIN32)
  SET(TEMPLATEDIR "${CMAKE_INSTALL_DATAROOTDIR}/templates/")
ELSE(WIN32)
  SET(TEMPLATEDIR "${CMAKE_INSTALL_DATAROOTDIR}/${MAIN_DIR_NAME}${TAG_VERSION}/templates/")
ENDIF(WIN32)
IF(NOT IS_ABSOLUTE ${TEMPLATEDIR})
    ADD_DEFINITIONS("-DTEMPLATEDIR=\\\"${CMAKE_INSTALL_PREFIX}/${TEMPLATEDIR}\\\"")
ELSE()
    ADD_DEFINITIONS("-DTEMPLATEDIR=\\\"${TEMPLATEDIR}\\\"")
ENDIF()

#DESKTOP
SET(DESKTOPDIR "${CMAKE_INSTALL_DATAROOTDIR}/applications/")
IF(NOT IS_ABSOLUTE ${DESKTOPDIR})
    ADD_DEFINITIONS("-DDESKTOPDIR=\\\"${CMAKE_INSTALL_PREFIX}/${DESKTOPDIR}\\\"")
ELSE()
    ADD_DEFINITIONS("-DDESKTOPDIR=\\\"${DESKTOPDIR}\\\"")
ENDIF()

#APPDATA
SET(APPDATADIR "${CMAKE_INSTALL_DATAROOTDIR}/metainfo/")
IF(NOT IS_ABSOLUTE ${APPDATADIRR})
    ADD_DEFINITIONS("-DAPPDATADIR=\\\"${CMAKE_INSTALL_PREFIX}/${APPDATADIR}\\\"")
ELSE()
    ADD_DEFINITIONS("-DAPPDATADIR=\\\"${APPDATADIR}\\\"")
ENDIF()


# APPLICATION_DATA_DIR
# It allows specify the user configuration directory in the compile time.
# Example: I want to use special ~/.scribus135svn config directory for my trunk
#          cmake -DAPPLICATION_DATA_DIR=.scribus135svn ...
IF (APPLICATION_DATA_DIR)
	MESSAGE(STATUS "Using ApplicationDataDir ${APPLICATION_DATA_DIR} instead of the platform default.")
    ADD_DEFINITIONS("-DAPPLICATION_DATA_DIR=\\\"${APPLICATION_DATA_DIR}\\\"")
ELSE (APPLICATION_DATA_DIR)
    MESSAGE(STATUS "Using standard ApplicationDataDir. You can change it with -DAPPLICATION_DATA_DIR")
ENDIF (APPLICATION_DATA_DIR)

#LIB LOCATION - lib or lib64 normally
#LIB
IF(WANT_LIB64)
  IF(NOT ARCH_X86_64)
    MESSAGE(STATUS "WARNING: BUILDING 64 Bit build on non 64 bit architecture")
  ENDIF(NOT ARCH_X86_64)
  SET(LIB_SUFFIX "64" CACHE TYPE STRING)
ENDIF(WANT_LIB64)
SET(LIB_DIR_NAME "lib${LIB_SUFFIX}")
IF (APPLEBUNDLE)
  SET(LIBDIR "lib/")
ELSE (APPLEBUNDLE)
  SET(LIBDIR "${LIB_DIR_NAME}/${MAIN_DIR_NAME}${TAG_VERSION}/")
ENDIF (APPLEBUNDLE)
ADD_DEFINITIONS("-DLIBDIR=\\\"${CMAKE_INSTALL_PREFIX}/${LIBDIR}\\\"")

#PLUGINS
IF(WIN32)
  SET(PLUGINDIR "plugins")
ELSE(WIN32)
  IF (APPLEBUNDLE)
    SET(PLUGINDIR "${LIBDIR}")
  ELSE (APPLEBUNDLE)
    SET(PLUGINDIR "${LIB_DIR_NAME}/${MAIN_DIR_NAME}${TAG_VERSION}/plugins/")
  ENDIF (APPLEBUNDLE)
ENDIF(WIN32)
ADD_DEFINITIONS("-DPLUGINDIR=\\\"${CMAKE_INSTALL_PREFIX}/${PLUGINDIR}\\\"")

#INCLUDE
SET(INCLUDEDIR "include/${MAIN_DIR_NAME}${TAG_VERSION}/")
#NO ADD DEFINITIONS, WE ONLY INSTALL WITH IT

#RPATH
IF (WANT_NORPATH OR WANT_DISTROBUILD)
  set(CMAKE_INSTALL_RPATH "")
ELSE (WANT_NORPATH OR WANT_DISTROBUILD)
  set(CMAKE_INSTALL_RPATH ${PLUGINDIR})
ENDIF (WANT_NORPATH OR WANT_DISTROBUILD)

# Set the XDG mime stuff
SET(MIMEDIR "${CMAKE_INSTALL_DATAROOTDIR}/mime/packages/")

##############################################################################################################
########## Build Setup                                                                              ##########

#Convert our simpler command line option to the CMake style
#None, Debug, Release, .. or custom ones
# SET(WANT_DEBUG 1)
IF(WANT_DEBUG)
  SET(CMAKE_BUILD_TYPE Debug)
ENDIF(WANT_DEBUG)
IF (WANT_RELEASEWITHDEBUG)
  SET(CMAKE_BUILD_TYPE RelWithDebInfo)
ENDIF (WANT_RELEASEWITHDEBUG)
IF(NOT WANT_DEBUG AND NOT WANT_RELEASEWITHDEBUG)
  SET(CMAKE_BUILD_TYPE RELEASE)
ENDIF(NOT WANT_DEBUG AND NOT WANT_RELEASEWITHDEBUG)



#Based on our build type, setup our build options
IF(APPLE)
	IF(APPLE_10_10_X)
		SET(OSXMINVER "10.10" CACHE TYPE STRING)
		IF (WANT_OSX_SDK)
			SET(CMAKE_OSX_SYSROOT "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk")
		ENDIF (WANT_OSX_SDK)
	ENDIF(APPLE_10_10_X)
	IF(APPLE_10_9_X)
		SET(OSXMINVER "10.9" CACHE TYPE STRING)
		IF (WANT_OSX_SDK)
			SET(CMAKE_OSX_SYSROOT "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk")
		ENDIF (WANT_OSX_SDK)
	ENDIF(APPLE_10_9_X)
	IF(APPLE_10_8_X)
		SET(OSXMINVER "10.8" CACHE TYPE STRING)
		IF (WANT_OSX_SDK)
			SET(CMAKE_OSX_SYSROOT "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk")
		ENDIF (WANT_OSX_SDK)
	ENDIF(APPLE_10_8_X)
	IF(APPLE_10_7_X)
		SET(OSXMINVER "10.7" CACHE TYPE STRING)
		IF (WANT_OSX_SDK)
			SET(CMAKE_OSX_SYSROOT "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk")
		ENDIF (WANT_OSX_SDK)
	ENDIF(APPLE_10_7_X)
	IF(APPLE_10_6_X)
		SET(OSXMINVER "10.6" CACHE TYPE STRING)
		IF (WANT_OSX_SDK)
			SET(CMAKE_OSX_SYSROOT "/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.6.sdk")
		ENDIF (WANT_OSX_SDK)
	ENDIF(APPLE_10_6_X)
	IF(APPLE_10_5_X)
		SET(OSXMINVER "10.5" CACHE TYPE STRING)
		IF (WANT_OSX_SDK)
			SET(CMAKE_OSX_SYSROOT "/Developer/SDKs/MacOSX10.5.sdk")
		ENDIF (WANT_OSX_SDK)
	ENDIF(APPLE_10_5_X)
	IF(APPLE_10_4_X)
		SET(OSXMINVER "10.4" CACHE TYPE STRING)
		IF (WANT_OSX_SDK)
			SET(CMAKE_OSX_SYSROOT "/Developer/SDKs/MacOSX10.4u.sdk")
		ENDIF (WANT_OSX_SDK)
	ENDIF(APPLE_10_4_X)
	# gcc/mac
	IF(WANT_UNIVERSAL_BUNDLE)
		MESSAGE("Setting Universal (PPC/i386) Architecture for OSX Build/Bundle")
		SET(CMAKE_OSX_ARCHITECTURES "ppc;i386" )
		SET(CMAKE_TRY_COMPILE_OSX_ARCHITECTURES "ppc;i386" )
		IF (WANT_OSX_SDK)
			SET(CMAKE_OSX_DEPLOYMENT_TARGET "10.4")
		ENDIF (WANT_OSX_SDK)
	ELSE(WANT_UNIVERSAL_BUNDLE)
		IF(ARCH_PPC OR ARCH_PPC_64)
			MESSAGE("Setting PPC Architecture for OSX Build/Bundle")
			SET(CMAKE_OSX_ARCHITECTURES "ppc" )
			SET(CMAKE_TRY_COMPILE_OSX_ARCHITECTURES "ppc" )
		ELSE(ARCH_PPC OR ARCH_PPC_64)
			IF (WANT_OSX_SDK)
				SET(CMAKE_OSX_DEPLOYMENT_TARGET "${OSXMINVER}")
			ENDIF (WANT_OSX_SDK)
			IF(APPLE_10_6_X OR APPLE_10_7_X OR APPLE_10_8_X OR APPLE_10_9_X OR APPLE_10_10_X)
				MESSAGE("Setting x86_64 Architecture for OSX Build/Bundle")
				SET(CMAKE_OSX_ARCHITECTURES "x86_64" )
				SET(CMAKE_TRY_COMPILE_OSX_ARCHITECTURES "x86_64" )
			ELSE(APPLE_10_6_X OR APPLE_10_7_X OR APPLE_10_8_X OR APPLE_10_9_X OR APPLE_10_10_X)
				MESSAGE("Setting i386 Architecture for OSX Build/Bundle")
				SET(CMAKE_OSX_ARCHITECTURES "i386" )
				SET(CMAKE_TRY_COMPILE_OSX_ARCHITECTURES "i386" )
			ENDIF(APPLE_10_6_X OR APPLE_10_7_X OR APPLE_10_8_X OR APPLE_10_9_X OR APPLE_10_10_X)
		ENDIF(ARCH_PPC OR ARCH_PPC_64)
	ENDIF(WANT_UNIVERSAL_BUNDLE)
	MESSAGE(STATUS "${CMAKE_OSX_ARCHITECTURES} ${CMAKE_OSX_SYSROOT}")
	SET(ENV{MACOSX_DEPLOYMENT_TARGET} ${OSXMINVER} )
	SET(ENV{LD_PREBIND} 1 )
	SET(ENV{LD_PREBIND_ALLOW_OVERLAP} 1 )
	IF (WANT_DEBUG)
		SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3 -fno-inline-functions -Wall -mmacosx-version-min=${OSXMINVER}")
		SET(CMAKE_C_FLAGS_DEBUG "-O0 -g3 -fno-inline-functions -Wall -mmacosx-version-min=${OSXMINVER}")
	ENDIF (WANT_DEBUG)
	IF (WANT_RELEASEWITHDEBUG)
		SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g3 -fno-inline-functions -Wall -mmacosx-version-min=${OSXMINVER}")
		SET(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g3 -fno-inline-functions -Wall -mmacosx-version-min=${OSXMINVER}")
	ENDIF (WANT_RELEASEWITHDEBUG)
	IF (NOT WANT_DEBUG AND NOT WANT_RELEASEWITHDEBUG)
		SET(CMAKE_CXX_FLAGS_RELEASE "-O2 -fno-inline-functions -Wall -mmacosx-version-min=${OSXMINVER}")
		SET(CMAKE_C_FLAGS_RELEASE "-O2 -fno-inline-functions -Wall -mmacosx-version-min=${OSXMINVER}")
	ENDIF (NOT WANT_DEBUG AND NOT WANT_RELEASEWITHDEBUG)
ELSE(APPLE)
  IF(${CMAKE_GENERATOR} MATCHES "^(Visual Studio|NMake).*")
    # Windows build with Visual Studio
    # Surely there's a better way to identify the compiler?
    SET(CMAKE_CXX_FLAGS_DEBUG)
    SET(CMAKE_C_FLAGS_DEBUG)
  ELSE(${CMAKE_GENERATOR} MATCHES "^(Visual Studio|NMake).*")
    # vanilla gcc
    SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3 -Wall -fstrict-aliasing")
    SET(CMAKE_C_FLAGS_DEBUG "-O0 -g3 -Wall -fstrict-aliasing")
    
    IF (_machine_x86 OR _machine_x86_64)
      SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fPIC")
      SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fPIC")
    ENDIF (_machine_x86 OR _machine_x86_64)
    
  ENDIF(${CMAKE_GENERATOR} MATCHES "^(Visual Studio|NMake).*")
ENDIF(APPLE)

IF(${CMAKE_GENERATOR} MATCHES "^(Visual Studio|NMake).*")
  SET(CMAKE_CXX_FLAGS_RELEASE)
  SET(CMAKE_C_FLAGS_RELEASE)
ELSE(${CMAKE_GENERATOR} MATCHES "^(Visual Studio|NMake).*")
  SET(CMAKE_CXX_FLAGS_RELEASE "-O2 -Wall -fPIC")
  SET(CMAKE_C_FLAGS_RELEASE "-O2 -Wall -fPIC")
  ADD_DEFINITIONS(-DNDEBUG)
ENDIF(${CMAKE_GENERATOR} MATCHES "^(Visual Studio|NMake).*")

IF(WIN32)
  ADD_DEFINITIONS(-DWIN32_LEAN_AND_MEAN
                  -DAVOID_WIN32_FILEIO
                  -D_CRT_SECURE_NO_DEPRECATE
                  -D_USE_MATH_DEFINES
                  -DCOMPILE_PLUGIN_AS_DLL
  )
  SET(BUILD_WINDOWS_VERSION 1)
  SET(DLL_USE_NATIVE_API 1)
ENDIF(WIN32)

##############################################################################################################
########## Find Dependencies                                                                        ##########

#<< Qt
SET (QT_MT_REQUIRED TRUE)
SET (QT_MIN_VERSION "4.6.0")
IF(APPLE)
  IF (WANT_QT4MAC_COCOA)
	SET (QT_MAC_USE_COCOA TRUE)
  ELSE (WANT_QT4MAC_COCOA)
	SET (HAVE_CARBON 1 CACHE TYPE BOOL)
	ADD_DEFINITIONS("-DHAVE_CARBON=1")
  ENDIF (WANT_QT4MAC_COCOA)
  SET( QT_USE_QTSQL TRUE )
ENDIF(APPLE)
IF (WANT_QT3SUPPORT)
  SET (QT_USE_QT3SUPPORT TRUE)
ELSE (WANT_QT3SUPPORT)
  SET (QT_USE_QT3SUPPORT FALSE)
ENDIF (WANT_QT3SUPPORT)
SET (QT_USE_QTXML TRUE )
SET( QT_USE_QTNETWORK TRUE )
FIND_PACKAGE(Qt4 REQUIRED)
INCLUDE( ${QT_USE_FILE} )
IF (QT_FOUND)
  MESSAGE("Qt4 Found OK")
  IF (WANT_QT3SUPPORT)
    MESSAGE(STATUS "Building with Qt3 Support")
  ELSE (WANT_QT3SUPPORT)
    MESSAGE(STATUS "Building without Qt3 Support (GOOD)")
  ENDIF (WANT_QT3SUPPORT)
  #Add our Qt definitions
  ADD_DEFINITIONS(
    ${QT_DEFINITIONS}
    -DQT_CORE_LIB
    -DQT_GUI_LIB
    -DQT_THREAD_LIB
    -DQT_XML_LIB
  )
ELSE(QT_FOUND)
  MESSAGE(FATAL_ERROR "No Qt4 found")
ENDIF(QT_FOUND)
#>> Qt

#<< ZLIB, PNG
IF (WIN32)
  # On win32 we can use Qt's zlib and libpng, so we use some
  # custom cmake includes. This permits us to honour the 
  # USE_QT_ZLIB_PNGLIB flag if passed.
  SET(PNG_DIR ${CMAKE_MODULE_PATH})
  SET(ZLIB_DIR ${CMAKE_MODULE_PATH})
ENDIF (WIN32)
FIND_PACKAGE(ZLIB REQUIRED)
IF (ZLIB_FOUND)
  MESSAGE("ZLIB Library Found OK")
  SET(HAVE_LIBZ 1)
ENDIF(ZLIB_FOUND)
FIND_PACKAGE(PNG REQUIRED)
IF (PNG_FOUND)
  MESSAGE("PNG Library Found OK")
ENDIF(PNG_FOUND)
#>> ZLIB, PNG

#<< JPEG, TIFF
FIND_PACKAGE(JPEG REQUIRED)
IF (JPEG_FOUND)
  MESSAGE("JPEG Library Found OK")
ENDIF(JPEG_FOUND)
FIND_PACKAGE(TIFF REQUIRED)
IF (TIFF_FOUND)
  MESSAGE("TIFF Library Found OK")
  SET(HAVE_TIFF 1)
ELSE(TIFF_FOUND)
  MESSAGE(FATAL_ERROR "Could not find the TIFF Library")
ENDIF(TIFF_FOUND)
#<< JPEG, TIFF

#<< PYTHON
#SET(PythonLibs_FIND_VERSION 2)
FIND_PACKAGE(PythonLibs 2 REQUIRED)
IF (PYTHON_LIBRARY)
  MESSAGE("Python Library Found OK")
  SET(HAVE_PYTHON 1)
  SET(COMPILE_PYTHON 1)
ENDIF(PYTHON_LIBRARY)
#>> PYTHON

#<< FreeType2
IF (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} LESS 2.6)
  SET(FREETYPE_DIR ${CMAKE_MODULE_PATH})
  FIND_PACKAGE(FREETYPE REQUIRED)
  IF(FREETYPE_FOUND)
    MESSAGE("FreeType2 Library Found OK")
    INCLUDE(CheckLibraryExists)
    CHECK_LIBRARY_EXISTS(${FREETYPE_LIBRARY} FT_Get_First_Char "" HAVE_FREETYPE_FIRST)
    CHECK_LIBRARY_EXISTS(${FREETYPE_LIBRARY} FT_Get_Next_Char "" HAVE_FREETYPE_NEXT)
  ENDIF(FREETYPE_FOUND)
  SET(CFLAGS "${CFLAGS}"."${LIBFREETYPE_CFLAGS}")
ELSE(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} LESS 2.6)
  FIND_PACKAGE(Freetype REQUIRED)
  IF (FREETYPE_FOUND)
    MESSAGE(STATUS "FreeType2 Library Found OK")
    INCLUDE(CheckLibraryExists)
    CHECK_LIBRARY_EXISTS(${FREETYPE_LIBRARY} FT_Get_First_Char "" HAVE_FREETYPE_FIRST)
    CHECK_LIBRARY_EXISTS(${FREETYPE_LIBRARY} FT_Get_Next_Char "" HAVE_FREETYPE_NEXT)
    # here we have an alternative
    # a) Setup CFLAGS with the FREETYPE_INCLUDE_DIR_freetype2 provided by cmake
    # b) Insert ${FREETYPE_INCLUDE_DIRS} in include sections of CMakeLists that need it
    # I prefer (b) and at some point & from my opinion it should  be just needed in scribus/fonts/CmakeLists.txt - pm
  ELSE (FREETYPE_FOUND)
    MESSAGE(FATAL_ERROR "No Freetype Found")
  ENDIF(FREETYPE_FOUND)
ENDIF(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} LESS 2.6)
#>> FreeType2

#<<Render Library
# Select our rendering library
# As of Scribus 1.3.5, we can use cairo or Qt4's Arthur
# If we have a RENDER_LIB selected from a previous cmake run, then use it
# otherwise, we should be defaulting to Libart_LGPL for 1.3.4.x
IF(RENDER_LIB)
  MESSAGE(STATUS "Previously selected rendering system: ${RENDER_LIB}")
ELSE(RENDER_LIB)
  IF (NOT WANT_QTARTHUR)
    SET(WANT_CAIRO 1)
  ENDIF (NOT WANT_QTARTHUR)
ENDIF(RENDER_LIB)

IF (WANT_CAIRO OR RENDER_LIB STREQUAL "CAIRO")
  SET(CAIRO_DIR ${CMAKE_MODULE_PATH})
  FIND_PACKAGE(CAIRO)
  IF(CAIRO_FOUND)
    MESSAGE("CAIRO Library Found OK")
    SET(RENDER_LIB "CAIRO" CACHE TYPE STRING)
  ELSE(CAIRO_FOUND)
    SET(OLDRENDERLIBLOST TRUE)
  ENDIF(CAIRO_FOUND)
ENDIF (WANT_CAIRO OR RENDER_LIB STREQUAL "CAIRO")

#Cairo is required on Windows for printing system
IF (WIN32)
  IF (NOT CAIRO_FOUND)
    MESSAGE(FATAL_ERROR "Cairo >= 1.5.16 is required for Windows build")  
  ENDIF (NOT CAIRO_FOUND)
ENDIF (WIN32)

IF (OLDRENDERLIBLOST OR WANT_QTARTHUR OR RENDER_LIB STREQUAL "QTARTHUR" OR NOT RENDER_LIB)
  SET(RENDER_LIB "QTARTHUR" CACHE TYPE STRING)
  MESSAGE("Qt4's Arthur selected for renderer")
  IF (OLDRENDERLIBLOST)
    MESSAGE("CAIRO could no longer be found, replaced by Qt4's Arthur")
  ENDIF (OLDRENDERLIBLOST)
ENDIF (OLDRENDERLIBLOST OR WANT_QTARTHUR OR RENDER_LIB STREQUAL "QTARTHUR" OR NOT RENDER_LIB)
#>>Render Library

#<<CUPS
IF(NOT WIN32 AND NOT HAIKU)
  IF (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} LESS 2.5)
    SET(Cups_DIR ${CMAKE_MODULE_PATH})
  ENDIF (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} LESS 2.5)
  FIND_PACKAGE(Cups REQUIRED)
  IF(CUPS_FOUND)
    SET(HAVE_CUPS 1)
    MESSAGE("CUPS Library Found OK")
  ENDIF(CUPS_FOUND)
ELSE (NOT WIN32 AND NOT HAIKU)
  # Windows doesn't use CUPS
  SET(CUPS_INCLUDE_DIR)
ENDIF(NOT WIN32 AND NOT HAIKU)
#>>CUPS

#<<LibXML2
IF (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} LESS 2.5)
  SET(LibXml2_DIR ${CMAKE_MODULE_PATH})
ENDIF (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} LESS 2.5)
FIND_PACKAGE(LibXml2 REQUIRED)
IF(LIBXML2_FOUND)
  SET(HAVE_XML 1)
  MESSAGE("LIBXML2 Library Found OK")
ENDIF(LIBXML2_FOUND)
#>>LibXML2

#<<LittleCMS
SET(LCMS_DIR ${CMAKE_MODULE_PATH})
FIND_PACKAGE(LCMS2)
IF (LCMS2_FOUND)
  IF (LCMS2_VERSION GREATER 2010 OR LCMS2_VERSION EQUAL 2010)
    SET(HAVE_CMS 1)
    SET(HAVE_LCMS21 1)
    SET(CMS_INC "\"lcms2.h\"")
    MESSAGE("LittleCMS Library >= 2.1 Found OK")
  ENDIF (LCMS2_VERSION GREATER 2010 OR LCMS2_VERSION EQUAL 2010)
ENDIF (LCMS2_FOUND)
IF (NOT HAVE_LCMS21)
  FIND_PACKAGE(LCMS REQUIRED)
  IF(LCMS_FOUND)
    SET(HAVE_CMS 1)
    SET(CMS_INC "\"lcms.h\"")
    MESSAGE("LittleCMS Library Found OK")
  ELSE(LCMS_FOUND)
    MESSAGE(FATAL_ERROR "Could not find the LittleCMS Library")
  ENDIF(LCMS_FOUND)
ENDIF (NOT HAVE_LCMS21)
#>>LittleCMS

#<<FontConfig
IF(NOT WIN32)
  SET(FONTCONFIG_DIR ${CMAKE_MODULE_PATH})
  FIND_PACKAGE(FONTCONFIG)
  IF(FONTCONFIG_FOUND)
	MESSAGE("FontConfig Found OK")
	SET(HAVE_FONTCONFIG 1)
  ENDIF(FONTCONFIG_FOUND)
ELSE(NOT WIN32)
  # Windows builds neither use nor require fontconfig
  SET(FONTCONFIG_INCLUDE_DIR)
ENDIF(NOT WIN32)
#>>FontConfig

#<<ASPELL for Speelling support
#OPTION(WITH_ASPELL "Enable support for spell checking" ON)
#IF (WITH_ASPELL)
#  FIND_PACKAGE(ASPELL)
#  IF (ASPELL_FOUND)
#    MESSAGE("ASpell Found OK")
#    SET(HAVE_ASPELL 1)
#  ELSE (ASPELL_FOUND)
#    MESSAGE("ASpell or its developer libraries NOT found - Disabling support for spell checking")
#  ENDIF (ASPELL_FOUND)
#ENDIF (WITH_ASPELL)
#>>ASPELL for Speelling support

#<<HUNSPELL for Speelling support
OPTION(WANT_HUNSPELL "Enable support for spell checking with hunspell" ON)
IF (WANT_HUNSPELL)
  FIND_PACKAGE(HUNSPELL)
  IF (HUNSPELL_FOUND)
    MESSAGE("Hunspell Found OK")
    SET(HAVE_HUNSPELL 1)
  ELSE (HUNSPELL_FOUND)
    MESSAGE("HunSpell or its developer libraries NOT found - Disabling support for spell checking")
  ENDIF (HUNSPELL_FOUND)
ENDIF (WANT_HUNSPELL)
#>>HUNSPELL for Speelling support


#<<PoDoFo for AI PDF import
OPTION(WITH_PODOFO "Enable support for PDF embedded in AI" ON)
IF (WITH_PODOFO)
  FIND_PACKAGE(LIBPODOFO)
  IF (LIBPODOFO_FOUND)
    MESSAGE("PoDoFo found OK")
    SET(HAVE_PODOFO 1)
  ELSE (LIBPODOFO_FOUND)
    MESSAGE("PoDoFo NOT found - Disabling support for PDF embedded in AI")
  ENDIF (LIBPODOFO_FOUND)
ENDIF (WITH_PODOFO)
#>>PoDoFo for AI PDF import

#<<HYPHEN for system hyphenation library
FIND_PACKAGE(HYPHEN)
IF(HYPHEN_FOUND)
  MESSAGE("system hyphenation library found OK")
  SET(HAVE_HYPHEN 1)
ELSE(HYPHEN_FOUND)
  MESSAGE("system hyphenation library NOT found - will use internal one")
ENDIF(HYPHEN_FOUND)
#>>HYPHEN for system hyphenation library

##############################################################################################################
########## Include Setup                                                                            ##########

TEST_BIG_ENDIAN(WORDS_BIGENDIAN)
  
CHECK_INCLUDE_FILE("dlfcn.h" HAVE_DLFCN_H)
IF(HAVE_DLFCN_H)
  ADD_DEFINITIONS(-DHAVE_DLFCN_H)
ENDIF(HAVE_DLFCN_H)

CHECK_INCLUDE_FILE("unistd.h" HAVE_UNISTD_H)
IF(HAVE_UNISTD_H)
  ADD_DEFINITIONS(-DHAVE_UNISTD_H)
ENDIF(HAVE_UNISTD_H)

CHECK_INCLUDE_FILE("sys/types.h" HAVE_SYS_TYPES_H)
# IF(HAVE_SYS_TYPES_H)
#   ADD_DEFINITIONS(-DHAVE_SYS_TYPES_H)
# ENDIF(HAVE_SYS_TYPES_H)

CHECK_INCLUDE_FILE("sys/stat.h" HAVE_SYS_STAT_H)
# IF(HAVE_SYS_STAT_H)
#   ADD_DEFINITIONS(-DHAVE_SYS_STAT_H)
# ENDIF(HAVE_SYS_STAT_H)
#>>Test for existing include files


#Create configure files.. config.h and uninstall
#config.h
INCLUDE (ConfigureChecks.cmake)
  IF(WIN32)
    SET(CONFIG_NAME win-config.h)
  ELSE(WIN32)
    SET(CONFIG_NAME config.h)
  ENDIF(WIN32)
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME})
ADD_DEFINITIONS("-DHAVE_CONFIG_H")



#Set up include dirs with all found packages
INCLUDE_DIRECTORIES(
  ${CMAKE_BINARY_DIR}
  ${CMAKE_BINARY_DIR}/scribus
  ${QT_INCLUDES}
  ${FREETYPE_INCLUDE_DIR}
  ${FONTCONFIG_INCLUDE_DIR}
  ${JPEG_INCLUDE_DIR}
  ${LCMS_INCLUDE_DIR}
  ${LIBXML2_INCLUDE_DIR}
  ${PYTHON_INCLUDE_PATH}
  ${TIFF_INCLUDE_DIR}
  ${ZLIB_INCLUDE_DIR}
)

IF(NOT WIN32 AND NOT HAIKU)
  INCLUDE_DIRECTORIES(
    ${CUPS_INCLUDE_DIR}
  )
ENDIF(NOT WIN32 AND NOT HAIKU)

##############################################################################################################
########## Uninstall Setup                                                                          ##########

CONFIGURE_FILE(
  "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
  "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
  IMMEDIATE @ONLY
)

ADD_CUSTOM_TARGET(uninstall
  "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
  
  
##############################################################################################################
########## Add our subdirs                                                                          ##########

#Add our source subdirs
ADD_SUBDIRECTORY(scribus)
ADD_SUBDIRECTORY(resources/editorconfig)
ADD_SUBDIRECTORY(resources/icons)
ADD_SUBDIRECTORY(resources/keysets)
ADD_SUBDIRECTORY(resources/loremipsum)
ADD_SUBDIRECTORY(resources/manpages)
ADD_SUBDIRECTORY(resources/profiles)
ADD_SUBDIRECTORY(resources/swatches)
ADD_SUBDIRECTORY(resources/templates)
ADD_SUBDIRECTORY(resources/translations/po)
ADD_SUBDIRECTORY(resources/unicodemap)

#Install our READMEs etc.
INSTALL(FILES
  AUTHORS
  BUILDING
  ChangeLog
  ChangeLogSVN
  COPYING
  LINKS
  NEWS
  PACKAGING
  README
  TODO
  TRANSLATION
  DESTINATION ${DOCDIR}
)

IF (APPLE)
  INSTALL(FILES
	README.MacOSX
	DESTINATION ${DOCDIR}
  )
ENDIF (APPLE)

#Install our MIME data
INSTALL(FILES
  scribus.xml
  DESTINATION ${MIMEDIR}
)

#Install the desktop file
INSTALL(FILES
scribus.desktop
DESTINATION ${DESKTOPDIR}
)

#Install the appdata file
INSTALL(FILES
scribus.appdata.xml
DESTINATION ${APPDATADIR}
)


#If building an Apple bundle, install these specific files
IF(APPLEBUNDLE)
  INSTALL(FILES
    Scribus.app/Contents/Info.plist
    DESTINATION ${CMAKE_INSTALL_PREFIX}
  )
  INSTALL(FILES
    Scribus.app/Contents/Resources/Scribus.icns
    Scribus.app/Contents/Resources/Scribus-doc.icns
    DESTINATION ${CMAKE_INSTALL_PREFIX}/Resources
  )
ENDIF(APPLEBUNDLE)

##############################################################################################################
########## Install/CPack Setup                                                                      ##########

# If the cmake version includes cpack, use it for tarball building
IF(EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake")
  SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Scribus is an open source publishing application for Linux, Mac OSX and Windows")
  SET(CPACK_PACKAGE_VENDOR "Scribus Team")
  SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README")
  SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/README")
  SET(CPACK_PACKAGE_VERSION_MAJOR "${VERSION_MAJOR}")
  SET(CPACK_PACKAGE_VERSION_MINOR "${VERSION_MINOR}")
  SET(CPACK_PACKAGE_VERSION_PATCH "${VERSION_PATCH}")
  SET(CPACK_PACKAGE_INSTALL_DIRECTORY "Scribus ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
  SET(CPACK_PACKAGE_EXECUTABLES "scribus${TAG_VERSION}")
  SET(CPACK_SOURCE_PACKAGE_FILE_NAME "scribus-${VERSION}${VERSION_SUFFIX}")
  SET(CPACK_SOURCE_GENERATOR TBZ2)
  SET(CPACK_SYSTEM_NAME "")
  SET(CPACK_TOPLEVEL_TAG "")
  SET(CPACK_SOURCE_IGNORE_FILES
    CMakeCache.txt
	scribus-1.4.8.svn.tar.gz
	scribus-1.4.8.svn.tar.Z
	scribus-1.4.8.svn.tar.xz
	scribus-1.4.8.svn.gz
	scribus-1.4.8.svn.tar.bz2
	scribus-1.4.8.svn.tar.7z
	scribus-1.4.8.tar.gz
	scribus-1.4.8.tar.Z
	scribus-1.4.8.tar.xz
	scribus-1.4.8.gz
	scribus-1.4.8.tar.bz2
	scribus-1.4.8.tar.7z
    "~$"
    "\\\\.cvsignore$"
    "\\\\.o$"
    "\\\\.svn-base$"
    "\\\\.svn$"
    "^${PROJECT_SOURCE_DIR}.*/CVS/"
    "^${PROJECT_SOURCE_DIR}/debian/"
    "^${PROJECT_SOURCE_DIR}/old/"
    "^${PROJECT_SOURCE_DIR}.*/CVSROOT/"
    "^${PROJECT_SOURCE_DIR}/admin/"
  )
  INCLUDE(CPack)
ENDIF(EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake")