-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmulle-sourcetree-to-cmake
executable file
·1750 lines (1453 loc) · 46.1 KB
/
mulle-sourcetree-to-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
#! /usr/bin/env mulle-bash
# shellcheck shell=bash
#
# shellcheck shell=bash
# shellcheck disable=SC2236
# shellcheck disable=SC2166
# shellcheck disable=SC2006
# shellcheck disable=SC1090
# shellcheck disable=SC1091
#
# Copyright (c) 2018 Nat! - Mulle kybernetiK
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# Neither the name of Mulle kybernetiK nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
[ "${TRACE}" = 'YES' -o "${MULLE_CMAKE_SOURCETREE_REFLECT_TRACE}" = 'YES' ] && set -x && : "$0" "$@"
MULLE_EXECUTABLE_VERSION="1.4.0"
usage()
{
[ $# -ne 0 ] && log_error "$1"
cat <<EOF >&2
Usage:
${MULLE_USAGE_NAME} [flags]
Create the _Dependencies.cmake and _Libraries.cmake files from the
information contained in the sourcetree config.
${MULLE_USAGE_NAME} has to run in a mulle-sde environment. You can run it
with \`mulle-sde run ${MULLE_USAGE_NAME}\`.
Marks used:
cmake-all-load : library that need all symbols (ObjC)
cmake-add : add to the list of libraries to link
cmake-dependency : inherit foreign DependenciesAndLibraries.cmake
cmake-inherit : inherit anything from foreign library
cmake-intermediate-link : prefix container name with STARTUP_
cmake-loader : inherit foreign objc-loader.h
require : combines require-link and require-header
require-header : the header must exist
require-link : the library must exist
Flags:
--serial : serial operation
--stdout : emit to stdout (implies --serial)
Environment:
MULLE_SOURCETREE_CONFIG_NAME : the config to use (config)
MULLE_SOURCETREE_TO_CMAKE_DEPENDENCIES_FILE : the dependencies output file
MULLE_SOURCETREE_TO_CMAKE_LIBRARIES_FILE : the libraries output file
MULLE_SOURCETREE_CMAKE_SEARCHPATH_ENABLED : if cmake-searchpath is used
EOF
exit 1
}
# https://cmake.org/Wiki/CMake_Checking_Platform
r_uname_to_cmake()
{
log_entry "r_uname_to_cmake" "$@"
local uname="$1"
local systemname
case "${uname}" in
"")
fail "uname is empty"
;;
'dragonfly')
RVAL="DragonFlyBSD" # guess
;;
'freebsd')
systemname="FreeBSD"
;;
'openbsd')
systemname="OpenBSD"
;;
'netbsd')
systemname="NetBSD"
;;
'mingw'|'msys')
systemname="Windows"
;;
'sun'|'sunos')
RVAL="Solaris"
;;
*)
r_uppercase "${uname:0:1}"
systemname="${RVAL}${uname:1}"
;;
esac
RVAL="\${CMAKE_SYSTEM_NAME} MATCHES \"${systemname}\""
}
r_sdk_to_cmake()
{
log_entry "r_uname_to_cmake" "$@"
local sdk="$1"
local sdkname
case "${sdk}" in
'musl')
sdkname="MUSL_STATIC_ONLY"
;;
*)
r_uppercase "${sdk}"
sdkname="${RVAL}"
;;
esac
RVAL="${sdkname}" # sic
}
r_create_exclude_only_if()
{
log_entry "r_create_exclude_only_if" "$@"
local excludes="$1"
local onlys="$2"
IFS="${DEFAULT_IFS}"; shell_enable_glob
if [ ! -z "${onlys}" ]
then
RVAL="if( ${onlys})"
return
fi
if [ ! -z "${excludes}" ]
then
case "${excludes}" in
*" OR "*)
RVAL="if( NOT (${excludes}))"
return
;;
*)
RVAL="if( NOT ${excludes})"
return
;;
esac
fi
RVAL=""
}
#
# key is "platform" usually
#
r_osexclude_configuration_to_cmake_if()
{
log_entry "r_osexclude_configuration_to_cmake_if" "$@"
local marks="$1"; shift
local excludes
local onlys
local mark
local length
local len1
local len2
while [ $# -ne 0 ]
do
key="$1"
shift
length="${#key}"
len1=$((length + 6))
len2=$((length + 4))
.foreachitem mark in ${marks}
.do
case "${mark}" in
only-${key}-*)
r_uname_to_cmake "${mark:${len1}}"
case " OR ${onlys} OR " in
*" OR ${RVAL} OR "*)
;;
*)
r_concat "${onlys}" "${RVAL}" " OR "
onlys="${RVAL}"
;;
esac
;;
no-${key}-*)
r_uname_to_cmake "${mark:${len2}}"
case " OR ${excludes} OR " in
*" OR ${RVAL} OR "*)
;;
*)
r_concat "${excludes}" "${RVAL}" " OR "
excludes="${RVAL}"
;;
esac
;;
esac
.done
done
r_create_exclude_only_if "${excludes}" "${onlys}"
}
#
# key is "sdk" usually
#
r_sdk_exclude_configuration_to_cmake_if()
{
log_entry "r_sdk_exclude_configuration_to_cmake_if" "$@"
local marks="$1"; shift
local excludes
local onlys
local mark
local length
local len1
local len2
while [ $# -ne 0 ]
do
key="$1"
shift
length="${#key}"
len1=$((length + 6)) # only-- 6
len2=$((length + 4)) # no-- 4
.foreachitem mark in ${marks}
.do
case "${mark}" in
only-${key}-*)
r_sdk_to_cmake "${mark:${len1}}"
case " OR ${onlys} OR " in
*" OR ${RVAL} OR "*)
;;
*)
r_concat "${onlys}" "${RVAL}" " OR "
onlys="${RVAL}"
;;
esac
;;
no-${key}-*)
r_sdk_to_cmake "${mark:${len2}}"
case " OR ${excludes} OR " in
*" OR ${RVAL} OR "*)
;;
*)
r_concat "${excludes}" "${RVAL}" " OR "
excludes="${RVAL}"
;;
esac
;;
esac
.done
done
r_create_exclude_only_if "${excludes}" "${onlys}"
}
# CMAKE must have global variable set for
#
# _TMP_${identifier}_ROOT} -> ${DEPENDENCY_DIR}/include
#
# _TMP_${identifier}_NAME} -> "MulleXYFoundation" if quoted_names is empty
#
_emit_dependencies_loader_cmake_code()
{
log_entry "_emit_dependencies_loader_cmake_code" "$@"
local address="$1"
local identifier="$2"
local quoted_names="$3"
local marks="$4"
local indent="$5"
if [ -z "${quoted_names}" ]
then
quoted_names="IN LISTS _TMP_${identifier}_NAME"
fi
local headerdir_name
headerdir_name="include"
case ",${marks}," in
*',only-framework,'*)
headerdir_name="Headers"
;;
esac
local emit_objc_loader
#
# all-load is a bad obj-c differentiator
#
emit_objc_loader='NO'
case ",${marks}," in
*,no-all-load,*|*,no-cmake-loader,*)
emit_objc_loader='YES'
case ",${marks}," in
*,no-cmake-loader,*)
emit_objc_loader='NO'
;;
esac
;;
esac
# case ",${marks}," in
# *,no-all-load,*)
# emit_objc_loader='YES'
# ;;
# esac
if [ "${OPTION_CMAKE_SEARCHPATH_ENABLED}" = 'YES' ]
then
case ",${marks}," in
*,no-cmake-searchpath,*)
;;
*)
case ",${marks}," in
*',only-framework,'*)
cat <<EOF
${indent} #
${indent} # Append header directory to user search path.
${indent} # Disable with: \`mulle-sourcetree mark ${address} no-cmake-searchpath\`
${indent} #
${indent} set( _TMP_${identifier}_DIR "\${_TMP_${identifier}_ROOT}/${headerdir_name}")
${indent} if( IS_DIRECTORY "\${_TMP_${identifier}_DIR}")
${indent} list( APPEND INHERITED_INCLUDE_DIRS "\${_TMP_${identifier}_DIR}")
${indent} else()
${indent} message( STATUS "\${_TMP_${identifier}_DIR} not found")
${indent} endif()
EOF
;;
*)
cat <<EOF
${indent} #
${indent} # Append header directory to user search path.
${indent} # Disable with: \`mulle-sourcetree mark ${address} no-cmake-searchpath\`
${indent} #
${indent} foreach( _TMP_${identifier}_NAME ${quoted_names})
${indent} set( _TMP_${identifier}_DIR "\${_TMP_${identifier}_ROOT}/${headerdir_name}/\${_TMP_${identifier}_NAME}")
${indent} if( IS_DIRECTORY "\${_TMP_${identifier}_DIR}")
${indent} list( APPEND INHERITED_INCLUDE_DIRS "\${_TMP_${identifier}_DIR}")
${indent} break()
${indent} else()
${indent} message( STATUS "\${_TMP_${identifier}_DIR} not found")
${indent} endif()
${indent} endforeach()
EOF
;;
esac
;;
esac
fi
case ",${marks}," in
*,no-cmake-dependency,*)
;;
*)
case ",${marks}," in
*',only-framework,'*)
cat <<EOF
${indent} #
${indent} # Search for "DependenciesAndLibraries.cmake" to include.
${indent} # Disable with: \`mulle-sourcetree mark ${address} no-cmake-dependency\`
${indent} #
${indent} set( _TMP_${identifier}_DIR "\${_TMP_${identifier}_ROOT}/${headerdir_name}/cmake")
${indent} # use explicit path to avoid "surprises"
${indent} if( IS_DIRECTORY "\${_TMP_${identifier}_DIR}")
${indent} list( INSERT CMAKE_MODULE_PATH 0 "\${_TMP_${identifier}_DIR}")
${indent} # we only want top level INHERIT_OBJC_LOADERS, so disable them
${indent} if( NOT NO_INHERIT_OBJC_LOADERS)
${indent} set( NO_INHERIT_OBJC_LOADERS OFF)
${indent} endif()
${indent} list( APPEND _TMP_INHERIT_OBJC_LOADERS \${NO_INHERIT_OBJC_LOADERS})
${indent} set( NO_INHERIT_OBJC_LOADERS ON)
${indent} #
${indent} include( "\${_TMP_${identifier}_DIR}/DependenciesAndLibraries.cmake" OPTIONAL)
${indent} #
${indent} list( GET _TMP_INHERIT_OBJC_LOADERS -1 NO_INHERIT_OBJC_LOADERS)
${indent} list( REMOVE_AT _TMP_INHERIT_OBJC_LOADERS -1)
${indent} list( REMOVE_ITEM CMAKE_MODULE_PATH "\${_TMP_${identifier}_DIR}")
${indent} #
${indent} unset( ${identifier}_DEFINITIONS)
${indent} include( "\${_TMP_${identifier}_DIR}/Definitions.cmake" OPTIONAL)
${indent} list( APPEND INHERITED_DEFINITIONS \${${identifier}_DEFINITIONS})
${indent} else()
${indent} message( STATUS "\${_TMP_${identifier}_DIR} not found")
${indent} endif()
EOF
;;
*)
cat <<EOF
${indent} #
${indent} # Search for "Definitions.cmake" and "DependenciesAndLibraries.cmake" to include.
${indent} # Disable with: \`mulle-sourcetree mark ${address} no-cmake-dependency\`
${indent} #
${indent} foreach( _TMP_${identifier}_NAME ${quoted_names})
${indent} set( _TMP_${identifier}_DIR "\${_TMP_${identifier}_ROOT}/${headerdir_name}/\${_TMP_${identifier}_NAME}/cmake")
${indent} # use explicit path to avoid "surprises"
${indent} if( IS_DIRECTORY "\${_TMP_${identifier}_DIR}")
${indent} list( INSERT CMAKE_MODULE_PATH 0 "\${_TMP_${identifier}_DIR}")
EOF
if [ "${emit_objc_loader}" = 'YES' ]
then
cat <<EOF
${indent} # we only want top level INHERIT_OBJC_LOADERS, so disable them
${indent} if( NOT NO_INHERIT_OBJC_LOADERS)
${indent} set( NO_INHERIT_OBJC_LOADERS OFF)
${indent} endif()
${indent} list( APPEND _TMP_INHERIT_OBJC_LOADERS \${NO_INHERIT_OBJC_LOADERS})
${indent} set( NO_INHERIT_OBJC_LOADERS ON)
EOF
fi
cat <<EOF
${indent} #
${indent} include( "\${_TMP_${identifier}_DIR}/DependenciesAndLibraries.cmake" OPTIONAL)
${indent} #
EOF
if [ "${emit_objc_loader}" = 'YES' ]
then
cat <<EOF
${indent} list( GET _TMP_INHERIT_OBJC_LOADERS -1 NO_INHERIT_OBJC_LOADERS)
${indent} list( REMOVE_AT _TMP_INHERIT_OBJC_LOADERS -1)
EOF
fi
cat <<EOF
${indent} list( REMOVE_ITEM CMAKE_MODULE_PATH "\${_TMP_${identifier}_DIR}")
${indent} #
${indent} unset( ${identifier}_DEFINITIONS)
${indent} include( "\${_TMP_${identifier}_DIR}/Definitions.cmake" OPTIONAL)
${indent} list( APPEND INHERITED_DEFINITIONS \${${identifier}_DEFINITIONS})
${indent} break()
${indent} else()
${indent} message( STATUS "\${_TMP_${identifier}_DIR} not found")
${indent} endif()
${indent} endforeach()
EOF
;;
esac
;;
esac
#
# for objective-c we find objc-loader.inc in the public include files
#
case ",${marks}," in
*,no-all-load,*|*,no-cmake-loader,*)
;;
*)
case ",${marks}," in
*',only-framework,'*)
cat <<EOF
${indent} #
${indent} # Search for "MulleObjCLoader+<name>.h" in include directory.
${indent} # Disable with: \`mulle-sourcetree mark ${address} no-cmake-loader\`
${indent} #
${indent} if( NOT NO_INHERIT_OBJC_LOADERS)
${indent} get_filename_component( _TMP_${identifier}_NAME "\${_TMP_${identifier}_ROOT}" NAME_WE)
${indent} set( _TMP_${identifier}_FILE "\${_TMP_${identifier}_ROOT}/Headers/MulleObjCLoader+\${_TMP_${identifier}_NAME}.h")
${indent} if( EXISTS "\${_TMP_${identifier}_FILE}")
${indent} list( APPEND INHERITED_OBJC_LOADERS \${_TMP_${identifier}_FILE})
${indent} endif()
${indent} endif()
EOF
;;
*)
cat <<EOF
${indent} #
${indent} # Search for "MulleObjCLoader+<name>.h" in include directory.
${indent} # Disable with: \`mulle-sourcetree mark ${address} no-cmake-loader\`
${indent} #
${indent} if( NOT NO_INHERIT_OBJC_LOADERS)
${indent} foreach( _TMP_${identifier}_NAME ${quoted_names})
${indent} set( _TMP_${identifier}_FILE "\${_TMP_${identifier}_ROOT}/include/\${_TMP_${identifier}_NAME}/MulleObjCLoader+\${_TMP_${identifier}_NAME}.h")
${indent} if( EXISTS "\${_TMP_${identifier}_FILE}")
${indent} list( APPEND INHERITED_OBJC_LOADERS \${_TMP_${identifier}_FILE})
${indent} break()
${indent} endif()
${indent} endforeach()
${indent} endif()
EOF
;;
esac
;;
esac
}
_emit_find_library_names()
{
local libraries="$1"
local indent="$2"
local library
.foreachline library in ${libraries}
.do
printf "%s%s\n" "${indent}" "${library}"
.done
}
_emit_find_library_command()
{
local key="$1"
local libraries="$2"
local findoptions="$3"
local indent="$4"
printf "%s%s\n" "${indent}" "find_library( ${key} NAMES"
_emit_find_library_names "${libraries}" "${indent} "
if [ ! -z "${findoptions}" ]
then
printf "%s%s\n" "${indent} " "${findoptions}"
fi
printf "%s%s\n" "${indent}" ")"
}
_emit_find_library()
{
local key="$1"
local libraries="$2"
local findoptions="$3"
local findoptionskey="$4"
local indent="$5"
if [ ! -z "${findoptions}" ]
then
# prefer finding a "local" library regardless of name
_emit_find_library_command "${key}" "${libraries}" "${findoptions}" "${indent}"
# fallback to system library
printf "%s%s\n" "${indent}" "if( NOT ${key} AND NOT ${findoptionskey})"
_emit_find_library_command "${key}" "${libraries}" "" "${indent} "
printf "%s%s\n" "${indent}" "endif()"
else
_emit_find_library_command "${key}" "${libraries}" "" "${indent}"
fi
}
#
# no-require-link and no-require, means that find_library may fail and it's OK
# no-cmake-add is hack for subprojects, all the "logic" of a dependency
# runs but the dependency is not actually added to the linkables
# no-cmake-loader is sort of the inverse, the "loader" part is removed, but
# the library is actually linked
#
_emit_cmake_find_library()
{
log_entry "_emit_cmake_find_library" "$@"
local preference="$1"; shift
local findoptions="$1"; shift
local findoptionskey="$1"; shift
local names="$1"
local address="$2"
local identifier="$3"
local containername="$4"
local marks="$5"
local header="$6"
local indent="$7"
local Debug_libraries # sic
local Release_libraries # sic
local RelWithDebug_libraries # sic
local MinSizeRel_libraries # sic
local quoted_names
local type
local name
local library_key
local types
.foreachitem i in ${names}
.do
# Split Release:curl into Release (type) and curl (name)
name=""
type=""
case "${i}" in
*:*)
name="${i#*:}"
type="${i%%:*}"
;;
esac
name="${name:-$i}"
type="${type:-Release}"
r_add_unique_line "${types}" "${type}"
types="${RVAL}"
r_concat "${quoted_names}" "\"${name}\""
quoted_names="${RVAL}"
# get appropriate libraries into local variable libraries
library_key="${type}_libraries"
if [ ${ZSH_VERSION+x} ]
then
libraries="${(P)library_key}"
else
libraries="${!library_key}"
fi
# frameworks only have one name or ?
case ",${marks}," in
*',only-framework,'*)
r_concat "${libraries}" "${name}"
libraries="${RVAL}"
printf -v "${library_key}" "%s" "${libraries}"
.break
;;
esac
#
# /usr/local/lib is apparently NOT part of system path, and therefore
# can not be easily excluded with NO_CMAKE_SYSTEM_PATH. Which is bad,
# if we are searching for static first, but the test really wants the
# dynamic local one
#
case ",${marks}," in
*',no-dynamic-link,'*)
case "${preference}" in
'any'|'shared')
preference='static'
;;
esac
;;
*',no-static-link,'*)
case "${preference}" in
'any'|'static')
preference='shared'
;;
esac
;;
# Prefer default linking... On Linux, you can't link libm.a statically
# with glibc.so. Also making a preference here would probably work
# badly with gcc -static / -dynamic. So it was a bad idea.
# *)
# case "${preference}" in
# 'any'|'static')
# preference='static'
# ;;
# esac
# ;;
esac
case "${preference}" in
'any')
# do no preference (see above comment)
;;
'static')
r_add_line "${libraries}" "\${CMAKE_STATIC_LIBRARY_PREFIX}${name}\${CMAKE_DEBUG_POSTFIX}\${CMAKE_STATIC_LIBRARY_SUFFIX}"
libraries="${RVAL}"
# fallback to non CMAKE_DEBUG_POSTFIX
r_add_line "${libraries}" "\${CMAKE_STATIC_LIBRARY_PREFIX}${name}\${CMAKE_STATIC_LIBRARY_SUFFIX}"
libraries="${RVAL}"
;;
'shared')
r_add_line "${libraries}" "\${CMAKE_SHARED_LIBRARY_PREFIX}${name}\${CMAKE_DEBUG_POSTFIX}\${CMAKE_SHARED_LIBRARY_SUFFIX}"
libraries="${RVAL}"
# fallback to non CMAKE_DEBUG_POSTFIX
r_add_line "${libraries}" "\${CMAKE_SHARED_LIBRARY_PREFIX}${name}\${CMAKE_SHARED_LIBRARY_SUFFIX}"
libraries="${RVAL}"
;;
esac
# fallback to whatever linkage, if the preference wasn't overridden
case ",${marks}," in
*',no-dynamic-link,'*|*',no-static-link,'*)
;;
*)
r_add_line "${libraries}" "${name}"
libraries="${RVAL}"
;;
esac
printf -v "${library_key}" "%s" "${libraries}"
.done
local failstring
local failstatus
local key
key="${identifier}_LIBRARY"
case ",${marks}," in
*',only-framework,'*)
key="${identifier}_FRAMEWORK"
;;
esac
case ",${marks}," in
*',no-require-link,'*)
failcomment="\
# Enable with: \`mulle-sourcetree mark ${address} require-link\`"
failstatus="STATUS"
failstring="${key} is missing but it is marked as \\\"no-require-link\\\""
;;
*',no-require,'*)
failcomment="\
# Enable with: \`mulle-sourcetree mark ${address} require\`"
failstatus="STATUS"
failstring="${key} is missing but it is marked as \\\"no-require\\\""
;;
*)
failcomment="\
# Disable with: \`mulle-sourcetree mark ${address} no-require-link\`"
failstatus="SEND_ERROR"
failstring="${key} was not found"
;;
esac
#
# this is getting unwieldy, should probably use a function
#
# Maybe need to use two find_library calls to first get things in
# DEPENDENCY_DIR and ADDICTION_DIR, which will be in
# CMAKE_LIBRARY_PATH and CMAKE_LIBRARY_PATH
#
# Seems to fix a problem when old libs are in /usr/local/lib
# TODO: maybenot use CMAKE_LIBRARY_PATH and CMAKE_FRAMEWORK_PATH then ?
cat <<EOF
${indent}if( COLLECT_${containername}_AS_NAMES)
${indent} list( APPEND ${containername} "${names%%,*}")
${indent}else()
EOF
indent="${indent} "
cat <<EOF
${indent}if( NOT ${key})
EOF
# if ir's just the default emit a simple line
if [ "${types}" = "Release" ]
then
_emit_find_library "${key}" \
"${Release_libraries}" \
"${findoptions}" \
"${findoptionskey}" \
"${indent} "
else
local clause
#
# we have multiple lines for build types, so we produce a more elaborate
# find_library call sequence. But Release is always a fallback option!
#
shell_disable_glob
for type in ${types}
do
if [ "${type}" != "Release" ]
then
library_key="${type}_libraries"
if [ ${ZSH_VERSION+x} ]
then
libraries="${(P)library_key}"
else
libraries="${!library_key}"
fi
cat <<EOF
${indent} if(${clause} "\${CMAKE_BUILD_TYPE}" STREQUAL "${type}")
EOF
_emit_find_library "${key}" \
"${libraries}" \
"${findoptions}" \
"${findoptionskey}" \
"${indent} "
cat <<EOF
${indent} endif()
EOF
clause=" NOT ${key} AND"
fi
done
shell_enable_glob
# fallback Reelase
cat <<EOF
${indent} if( NOT ${key})
EOF
_emit_find_library "${key}" \
"${Release_libraries}" \
"${findoptions}" \
"${findoptionskey}" \
"${indent} "
cat <<EOF
${indent} endif()
EOF
fi
cat <<EOF
${indent} message( STATUS "${key} is \${${key}}")
${indent} #
${indent} # The order looks ascending, but due to the way this file is read
${indent} # it ends up being descending, which is what we need.
${indent} #
${indent} if( ${key})
EOF
case ",${marks}," in
*',no-cmake-add,'*)
;;
*)
cat <<EOF
${indent} #
${indent} # Add ${key} to ${containername} list.
${indent} # Disable with: \`mulle-sourcetree mark ${address} no-cmake-add\`
${indent} #
${indent} list( APPEND ${containername} \${${key}})
EOF
;;
esac
case ",${marks}," in
*',no-cmake-inherit,'*)
cat <<EOF
${indent} # intentionally left blank
EOF
;;
*)
case ",${marks}," in
*',only-framework,'*)
cat <<EOF
${indent} #
${indent} # Inherit information from dependency.
${indent} # Disable with: \`mulle-sourcetree mark ${address} no-cmake-inherit\`
${indent} #
${indent} # temporarily expand CMAKE_MODULE_PATH
${indent} set( _TMP_${identifier}_ROOT "\${${key}}")
${indent} #
EOF
;;
*)
cat <<EOF
${indent} #
${indent} # Inherit information from dependency.
${indent} # Encompasses: no-cmake-searchpath,no-cmake-dependency,no-cmake-loader
${indent} # Disable with: \`mulle-sourcetree mark ${address} no-cmake-inherit\`
${indent} #
${indent} # temporarily expand CMAKE_MODULE_PATH
${indent} get_filename_component( _TMP_${identifier}_ROOT "\${${key}}" DIRECTORY)
${indent} get_filename_component( _TMP_${identifier}_ROOT "\${_TMP_${identifier}_ROOT}" DIRECTORY)
${indent} #
EOF
;;
esac
_emit_dependencies_loader_cmake_code "${address}" \
"${identifier}" \
"${quoted_names}" \
"${marks}" \
"${indent}"
;;
esac
# ${indent} message( STATUS "_TMP_${identifier}_DIR is \${_TMP_${identifier}_DIR}")
cat <<EOF
${indent} else()
${indent} ${failcomment}
${indent} message( ${failstatus} "${failstring}")
${indent} endif()
EOF
indent="${indent% }"
cat <<EOF
${indent} endif()
EOF
cat <<EOF
${indent}endif()
EOF
}
_emit_cmake_library()
{
log_entry "_emit_cmake_library" "$@"
_emit_cmake_find_library "any" "" "" "$@"
}
#
# dependencies will not be searched in the host system
#
_emit_cmake_dependency()
{
log_entry "_emit_cmake_dependency" "$@"
local marks="$5"
# local header="$6"
local indent="$7"
local findoptions
local findoptionskey
#
# w/o NO_SYSTEM_ENVIRONMENT_PATH, cmake picks up libraries from
# /usr/local/lib
#
findoptions="NO_CMAKE_SYSTEM_PATH NO_SYSTEM_ENVIRONMENT_PATH"
findoptionskey="DEPENDENCY_IGNORE_SYSTEM_LIBARIES"
case ",${marks}," in
*,no-cmake-suppress-system-path,*)
findoptions=""
findoptionskey=""
;;
esac
# alternative
# findoptions="