-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVistaCommon.cmake
2263 lines (2012 loc) · 110 KB
/
VistaCommon.cmake
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
# $Id$
# This file contains common settings and macros for setting up Vista projects
# PACKAGE MACROS:
# vista_add_external_msvc_project_of_package( PACKAGE_NAME [SOLUTION_FOLDER] [DEPENDENT (DENENDENT_TARGET)+ ] [ DEPENDS (DEPENDANT_TRAGET)+ ] )
# vista_find_package( <package> [version] [EXACT] [QUIET] [[REQUIRED|COMPONENTS] [components...]] [NO_POLICY_SCOPE] [NO_MODULE] )
# vista_use_package( <package> [version] [EXACT] [QUIET] [[REQUIRED|COMPONENTS] [components...]] [NO_POLICY_SCOPE] [NO_MODULE] [FIND_DEPENDENCIES] [SYSTEM_HEADERS] )
# vista_find_shader_dirs( PACKAGE_NAME )
# vista_configure_app( PACKAGE_NAME [OUT_NAME] )
# vista_configure_lib( PACKAGE_NAME [OUT_NAME] )
# vista_install( TARGET [INCLUDE/BIN_SUBDIRECTORY [LIBRARY_SUBDIRECTORY] ] [NO_POSTFIX] )
# vista_install_files_by_extension( SEARCH_ROOT INSTALL_SUBDIR EXTENSION1 [EXTENSION2 ...] )
# vista_install_all_dlls( INSTALL_SUBDIR )
# vista_add_target_pathscript_dynamic_lib_path( _PACKAGE_NAME _VALUE [PATH_LIST] )
# vista_add_pathscript_dynamic_lib_path( _VALUE [PATH_LIST] )
# vista_add_target_pathscript_envvar( _PACKAGE_NAME _ENVVAR _VALUE [PATH_LIST] )
# vista_add_pathscript_envvar( _ENVVAR _VALUE [PATH_LIST] )
# vista_set_target_msvc_arguments( _PACKAGE_NAME _COMMANDLINE_VARS )
# vista_create_cmake_config_build( PACKAGE_NAME CONFIG_PROTO_FILE TARGET_DIR )
# vista_create_cmake_config_install( PACKAGE_NAME CONFIG_PROTO_FILE TARGET_DIR )
# vista_create_version_config( PACKAGE_NAME VERSION_PROTO_FILE )
# vista_create_cmake_configs( TARGET [CUSTOM_CONFIG_FILE_BUILD [CUSTOM_CONFIG_FILE_INSTALL] ] )
# vista_set_outdir( TARGET DIRECTORY [USE_CONFIG_SUBDIRS])
# vista_set_version( PACKAGE TYPE NAME [ MAJOR [ MINOR [ PATCH [ TWEAK ]]]] )
# vista_adopt_version( PACKAGE ADOPT_PARENT )
# vista_create_info_file( PACKAGE_NAME TARGET_DIR INSTALL_DIR ) included from VistaBuildInfo.cmake
# vista_delete_info_file( PACKAGE_NAME TARGET_DIR ) included from VistaBuildInfo.cmake
# vista_create_default_info_file( PACKAGE_NAME )
# vista_create_doxygen_target( DOXYFILE [WORKING_DIR] )
# vista_create_uninstall_target( [ON|OFF] )
# vista_set_install_permissions( OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_WRITE GROUP_EXECUTE WORLD_READ WORLD_WRITE WORLD_EXECUTE )
# UTILITY MACROS:
# require_vistacommon_version( SVN_REVISION )
# vista_set_defaultvalue( <cmake set syntax> )
# vista_add_files_to_sources( TARGET_LIST ROOT_DIR [SOURCE_GROUP group_name] EXTENSION1 [EXTENSION2 ...] )
# vista_conditional_add_subdirectory( VARIABLE_NAME DIRECTORY [ON|OFF] [ADVANCED [MSG string] )
# replace_svn_revision_tag( STRING )
# vista_enable_all_compiler_warnings()
# vista_enable_most_compiler_warnings()
# GENERAL SETTINGS
# adds info variables
# VISTACMAKECOMMON_REVISION - current svn revision of the VistaCMakeCommon
# FIRST_CONFIGURATION_RUN - true if this is the first configuration run
# VISTA_HWARCH - variable describing Hardware architecture, e.g. win32.vc9 or LINUX.X86
# VISTA_COMPATIBLE_HWARCH - architectures that are compatible to the current HWARCH,
# e.g. for win32.vc9 this will be "win32.vc9 win32"
# VISTA_64BIT - set to true if the code is compiled for 64bit execution
# VISTA_PLATFORM_DEFINE - compiler definition for the platform ( -DWIN32 or -DLINUX or -DDARWIN )
# adds some general flags/configurations
# sets CMAKE_DEBUG_POSTFIX to "D"
# enables global cmake property USE_FOLDERS - allows grouping of projects in msvc
# conditionally adds DEBUG and OS definitions
# some visual studio flags
# VISTA_USE_RPATH cache flag to enable/disable use of RPATH
# scans XYZConfig.cmake files in VISTA_CMAKE_COMMON/share, and deletes outdated ones
# we clean the CMAKE_MODULE_PATH - just in case there are some \ pathes in there
# this, we also do on multiple inclusions
set( _TMP_MODULE_PATH ${CMAKE_MODULE_PATH} )
set( CMAKE_MODULE_PATH )
foreach( _PATH ${_TMP_MODULE_PATH} )
file( TO_CMAKE_PATH ${_PATH} _CHANGED_PATH )
list( APPEND CMAKE_MODULE_PATH ${_CHANGED_PATH} )
endforeach( _PATH )
list( REMOVE_DUPLICATES CMAKE_MODULE_PATH )
# avoid multiple includes of this file (for performance reasons )
if( NOT VISTA_COMMON_INCLUDED )
set( VISTA_COMMON_INCLUDED TRUE )
set( CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS TRUE )
if( CMAKE_VERSION VERSION_GREATER 2.8.12 OR CMAKE_VERSION VERSION_EQUAL 2.8.12 )
cmake_policy( SET CMP0022 OLD )
endif()
#this package sets the variables VISTA_HWARCH, VISTA_COMPATIBLE_HWARCH and VISTA_64BIT
include( VistaHWArchSettings )
include( VistaFindUtils )
include( VistaBuildInfo )
###########################
### Utility macros ###
###########################
# require_vistacommon_version( SVN_REVISION )
# macro to verify that the VistaCMakeCommon's svn revision is high enough (e.g. to ensure that bugfixes are
# used. If the VistaCMakeCommon's svn revisionis less than the provided number, a warning it emitted
macro( require_vistacommon_version _SVN_REVISION )
if( ${VISTACMAKECOMMON_REVISION} LESS ${_SVN_REVISION} )
message( WARNING "VistaCMakeCommon is requested to have at least revision ${_SVN_REVISION}, but is only "
"Revision ${VISTACMAKECOMMON_REVISION} - please update your VistaCMakeCommon!" )
endif( ${VISTACMAKECOMMON_REVISION} LESS ${_SVN_REVISION} )
endmacro( require_vistacommon_version )
# vista_set_defaultvalue( <cmake set() syntax> )
# macro for overriding default values of pre-initialized variables
# sets the variable only once
macro( vista_set_defaultvalue _VAR_NAME )
if( NOT VISTA_${_VAR_NAME}_ALREADY_INITIALIZED )
set( _ARGS )
list( APPEND _ARGS ${ARGV} )
list( FIND _ARGS FORCE _FORCE_FOUND )
if( ${_FORCE_FOUND} EQUAL -1 )
set( ${_ARGS} FORCE )
else( ${_FORCE_FOUND} EQUAL -1 )
set( ${_ARGS} )
endif( ${_FORCE_FOUND} EQUAL -1 )
set( VISTA_${_VAR_NAME}_ALREADY_INITIALIZED TRUE CACHE INTERNAL "" FORCE )
endif()
endmacro( vista_set_defaultvalue )
# vista_add_files_to_sources( TARGET_LIST ROOT_DIR [NON_RECURSIVE] [SOURCE_GROUP group_name | SOURCE_GROUP_MIRROR_DIR prefix] EXTENSION1 [EXTENSION2 ...] )
# searches files with any of the passed extensions in the specified root_dir. These files are added to the
# passed list. If the source_group option is given, the files are also added to the specified source group.
# The root folder will be searched recursively unless the NON_RECURSIVE option is given
# IMPORTANT NOTE: due to cmake's string replacement hicka-di-hoo, if you want to use subfolders in your sourcegroups,
# you'll have to use 4(!) backslashes as separator (e.g. "folder\\\\subfolder")
macro( vista_add_files_to_sources _TARGET_LIST _SEARCH_ROOT )
set( _RECURSIVE TRUE )
set( _EXTENSIONS ${ARGN} )
set( _SOURCE_GROUP )
set( _SOURCE_GROUP_MIRROR_PATH FALSE )
if( "${ARGV2}" STREQUAL "NON_RECURSIVE" )
set( _RECURSIVE FALSE )
if( ${ARGV3} STREQUAL "SOURCE_GROUP" )
set( _SOURCE_GROUP ${ARGV4} )
list( REMOVE_AT _EXTENSIONS 0 1 2 )
else()
list( REMOVE_AT _EXTENSIONS 0 )
endif()
elseif( ${ARGV2} STREQUAL "SOURCE_GROUP" )
set( _SOURCE_GROUP ${ARGV3} )
if( ${ARGV4} STREQUAL "NON_RECURSIVE" )
set( _RECURSIVE FALSE )
list( REMOVE_AT _EXTENSIONS 0 1 2 )
else()
list( REMOVE_AT _EXTENSIONS 0 1 )
endif()
elseif( ${ARGV2} STREQUAL "SOURCE_GROUP_MIRROR_DIR" )
set( _SOURCE_GROUP ${ARGV3} )
set( _SOURCE_GROUP_MIRROR_PATH TRUE )
if( ${ARGV4} STREQUAL "NON_RECURSIVE" )
set( _RECURSIVE FALSE )
list( REMOVE_AT _EXTENSIONS 0 1 2 )
else()
list( REMOVE_AT _EXTENSIONS 0 1 )
endif()
endif()
set( _FOUND_FILES )
foreach( _EXT ${_EXTENSIONS} )
if( _RECURSIVE )
file( GLOB_RECURSE _FOUND_FILES "${_SEARCH_ROOT}/*.${_EXT}" "${_SEARCH_ROOT}/**/*.${_EXT}" )
else()
file( GLOB _FOUND_FILES "${_SEARCH_ROOT}/*.${_EXT}" )
endif()
list( APPEND ${_TARGET_LIST} ${_FOUND_FILES} )
if( _SOURCE_GROUP_MIRROR_PATH )
get_filename_component( _ABSOLUTE_SEARCH_ROOT "${_SEARCH_ROOT}" ABSOLUTE )
foreach( _FILE ${_FOUND_FILES} )
file( RELATIVE_PATH _REL_PATH "${_ABSOLUTE_SEARCH_ROOT}" "${_FILE}" )
get_filename_component( _REL_PATH "${_REL_PATH}" PATH )
source_group( "${_SOURCE_GROUP}\\${_REL_PATH}" FILES "${_FILE}" )
endforeach()
elseif( _SOURCE_GROUP )
source_group( ${_SOURCE_GROUP} FILES ${_FOUND_FILES} )
endif()
endforeach( _EXT ${_EXTENSIONS} )
endmacro( vista_add_files_to_sources )
# vista_conditional_add_subdirectory( VARIABLE_NAME DIRECTORY [ON|OFF] [ADVANCED [MSG string] )
# creates a cache bool variable with the specified name and cache message, initialized to the desired
# value (defaults to ON ). ADVANCED marks the cache variable as advanced. Nothing is done if the specified
# directory does not exist
macro( vista_conditional_add_subdirectory )
if( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${ARGV1}" )
set( _VISTA_CONDITIONAL_SET_STATE ON )
set( _VISTA_CONDITIONAL_SET_ADVANCED FALSE )
set( _VISTA_CONDITIONAL_SET_MSG "Build the ${ARGV1} library" )
set( _VISTA_CONDITIONAL_SET_MSG_NEXT FALSE )
set( _VISTA_CONDITIONAL_ADD_TO_LIST_NEXT FALSE )
set( _APPEND_TO_LIST "" )
foreach( _ARG ${ARGV} )
if( _VISTA_CONDITIONAL_SET_MSG_NEXT )
set( _VISTA_CONDITIONAL_SET_MSG ${_ARG} ${ARGV0} )
set( _VISTA_CONDITIONAL_SET_MSG_NEXT FALSE )
elseif( _VISTA_CONDITIONAL_ADD_TO_LIST_NEXT )
set( _VISTA_CONDITIONAL_ADD_TO_LIST_NEXT FALSE )
set( _APPEND_TO_LIST ${_ARG} )
elseif( ${_ARG} STREQUAL "ON" )
set( _VISTA_CONDITIONAL_SET_STATE ON )
elseif( ${_ARG} STREQUAL "OFF" )
set( _VISTA_CONDITIONAL_SET_STATE OFF )
elseif( ${_ARG} STREQUAL "ADVANCED" )
set( _VISTA_CONDITIONAL_SET_ADVANCED TRUE )
elseif( ${_ARG} STREQUAL "MSG" )
set( _VISTA_CONDITIONAL_SET_MSG_NEXT TRUE )
elseif( ${_ARG} STREQUAL "ADD_TO_LIST" )
set( _VISTA_CONDITIONAL_ADD_TO_LIST_NEXT TRUE )
endif( _VISTA_CONDITIONAL_SET_MSG_NEXT )
endforeach( _ARG ${ARGV} )
set( ${ARGV0} ${_VISTA_CONDITIONAL_SET_STATE} CACHE BOOL "${_VISTA_CONDITIONAL_SET_MSG}" )
if( _VISTA_CONDITIONAL_SET_ADVANCED )
mark_as_advanced( ${ARGV0} )
endif( _VISTA_CONDITIONAL_SET_ADVANCED )
if( ${ARGV0} )
add_subdirectory( "${ARGV1}" )
if( _APPEND_TO_LIST )
list( APPEND ${_APPEND_TO_LIST} ${ARGV1} )
endif( _APPEND_TO_LIST )
endif( ${ARGV0} )
endif( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${ARGV1}" )
endmacro( vista_conditional_add_subdirectory )
# local macro, for use in this file only
function( local_clean_old_config_references _PACKAGE_NAME _PACKAGE_TARGET_FILE _EXCLUDE_DIR )
string( TOUPPER _PACKAGE_NAME_UPPER ${_PACKAGE_NAME} )
# we only want to do this if the version changes! (and only if a version exists at all
if( NOT "${VISTA_${_PACKAGE_NAME_UPPER}_INTERNAL_LAST_CHECK_VERSION}" STREQUAL "${${_PACKAGE_NAME_UPPER}_VERSION_EXT}" )
set( VISTA_${_PACKAGE_NAME_UPPER}_INTERNAL_LAST_CHECK_VERSION "${${_PACKAGE_NAME_UPPER}_VERSION_EXT}" CACHE INTERNAL "" FORCE )
set( PACKAGE_REFERENCE_EXISTS_TEST TRUE )
set( _OWN_FILE "${_EXCLUDE_DIR}/${_PACKAGE_NAME}Config.cmake" )
file( GLOB_RECURSE _ALL_VERSION_FILES "${VISTA_CMAKE_COMMON}/share/${_PACKAGE_NAME}*/${_PACKAGE_NAME}Config.cmake" )
foreach( _FILE ${_ALL_VERSION_FILES} )
file( TO_CMAKE_PATH "${_FILE}" _FILE )
if( NOT _FILE STREQUAL _OWN_FILE )
set( PACKAGE_REFERENCE_OUTDATED FALSE )
include( "${_FILE}" )
if( PACKAGE_REFERENCE_OUTDATED OR "${_PACKAGE_TARGET_FILE}" STREQUAL "${${_PACKAGE_NAME_UPPER}_REFERENCED_FILE}" )
string( REGEX MATCH "(${VISTA_CMAKE_COMMON}/share/.+)/.*" _MATCHED ${_FILE} )
if( _MATCHED )
set( _DIR "${CMAKE_MATCH_1}" )
message( STATUS "Removing old config reference copied to \"${_DIR}\"" )
file( REMOVE_RECURSE "${_DIR}" )
endif( _MATCHED )
endif( PACKAGE_REFERENCE_OUTDATED OR "${_PACKAGE_TARGET_FILE}" STREQUAL "${${_PACKAGE_NAME_UPPER}_REFERENCED_FILE}" )
endif( NOT _FILE STREQUAL _OWN_FILE )
endforeach( _FILE ${_ALL_VERSION_FILES} )
set( PACKAGE_REFERENCE_EXISTS_TEST )
endif()
endfunction()
# local macro, for use in this file only
function( local_use_existing_config_libs _NAME _ROOT_DIR _CONFIG_FILE _LIBRARY_DIR_LIST )
get_filename_component( _ROOT_DIR "${_ROOT_DIR}" REALPATH )
string( TOUPPER ${_NAME} _NAME_UPPER )
if( EXISTS "${_CONFIG_FILE}" )
include( "${_CONFIG_FILE}" )
get_filename_component( ${_NAME_UPPER}_ROOT_DIR "${${_NAME_UPPER}_ROOT_DIR}" REALPATH )
if( "${${_NAME_UPPER}_ROOT_DIR}" STREQUAL "${_ROOT_DIR}" )
if( ${_NAME_UPPER}_LIBRARY_DIRS )
list( APPEND ${_LIBRARY_DIR_LIST} "${${_NAME_UPPER}_LIBRARY_DIRS}" )
list( REMOVE_DUPLICATES ${_LIBRARY_DIR_LIST} )
endif()
endif()
endif()
set( ${_LIBRARY_DIR_LIST} ${${_LIBRARY_DIR_LIST}} PARENT_SCOPE )
endfunction()
# vista_enable_all_compiler_warnings()
# Enables all compiler warnings, excluding some (subjectively less important) ones
macro( vista_enable_all_compiler_warnings )
if( NOT "${VISTA_SHOW_ALL_WARNINGS_EXECUTED}" )
set( VISTA_SHOW_ALL_WARNINGS_EXECUTED TRUE CACHE INTERNAL "" )
if( MSVC )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4" CACHE STRING "Flags used by the compiler during all build types." FORCE )
elseif( UNIX )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra" CACHE STRING "Flags used by the compiler during all build types." FORCE )
endif( MSVC )
endif( NOT "${VISTA_SHOW_ALL_WARNINGS_EXECUTED}" )
endmacro( vista_enable_all_compiler_warnings )
# vista_enable_most_compiler_warnings()
# Enables most compilerwarnings, excluding some (subjectively less important) ones
macro( vista_enable_most_compiler_warnings )
if( NOT "${VISTA_SHOW_MOST_WARNINGS_EXECUTED}" )
set( VISTA_SHOW_MOST_WARNINGS_EXECUTED TRUE CACHE INTERNAL "" )
if( MSVC )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /wd4244 /wd4100 /wd4512 /wd4245 /wd4389" CACHE STRING "Flags used by the compiler during all build types." FORCE )
elseif( UNIX )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-reorder" CACHE STRING "Flags used by the compiler during all build types." FORCE )
endif( MSVC )
endif( NOT "${VISTA_SHOW_MOST_WARNINGS_EXECUTED}" )
endmacro( vista_enable_most_compiler_warnings )
###########################
### Package macros ###
###########################
# vista_add_external_msvc_project_of_package( PACKAGE_NAME [SOLUTION_FOLDER] [DEPENDENT (DENENDENT_TARGET)+ ] [ DEPENDS (DEPENDANT_TRAGET)+ ] [SILENT | WARNING | ERROR] )
# Adds msvc projects that were exported by a package to the solution (Visual Studio only)
# note: the targets will NOT be named by their original name, but
# instead external_NAME, to prevent name clashes (e.g. with included libraries)
# will only work if a project exists, and other wise fails silently (note: deployments, i.e. installed libs, have no projects and will hence always fail)
# Parameters:
# - PACKAGE_NAME: name of the package (from vista_find|use_package) whose projects should become included
# - [SILENT | WARNING | ERROR] (optional, default is WARNING): SILENT will silently ignore all warnings and
# suppress information output, WARNING will emit warning but continues cmake execution,
# ERROR emits warning and stops cmake execution
# - SOLUTION_FOLDER (optional): Visual Studio solution folder where the project(s) should be put
# - DEPENDENT (targets)* (optional): list of targets that should depend on the added projects
# Note: for this to work, the macro has to be called AFTER defining the dependent targets
# - DEPENDS (targets)* (optional): list of targets on which the loaded targets depend. These can be either manually added targets,
# or other targets loaded with vista_add_external_msvc_project_of_package.
macro( vista_add_external_msvc_project_of_package _PACKAGE_NAME )
if( MSVC )
set( VISTA_ALLOW_ADDING_OF_EXTERNAL_MSVC_PROJECTS ON CACHE BOOL "If enabled, external msvc projects listed in vista_add_external_msvc_project_of_package will be added" )
mark_as_advanced( VISTA_ALLOW_ADDING_OF_EXTERNAL_MSVC_PROJECTS )
if( VISTA_ALLOW_ADDING_OF_EXTERNAL_MSVC_PROJECTS )
string( TOUPPER ${_PACKAGE_NAME} _PACKAGE_NAME_UPPER )
set( _NEXT_IS_NAME FALSE )
set( _NEXT_IS_PROJ FALSE )
set( _NEXT_IS_DEP FALSE )
set( _NAME "" )
set( _POSSIBLE_DEPENDENCIES "" )
set( _FOLDER "" )
set( _DEPENDS_TARGETS "" )
set( _DEPENDENT_TARGETS "" )
set( _WARNING_LEVEL "WARNING" )
set( _ARGUMENTS ${ARGV} )
list( REMOVE_AT _ARGUMENTS 0 )
# Extract all parameters and DEPENDS and DEPENDENT targets.
set( _MODE -1 ) # -1 = first, 0 = nothing, 1 = Depends, 2 = Dependent
foreach( _ARG ${_ARGUMENTS} )
if( "${_ARG}" STREQUAL "DEPENDS" )
set( _MODE 1 )
elseif( "${_ARG}" STREQUAL "DEPENDENT" )
set( _MODE 2 )
elseif( "${_ARG}" STREQUAL "SILENT" )
set( _WARNING_LEVEL "SILENT" )
set( _MODE 0 )
elseif( "${_ARG}" STREQUAL "WARNING" )
set( _WARNING_LEVEL "WARNING" )
set( _MODE 0 )
elseif( "${_ARG}" STREQUAL "ERROR" )
set( _WARNING_LEVEL "SEND_ERROR" )
set( _MODE 0 )
elseif( _MODE STREQUAL -1 )
# its the first after the name -> Folder
set( _FOLDER "${_ARG}" )
set( _MODE 0 )
elseif( _MODE STREQUAL 1 )
get_property( _EXTERNALLY_ADDED_PROJECTS GLOBAL PROPERTY VISTA_EXTERNALLY_ADDED_PROJECTS )
list( FIND _EXTERNALLY_ADDED_PROJECTS "${_ARG}" _VAL )
if( _VAL GREATER -1 )
list( APPEND _DEPENDS_TARGETS "external_${_ARG}" )
elseif( TARGET)
list( APPEND _DEPENDS_TARGETS ${_ARG} )
else()
message( STATUS "vista_add_external_msvc_project_of_package( ${_PACKAGE_NAME_UPPER} ) - dependency to non-existing target ${_ARG} ignored" )
endif()
elseif( _MODE STREQUAL 2 )
list( APPEND _DEPENDENT_TARGETS ${_ARG} )
else()
message( WARNING "vista_add_external_msvc_project_of_package: unknown parameter \"${_ARG}\"" )
endif()
endforeach()
if( "${${_PACKAGE_NAME_UPPER}_MSVC_PROJECT}" STREQUAL "" AND NOT "${_WARNING_LEVEL}" STREQUAL "SILENT" )
# Sorry for the mess below. But CMake requires it to write a string like this if you want to make it multi-line and formatted...
message( "${_WARNING_LEVEL}"
" vista_add_external_msvc_project_of_package - Project \"${_PACKAGE_NAME}\" not found. Check the following:
1. Check spelling of the project name, i.e. whether \"${_PACKAGE_NAME}\" is correct.
2. Check if the CMakeLists.txt includes an appropriate vista_add_package line, e.g. \"vista_use_package( ${_PACKAGE_NAME} )\".
3. Check that you are using the affected library in its \"build\" version and not the \"installed/deployed\" package." )
endif()
foreach( _ENTRY ${${_PACKAGE_NAME_UPPER}_MSVC_PROJECT} )
if( "${_ENTRY}" STREQUAL "PROJ" )
set( _NEXT_IS_NAME TRUE )
set( _NEXT_IS_PROJ FALSE )
set( _NEXT_IS_DEP FALSE )
elseif( "${_ENTRY}" STREQUAL "DEP" )
set( _NEXT_IS_PROJ FALSE )
set( _NEXT_IS_NAME FALSE )
set( _NEXT_IS_DEP TRUE )
elseif( _NEXT_IS_NAME )
set( _NEXT_IS_NAME FALSE )
set( _NEXT_IS_PROJ TRUE )
set( _NEXT_IS_DEP FALSE )
set( _NAME "${_ENTRY}" )
elseif( _NEXT_IS_PROJ )
set( _NEXT_IS_PROJ FALSE )
set( _NEXT_IS_NAME FALSE )
set( _NEXT_IS_DEP FALSE )
# sanity check if project exists
if( EXISTS "${_ENTRY}" )
get_property( _EXTERNALLY_ADDED_PROJECTS GLOBAL PROPERTY VISTA_EXTERNALLY_ADDED_PROJECTS )
# check if the project was already added before, e.g. in another subproject
list( FIND _EXTERNALLY_ADDED_PROJECTS "${_NAME}" _PROJ_ALREADY_ADDED )
if( _PROJ_ALREADY_ADDED EQUAL -1 )
if( NOT "${_WARNING_LEVEL}" STREQUAL "SILENT" )
message( STATUS "vista_add_external_msvc_project_of_package( ${_PACKAGE_NAME_UPPER} ) - adding external project as external_${_NAME}" )
endif()
if( MSVC11 OR MSVC12 )
#file( STRINGS "${_ENTRY}" _MSVCPROJ_GUID REGEX "<ProjectGUID>{[^}]+}</ProjectGUID>" )
#string( REGEX REPLACE "<ProjectGUID>{([^}]+)}</ProjectGUID>" "\\1" _MSVCPROJ_GUID "${_MSVCPROJ_GUID}" )
#message( "_MSVCPROJ_GUID ${_MSVCPROJ_GUID}" )
#include_external_msproject( "external_${_NAME}" "${_ENTRY}" GUID ${_MSVCPROJ_GUID} )
include_external_msproject( "external_${_NAME}" "${_ENTRY}" )
else()
include_external_msproject( "external_${_NAME}" "${_ENTRY}" )
endif()
set_property( GLOBAL APPEND PROPERTY VISTA_EXTERNALLY_ADDED_PROJECTS ${_NAME} )
endif()
list( APPEND _POSSIBLE_DEPENDENCIES ${_NAME} )
if( _FOLDER AND CMAKE_VERSION VERSION_GREATER 2.8.4 )
set_target_properties( "external_${_NAME}" PROPERTIES FOLDER ${_FOLDER} )
endif()
foreach( _DEP ${_DEPENDS_TARGETS} )
add_dependencies( external_${_NAME} ${_DEP} )
endforeach()
foreach( _DEP ${_DEPENDENT_TARGETS} )
add_dependencies( ${_DEP} external_${_NAME} )
endforeach()
endif()
elseif( _NEXT_IS_DEP )
list( FIND _POSSIBLE_DEPENDENCIES ${_ENTRY} _FOUND )
if( _FOUND GREATER -1 )
add_dependencies( external_${_NAME} external_${_ENTRY} )
elseif( NOT "${_WARNING_LEVEL}" STREQUAL "SILENT" )
message( "vista_add_external_msvc_project_of_package( ${_PACKAGE_NAME} ) - project ${_NAME} requests unknown dependency ${_ENTRY}" )
endif()
else()
message( WARNING "vista_add_external_msvc_project_of_package( ${_PACKAGE_NAME_UPPER} ) - unknown parameter \"${_ENTRY}\"" )
endif()
endforeach()
endif()
endif()
endmacro( vista_add_external_msvc_project_of_package )
# vista_find_package( <package> [version] [EXACT] [QUIET] [[REQUIRED|COMPONENTS] [components...]] [NO_POLICY_SCOPE] [NO_MODULE] )
# wrapper for the cmake-native find_package with the same (basic) syntax and the following extensions:
# - allows extended versions (e.g. NAME, 1.2.4-8, etc.)
# - checks if a vista-specific FindV<package>.cmake file exists, and prefers this
# - if no module is found, the config files are searched in additional subdirectories
macro( vista_find_package _PACKAGE_NAME )
string( TOUPPER ${_PACKAGE_NAME} _PACKAGE_NAME_UPPER )
# parse arguments
set( _FIND_PACKAGE_ARGS )
set( _FIND_DEPENDENCIES FALSE )
set( _PACKAGE_VERSION )
set( _PACKAGE_COMPONENTS )
set( _QUIET FALSE )
set( _REQUIRED FALSE )
set( _USING_COMPONENTS FALSE )
set( _NO_MODULE FALSE )
set( _EXACT FALSE )
foreach( _ARG ${ARGV} )
if( ${_ARG} STREQUAL "FIND_DEPENDENCIES" )
set( _PARSE_COMPONENTS FALSE )
set( _FIND_DEPENDENCIES TRUE )
elseif( ${_ARG} STREQUAL "QUIET" )
set( _PARSE_COMPONENTS FALSE )
list( APPEND _FIND_PACKAGE_ARGS "QUIET" )
set( _QUIET TRUE )
elseif( ${_ARG} STREQUAL "REQUIRED" )
set( _PARSE_COMPONENTS TRUE )
list( APPEND _FIND_PACKAGE_ARGS "REQUIRED" )
if( _VISTAUSEPACKAGE_COMPONENTS ) # possible overwrite of components from vista_use_package
list( APPEND _FIND_PACKAGE_ARGS ${_VISTAUSEPACKAGE_COMPONENTS} )
set( _PACKAGE_COMPONENTS ${_VISTAUSEPACKAGE_COMPONENTS} )
set( _USING_COMPONENTS TRUE )
endif()
set( _REQUIRED TRUE )
elseif( ${_ARG} STREQUAL "COMPONENTS" )
set( _PARSE_COMPONENTS TRUE )
list( APPEND _FIND_PACKAGE_ARGS "COMPONENTS" )
if( _VISTAUSEPACKAGE_COMPONENTS ) # possible overwrite of components from vista_use_package
list( APPEND _FIND_PACKAGE_ARGS ${_VISTAUSEPACKAGE_COMPONENTS} )
set( _PACKAGE_COMPONENTS ${_VISTAUSEPACKAGE_COMPONENTS} )
set( _USING_COMPONENTS TRUE )
endif()
elseif( ${_ARG} STREQUAL "EXACT" )
set( _EXACT TRUE )
set( _PARSE_COMPONENTS FALSE )
list( APPEND _FIND_PACKAGE_ARGS "EXACT" )
elseif( ${_ARG} STREQUAL "NO_POLICY_SCOPE" )
set( _PARSE_COMPONENTS FALSE )
list( APPEND _FIND_PACKAGE_ARGS "NO_POLICY_SCOPE" )
elseif( ${_ARG} STREQUAL "NO_MODULE" )
set( _NO_MODULE TRUE )
list( APPEND _FIND_PACKAGE_ARGS "NO_MODULE" )
elseif( ${_ARG} STREQUAL "${ARGV0}" )
# it's okay, just the name
elseif( ${_ARG} STREQUAL "${ARGV1}" )
# the requested version
set( _PACKAGE_VERSION ${_ARG} )
elseif( _PARSE_COMPONENTS )
if( NOT _VISTAUSEPACKAGE_COMPONENTS ) # only re-parse components if they aren't specified by vista_use_package alreaedy
list( APPEND _FIND_PACKAGE_ARGS ${_ARG} )
list( APPEND _PACKAGE_COMPONENTS ${_ARG} )
set( _USING_COMPONENTS TRUE )
endif()
else()
message( WARNING "vista_find_package( ${_PACKAGE_NAME} ) - Unknown argument [${_ARG}]" )
endif( ${_ARG} STREQUAL "FIND_DEPENDENCIES" )
endforeach( _ARG ${ARGV} )
set( _DO_FIND TRUE )
if( ${_PACKAGE_NAME_UPPER}_FOUND )
set( _DO_FIND FALSE )
set( _PREVIOUSLY_FOUND_VERSION )
if( ${_PACKAGE_NAME_UPPER}_VERSION_EXT )
set( _PREVIOUSLY_FOUND_VERSION ${${_PACKAGE_NAME_UPPER}_VERSION_EXT} )
elseif( ${_PACKAGE_NAME}_VERSION_EXT )
set( _PREVIOUSLY_FOUND_VERSION ${${_PACKAGE_NAME}_VERSION_EXT} )
elseif( ${_PACKAGE_NAME_UPPER}_VERSION )
set( _PREVIOUSLY_FOUND_VERSION ${${_PACKAGE_NAME_UPPER}_VERSION_EXT} )
elseif( ${_PACKAGE_NAME}_VERSION )
set( _PREVIOUSLY_FOUND_VERSION ${${_PACKAGE_NAME}_VERSION} )
elseif( ${_PACKAGE_NAME_UPPER}_VERSION_STRING )
set( _PREVIOUSLY_FOUND_VERSION ${${_PACKAGE_NAME_UPPER}_VERSION_STRING} )
elseif( ${_PACKAGE_NAME}_VERSION_STRING )
set( _PREVIOUSLY_FOUND_VERSION ${${_PACKAGE_NAME}_VERSION_STRING} )
endif( ${_PACKAGE_NAME_UPPER}_VERSION_EXT )
if( _PREVIOUSLY_FOUND_VERSION )
if( _PACKAGE_VERSION )
# we have to check that we don't include different versions!
vista_string_to_version( ${_PREVIOUSLY_FOUND_VERSION} "PREVIOUS" )
vista_string_to_version( ${_PACKAGE_VERSION} "REQUESTED" )
vista_compare_versions( "REQUESTED" "PREVIOUS" _DIFFERENCE )
if( _DIFFERENCE EQUAL -1 )
message( WARNING "vista_find_package( ${_PACKAGE_NAME} ) - Package was previously found with"
" version (${_PREVIOUSLY_FOUND_VERSION}), but is now requested with"
" incompatible version (${_PACKAGE_VERSION}) - first found version is used,"
" but this may lead to conflicts" )
elseif( _DIFFERENCE VERSION_GREATER 0.0.0.0 AND _EXACT )
message( "vista_find_package( ${_PACKAGE_NAME} ) - Package was previously found with"
" version (${_PREVIOUSLY_FOUND_VERSION}), but is now requested with"
" different, but compatible version (${_PACKAGE_VERSION}) - first found version is used" )
#else: prefect match
endif( _DIFFERENCE EQUAL -1 )
endif()
# we always want to find the sam eversiona gain, so set it to the former one
set( _PACKAGE_VERSION ${_PREVIOUSLY_FOUND_VERSION} )
endif()
if( _USING_COMPONENTS )
# we need to check if the components are already included or not
if( ${_PACKAGE_NAME_UPPER}_FOUND_COMPONENTS )
foreach( _COMPONENT ${_PACKAGE_COMPONENTS} )
list( FIND ${_PACKAGE_NAME_UPPER}_FOUND_COMPONENTS ${_COMPONENT} _COMPONENT_FOUND )
if( _COMPONENT_FOUND LESS 0 )
set( _DO_FIND TRUE )
break()
endif( _COMPONENT_FOUND LESS 0 )
endforeach( _COMPONENT ${_PACKAGE_COMPONENTS} )
else()
set( _DO_FIND TRUE )
endif()
endif()
endif()
if( _DO_FIND )
# this is somewhat of an intransparent hack: if _MESSAGE_IF_DO_FIND is set, we print a message
# with it and reset the value. This is to allow vista_use_package to print additional info
# - no one else should need to use thsi
if( _MESSAGE_IF_DO_FIND )
message( STATUS "${_MESSAGE_IF_DO_FIND}" )
set( _MESSAGE_IF_DO_FIND )
endif( _MESSAGE_IF_DO_FIND )
if( _PACKAGE_VERSION )
# check if it is a "normal" or an extended version
string( REGEX MATCH "^[0-9\\.]*$" _MATCH ${_PACKAGE_VERSION} )
if( NOT _MATCH )
# its an extended version
set( PACKAGE_FIND_VERSION_EXT ${_PACKAGE_VERSION} )
set( ${_PACKAGE_NAME}_FIND_VERSION_EXT ${_PACKAGE_VERSION} )
set( V${_PACKAGE_NAME}_FIND_VERSION_EXT ${_PACKAGE_VERSION} )
set( _PACKAGE_VERSION 0.0.0.0 )
endif( NOT _MATCH )
endif( _PACKAGE_VERSION )
# there can be three differnet options
# - there is a Vista-custom FindV<PackageName>.cmake
# - there is a generic Find<PackageName>.cmake
# - if none of the above, we use config mode
# however, we skip the first two steps if no module should be found
set( _FIND_VMODULE_EXISTS FALSE )
set( _FIND_MODULE_EXISTS FALSE )
if( NOT _NO_MODULE )
foreach( _PATH ${CMAKE_MODULE_PATH} ${CMAKE_ROOT} ${CMAKE_ROOT}/Modules )
if( EXISTS "${_PATH}/FindV${_PACKAGE_NAME}.cmake" )
set( _FIND_VMODULE_EXISTS TRUE )
endif( EXISTS "${_PATH}/FindV${_PACKAGE_NAME}.cmake" )
if( EXISTS "${_PATH}/Find${_PACKAGE_NAME}.cmake" )
set( _FIND_MODULE_EXISTS TRUE )
endif( EXISTS "${_PATH}/Find${_PACKAGE_NAME}.cmake" )
endforeach( _PATH ${CMAKE_MODULE_PATH} )
endif( NOT _NO_MODULE )
set( ${_PACKAGE_NAME_UPPER}_FOUND_COMPONENTS )
if( _FIND_VMODULE_EXISTS )
find_package( V${_PACKAGE_NAME} ${_PACKAGE_VERSION} ${_FIND_PACKAGE_ARGS} )
set( ${_PACKAGE_NAME_UPPER}_FOUND ${V${_PACKAGE_NAME_UPPER}_FOUND} )
elseif( _FIND_MODULE_EXISTS )
find_package( ${_PACKAGE_NAME} ${_PACKAGE_VERSION} ${_FIND_PACKAGE_ARGS} )
if( NOT ${_PACKAGE_NAME_UPPER}_FOUND AND ${_PACKAGE_NAME}_FOUND )
set( ${_PACKAGE_NAME_UPPER}_FOUND ${${_PACKAGE_NAME}_FOUND} )
endif()
else()
if( NOT ${PACKAGE_NAME_UPPER}_ADDITIONAL_CONFIG_DIRS )
# we look for additional directories to search for the config files
# we also search for CoreLibs directories manually
foreach( _PATH $ENV{${_PACKAGE_NAME_UPPER}_ROOT} ${VISTA_PACKAGE_SEARCH_PATHS} )
if( EXISTS "${_PATH}" )
file( TO_CMAKE_PATH ${_PATH} _PATH )
list( APPEND _SEARCH_PREFIXES
"${_PATH}/${_PACKAGE_NAME}*/${VISTA_HWARCH}"
"${_PATH}/${_PACKAGE_NAME}*"
"${_PATH}/${_PACKAGE_NAME}/*/${VISTA_HWARCH}"
"${_PATH}/${_PACKAGE_NAME}/*/"
)
endif( EXISTS "${_PATH}" )
endforeach( _PATH ${_SEARCH_DIRS} )
foreach( _PATH ${_SEARCH_PREFIXES} )
file( GLOB _TMP_PATHES "${_PATH}" )
list( APPEND ${PACKAGE_NAME_UPPER}_ADDITIONAL_CONFIG_DIRS ${_TMP_PATHES} )
endforeach( _PATH ${_PREFIX_PATHES} )
if( ${PACKAGE_NAME_UPPER}_ADDITIONAL_CONFIG_DIRS )
list( REMOVE_DUPLICATES ${PACKAGE_NAME_UPPER}_ADDITIONAL_CONFIG_DIRS )
endif( ${PACKAGE_NAME_UPPER}_ADDITIONAL_CONFIG_DIRS )
endif( NOT ${PACKAGE_NAME_UPPER}_ADDITIONAL_CONFIG_DIRS )
set( ${_PACKAGE_NAME}_ACTUAL_DIR )
#if( PACKAGE_FIND_VERSION_EXT AND NOT _QUIET )
if( NOT _QUIET )
string( REPLACE "REQUIRED" "COMPONENTS" _CLEANED_FIND_PACKAGE_ARGS "${_FIND_PACKAGE_ARGS}" )
find_package( ${_PACKAGE_NAME} ${_PACKAGE_VERSION} ${_CLEANED_FIND_PACKAGE_ARGS}
PATHS ${${PACKAGE_NAME_UPPER}_ADDITIONAL_CONFIG_DIRS} ${VISTA_PACKAGE_SEARCH_PATHS} QUIET )
if( NOT ${_PACKAGE_NAME}_FOUND )
set( _VERSION_NAME ${_PACKAGE_VERSION} )
if( PACKAGE_FIND_VERSION_EXT )
set( _VERSION_NAME ${PACKAGE_FIND_VERSION_EXT} )
endif()
if(${_PACKAGE_NAME}_CONSIDERED_CONFIGS)
set( _MESSAGE " Could not find a configuration file for package \"${_PACKAGE_NAME}\" that is" )
set( _MESSAGE "${_MESSAGE}\n compatible with requested version \"${_VERSION_NAME}\" (Architecture: ${VISTA_HWARCH})" )
set( _MESSAGE "${_MESSAGE}\n The following configuration files were considered but not accepted:" )
list( LENGTH ${_PACKAGE_NAME}_CONSIDERED_CONFIGS _CONFIG_COUNT )
math( EXPR _CONFIG_COUNT "${_CONFIG_COUNT} - 1")
foreach( _CONFIG_INDEX RANGE ${_CONFIG_COUNT} )
list( GET ${_PACKAGE_NAME}_CONSIDERED_CONFIGS ${_CONFIG_INDEX} _FILENAME )
list( GET ${_PACKAGE_NAME}_CONSIDERED_VERSIONS ${_CONFIG_INDEX} _VERSION )
set( _MESSAGE "${_MESSAGE}\n ${_FILENAME}" )
if( NOT "${_VERSION}" STREQUAL "" AND NOT "${_VERSION}" STREQUAL "unknown" )
set( _MESSAGE "${_MESSAGE}\n ${_VERSION}" )
endif()
endforeach()
if( NOT _VERSION_NAME )
set( _MESSAGE "${_MESSAGE}\n Probably, no build with matching architecture \"${VISTA_HWARCH}\" was found" )
endif()
else()
string( TOLOWER ${_PACKAGE_NAME} _PACKAGE_NAME_LOWER )
set( _MESSAGE " Could not find a configuration file for package \"${_PACKAGE_NAME}\"." )
set( _MESSAGE "${_MESSAGE}\n Set ${_PACKAGE_NAME}_DIR to the directory containing a CMake configuration" )
set( _MESSAGE "${_MESSAGE}\n file for ${_PACKAGE_NAME}. The file will have one of the following names" )
set( _MESSAGE "${_MESSAGE}\n ${_PACKAGE_NAME}Config.cmake" )
set( _MESSAGE "${_MESSAGE}\n ${_PACKAGE_NAME_LOWER}-config.cmake" )
endif()
if( _REQUIRED )
message( SEND_ERROR "${_MESSAGE}\n" )
else()
message( WARNING "${_MESSAGE}\n" )
endif()
endif()
else()
find_package( ${_PACKAGE_NAME} ${_PACKAGE_VERSION} ${_FIND_PACKAGE_ARGS}
PATHS ${${PACKAGE_NAME_UPPER}_ADDITIONAL_CONFIG_DIRS} ${VISTA_PACKAGE_SEARCH_PATHS} )
endif()
# in case we dound a reference file (e.g. in VistaCMakeCommon/share), the Package_DIR would point
# to the reference. Instead, we want it to point to the actual file directory
if( ${_PACKAGE_NAME}_ACTUAL_DIR )
set( ${_PACKAGE_NAME}_DIR "${${_PACKAGE_NAME}_ACTUAL_DIR}" CACHE PATH "The directory containing a CMake configuration file for $_PACKAGE_NAME}" FORCE )
endif()
endif()
if( NOT ${_PACKAGE_NAME_UPPER}_FOUND_COMPONENTS )
set( ${_PACKAGE_NAME_UPPER}_FOUND_COMPONENTS ${_PACKAGE_COMPONENTS} )
endif()
endif( _DO_FIND )
set( _MESSAGE_IF_DO_FIND )
endmacro( vista_find_package )
# vista_use_package( PACKAGE [VERSION] [EXACT] [[COMPONENTS | REQUIRED] comp1 comp2 ... ] [QUIET] [FIND_DEPENDENCIES] [NO_RECURSIVE_DEPENCENCY] [SYSTEM_HEADERS] )
# finds the desired Package and automatically sets the include dirs, library dirs, definitions for the project.
# Libraries have to be included using the VARIABLE PACKAGENAME_LIBRARIES. Alternatively, VISTA_USE_PACKAGE_LIBRARIES contains
# all libraries that have been linked by vista_use_package calls. Additionally, buildsystem-specific variables are set that
# keep track of dependencies
# Parameters
# VERSION - string describing the version - either the normal cmake-format XX.YY.ZZ.WW or the vista-specific extended version string
# EXACT specifies that the version has to be matched exactly
# REQUIRED specifies that the package must be found to continue. can optionally be followed by a list of required components
# COMPONENTS can be followed by a list of optional, desired components
# QUIET suppresses any warnings and other output except for errors
# FIND_DEPENDENCIES If set, all packages that are required by the included packages are tried to be found and used automatically
# NO_RECURSIVE_DEPENCENCY specifies that this package should not count as a recursive dependency, i.e. if a library uses this package,
# and is then used (via vista_use_package) by another project, this package will not count as dependency for the
# new project. This is useful e.g. for header-only-libraries or libs that are statically linked-in
# SYSTEM_HEADERS marks all include paths of this package as system include pathes on supported compilers (e.g. gcc), which
# may have multiple effects, e.g. ignoring of warnings in these files
macro( vista_use_package _PACKAGE_NAME )
string( TOUPPER ${_PACKAGE_NAME} _PACKAGE_NAME_UPPER )
# check if we need to rerun. this is the case it has not been used yet,
# or if it has been used, but now additional dependencies are requested
set( _REQUIRES_RERUN TRUE )
set( _VISTAUSEPACKAGE_COMPONENTS )
if( VISTA_USE_${_PACKAGE_NAME_UPPER} )
# extract components, to see if they are met already or not
set( _REQUESTED_COMPONENTS )
set( _PARSE_COMPONENTS FALSE )
set( _COMPONENTS_FOUND FALSE )
foreach( _ARG ${ARGV} )
if( ${_ARG} STREQUAL "COMPONENTS" OR ${_ARG} STREQUAL "REQUIRED" )
set( _PARSE_COMPONENTS TRUE )
elseif( ${_ARG} STREQUAL "QUIET"
OR ${_ARG} STREQUAL "EXACT"
OR ${_ARG} STREQUAL "NO_POLICY_SCOPE"
OR ${_ARG} STREQUAL "FIND_DEPENDENCIES"
OR ${_ARG} STREQUAL "NO_RECURSIVE_DEPENCENCY"
OR ${_ARG} STREQUAL "NO_RMODULE"
OR ${_ARG} STREQUAL "SYSTEM_HEADERS" )
set( _PARSE_COMPONENTS FALSE )
elseif( _PARSE_COMPONENTS )
list( APPEND _REQUESTED_COMPONENTS ${_ARG} )
set( _COMPONENTS_FOUND TRUE )
endif( ${_ARG} STREQUAL "COMPONENTS" OR ${_ARG} STREQUAL "REQUIRED" )
endforeach( _ARG ${ARGV} )
set( _REQUIRES_RERUN FALSE )
if( _COMPONENTS_FOUND )
# we need to check if any additional components are required
foreach( _COMPONENT ${_REQUESTED_COMPONENTS} )
list( FIND ${_PACKAGE_NAME_UPPER}_FOUND_COMPONENTS ${_COMPONENT} _FOUND )
if( _FOUND EQUAL -1 )
# we need to find additional components - merge the requested and the already found ones
# so that the new search finds both the newly requested components and those from the last run
set( _VISTAUSEPACKAGE_COMPONENTS ${_REQUESTED_COMPONENTS} ${${_PACKAGE_NAME_UPPER}_FOUND_COMPONENTS} )
list( REMOVE_DUPLICATES _VISTAUSEPACKAGE_COMPONENTS )
set( _REQUIRES_RERUN TRUE )
break()
endif()
endforeach()
endif()
# todo: check version
endif()
if( _REQUIRES_RERUN )
# we first extract some parameters, then try to find the package
set( _ARGUMENTS ${ARGV} )
# parse arguments
list( FIND _ARGUMENTS "FIND_DEPENDENCIES" _FIND_DEPENDENCIES_FOUND )
if( _FIND_DEPENDENCIES_FOUND GREATER -1 )
set( _FIND_DEPENDENCIES TRUE )
else()
set( _FIND_DEPENDENCIES FALSE )
endif()
list( FIND _ARGUMENTS "NO_RECURSIVE_DEPENCENCY" _NO_RECURSIVE_DEPENCENCY_FOUND )
if( _NO_RECURSIVE_DEPENCENCY_FOUND GREATER -1 )
set( _NO_RECURSIVE_DEPENCENCY TRUE )
list( REMOVE_ITEM _ARGUMENTS "NO_RECURSIVE_DEPENCENCY" )
else()
set( _NO_RECURSIVE_DEPENCENCY FALSE )
endif()
list( FIND _ARGUMENTS "QUIET" _QUIET_FOUND )
if( _QUIET_FOUND GREATER -1 )
set( _QUIET TRUE )
else()
set( _QUIET FALSE )
endif()
list( FIND _ARGUMENTS "SYSTEM_HEADERS" _SYSTEM_HEADERS_FOUND )
if( _SYSTEM_HEADERS_FOUND GREATER -1 )
set( _PACKAGE_INCLUDES_ARE_SYSTEM_HEADERS TRUE )
list( REMOVE_ITEM _ARGUMENTS SYSTEM_HEADERS )
else()
set( _PACKAGE_INCLUDES_ARE_SYSTEM_HEADERS FALSE )
endif()
# finding will handle differences to already run find's
vista_find_package( ${_ARGUMENTS} )
set( _VISTAUSEPACKAGE_COMPONENTS )
# set required variables if package was found AND it wasn't sufficiently included before (in which case _DO_FIND is FALSE )
if( ${_PACKAGE_NAME_UPPER}_FOUND AND ( _DO_FIND OR NOT VISTA_USE_${_PACKAGE_NAME_UPPER} ) )
# check if HWARCH matches
if( ${_PACKAGE_NAME_UPPER}_HWARCH AND NOT ${${_PACKAGE_NAME_UPPER}_HWARCH} STREQUAL ${VISTA_HWARCH} )
message( WARNING "vista_use_package( ${_PACKAGE_NAME} ) - Package was built as ${${_PACKAGE_NAME_UPPER}_HWARCH}, but is used with ${VISTA_HWARCH}" )
endif( ${_PACKAGE_NAME_UPPER}_HWARCH AND NOT ${${_PACKAGE_NAME_UPPER}_HWARCH} STREQUAL ${VISTA_HWARCH} )
# if a USE_FILE is specified, we assume that it handles all the settings
# if not, we set the necessary values ourselves
if( ${_PACKAGE_NAME_UPPER}_USE_FILE )
include( "${${_PACKAGE_NAME_UPPER}_USE_FILE}" )
else()
if( _PACKAGE_INCLUDES_ARE_SYSTEM_HEADERS )
include_directories( SYSTEM ${${_PACKAGE_NAME_UPPER}_INCLUDE_DIRS} )
else()
include_directories( ${${_PACKAGE_NAME_UPPER}_INCLUDE_DIRS} )
endif()
link_directories( ${${_PACKAGE_NAME_UPPER}_LIBRARY_DIRS} )
add_definitions( ${${_PACKAGE_NAME_UPPER}_DEFINITIONS} )
endif( ${_PACKAGE_NAME_UPPER}_USE_FILE )
list( APPEND VISTA_TARGET_LINK_DIRS ${${_PACKAGE_NAME_UPPER}_LIBRARY_DIRS} )
if( VISTA_TARGET_LINK_DIRS )
list( REMOVE_DUPLICATES VISTA_TARGET_LINK_DIRS )
endif( VISTA_TARGET_LINK_DIRS )
set( VISTA_USING_${_PACKAGE_NAME_UPPER} TRUE )
if( NOT _NO_RECURSIVE_DEPENCENCY )
list( APPEND VISTA_TARGET_FULL_DEPENDENCIES ${_PACKAGE_NAME} )
list( REMOVE_DUPLICATES VISTA_TARGET_FULL_DEPENDENCIES )
# store dependencies only if we were not called recursively, and only if at least one library is actually added
if( NOT VISTA_USE_PACKAGE_RECURSION_COUNT OR VISTA_USE_PACKAGE_RECURSION_COUNT EQUAL 0 )
list( APPEND VISTA_TARGET_DEPENDENCIES "package" ${ARGV} )
endif()
endif()
# add libraries to VISTA_USE_PACKAGE_LIBRARIES. We do this after adding dependencies, and
# by pre-prending, in order to provide correct static linking under linux, where the dependent library
# has to be listed before the one it depends on
# To achieve this, we must first build a list of the current package's libraries, then process all
# its dependencies (which may append libraries to the internal storage), and finally prepend
# the internal storage to VISTA_USE_PACKAGE_LIBRARIES
set( INTERNAL_VISTA_FIND_PACKAGE_LIBS ${INTERNAL_VISTA_FIND_PACKAGE_LIBS} ${${_PACKAGE_NAME_UPPER}_LIBRARIES} )
if( ${_PACKAGE_NAME_UPPER}_SHADER_DIRS )
list( APPEND VISTA_SHADER_DIRECTORIS ${${_PACKAGE_NAME_UPPER}_SHADER_DIRS} )
list( REMOVE_DUPLICATES VISTA_SHADER_DIRECTORIS )
endif( ${_PACKAGE_NAME_UPPER}_SHADER_DIRS )
#mark call now (lateron, _PACKAGE_NAME_UPPER might be overwritten by sub-calls for dependencies)
set( VISTA_USE_${_PACKAGE_NAME_UPPER} TRUE )
# parse dependencies automatically call vista_use_package on not previously found ones
# indicate for them that they are recursively called, to prevent adding them to the dependency list,
# and to ensure correct ordering of libraries
if( NOT VISTA_USE_PACKAGE_RECURSION_COUNT )
set( VISTA_USE_PACKAGE_RECURSION_COUNT 1 )
else()
math( EXPR VISTA_USE_PACKAGE_RECURSION_COUNT "${VISTA_USE_PACKAGE_RECURSION_COUNT} + 1" )
endif()
set( _DEPENDENCY_ARGS )
# the last package ensures that the last listed package is included, too
foreach( _DEPENDENCY ${${_PACKAGE_NAME_UPPER}_DEPENDENCIES} "package" )
string( REGEX MATCH "^([^\\-]+)\\-(.+)$" _MATCHED ${_DEPENDENCY} )
if( _DEPENDENCY STREQUAL "package" )
if( _DEPENDENCY_ARGS AND NOT "${_DEPENDENCY_ARGS}" STREQUAL "" )
list( GET _DEPENDENCY_ARGS 0 _DEPENDENCY_NAME )
string( TOUPPER "${_DEPENDENCY_NAME}" _DEPENDENCY_NAME_UPPER )
if( _FIND_DEPENDENCIES )
#if( NOT ${_DEPENDENCY_NAME_UPPER}_FOUND )
# find and use the dependency. If it fails, utter a warning
if( NOT _QUIET )
string( REPLACE ";" " " _DEPENDENCY_ARGS_STRING "${_DEPENDENCY_ARGS}" )
set( _MESSAGE_IF_DO_FIND "Automatically adding ${_PACKAGE_NAME}-dependency \"${_DEPENDENCY_ARGS_STRING}\"" )
endif( NOT _QUIET )
vista_use_package( ${_DEPENDENCY_ARGS} FIND_DEPENDENCIES )
if( NOT ${_DEPENDENCY_NAME_UPPER}_FOUND AND NOT _QUIET )
message( WARNING "vista_use_package( ${_PACKAGE_NAME} ) - Package depends on \"${_DEPENDENCY_ARGS}\", but including it failed" )
endif( NOT ${_DEPENDENCY_NAME_UPPER}_FOUND AND NOT _QUIET )
#endif( NOT ${_DEPENDENCY_NAME_UPPER}_FOUND )
else()
# check if dependencies are already included. If not, utter a warning
if( NOT ${_DEPENDENCY_NAME_UPPER}_FOUND AND NOT _QUIET )
string( REPLACE ";" " " _DEPENDENCY_ARGS_STRING "${_DEPENDENCY_ARGS}" )
message( "vista_use_package( ${_PACKAGE_NAME} ) - Package depends on \"${_DEPENDENCY_ARGS_STRING}\", which was not found yet - "
"make sure to find this package before searchig for ${_PACKAGE_NAME}, or use parameter FIND_DEPENDENCIES" )
endif()
endif( _FIND_DEPENDENCIES )
set( _DEPENDENCY_ARGS )
endif()
else()
list( APPEND _DEPENDENCY_ARGS ${_DEPENDENCY} )
endif()
endforeach()
math( EXPR VISTA_USE_PACKAGE_RECURSION_COUNT "${VISTA_USE_PACKAGE_RECURSION_COUNT} - 1" )
#finally: prepend correctly ordered list of libraries to VISTA_USE_PACKAGE_LIBRARIES
if( VISTA_USE_PACKAGE_RECURSION_COUNT EQUAL 0 )
set( VISTA_USE_PACKAGE_LIBRARIES ${INTERNAL_VISTA_FIND_PACKAGE_LIBS} ${VISTA_USE_PACKAGE_LIBRARIES} )
set( INTERNAL_VISTA_FIND_PACKAGE_LIBS )
endif()
endif()
endif()
endmacro()
# vista_find_shader_dirs( PACKAGE_NAME )
# serches recursive for all subdirectories of CURRENT_SOURCE_DIR that contain shader files and
# adds them to the list of shader-directoriey.
macro( vista_find_shader_dirs _PACKAGE_NAME )
string( TOUPPER ${_PACKAGE_NAME} _PACKAGE_NAME_UPPER )
set ( ${_PACKAGE_NAME_UPPER}_INSTALL_SHADERS TRUE )
set ( _EXTENSIONS "vp" "fp" "glsl" )
foreach( _EXT ${_EXTENSIONS} )
file( GLOB_RECURSE _FOUND_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*.${_EXT}" )
foreach( _FILE ${_FOUND_FILES} )
string( REGEX REPLACE "(.*)/(.*)\\.${_EXT}" "\\1" _DIR ${_FILE} )
list( APPEND ${_PACKAGE_NAME_UPPER}_SHADER_DIRS ${_DIR} )
list( REMOVE_DUPLICATES ${_PACKAGE_NAME_UPPER}_SHADER_DIRS )
endforeach( _FILE ${_FOUND_FILES} )
endforeach( _EXT ${_EXTENSIONS} )
endmacro( vista_find_shader_dirs _PACKAGE_NAME )
# vista_configure_app( package_name [output_name] [DONT_COPY_EXECUTABLE | COPY_EXECUTABLE_TO dir] [WORKING_DIR dir] )
# sets some general properties for the target to configure it as application
# sets default out_dir (i.e. where the executable will be built) to the /bin subdir in the binary tree
# sets the Application Name to _PACKAGE_NAME with "D"-PostFix under Debug
# if not overwritten, sets the outdir to the target's source directory
# creates a shell script that sets the path to find required libraries
# for MSVC, a *.vcproj.user file is created, setting Working Directory and Path Environment
# By default, the executable (together with the path script and an optional build info file)
# is created in the outdir, but to the source dir copied after a successful build.
# This behavior can be controlled by adding the parameter DONT_COPY_EXECUTABLE if the files should
# not be copied, or by COPY_EXECUTABLE_TO TARGET_DIR to specify an alternative copy destination
macro( vista_configure_app _PACKAGE_NAME )
string( TOUPPER ${_PACKAGE_NAME} _PACKAGE_NAME_UPPER )
set( ${_PACKAGE_NAME_UPPER}_TARGET_TYPE "APP" )
set( ${_PACKAGE_NAME_UPPER}_OUTPUT_NAME ${_PACKAGE_NAME} CACHE INTERNAL "" FORCE )
# parse arguments
set( ${_PACKAGE_NAME_UPPER}_COPY_EXEC_DIR ${CMAKE_CURRENT_SOURCE_DIR} )
set( _OVERRIDE_WORKING_DIR )
set( _PARSE_MODE 0 ) # 0: first entry 1: awaiting command 2: next is TargetDir 3: next is WorkingDir
foreach( _ARG ${ARGN} )
if( _ARG STREQUAL "DONT_COPY_EXECUTABLE" )
set( ${_PACKAGE_NAME_UPPER}_COPY_EXEC_DIR )
set( _PARSE_MODE 1 )
elseif( _ARG STREQUAL "COPY_EXECUTABLE_TO" )
set( _PARSE_MODE 2 )
elseif( _ARG STREQUAL "WORKING_DIR" )
set( _PARSE_MODE 3 )
else()
if( _PARSE_MODE EQUAL 0 )
set( ${_PACKAGE_NAME_UPPER}_OUTPUT_NAME ${_ARG} CACHE INTERNAL "" FORCE )