-
Notifications
You must be signed in to change notification settings - Fork 29
/
CMakeLists.txt
1118 lines (952 loc) · 40 KB
/
CMakeLists.txt
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
#--------------------------------------------------------------------------------------
# This file is part of the Lomse library.
# Copyright (c) 2010-present, Lomse Developers
#
# Licensed under the MIT license.
#
# See LICENSE and NOTICE.md files in the root directory of this source tree.
#---------------------------------------------------------------------------------------
#-------------------------------------------------------------------------------------
# This is a CMake configuration file for building makefiles and installfiles for
# the Lomse library
#-------------------------------------------------------------------------------------
#
# To use it you need CMake which can be downloaded from http://www.cmake.org/
#
# Usage
# cmake [<options>] <source-tree>
#
# The default target (in Linux) is "Unix Makefiles". If you would like to generate
# a diferent makefile use option -G<desired-target>. For instance:
# cmake -G "Ninja" [...]
#
#
# Default configuration
# ~~~~~~~~~~~~~~~~~~~~~~~
# - Build type is 'Release'
#
# - The Bravura.otf music font *IS INCLUDED* in the package.
# See "Bravura music font required to render scores" section.
#
# Please note that default values can be changed directly in the CMake GUI or
# through the command line by prefixing the option's name with '-D':
# i.e.: cmake -DLOMSE_DEBUG=ON ....
#
#
#
# ---------------------------------------------------------------------------
# Build options
# ---------------------------------------------------------------------------
#
# LOMSE_BUILD_MONOLITHIC (Default: OFF) [In development. Not yet implemented]
# To avoid dependencies, instead of linking with the required libraries,
# these libraries will be combined into lomse library so that the binaries
# will not have dependencies on any of these libraries.
# cmake -DLOMSE_BUILD_MONOLITHIC=ON [...]
#
# LOMSE_BUILD_STATIC_LIB (Default: OFF for Unix, ON for Windows)
# Build the static library
#
# LOMSE_BUILD_SHARED_LIB (Default: ON for Unix, OFF for Windows)
# Build the shared library
#
# LOMSE_BUILD_TESTS (Default: ON)
# By default the unit tests runner program 'testlib' is also built.
# You can disable building the tests with this option:
# cmake -DLOMSE_BUILD_TESTS:BOOL=OFF [...]
# When the tests are not build, the dependency from 'UnitTest++' is
# automatically removed.
#
# LOMSE_RUN_TESTS (Default: ON)
# When unit test runner program 'testlib' is built (enabled by default and
# controlled by option LOMSE_BUILD_TESTS) the tests will be automatically run
# after building the library. You can disable running the tests with
# this option:
# cmake -DLOMSE_RUN_TESTS:BOOL=OFF [...]
# But LOMSE_RUN_TESTS is useless when LOMSE_BUILD_TESTS == OFF
#
# LOMSE_BUILD_EXAMPLE (Default: OFF)
# Build the tutorial_1 program that uses the library, to test it.
#
# LOMSE_USING_EMSCRIPTEN (Default: OFF)
# This option is used to inform this script that it is being run with
# Emscripten tools, for creating JavaScript bindings. When setting this,
# all other settings, such as LOMSE_BUILD_SHARED_LIB, LOMSE_BUILD_TESTS,
# LOMSE_ENABLE_COMPRESSION, etc. are ignored and this script will use
# instead pre-defined settings, as required for JavaScript bindings.
# cmake -DLOMSE_USING_EMSCRIPTEN=ON [...]
#
#
# Debug options (ON / OFF values):
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# LOMSE_DEBUG (Default value: OFF)
# Force to create a debug build, with debug symbols. Default build type
# is 'Release'
#
# LOMSE_ENABLE_DEBUG_LOGS (Default value: OFF)
# Enable debug logs (performance loss). Doesn't require a debug build.
#
#
# Bravura music font required to render scores
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# LOMSE_INSTALL_BRAVURA_FONT (Default value: ON)
# By default, this font should not be included in Linux packages and the
# required font package must be set as an install dependency.
# As it is necessary to install it in Windows, and as in some Linux distros
# there is no package to install this font, this cmake scripts includes this
# font in the installer. To prevent this, you can use the option:
# cmake -DLOMSE_INSTALL_BRAVURA_FONT:BOOL=OFF [...]
#
# LOMSE_DOWNLOAD_BRAVURA_FONT (Default value: ON)
# When it is requested that Bravura font be included in the package, this
# cmake script will download the Bravura.otf font in case it is not found in
# the system. You can use the option:
# cmake -DLOMSE_DOWNLOAD_BRAVURA_FONT:BOOL=OFF [...]
# to force not to download it if not found in the system. But if the font is
# not found, it will not be installed in any case.
#
#
# Installation folders
# ~~~~~~~~~~~~~~~~~~~~~
#
# CMAKE_INSTALL_PREFIX
# The default installation prefix is "/usr/local" for Linux and
# "C:/Program Files (x86)" or "C:/Program Files" for Windows.
# You can change the install location by running cmake like this:
# cmake -DCMAKE_INSTALL_PREFIX=/new/install/prefix ...
#
# LOMSE_PKG_CONFIG_INSTALL (Default "/usr/lib/pkgconfig")
# As part of the Lomse instalation process, a pkg-config file, named
# liblomse.pc, is installed. The default location is "/usr/lib/pkgconfig".
# You can change this default location by using the option
# -DLOMSE_PKG_CONFIG_INSTALL=/new/pkgconfig/path. For instance:
# cmake -DLOMSE_PKG_CONFIG_INSTALL=/usr/lib/x86_64-linux-gnu/pkgconfig [...]
#
#
#
#
#
# ---------------------------------------------------------------------------
# Dependencies from external libraries
# ---------------------------------------------------------------------------
#
# lomse has these external dependencies:
#
# a) for all platforms:
# freetype https://gitlab.freedesktop.org/freetype/freetype
# libpng https://github.com/glennrp/libpng
# zlib https://github.com/madler/zlib
# UnitTest++ https://github.com/unittest-cpp/unittest-cpp
#
# b) additional, for Linux & macOS platforms (but not for Android):
# fontconfig https://gitlab.freedesktop.org/fontconfig/fontconfig
#
# It also uses (included as part of the surce tree):
# utfcpp
# agg
# pugixml
# MiniZip
#
#
# Options to reduce dependencies from other libraries (ON / OFF values):
# --------------------------------------------------------------------------
#
# LOMSE_ENABLE_PNG (Default value: ON)
# Build with support for PNG images. This requires the 'libpng' library.
# By setting this to OFF the dependency from 'libpng' is removed and
# Lomse will ignore any png image embedded in the documents, but will not
# fail if the document contains PNG images, it will just log an error
# message. Example for disabling:
# cmake -G "Unix Makefiles" -DLOMSE_ENABLE_PNG=OFF [...]
#
# LOMSE_ENABLE_COMPRESSION (Default value: ON)
# Build with support for compressed files. This requires the 'zlib' library.
# By setting this to OFF the dependency from 'zlib' is removed but Lomse will
# not be able to deal with compressed files, such as MusicXML files in
# compressed format, or with png images embedded in the documents.
# But Lomse will not fail in those cases, just will log error
# messages. Example for disabling:
# cmake -G "Unix Makefiles" -DLOMSE_ENABLE_COMPRESSION=OFF [...]
#
# **Important**: trying to disable compression without also disabling png
# has no effect because libpng depends on zlib. Therefore, when png is
# enabled (LOMSE_ENABLE_PNG=ON) then compression is automatically enabled.
#
# LOMSE_ENABLE_FONTCONFIG (Default value: ON)
# ** Only meaningfull in Linux systems **
# In Linux systems, build with support to look for fonts in system installed
# fonts. This requires the ‘fontconfig’ library.
# By setting this to OFF the dependency from 'fontconfig' is removed and
# Lomse will use only the fonts available in the path provided by the user
# application at Lomse initialization. Example for disabling:
# cmake -G "Unix Makefiles" -DLOMSE_ENABLE_SYSTEM_FONTS=OFF [...]
#
# LOMSE_ENABLE_THREADS (Default value: ON)
# Build with support for threads. This requires the 'threads' library.
# Lomse uses threads for the ScorePlayer class, also used by ScorePlayerCtrl
# class. If your application will not use ScorePlayer, you can reduce
# lomse size and avoid the pthreads dependency by disabling the use
# of threads. Example for disabling:
# cmake -G "Unix Makefiles" -DLOMSE_ENABLE_THREADS=OFF [...]
#
#
#
# Other options (ON / OFF values):
# --------------------------------------------
# LOMSE_COMPATIBILITY_LDP_1_5 (Default value: ON)
# Enables backwards compatibility for accepting scores in LDP v1.5 syntax
#
#-------------------------------------------------------------------------------------
cmake_minimum_required(VERSION 3.4 FATAL_ERROR)
#Travis complains when building with clang. What is this for?
cmake_policy(SET CMP0042 NEW) #MACOSX_RPATH is enabled by default
#Windows 10 camplains
cmake_policy(SET CMP0054 NEW) # quoted arguments will not be further dereferenced
# project name
project(lomse)
#prevent in-source builds
# make sure the user doesn't play dirty with symlinks
get_filename_component(srcdir "${PROJECT_SOURCE_DIR}" REALPATH)
get_filename_component(bindir "${PROJECT_BINARY_DIR}" REALPATH)
# disallow in-source builds
if("${srcdir}" STREQUAL "${bindir}")
message("************** ERROR *************************************")
message(" Lomse should not be configured & built in the Lomse")
message(" source directory. You must run cmake in a build directory.")
message(" For example:")
message("")
message(" mkdir build; cd build; cmake ..")
message("")
message(" NOTE: Given that you already tried to make an in-source")
message(" build CMake have already created several files & directories")
message(" in your source tree. Remove them by doing:")
message("")
message(" rm -rf CMakeCache.txt CMakeFiles")
message("")
message("**********************************************************")
message(FATAL_ERROR "Quitting configuration")
endif()
# uncomment for debugging
#set(CMAKE_VERBOSE_MAKEFILE on)
# main directories
set( LOMSE_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR} )
set( LOMSE_SRC_DIR ${LOMSE_ROOT_DIR}/src )
set( LOMSE_PKG_DIR ${LOMSE_ROOT_DIR}/packages )
set( OUTDIR ${CMAKE_CURRENT_BINARY_DIR})
set( EXECUTABLE_OUTPUT_PATH ${OUTDIR})
set( LIBRARY_OUTPUT_PATH ${OUTDIR})
message(STATUS "Using cmake version ${CMAKE_VERSION}")
message(STATUS " LOMSE_ROOT_DIR: ${LOMSE_ROOT_DIR}")
message(STATUS " CMAKE_CURRENT_SOURCE_DIR: ${CMAKE_CURRENT_SOURCE_DIR}")
message(STATUS " LOMSE_SRC_DIR: ${LOMSE_SRC_DIR}")
message(STATUS " EXECUTABLE_OUTPUT_PATH: ${EXECUTABLE_OUTPUT_PATH}")
message(STATUS " LIBRARY_OUTPUT_PATH: ${LIBRARY_OUTPUT_PATH}")
message(STATUS " OUTDIR: ${OUTDIR}")
message(STATUS "")
# define directories to search for CMake modules
set( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${LOMSE_ROOT_DIR}/cmake-modules")
# define options
#------------------------------------------------------
# build options
if(WIN32)
option(LOMSE_BUILD_STATIC_LIB "Build the static library" ON)
option(LOMSE_BUILD_SHARED_LIB "Build the shared library" OFF)
else()
option(LOMSE_BUILD_STATIC_LIB "Build static library" OFF)
option(LOMSE_BUILD_SHARED_LIB "Build shared library" ON)
endif()
option(LOMSE_BUILD_MONOLITHIC
"Build a monolithic library with no dependencies"
OFF)
option(LOMSE_BUILD_TESTS
"Build the unit tests runner program 'testlib'"
ON)
option(LOMSE_RUN_TESTS
"Run unit tests after building"
ON)
option(LOMSE_BUILD_EXAMPLE
"Build the tutorial_1 program"
OFF)
option(LOMSE_USING_EMSCRIPTEN
"This is a build using Emscripten tools, for JavaScript bindings."
OFF)
# Debug options (ON / OFF values):
option(LOMSE_DEBUG
"Debug build, with debug symbols"
OFF)
option(LOMSE_ENABLE_DEBUG_LOGS
"Enable debug logs. Doesn't require debug build"
OFF)
# Bravura music font required to render scores
option(LOMSE_DOWNLOAD_BRAVURA_FONT
"Download Bravura.otf font if not present in source tree"
ON)
option(LOMSE_INSTALL_BRAVURA_FONT
"Include Bravura music font in the package"
ON)
# Options to reduce dependencies from other libraries
option(LOMSE_ENABLE_PNG
"Enable png format (requires pnglib and zlib)"
ON)
option(LOMSE_ENABLE_COMPRESSION
"Enable compressed formats (requires zlib)"
ON)
option(LOMSE_ENABLE_FONTCONFIG
"Enable search in system fonts (requires fontconfig)"
ON)
option(LOMSE_ENABLE_THREADS
"Enable to use threads (requires pthreads)"
ON)
# Other options
option(LOMSE_COMPATIBILITY_LDP_1_5
"Enable compatibility for LDP v1.5"
ON)
#----- end of options definition -----
#santity checks
if (LOMSE_ENABLE_PNG)
if (NOT LOMSE_ENABLE_COMPRESSION)
message(STATUS "**WARNING**: Enabling PNG requires enabling compression. LOMSE_ENABLE_COMPRESSION set to ON" )
set(LOMSE_ENABLE_COMPRESSION ON)
endif()
endif()
# when targeting Emscripten do not use external dependencies
set(LOMSE_ENABLE_FREETYPE ON)
if (LOMSE_USING_EMSCRIPTEN)
set(LOMSE_ENABLE_PNG OFF)
set(LOMSE_ENABLE_COMPRESSION OFF)
set(LOMSE_ENABLE_FONTCONFIG OFF)
set(LOMSE_BUILD_TESTS OFF)
set(LOMSE_RUN_TESTS OFF)
set(LOMSE_DOWNLOAD_BRAVURA_FONT OFF)
set(LOMSE_INSTALL_BRAVURA_FONT OFF)
set(LOMSE_ENABLE_FREETYPE OFF)
set(LOMSE_ENABLE_THREADS OFF)
#emscripten does not support dynamic linking
set(LOMSE_BUILD_STATIC_LIB ON)
set(LOMSE_BUILD_SHARED_LIB OFF)
endif()
#libraries to build
#if (WIN32)
# set(LOMSE_BUILD_STATIC_LIB ON)
# set(LOMSE_BUILD_SHARED_LIB OFF)
# message(STATUS "In Windows force to build the static library")
#else()
# set(LOMSE_BUILD_STATIC_LIB OFF)
# set(LOMSE_BUILD_SHARED_LIB ON)
# message(STATUS "In Unix force to build the dynamic library")
#endif()
#if (WIN32)
# if (LOMSE_BUILD_SHARED_LIB AND (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC"))
# message(FATAL_ERROR "Shared C++ libraries (C++ DLL) are not supported by MSVC")
# endif()
#endif()
# display options values for building
message(STATUS "Build options:")
message(STATUS " Building with emscripten = ${LOMSE_USING_EMSCRIPTEN}")
message(STATUS " Build monolithic library = ${LOMSE_BUILD_MONOLITHIC}")
message(STATUS " Build the static library = ${LOMSE_BUILD_STATIC_LIB}")
message(STATUS " Build the shared library = ${LOMSE_BUILD_SHARED_LIB}")
message(STATUS " Build testlib program = ${LOMSE_BUILD_TESTS}")
message(STATUS " Run tests after building = ${LOMSE_RUN_TESTS}")
message(STATUS " Build tutorial_1 program = ${LOMSE_BUILD_EXAMPLE}")
message(STATUS " Create Debug build = ${LOMSE_DEBUG}")
message(STATUS " Enable debug logs = ${LOMSE_ENABLE_DEBUG_LOGS}")
message(STATUS " Download Bravura font = ${LOMSE_DOWNLOAD_BRAVURA_FONT}")
message(STATUS " Install Bravura font = ${LOMSE_INSTALL_BRAVURA_FONT}")
message(STATUS " Enable libpng = ${LOMSE_ENABLE_PNG}")
message(STATUS " Enable zlib = ${LOMSE_ENABLE_COMPRESSION}")
message(STATUS " Enable fontconfig = ${LOMSE_ENABLE_FONTCONFIG}")
message(STATUS " Enable freetype = ${LOMSE_ENABLE_FREETYPE}")
message(STATUS " Enable pthreads = ${LOMSE_ENABLE_THREADS}")
message(STATUS " Compatibility for LDP v1.5 = ${LOMSE_COMPATIBILITY_LDP_1_5}")
message(STATUS "")
# set up configuration variables for lomse_config.h
#------------------------------------------------------
# build type (this variables affects lomse_config.h and are used
# in lomse_build_options.h. But there are two problems:
# 1. Both builds (static and shared) can be built in the same cmake command.
# And in this case there is (currently) a single lomse_config.h file
# common to both builds.
# 2. When defining LOMSE_USE_DLL=1 there are compilation errors in Windows.
# So, until further investigation, I have commented out this.
# Another issue to consider is that using makes it impossible to build both
# library versions in the same build.
#if (LOMSE_BUILD_STATIC_LIB)
set( LOMSE_USE_DLL "0")
set( LOMSE_CREATE_DLL "0")
#else()
# set( LOMSE_USE_DLL "1")
# set( LOMSE_CREATE_DLL "1")
#endif()
# set up lomse library version information
include( ${LOMSE_ROOT_DIR}/build-version.cmake )
add_custom_target (build-version ALL
COMMAND ${CMAKE_COMMAND} -D LOMSE_ROOT_DIR=${PROJECT_SOURCE_DIR} -P ${PROJECT_SOURCE_DIR}/build-version.cmake
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
COMMENT "setting Lomse version information ...")
# identify platform and compiler
if(WIN32 OR CYGWIN)
# for Windows operating system or Windows when using the CygWin version of cmake
set( LOMSE_PLATFORM_WIN32 "1")
set( LOMSE_PLATFORM_UNIX "0")
set( LOMSE_PLATFORM_APPLE "0")
elseif(APPLE)
# for MacOS X or iOS, watchOS, tvOS (since 3.10.3)
set( LOMSE_PLATFORM_WIN32 "0")
set( LOMSE_PLATFORM_UNIX "0")
set( LOMSE_PLATFORM_APPLE "1")
elseif(UNIX AND NOT APPLE AND NOT CYGWIN)
# for Linux, BSD, Solaris, Minix
set( LOMSE_PLATFORM_WIN32 "0")
set( LOMSE_PLATFORM_UNIX "1")
set( LOMSE_PLATFORM_APPLE "0")
endif()
# compiler
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set( LOMSE_COMPILER_MSVC "1")
else()
set( LOMSE_COMPILER_MSVC "0")
endif()
# Build environtment checks and settings
#------------------------------------------------------------------------------
# check that compiler supports namespace sdt
include(TestForSTDNamespace)
if(CMAKE_NO_STD_NAMESPACE)
message(FATAL_ERROR "The compiler doesn't support namespace std.")
endif()
# determine system arquitecture
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(SYSTEM_ARCHITECTURE "x64")
else()
set(SYSTEM_ARCHITECTURE "x86")
endif()
message(STATUS "SYSTEM_ARCHITECTURE = ${SYSTEM_ARCHITECTURE}" )
# force to use c++11
if (CMAKE_VERSION VERSION_LESS "3.1")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
else ()
set(CMAKE_CXX_STANDARD 11) #require c+11 or greater
set(CMAKE_CXX_STANDARD_REQUIRED ON) #prevent fallback to any previous standard
endif ()
#check that the compiler supports c++11 and std::regex
if(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
# require at least gcc 4.9
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9)
message(FATAL_ERROR "GCC version must be at least 4.9!")
endif()
elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
# require at least clang 3.4
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.4)
message(FATAL_ERROR "Clang version must be at least 3.4!")
endif()
elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL "AppleClang")
# require at least clang 3.4
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.4)
message(FATAL_ERROR "AppleClang version must be at least 3.4!")
endif()
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
# require at least msvc 15 (Visual Studio 2008 version 9.0)
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 15)
message(FATAL_ERROR "MSVC version must be at least 15!")
endif()
else()
message(WARNING "** Warning **: You are using an untested compiler! Lomse has not been tested with ${CMAKE_CXX_COMPILER_ID}.")
endif()
message(STATUS "** Compiler to use: ${CMAKE_CXX_COMPILER_ID} v.${CMAKE_CXX_COMPILER_VERSION}")
# names for libraries and execs.
#-------------------------------------------------------------------------------------
if( WIN32 )
set( CMAKE_STATIC_LIBRARY_PREFIX "" )
set( CMAKE_STATIC_LIBRARY_SUFFIX ".lib" )
set( CMAKE_SHARED_LIBRARY_PREFIX "" )
set( CMAKE_SHARED_LIBRARY_SUFFIX ".dll" )
set( CMAKE_EXECUTABLE_SUFFIX ".exe" )
elseif( UNIX )
set( CMAKE_STATIC_LIBRARY_PREFIX "lib" )
set( CMAKE_STATIC_LIBRARY_SUFFIX ".a" )
set( CMAKE_SHARED_LIBRARY_PREFIX "lib" )
set( CMAKE_SHARED_LIBRARY_SUFFIX ".so" )
set( CMAKE_EXECUTABLE_SUFFIX "" )
endif()
#----------------------------------------------------------------------------
# Determine installation folders and create the include file "lomse_config.h"
#
# values for configuration macros in "lomse_config.h" could depend on
# installation folders. Therefore, before configuring it is necessary to set
# installation folders. By default, CMake uses the following prefix:
# - Linux: "/usr/local"
# - Windows: "C:\Program Files\lomse\"
#
# You can change the install location by running cmake like this:
# cmake -DCMAKE_INSTALL_PREFIX=/new/install/prefix
#----------------------------------------------------------------------------
message(STATUS "CMAKE_INSTALL_PREFIX = " ${CMAKE_INSTALL_PREFIX} )
#set install folder
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT
OR (${CMAKE_INSTALL_PREFIX} STREQUAL "C:/Program Files/${CMAKE_PROJECT_NAME}")
OR (${CMAKE_INSTALL_PREFIX} STREQUAL "C:/Program Files (x86)/${CMAKE_PROJECT_NAME}")
)
message(STATUS " CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT = ${CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT}")
#Fix CMAKE_INSTALL_PREFIX for Windows.
#Sometimes it points to 'Program Files (x86)' for x64 builds
if(WIN32)
message(STATUS " Win32. SYSTEM_ARCHITECTURE = ${SYSTEM_ARCHITECTURE}")
if(${SYSTEM_ARCHITECTURE} STREQUAL "x64")
set(CMAKE_INSTALL_PREFIX "C:/Program Files/${CMAKE_PROJECT_NAME}")
else()
set(CMAKE_INSTALL_PREFIX "C:/Program Files (x86)/${CMAKE_PROJECT_NAME}")
endif()
endif()
endif()
message(STATUS "CMAKE_INSTALL_PREFIX = ${CMAKE_INSTALL_PREFIX}" )
set(LOMSE_LIBDIR ${CMAKE_INSTALL_PREFIX}/lib)
set(LOMSE_INCLUDEDIR ${CMAKE_INSTALL_PREFIX}/include/lomse )
#----------------------------------------------------------------------------
# Dependencies
# Check for needed libraries and set all related includes, flags, etc.
#----------------------------------------------------------------------------
set(CMAKE_FIND_FRAMEWORK LAST) #to avoid problems in macOS with Mono and other frameworks
#dependencies for building and for pkg-config file (intitially empty)
set(LOMSE_REQUIRES "")
set(LOMSE_DEBIAN_DEPS "") #Build deps: Debian "Build-Depends:" string
set(LOMSE_BUILD_DEPS "") #Build deps: Libraries to link
# include directories to be installed
set( INCLUDES_LOMSE ${LOMSE_ROOT_DIR}/include )
set( INCLUDES_AGG ${LOMSE_ROOT_DIR}/src/agg/include )
set( INCLUDES_UTFCPP ${LOMSE_ROOT_DIR}/packages/utfcpp )
set( INCLUDES_MINIZIP ${LOMSE_ROOT_DIR}/packages/minizip )
set( INCLUDES_PUGIXML ${LOMSE_ROOT_DIR}/packages )
include_directories(
${INCLUDES_LOMSE}
${INCLUDES_AGG}
${LOMSE_ROOT_DIR}/src/agg/font_freetype
${INCLUDES_UTFCPP}
${INCLUDES_PUGIXML}
${INCLUDES_MINIZIP}
)
# Check for Bravura music font required to render scores
set (INSTALL_BRAVURA_FONT ${LOMSE_INSTALL_BRAVURA_FONT})
find_path(BRAVURA_FONT_PATH
NAMES Bravura.otf
PATHS
/usr/share/fonts/truetype/ # Red Hat & fonts-lenmus-bravura.deb
${LOMSE_ROOT_DIR}/z_fonts # local builds
${LOMSE_ROOT_DIR}/fonts # local builds
${LOMSE_ROOT_DIR}/bravura/src # builds for PPA at Launchpad.net
)
if("${BRAVURA_FONT_PATH}" STREQUAL "BRAVURA_FONT_PATH-NOTFOUND")
if (LOMSE_DOWNLOAD_BRAVURA_FONT)
message(STATUS "Bravura font not found. Downloading it ...")
file(DOWNLOAD
"https://github.com/steinbergmedia/bravura/raw/master/redist/otf/Bravura.otf"
"${LOMSE_ROOT_DIR}/fonts/Bravura.otf"
SHOW_PROGRESS
# EXPECTED_HASH MD5=863c90e6f99c264a1747856130ebdc3c
STATUS status
LOG log
)
list(GET status 0 status_code)
list(GET status 1 status_string)
if(NOT status_code EQUAL 0)
message(FATAL_ERROR "Error downloading Bravura font. Status_code: ${status_code}
status_string: ${status_string}
log: ${log}
")
endif()
message(STATUS "Bravura font downloaded.")
set(BRAVURA_FONT_PATH "${LOMSE_ROOT_DIR}/fonts/")
set(INSTALL_BRAVURA_FONT ON)
else(LOMSE_DOWNLOAD_BRAVURA_FONT)
if (WIN32)
message(FATAL_ERROR "Bravura font not found. Aborting...")
else()
message(STATUS "Bravura font not found. It will not be installed.")
endif()
set(INSTALL_BRAVURA_FONT OFF)
endif(LOMSE_DOWNLOAD_BRAVURA_FONT)
else()
message(STATUS "Bravura font found in ${BRAVURA_FONT_PATH}")
endif()
# Check for UnitTest++. Required for unit test
if (LOMSE_BUILD_TESTS)
find_package(UnitTest++)
if(UNITTEST++_FOUND)
get_filename_component(UNITTEST++_LINK_DIR ${UNITTEST++_LIBRARY} DIRECTORY)
include_directories(${UNITTEST++_INCLUDE_DIR})
message(" include= ${UNITTEST++_INCLUDE_DIR}" )
else()
message(STATUS "Not found UnitTest++. Test program will not be built" )
set (LOMSE_BUILD_TESTS OFF)
endif()
endif(LOMSE_BUILD_TESTS)
# Check for zlib
if( LOMSE_ENABLE_COMPRESSION )
# libpng and freetype require zlib. So deal with zlib first.
find_package(ZLIB REQUIRED)
include_directories( ${ZLIB_INCLUDE_DIR} )
message(STATUS "Found ZLib: ${ZLIB_LIBRARIES}" )
message(" include= ${ZLIB_INCLUDE_DIR}" )
set(LOMSE_REQUIRES "${LOMSE_REQUIRES}, zlib")
set(LOMSE_BUILD_DEPS ${LOMSE_BUILD_DEPS} ${ZLIB_LIBRARIES})
set(LOMSE_DEBIAN_DEPS "${LOMSE_DEBIAN_DEPS}, zlib1g (>= ${ZLIB_VERSION_STRING})")
endif(LOMSE_ENABLE_COMPRESSION)
# Check for FreeType
if( LOMSE_ENABLE_FREETYPE )
find_package(Freetype REQUIRED)
include_directories( ${FREETYPE_INCLUDE_DIRS} )
message(STATUS "Found Freetype: ${FREETYPE_LIBRARY}" )
message(" include= ${FREETYPE_INCLUDE_DIRS}" )
set(LOMSE_REQUIRES "${LOMSE_REQUIRES}, freetype2")
set(LOMSE_DEBIAN_DEPS "${LOMSE_DEBIAN_DEPS}, libfreetype6")
set(LOMSE_BUILD_DEPS ${LOMSE_BUILD_DEPS} ${FREETYPE_LIBRARY})
endif()
# Check for libpng
if( LOMSE_ENABLE_PNG )
find_package(PNG REQUIRED)
include_directories( ${PNG_INCLUDE_DIRS} )
message(STATUS "Found PNG: ${PNG_LIBRARIES}" )
message(" include= ${PNG_INCLUDE_DIRS}" )
set(LOMSE_REQUIRES "${LOMSE_REQUIRES}, libpng")
set(LOMSE_BUILD_DEPS ${LOMSE_BUILD_DEPS} ${PNG_LIBRARIES})
set(LOMSE_DEBIAN_DEPS "${LOMSE_DEBIAN_DEPS},
libpng12-0 (>=1.2.42) | libpng16-16" )
endif(LOMSE_ENABLE_PNG)
# Check for fontconfig
if (UNIX AND LOMSE_ENABLE_FONTCONFIG) #UNIX = Linux, macOS & Android
find_path(FONTCONFIG_INCLUDE_DIR fontconfig/fontconfig.h)
find_library(FONTCONFIG_LIBRARIES NAMES fontconfig)
if (("${FONTCONFIG_INCLUDE_DIR}" STREQUAL "FONTCONFIG_INCLUDE_DIR-NOTFOUND")
OR ("${FONTCONFIG_LIBRARIES}" STREQUAL "FONTCONFIG_LIBRARIES-NOTFOUND")
)
set(FONTCONFIG_FOUND FALSE)
else()
set(FONTCONFIG_FOUND TRUE)
endif()
if(FONTCONFIG_FOUND )
include_directories( ${FONTCONFIG_INCLUDE_DIR}/fontconfig )
set(LOMSE_REQUIRES "${LOMSE_REQUIRES}, fontconfig")
set(LOMSE_BUILD_DEPS ${LOMSE_BUILD_DEPS} ${FONTCONFIG_LIBRARIES})
set(LOMSE_DEBIAN_DEPS "${LOMSE_DEBIAN_DEPS}, fontconfig")
message(STATUS "Found FontConfig: libraries= ${FONTCONFIG_LIBRARIES}" )
message(" include= ${FONTCONFIG_INCLUDE_DIR}/fontconfig" )
else()
message(FATAL_ERROR "fontconfig package not found.")
endif()
endif()
# Check for pthreads
# It is required for fontconfig and for Lomse
#
# Under Android, there is no need for FIND_PACKAGE(Threads) because the Android
# libc standard library (called "bionic") already includes the relevant functions
# in threads.h and pthread.h
# See: https://stackoverflow.com/questions/5990661/cmake-find-packagethreads-for-android-cross-compilation
#
if( LOMSE_ENABLE_THREADS )
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
if (NOT CMAKE_SYSTEM_NAME STREQUAL "Android")
find_package(Threads REQUIRED)
if( Threads_FOUND )
message(STATUS "Found pthreads:" )
message(STATUS " CMAKE_THREAD_LIBS_INIT=${CMAKE_THREAD_LIBS_INIT}")
message(STATUS " CMAKE_USE_PTHREADS_INIT=${CMAKE_USE_PTHREADS_INIT}")
message(STATUS " CMAKE_USE_WIN32_THREADS_INIT=${CMAKE_USE_WIN32_THREADS_INIT}")
message(STATUS " CMAKE_HP_PTHREADS_INIT=${CMAKE_HP_PTHREADS_INIT}")
else()
message(FATAL_ERROR "pthreads dependency not found.")
endif()
endif()
endif()
# strip leading commas from LOMSE_REQUIRES and LOMSE_DEBIAN_DEPS
if (LOMSE_REQUIRES)
string( REGEX REPLACE "^, " "" LOMSE_REQUIRES ${LOMSE_REQUIRES})
endif()
if (LOMSE_DEBIAN_DEPS)
string( REGEX REPLACE "^, " "" LOMSE_DEBIAN_DEPS ${LOMSE_DEBIAN_DEPS})
endif()
if(UNIX)
# macros for "Print all warnings", GCC & __UNIX__
add_definitions( -Wall -DGCC -D__UNIX__ )
endif(UNIX)
include_directories("${CMAKE_CURRENT_BINARY_DIR}")
# source files to compile
include( ${LOMSE_ROOT_DIR}/add-sources.cmake )
# Adds folders for Visual Studio and other IDEs
set (LOMSE_GROUP_FOLDER "lomse/" )
include( ${LOMSE_ROOT_DIR}/add-group-folders.cmake )
message(STATUS "LOMSE_BUILD_DEPS= ${LOMSE_BUILD_DEPS}")
#remove dependencies for monolithic builds
if (LOMSE_BUILD_MONOLITHIC)
set(LOMSE_DEBIAN_DEPS "")
endif()
# set other variables needed by lomse_config.h
# paths for tests
set( TESTLIB_SCORES_PATH "\"${LOMSE_ROOT_DIR}/test-scores/\"" )
set( TESTLIB_FONTS_PATH "\"${LOMSE_ROOT_DIR}/fonts/\"" )
# path to fonts (will be hardcoded in lomse library, so *MUST* be the
# path in which Lomse standard fonts will be installed)
set( LOMSE_FONTS_PATH "\"${BRAVURA_FONT_PATH}/\"" )
#define a header file to pass CMake settings to source code
configure_file(
"${LOMSE_ROOT_DIR}/lomse_config.h.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/lomse_config.h"
)
#======= End of dependencies checking ========================================
###############################################################################
#
# Target: Lomse static library
#
###############################################################################
if(LOMSE_BUILD_STATIC_LIB)
set(LOMSE_STATIC lomse)
#When targeting emscriptem use its libraries instead of system libraries
if (LOMSE_USING_EMSCRIPTEN)
add_compile_options(-sUSE_ZLIB=1 -sUSE_LIBPNG=1 -sUSE_FREETYPE=1)
endif()
add_library(${LOMSE_STATIC} STATIC ${ALL_LOMSE_SOURCES})
add_dependencies(${LOMSE_STATIC} build-version)
#dependencies
if (LOMSE_BUILD_MONOLITHIC)
target_link_libraries(${LOMSE_STATIC} PUBLIC ${LOMSE_BUILD_DEPS})
else()
target_link_libraries(${LOMSE_STATIC} ${LOMSE_BUILD_DEPS})
endif()
#properties
#if(UNIX)
set_target_properties(${LOMSE_STATIC} PROPERTIES
VERSION ${LOMSE_PACKAGE_VERSION}
SOVERSION ${LOMSE_PACKAGE_VERSION}
OUTPUT_NAME "lomse"
RUNTIME_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH}
)
#endif()
if (LOMSE_USING_EMSCRIPTEN)
set_target_properties(${LOMSE_STATIC} PROPERTIES LINK_FLAGS "--bind")
endif()
# Force not to link with standard MSVC libraries: /NODEFAULTLIB
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set_target_properties(${LOMSE_STATIC} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:LIBCMT")
endif()
get_target_property(VAR ${LOMSE_STATIC} LINK_FLAGS)
message("library target properties=" ${VAR})
endif(LOMSE_BUILD_STATIC_LIB)
###############################################################################
#
# Target: dynamic/shared library
#
###############################################################################
if(LOMSE_BUILD_SHARED_LIB)
set(LOMSE_SHARED lomse-shared)
add_library( ${LOMSE_SHARED} SHARED ${ALL_LOMSE_SOURCES} )
add_dependencies(${LOMSE_SHARED} build-version)
#dependencies
if (LOMSE_BUILD_MONOLITHIC)
target_link_libraries(${LOMSE_SHARED} PUBLIC ${LOMSE_BUILD_DEPS})
else()
target_link_libraries(${LOMSE_SHARED} ${LOMSE_BUILD_DEPS})
endif()
#properties
set_target_properties(${LOMSE_SHARED}
PROPERTIES POSITION_INDEPENDENT_CODE 1 #shared libraries need PIC
VERSION ${LOMSE_PACKAGE_VERSION}
SOVERSION ${LOMSE_PACKAGE_VERSION}
OUTPUT_NAME "lomse"
RUNTIME_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH}
)
endif(LOMSE_BUILD_SHARED_LIB)
###############################################################################
#
# Target: testlib. Program for running the library unit tests
#
###############################################################################
if(LOMSE_BUILD_TESTS)
set (TESTLIB testlib)
file(GLOB TESTLIB_SRC "${LOMSE_SRC_DIR}/tests/lomse_*.cpp" )
add_executable(${TESTLIB} ${TESTLIB_SRC})
# lomse library name
if (LOMSE_BUILD_SHARED_LIB)
set(LOMSE_LIBRARY ${LOMSE_SHARED})
else()
set(LOMSE_LIBRARY ${LOMSE_STATIC})
endif()
# libraries to link
if( Threads_FOUND )
target_link_libraries (${TESTLIB} ${LOMSE_LIBRARY}
${UNITTEST++_LIBRARY} ${LOMSE_BUILD_DEPS}
)
target_link_libraries (${TESTLIB} "${CMAKE_THREAD_LIBS_INIT}")
else()
target_link_libraries (${TESTLIB} ${LOMSE_LIBRARY}
${UNITTEST++_LIBRARY} ${LOMSE_BUILD_DEPS}
)
endif()
add_dependencies(${TESTLIB} ${LOMSE_LIBRARY})
# Windows properties
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set_target_properties(${TESTLIB} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:LIBCMT")
endif()
get_target_property(VAR ${TESTLIB} LINK_FLAGS)
message("${TESTLIB} target properties=" ${VAR})
# once generated, run tests
if (LOMSE_RUN_TESTS)
if(WIN32)
set(TESTLIB_EXECUTABLE ${EXECUTABLE_OUTPUT_PATH}/${TESTLIB}.exe )
else()
set(TESTLIB_EXECUTABLE ${EXECUTABLE_OUTPUT_PATH}/${TESTLIB} )
endif()
add_custom_command(
TARGET ${TESTLIB} POST_BUILD
COMMAND ${TESTLIB_EXECUTABLE}
WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}
)
endif(LOMSE_RUN_TESTS)
endif(LOMSE_BUILD_TESTS)
###############################################################################
#
# Target: Tutorial_1
#
###############################################################################
if (LOMSE_BUILD_EXAMPLE)
set (EXAMPLE1 tutorial_1)
if(WIN32)
set( EXAMPLE1_SRC ${LOMSE_ROOT_DIR}/examples/tutorials/tutorial-1-win )
include_directories(
${LOMSE_SRC_DIR}/agg/include/platform/win32/agg_win32_bmp.h
)
add_executable( ${EXAMPLE1} WIN32
${EXAMPLE1_SRC}/tutorial-1-win.cpp
${LOMSE_SRC_DIR}/agg/src/platform/win32/agg_win32_bmp.cpp
)
elseif(UNIX)
set( EXAMPLE1_SRC ${LOMSE_ROOT_DIR}/examples/tutorials/tutorial-1-x11 )
find_package(X11)
if(X11_FOUND)
include_directories(${X11_INCLUDE_DIRS})
link_libraries(${X11_LIBRARIES})
endif(X11_FOUND)
add_executable( ${EXAMPLE1} ""
${EXAMPLE1_SRC}/tutorial-1-x11.cpp
)
endif()
# libraries to link
if (LOMSE_BUILD_SHARED_LIB)
target_link_libraries ( ${EXAMPLE1} ${LOMSE_SHARED}
${UNITTEST++_LIBRARY} ${LOMSE_BUILD_DEPS} #${CMAKE_THREAD_LIBS_INIT}
)
add_dependencies(${EXAMPLE1} ${LOMSE_SHARED})
else()
# Check for pthreads
find_package (Threads)
target_link_libraries (${EXAMPLE1} ${LOMSE_STATIC}
${UNITTEST++_LIBRARY} ${LOMSE_BUILD_DEPS} ${CMAKE_THREAD_LIBS_INIT}
)
add_dependencies(${EXAMPLE1} ${LOMSE_STATIC})
endif()
endif(LOMSE_BUILD_EXAMPLE)
###############################################################################
# library installation
###############################################################################
if( UNIX )
# copy generated libraries
install( TARGETS ${LOMSE} DESTINATION ${LOMSE_LIBDIR} )
install( TARGETS ${LOMSE_SHARED} LIBRARY DESTINATION ${LOMSE_LIBDIR} )
#create symlink to library
install( CODE
"EXECUTE_PROCESS(COMMAND ln -fs ${CMAKE_INSTALL_PREFIX}/lib/${LOMSE_SHARED}
${CMAKE_INSTALL_PREFIX}/lib/liblomse.so )"
)
elseif( WIN32 )
#For Windows force to install Bravura font
set(INSTALL_BRAVURA_FONT 1)