-
Notifications
You must be signed in to change notification settings - Fork 262
/
CMakeLists.txt
2427 lines (2245 loc) · 98.7 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
# **********************************************************
# Copyright (c) 2010-2024 Google, Inc. All rights reserved.
# Copyright (c) 2009-2010 VMware, Inc. All rights reserved.
# **********************************************************
# Dr. Memory: the memory debugger
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation;
# version 2.1 of the License, and no later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Library General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# DR requires 3.7 which means we must also.
cmake_minimum_required(VERSION 3.7)
include(make/policies.cmake NO_POLICY_SCOPE)
# like DR, we collapse VS generator into one config since
# we don't have enough control over output dirs
# in build rules (until cmake 2.8.4).
# this must be prior to the project() command.
if ("${CMAKE_GENERATOR}" MATCHES "Visual Studio")
if ("${CMAKE_BUILD_TYPE}" MATCHES "Debug")
set(CMAKE_CONFIGURATION_TYPES "Debug" CACHE STRING "" FORCE)
else ()
set(CMAKE_CONFIGURATION_TYPES "RelWithDebInfo" CACHE STRING "" FORCE)
endif ()
# we want to use the _LOCATION_<config> property
string(TOUPPER "${CMAKE_CONFIGURATION_TYPES}" upper)
set(location_suffix "_${upper}")
else ("${CMAKE_GENERATOR}" MATCHES "Visual Studio")
set(location_suffix "")
endif ("${CMAKE_GENERATOR}" MATCHES "Visual Studio")
# I want to override the default CMAKE_INSTALL_PREFIX, but allow it to
# be set (as the same var name, so CPack and other standard tools
# work) externally. The best solution is to check whether defined BEFORE
# the project() command.
# If we didn't use standard tools we could set CMAKE_INSTALL_PREFIX
# to be CACHE INTERNAL FORCE to INSTALL_PREFIX.
if (NOT DEFINED CMAKE_INSTALL_PREFIX)
set(install_override ON)
else (NOT DEFINED CMAKE_INSTALL_PREFIX)
set(install_override OFF)
endif (NOT DEFINED CMAKE_INSTALL_PREFIX)
project(DrMemory NONE)
if (DEFINED GENERATE_PDBS AND NOT GENERATE_PDBS)
# support building over cygwin ssh where we cannot build pdbs.
# using the same solution as DynamoRIO i#310.
# To prevent cmake's try-compile for its working compiler test and
# its ABI determination test we request a Release build config
# via a custom Plaform/Windows-cl.cmake in our make/ dir.
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/make")
endif ()
enable_language(C)
enable_language(CXX)
include(CheckCCompilerFlag)
# The target OS:
if (APPLE)
set(MACOS 1)
elseif (UNIX)
set(LINUX 1)
endif (APPLE)
if (CMAKE_SYSTEM_NAME MATCHES "^Android")
set(ANDROID 1)
set(DEFINES ${DEFINES} -DANDROID)
set(DRM_DEVICE_BASEDIR "/data/local/tmp" CACHE STRING "base dir for Android binaries")
option(DRM_COPY_TO_DEVICE "copy cross-compiled binaries to DRM_DEVICE_BASEDIR" OFF)
if (DRM_COPY_TO_DEVICE)
find_program(ADB adb DOC "adb Android utility")
if (NOT ADB)
message(FATAL_ERROR "Unable to find adb for DRM_COPY_TO_DEVICE")
else ()
execute_process(COMMAND ${ADB} get-state
RESULT_VARIABLE adb_result
ERROR_VARIABLE adb_err
OUTPUT_VARIABLE adb_out OUTPUT_STRIP_TRAILING_WHITESPACE)
if (adb_result OR NOT adb_out STREQUAL "device")
message(FATAL_ERROR "Android device not connected for DRM_COPY_TO_DEVICE")
endif ()
message(STATUS "Binaries will be copied to the attached Android device")
endif ()
endif ()
endif ()
# The target arch:
if (CMAKE_SYSTEM_PROCESSOR MATCHES "^arm")
set(ARM 1)
else ()
set(X86 1)
endif ()
if (UNIX)
set(DEFINES ${DEFINES} -DUNIX)
endif (UNIX)
option(VMKERNEL "target vmkernel")
if (VMKERNEL)
# if we get enough of these, should use a configure.h, but would need to
# pull the ops out like DR core does to pass to options_perl below
set(DEFINES ${DEFINES} -DVMX86_SERVER)
endif (VMKERNEL)
option(TOOL_DR_HEAPSTAT "build Dr. Heapstat instead of Dr. Memory")
option(USE_MD5 "use md5 instead of crc32 for callstack hashes for Dr. Heapstat")
if (USE_MD5)
set(DEFINES ${DEFINES} -DUSE_MD5)
endif (USE_MD5)
option(CHECK_WITH_MD5 "use crc32 for callstack hashes but check for collisions with md5")
if (CHECK_WITH_MD5)
set(DEFINES ${DEFINES} -DCHECK_WITH_MD5)
endif (CHECK_WITH_MD5)
option(STATIC_DRSYMS "use static drsyms library" ON)
if (UNIX AND NOT STATIC_DRSYMS)
# we could support dynamic but we'd have to copy libdrsym.so
message(FATAL_ERROR "non-static drsyms not supported for Linux")
endif ()
option(TEST_SUITE "we are running a series of builds for official purposes")
if (TOOL_DR_HEAPSTAT)
# Dr. Heapstat
set(TOOL_DR_MEMORY OFF)
set(toolname drheapstat)
set(tooldir ${toolname})
set(toolname_cap DrHeapstat)
set(toolname_cap_spc "Dr. Heapstat")
set(DEFINES ${DEFINES} -DTOOL_DR_HEAPSTAT)
# Dr. Heapstat uses drsyms only to avoid false neg on leaks (i#762, i#292).
# XXX: use drsyms for leak reports (i#926) and usage (i#282).
else (TOOL_DR_HEAPSTAT)
# Dr. Memory
set(TOOL_DR_MEMORY ON)
set(toolname drmemory)
set(tooldir ${toolname})
set(toolname_cap DrMemory)
set(toolname_cap_spc "Dr. Memory")
set(DEFINES ${DEFINES} -DTOOL_DR_MEMORY)
endif (TOOL_DR_HEAPSTAT)
# We use a monotonically increasing integer that's larger than any bugfix
# release version as the patchlevel ver# to distinguish
# We used to use the svn revision (i#83) and we leave that code in place
# (for now at least) for anyone building an old checkout.
# For git, we follow DRi#1565 and use a date.
set(VERSION_NUMBER_PATCHLEVEL 0)
if (EXISTS "${PROJECT_SOURCE_DIR}/.svn")
find_program(SVN svn DOC "subversion client")
if (SVN)
execute_process(COMMAND ${SVN} info
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
RESULT_VARIABLE svn_result
ERROR_VARIABLE svn_err
OUTPUT_VARIABLE svn_out)
if (svn_result OR svn_err)
message(FATAL_ERROR "*** ${SVN} info failed: ***\n${svn_result} ${svn_err}")
endif (svn_result OR svn_err)
string(REGEX MATCH "Revision: [0-9]+" svn_out "${svn_out}")
string(REGEX REPLACE "Revision: " "" svn_out "${svn_out}")
set(VERSION_NUMBER_PATCHLEVEL "${svn_out}")
endif (SVN)
else (EXISTS "${PROJECT_SOURCE_DIR}/.svn")
if (EXISTS "${PROJECT_SOURCE_DIR}/.git")
find_program(GIT git DOC "git client")
if (GIT)
# We want the committer date (not author date) (xref DRi#1565). We request
# UNIX timestamp format and then divide down to days to get a small enough
# number for the Windows resource limits.
execute_process(COMMAND ${GIT} log -n 1 --format=%ct
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
RESULT_VARIABLE git_result
ERROR_VARIABLE git_err
OUTPUT_VARIABLE git_out)
if (git_result OR git_err)
message("*** ${GIT} log failed: ***\n${git_err}")
else (git_result OR git_err)
math(EXPR daycount "${git_out} / (60*60*24)")
endif (git_result OR git_err)
endif (GIT)
if (NOT daycount)
# XXX DRi#1565: to support building when not in a git repo (e.g., from a source
# tarball) we use date to get current time for timestamp.
# This is not ideal as it confuses the build timestamp with the commit
# timestamp. We should add support for a local file holding the version.
find_program(DATE date DOC "system date")
if (DATE)
execute_process(COMMAND ${DATE} +%s
RESULT_VARIABLE date_result
ERROR_VARIABLE date_err
OUTPUT_VARIABLE date_out)
if (date_result OR date_err)
message("*** ${DATE} failed: ***\n${date_err}")
else (date_result OR date_err)
math(EXPR daycount "${date_out} / (60*60*24)")
endif (date_result OR date_err)
endif (DATE)
endif (NOT daycount)
if (NOT daycount)
# set a much further date in the future to avoid confusing
# this fake date with the real date from git log
set(daycount 33333)
endif (NOT daycount)
set(VERSION_NUMBER_PATCHLEVEL "${daycount}")
endif (EXISTS "${PROJECT_SOURCE_DIR}/.git")
endif (EXISTS "${PROJECT_SOURCE_DIR}/.svn")
if (APPLE)
# clang linker disallows any but major # being >= 256 (1024 for x64) so we do
# mod 200 (we assume we'll never confuse versions 200 apart) and add 56 (to
# distinguish from real releases).
# If we change this we need to also update .github/workflows/ci-package.yml.
math(EXPR VERSION_NUMBER_PATCHLEVEL "(${VERSION_NUMBER_PATCHLEVEL} % 200) + 56")
endif (APPLE)
# N.B.: When updating this, update all instances in .github/workflows/ci-package.yml.
# We should find a way to share (xref DRi#1565).
set(VERSION_NUMBER_DEFAULT "2.6.${VERSION_NUMBER_PATCHLEVEL}")
# Do not store the default TOOL_VERSION_NUMBER in the cache to prevent a stale one
# from preventing future version updates in a pre-existing build dir.
# Avoid "VERSION_NUMBER" name since conflics w/ DR's var.
set(TOOL_VERSION_NUMBER "" CACHE STRING "Version number: leave empty for default")
if ("${TOOL_VERSION_NUMBER}" STREQUAL "")
set(TOOL_VERSION_NUMBER ${VERSION_NUMBER_DEFAULT})
endif()
message(STATUS "Dr. Memory version number: ${TOOL_VERSION_NUMBER}")
# Avoid "BUILD_NUMBER" name since conflics w/ DR's var
set(TOOL_BUILD_NUMBER "1" CACHE STRING "Build number (must be <64K)")
# However, we do want to set it to avoid "custom build" in messages
# from embedded DR when run alone (i#1717's dr_set_client_version_string() has
# already solved this for messages for DrMem on DR). To make it easy to
# correlate, we set it to a formula computed from the DrMem ver.
string(REPLACE "." ";" ver_list ${TOOL_VERSION_NUMBER})
list(GET ver_list 0 TOOL_VERSION_MAJOR)
list(GET ver_list 1 TOOL_VERSION_MINOR)
math(EXPR BUILD_NUMBER
"${TOOL_VERSION_MAJOR}*100 + ${TOOL_VERSION_MINOR}*10 + ${VERSION_NUMBER_PATCHLEVEL}")
string(REGEX REPLACE "\\." "," TOOL_VERSION_COMMAS "${TOOL_VERSION_NUMBER}")
set(DEFINES ${DEFINES}
-DBUILD_NUMBER=${TOOL_BUILD_NUMBER}
-DVERSION_NUMBER=${TOOL_VERSION_NUMBER}
-DVERSION_STRING="${TOOL_VERSION_NUMBER}"
-DVERSION_COMMAS=${TOOL_VERSION_COMMAS})
if (CMAKE_C_SIZEOF_DATA_PTR EQUAL 8 OR CMAKE_CXX_SIZEOF_DATA_PTR EQUAL 8)
set(X64 ON)
set(LIB_ARCH "lib64")
set(BIN_ARCH "bin64")
set(DEFINES ${DEFINES} -DX64)
else()
set(X64 OFF)
set(LIB_ARCH "lib32")
set(BIN_ARCH "bin32")
endif ()
if ("${CMAKE_BUILD_TYPE}" MATCHES "Debug")
# FIXME: use a configure.h
set(DEFINES ${DEFINES} -DDEBUG -DSTATISTICS)
set(DEBUG_BUILD ON) # "DEBUG" conflicts w/ DR
else ()
# We want Windows pdb and Unix line #s for release build.
# We make separate debug info for Unix, and are fine shipping it to users
# in any case as we're open-source.
set(CMAKE_BUILD_TYPE "RelWithDebInfo")
set(DEBUG_BUILD OFF)
endif ()
string(TOUPPER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_UPPER)
# i#1781: cmake 2.8.12+ fails to create static lib pdb by default
# XXX: we should share this with DR's copy
macro(add_static_lib_debug_info target dest_dir)
if (WIN32)
if ("${CMAKE_VERSION}" VERSION_EQUAL "3.1" OR
"${CMAKE_VERSION}" VERSION_GREATER "3.1")
append_property_string(TARGET ${target}
COMPILE_PDB_NAME${location_suffix} "${target}"
COMPILE_PDB_OUTPUT_DIRECTORY{location_suffix} "${dest_dir}")
else ()
# We just don't support it for < 3.1
endif ()
endif ()
endmacro()
if (UNIX)
# there's no cmake warning control so we hardcode it
# disabling strict aliasing since giving weird warning I'm not sure how to fix:
# alloc.c:716: warning: dereferencing type-punned pointer will break strict-aliasing rules
set(WARN "-Wall -Werror -Wno-strict-aliasing")
# Disabling format-truncation due to too many warnings about string construction
# where truncating added strings is fine if the final doesn't fit anyway.
CHECK_C_COMPILER_FLAG("-Wno-format-truncation" have_format_truncation_warning)
if (have_format_truncation_warning)
set(WARN "${WARN} -Wno-format-truncation")
endif ()
# Disable string compare warning in clang about our assert on defval for
# bool options from optionsx.h expansion.
CHECK_C_COMPILER_FLAG("-Wno-string-compare" have_str_cmp_warning)
if (have_str_cmp_warning)
set(WARN "${WARN} -Wno-string-compare")
endif ()
if (CMAKE_C_COMPILER MATCHES "/build/toolchain")
# needed for linux/ipmi.h (PR 531644)
set(EXTRA_FLAGS "-idirafter /build/toolchain/lin32/glibc-2007q3-51/usr/include")
else ()
if (APPLE AND NOT CMAKE_COMPILER_IS_GNUCC)
# Ensure our binaries can run on older OSX
set(EXTRA_FLAGS "-mmacosx-version-min=10.9")
else ()
set(EXTRA_FLAGS "")
endif ()
endif ()
if (ARM)
set(EXTRA_FLAGS "${EXTRA_FLAGS} -mthumb -march=armv7-a")
if (ANDROID OR CMAKE_C_LIBRARY_ARCHITECTURE MATCHES "gnueabi$")
set(EXTRA_FLAGS "${EXTRA_FLAGS} -mfloat-abi=softfp")
# Android requires PIE. We export symbols to match our test assumptions.
set(CMAKE_EXE_LINKER_FLAGS
"${CMAKE_EXE_LINKER_FLAGS} -fPIE -pie -Wl,--export-dynamic")
endif ()
endif ()
if (APPLE)
# TODO i#2485: Add DWARF-5 support to Mac.
CHECK_C_COMPILER_FLAG("-gdwarf-5" have_dwarf5)
if (have_dwarf5)
set(EXTRA_FLAGS "${EXTRA_FLAGS} -gdwarf-4")
endif ()
endif ()
# We use C++11.
set(EXTRA_CXXFLAGS "-std=c++11")
set(CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE_UPPER}
"${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE_UPPER}} ${ARCH_CFLAGS} ${WARN} ${EXTRA_FLAGS}")
set(CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE_UPPER}
"${CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE_UPPER}} ${ARCH_CFLAGS} ${WARN} ${EXTRA_FLAGS} ${EXTRA_CXXFLAGS}")
else (UNIX)
# FIXME i#1204: fix warnings and up to /W4
set(WARN "/W2 /WX")
# update flags for our types and Debug (tests always use Debug).
# ok to double-update b/c these are are regex-replace.
foreach (config ${CMAKE_BUILD_TYPE} ${CMAKE_CONFIGURATION_TYPES} Debug)
string(TOUPPER "${config}" config_upper)
foreach (var CMAKE_C_FLAGS;CMAKE_CXX_FLAGS;
CMAKE_C_FLAGS_${config_upper};
CMAKE_CXX_FLAGS_${config_upper})
# default from cmake has /W3 so remove to avoid warning about overriding
string(REGEX REPLACE "/W[0-9]" "" ${var} "${${var}}")
# /GZ requires RTC runtime support which we don't want (i#925)
string(REGEX REPLACE "/GZ" "" ${var} "${${var}}")
# avoid warnings (i#925)
string(REGEX REPLACE "/GX" "/EHsc" ${var} "${${var}}")
if (NOT DEBUG_BUILD)
# RelWithDebInfo asks for /Ob1 but we want full inlining
string(REGEX REPLACE "/Ob1" "/Ob2" ${var} "${${var}}")
endif ()
endforeach ()
endforeach ()
# disable stack protection: "unresolved external symbol ___security_cookie"
set(CL_CFLAGS "/GS-")
# build in parallel, always.
# note that /MP is not officially supported on VS 2005 and others
# have seen occasional problems: we'll risk it. we could check for
# "MSVC10 OR MSVC90".
set(CL_CFLAGS "${CL_CFLAGS} /MP")
if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 18.0)
# i#1376: VS2013 requires /FS w/ multiple cl.exe in parallel (which Ninja
# uses). While /MP is supposed to enable it, it doesn't seem to.
# This is recommended after /Fd but it seems to work here.
set(CL_CFLAGS "${CL_CFLAGS} /FS")
endif()
set(CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE_UPPER} "${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE_UPPER}} ${WARN} ${CL_CFLAGS}")
endif (UNIX)
set(CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE_UPPER} "${CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE_UPPER}} ${ARCH_CFLAGS} ${WARN}")
string(STRIP "${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE_UPPER}}"
CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE_UPPER})
string(STRIP "${CMAKE_CXX_FLAGS}" CMAKE_CXX_FLAGS)
if (WIN32)
# DRi#1424: target the oldest possible platform we can
if (X64)
set(os_target "5.02") # Win2003x64/WinXPx64
else (X64)
if (CMAKE_C_COMPILER_VERSION VERSION_LESS 17.0) # up to and including VS2010
set(os_target "5.00") # Win2K
else () # VS2012, VS2013
set(os_target "5.01") # WinXP
endif ()
endif (X64)
foreach (lflags CMAKE_EXE_LINKER_FLAGS
CMAKE_MODULE_LINKER_FLAGS
CMAKE_SHARED_LINKER_FLAGS)
set(${lflags} "${${lflags}} /subsystem:console,${os_target}")
endforeach()
message(STATUS "Targeting subsystem ${os_target}")
endif (WIN32)
if (UNIX)
include(CheckIncludeFiles)
check_include_files("asm-i386/stat.h" HAVE_ASM_I386)
if (HAVE_ASM_I386)
# see comments above about adding configure.h
set(DEFINES ${DEFINES} -DHAVE_ASM_I386)
endif (HAVE_ASM_I386)
if (LINUX)
check_include_files("libunwind.h" HAVE_LIBUNWIND_H)
if (HAVE_LIBUNWIND_H)
set(DEFINES ${DEFINES} -DHAVE_LIBUNWIND_H)
endif ()
else ()
set(HAVE_LIBUNWIND_H OFF)
endif ()
endif (UNIX)
if (UNIX)
# We don't want our instrument_init() pre-empted by debug-internal DynamoRIO
# that has visible internal routines.
CHECK_C_COMPILER_FLAG("-fvisibility=internal" HAVE_FVISIBILITY_INTERNAL)
CHECK_C_COMPILER_FLAG("-fvisibility=hidden" HAVE_FVISIBILITY_HIDDEN)
# Mac accepts internal but warns about it so we avoid it there.
if (HAVE_FVISIBILITY_INTERNAL AND NOT APPLE)
set(VISIBILITY "internal")
elseif (HAVE_FVISIBILITY_HIDDEN)
set(VISIBILITY "hidden")
else ()
message("${CMAKE_C_COMPILER} missing flag -fvisibility, using linker "
"script instead")
set(VISIBILITY " ")
endif ()
if (HAVE_FVISIBILITY_INTERNAL OR HAVE_FVISIBILITY_HIDDEN)
set(CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE_UPPER}
"${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE_UPPER}} -fvisibility=${VISIBILITY}")
endif ()
if (APPLE)
# Incredibly, for both clang and g++, while a single compile-and-link
# invocation will create an executable.dSYM/ dir with debug info,
# with separate compilation the final link does NOT create the
# dSYM dir.
# The "dsymutil" program will create the dSYM dir for us.
# Strangely it takes in the executable and not the object
# files even though it's the latter that contain the debug info.
# Thus it will only work if the object files are still sitting around.
find_program(DSYMUTIL_PROGRAM dsymutil)
if (DSYMUTIL_PROGRAM)
set(CMAKE_C_LINK_EXECUTABLE
"${CMAKE_C_LINK_EXECUTABLE}"
"${DSYMUTIL_PROGRAM} <TARGET>")
set(CMAKE_C_CREATE_SHARED_LIBRARY
"${CMAKE_C_CREATE_SHARED_LIBRARY}"
"${DSYMUTIL_PROGRAM} <TARGET>")
set(CMAKE_CXX_LINK_EXECUTABLE
"${CMAKE_CXX_LINK_EXECUTABLE}"
"${DSYMUTIL_PROGRAM} <TARGET>")
set(CMAKE_CXX_CREATE_SHARED_LIBRARY
"${CMAKE_CXX_CREATE_SHARED_LIBRARY}"
"${DSYMUTIL_PROGRAM} <TARGET>")
endif ()
endif ()
endif (UNIX)
if (WIN32)
# Ensure that _AMD64_ or _X86_ are defined on Microsoft Windows, as otherwise
# um/winnt.h provided since Windows 10.0.22000 will error.
if (X64)
add_definitions(-D_AMD64_)
else (X64)
add_definitions(-D_X86_)
endif (X64)
# Use convention of DynamoRIO sources: DDKROOT env var (or DDK_ROOT cmake var).
# We don't require the DDK as dbghelp and symsrv are in the SDK as well, and
# we get ntdll_imports.lib from DR.
set(DDK_ROOT "$ENV{DDKROOT}" CACHE PATH "Path to DDK or WDK.")
if ("${DDK_ROOT}" STREQUAL "")
# Check default install path
if (EXISTS "$ENV{SYSTEMDRIVE}/WINDDK/3790.1830/")
set(DDK_ROOT "$ENV{SYSTEMDRIVE}/WINDDK/3790.1830/")
elseif (EXISTS "$ENV{SYSTEMDRIVE}/WINDDK/6000/")
set(DDK_ROOT "$ENV{SYSTEMDRIVE}/WINDDK/6000/")
elseif (EXISTS "$ENV{SYSTEMDRIVE}/WINDDK/7600.16385.1/")
set(DDK_ROOT "$ENV{SYSTEMDRIVE}/WINDDK/7600.16385.1/")
endif ()
endif ("${DDK_ROOT}" STREQUAL "")
# We can't include directly from DDK b/c the DDK include dir and VS include
# dirs are incompatible, so we have our own copies of the headers we need.
include_directories(wininc/psdk wininc/dxsdk)
# We need a newer version of dbghelp.dll than is in system32/ on 2K or XP.
# The versions that come with Debugging Tools for Windows are redistributable:
# "you can distribute the DLL with your application".
# The dbghelp.dll that comes in system32/ is not redistributable.
# We want 6.3+ for full drsyms features.
# 5.2 does not work (it's not just slower w/o SymSearch: it fails).
# Haven't tested in between.
# WINDDK/3790.1830/bin/x86/dbghelp.dll is 6.3.
# Older CMake binaries are 32-bit but newer ones can be 64-bit so we
# cannot rely on one or the other.
if ("$ENV{PROGRAMW6432}" STREQUAL "")
if (X64)
message(FATAL_ERROR "On 32-bit Windows: 64-bit build not supported")
endif ()
set(PROGFILES "$ENV{PROGRAMFILES}")
set(PROGFILES32 "$ENV{PROGRAMFILES}")
set(ARCH_SFX "x86")
set(DDK_SFX "i386")
else ()
set(PROGFILES "$ENV{PROGRAMW6432}")
set(PROGFILES32 "$ENV{PROGRAMFILES\(x86\)}")
if ("${PROGFILES32}" STREQUAL "")
set(PROGFILES32 "$ENV{PROGRAMFILES}")
endif ()
if (X64)
set(ARCH_SFX "x64")
set(DDK_SFX "amd64")
else (X64)
set(ARCH_SFX "x86")
set(DDK_SFX "i386")
endif (X64)
endif ()
# Allow packaging to specify a glob for a prefered path for x86 and x64.
set(DBGHELP_GLOB "" CACHE STRING
"Preferred path for dbghelp.dll with wildcard expansion")
# Even the VS2005 copy is 6.5 (despite its headers being < 6.3) so we can
# use those as well as the later SDK and standalone DTFW versions.
set(dbghelp_paths
"${DBGHELP_GLOB}"
"${DDK_ROOT}/bin/${ARCH_SFX}/dbghelp.dll"
"${DDK_ROOT}/tools/tracing/${DDK_SFX}/dbghelp.dll"
"${PROGFILES32}/Windows Kits/*/Debuggers/${ARCH_SFX}/dbghelp.dll"
# In case if SDK is not installed and we have Visual Studio, dbghelp.dll may be found in the
# Visual Studio's directory in subfolders Remote Debugger/x86 or Remote Debugger/x64 (xref i#1956).
# We look in both paths (Program Files and Program Files (x86)) because some versions of
# Visual Studio put dbghelp.dll in progfiles (especially 2008) and some in progfiles32.
"${PROGFILES}/Microsoft Visual Studio */Common7/IDE/Remote Debugger/${ARCH_SFX}/dbghelp.dll"
"${PROGFILES32}/Microsoft Visual Studio */Common7/IDE/Remote Debugger/${ARCH_SFX}/dbghelp.dll"
"${PROGFILES32}/Microsoft Visual Studio */Common7/Packages/Debugger/${ARCH_SFX}/dbghelp.dll"
"${PROGFILES32}/Microsoft Visual Studio/*/Professional/Common7/IDE/Remote Debugger/${ARCH_SFX}/dbghelp.dll")
if (X64)
set(dbghelp_paths ${dbghelp_paths}
# For older versions of windbg, x64 dbghelp.dll resides here.
"${PROGFILES}/Debugging Tools for Windows (x64)/dbghelp.dll")
else (X64)
set(dbghelp_paths ${dbghelp_paths}
"${PROGFILES}/Microsoft Visual Studio */Common7/IDE/dbghelp.dll"
# Putting this last mainly b/c only older versions (like my 6.3) are here.
"${PROGFILES}/Debugging Tools for Windows/dbghelp.dll")
endif (X64)
file(GLOB dbghelp_hint ${dbghelp_paths})
# XXX i#908: it seems cmake has trouble to lookup dbghelp.dll in
# 64-bit directory, so we just explicitly check several possible locations.
# Plus, we don't want system32, but NO_SYSTEM_ENVIRONMENT_PATH also
# excludes Program Files, so we avoid find_file() in general.
if (dbghelp_hint)
# DRi#1219: exclude VS2005 x64 dbghelp as it is buggy
list(LENGTH dbghelp_hint dbghelp_max)
math(EXPR dbghelp_max "${dbghelp_max} - 1")
set(dbghelp_index 0)
list(GET dbghelp_hint 0 dbghelp_default)
while (${dbghelp_index} LESS ${dbghelp_max})
if (X64 AND dbghelp_default MATCHES "Visual Studio 8")
# Keep looking.
elseif (X64 AND dbghelp_default MATCHES "/x86/")
# Keep looking.
elseif (NOT X64 AND dbghelp_default MATCHES "/x64/")
# Keep looking.
elseif (NOT X64 AND dbghelp_default MATCHES "/amd64/")
# Keep looking.
else ()
break ()
endif ()
math(EXPR dbghelp_index "${dbghelp_index} + 1")
list(GET dbghelp_hint ${dbghelp_index} dbghelp_default)
endwhile()
if (X64 AND dbghelp_default MATCHES "Visual Studio 8")
message(STATUS "Unable to find non-VS2005 dbghelp.dll")
set(dbghelp_default "DBGHELP_DLL-NOTFOUND")
endif ()
else ()
set(dbghelp_default "DBGHELP_DLL-NOTFOUND")
endif ()
set(DBGHELP_DLL "" CACHE STRING
"location of dbghelp.dll from recent Debugging Tools for Windows")
if ("${DBGHELP_DLL}" STREQUAL "")
set(DBGHELP_DLL ${dbghelp_default})
endif()
if (DBGHELP_DLL-NOTFOUND OR NOT EXISTS "${DBGHELP_DLL}")
message(FATAL_ERROR "dbghelp.dll required and not found")
else ()
message(STATUS "Using ${DBGHELP_DLL}")
endif ()
# Allow packaging to specify a glob for a prefered path for x86 and x64.
set(SYMSRV_GLOB "" CACHE STRING
"Preferred path for dbghelp.dll with wildcard expansion")
set(symsrv_paths
"${SYMSRV_GLOB}"
"${PROGFILES32}/Windows Kits/*/Debuggers/${ARCH_SFX}/symsrv.dll"
# In case if SDK is not installed and we have Visual Studio, symsrv.dll may be found in the
# same place as dbghelp.dll (see comment for dbghelp.dll) (xref i#1956).
"${PROGFILES}/Microsoft Visual Studio */Common7/IDE/Remote Debugger/${ARCH_SFX}/symsrv.dll"
"${PROGFILES32}/Microsoft Visual Studio */Common7/IDE/Remote Debugger/${ARCH_SFX}/symsrv.dll"
"${PROGFILES32}/Microsoft Visual Studio */Common7/Packages/Debugger/${ARCH_SFX}/symsrv.dll")
if (X64)
set(symsrv_paths ${symsrv_paths}
# For older versions of windbg, x64 symsrv.dll resides here.
"${PROGFILES}/Debugging Tools for Windows (x64)/symsrv.dll")
else (X64)
set(symsrv_paths ${symsrv_paths}
"${PROGFILES}/Microsoft Visual Studio */Common7/IDE/symsrv.dll"
# Putting this last mainly b/c only older versions (like my 6.3) are here.
"${PROGFILES}/Debugging Tools for Windows/symsrv.dll")
endif (X64)
file(GLOB symsrv_hint ${symsrv_paths})
if (symsrv_hint)
list(GET symsrv_hint 0 symsrv_default)
list(LENGTH symsrv_hint symsrv_max)
math(EXPR symsrv_max "${symsrv_max} - 1")
set(symsrv_index 0)
while (${symsrv_index} LESS ${symsrv_max})
if (X64 AND symsrv_default MATCHES "/x86/")
# Keep looking.
elseif (NOT X64 AND symsrv_default MATCHES "/x64/")
# Keep looking.
elseif (NOT X64 AND symsrv_default MATCHES "/amd64/")
# Keep looking.
else ()
break ()
endif ()
math(EXPR symsrv_index "${symsrv_index} + 1")
list(GET symsrv_hint ${symsrv_index} symsrv_default)
endwhile()
else ()
set(symsrv_default "SYMSRV_DLL-NOTFOUND")
endif ()
set(SYMSRV_DLL "" CACHE STRING
"location of symsrv.dll from recent Debugging Tools for Windows")
if ("${SYMSRV_DLL}" STREQUAL "")
set(SYMSRV_DLL ${symsrv_default})
endif()
if (SYMSRV_DLL-NOTFOUND OR NOT EXISTS "${SYMSRV_DLL}")
message(FATAL_ERROR "symsrv.dll required and not found")
else ()
message(STATUS "Using ${SYMSRV_DLL}")
endif ()
endif (WIN32)
if (BUILDING_SUB_PACKAGE)
set(INSTALL_PREFIX "drmemory/")
else ()
set(INSTALL_PREFIX "")
endif()
# To run out of build dir we put libs and scripts in dirs that match install layout
# except minus the toolname prefix dir.
# The CPack NSIS interface requires a bin/ dir, so for the Windows package
# we prefix bin/
# XXX: should clean all this up and normalize across platforms now
# that we have drsyms on Linux and once we're sure we don't need to
# support the old layout.
if (WIN32 AND TOOL_DR_MEMORY)
set(INSTALL_BIN_PREFIX "${INSTALL_PREFIX}.")
set(BUILD_BIN_PREFIX ".")
else ()
# Unified layout: match Windows since we're moving toward C-based frontends
# that won't have auxiliary scripts we want to hide.
set(INSTALL_BIN_PREFIX "${INSTALL_PREFIX}.")
set(BUILD_BIN_PREFIX ".")
endif ()
# For NSIS we have everything in top-level bin/
# Once we have x64 we'll need to address: fix CPack?
if (X64)
set(INSTALL_BIN "${INSTALL_BIN_PREFIX}/bin64")
set(BUILD_BIN "${BUILD_BIN_PREFIX}/bin64")
else (X64)
set(INSTALL_BIN "${INSTALL_BIN_PREFIX}/bin")
set(BUILD_BIN "${BUILD_BIN_PREFIX}/bin")
endif (X64)
if (DEBUG_BUILD)
set(build_type "debug")
else (DEBUG_BUILD)
set(build_type "release")
endif (DEBUG_BUILD)
set(INSTALL_LIB "${INSTALL_BIN}/${build_type}")
set(BUILD_LIB "${BUILD_BIN}/${build_type}")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/${BUILD_LIB}")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/${BUILD_BIN}")
if ("${CMAKE_GENERATOR}" MATCHES "Visual Studio")
# we don't support the Debug and Release subdirs
foreach (config ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER "${config}" config_upper)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${config_upper}
"${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${config_upper}
"${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${config_upper}
"${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
endforeach ()
endif ()
##################################################
# option sharing (PR 478146)
set(CPP_IGNORE_EMPTY "")
if (UNIX)
if (APPLE)
# /usr/bin/cpp is broken and won't honor -B flags
set(CMAKE_CPP_FOR_OPS ${CMAKE_C_COMPILER})
set(CPP_INC -Wp,-I,)
# Avoid clang warning on perl ''
set(CPP_IGNORE_EMPTY -Wno-invalid-pp-token)
else (APPLE)
# "gcc -E" on a non-.c-extension file gives message:
# "linker input file unused because linking not done"
# and doesn't produce any output, so we must use cpp for our .asm files.
# we assume it's in the same dir.
get_filename_component(compiler_path ${CMAKE_C_COMPILER} PATH)
find_program(CMAKE_CPP_FOR_OPS cpp HINTS "${compiler_path}"
DOC "path to C preprocessor")
if (cpp-NOTFOUND OR NOT EXISTS "${CMAKE_CPP_FOR_OPS}")
message(FATAL_ERROR "cpp is required to build")
endif (cpp-NOTFOUND OR NOT EXISTS "${CMAKE_CPP_FOR_OPS}")
mark_as_advanced(CMAKE_CPP_FOR_OPS)
set(CPP_INC -I)
endif (APPLE)
set(CPP_NO_LINENUM -P)
else (UNIX)
set(CMAKE_CPP_FOR_OPS ${CMAKE_C_COMPILER})
set(CPP_NO_LINENUM /EP)
set(CPP_INC /I)
endif (UNIX)
# options_for_docs is built in docs/CMakeLists.txt since custom commands
# are directory-local
##################################################
# utility functions
function (append_property_string type target name value)
# XXX: if we require cmake 2.8.6 we can simply use APPEND_STRING
get_property(cur ${type} ${target} PROPERTY ${name})
if (cur)
set(value "${cur} ${value}")
endif (cur)
set_property(${type} ${target} PROPERTY ${name} "${value}")
endfunction (append_property_string)
function (set_output_dirs dir)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${dir}" PARENT_SCOPE)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${dir}" PARENT_SCOPE)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${dir}" PARENT_SCOPE)
if ("${CMAKE_GENERATOR}" MATCHES "Visual Studio")
# we don't support the Debug and Release subdirs
foreach (config ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER "${config}" config_upper)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${config_upper}
"${dir}" PARENT_SCOPE)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${config_upper}
"${dir}" PARENT_SCOPE)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${config_upper}
"${dir}" PARENT_SCOPE)
endforeach ()
endif ()
endfunction (set_output_dirs)
##################################################
# find DynamoRIO so tests has its path, but don't include it or run
# its configure commands to avoid changing cflags:
# DR clobbers the global cflags, so we save and then restore them for
# our tests (and ourselves for non-pre-built DR).
# configure_DynamoRIO_client() also does so we do this even for pre-built DR
# for tests.
foreach (config "" ${CMAKE_BUILD_TYPE} ${CMAKE_CONFIGURATION_TYPES})
if ("${config}" STREQUAL "")
set(config_upper "")
else ("${config}" STREQUAL "")
string(TOUPPER "_${config}" config_upper)
endif ("${config}" STREQUAL "")
foreach (var CMAKE_C_FLAGS${config_upper};CMAKE_CXX_FLAGS${config_upper})
set(SAVE_${var} "${${var}}")
endforeach (var)
endforeach (config)
# we write DynamoRIO_DIR to the cache, so on re-interpreting the file later
# we can't tell whether the user set a value or not. we could
# use a differently-named var for the user but instead we check vs
# the local build path to avoid breaking existing scripts.
set(LOCAL_DynamoRIO_DIR "${PROJECT_BINARY_DIR}/dynamorio/cmake")
if (DEFINED DynamoRIO_DIR AND NOT "${DynamoRIO_DIR}" STREQUAL "${LOCAL_DynamoRIO_DIR}")
set(USER_SPECIFIED_DynamoRIO_DIR ON)
else ()
set(USER_SPECIFIED_DynamoRIO_DIR OFF)
endif ()
# when updating this, also update the git submodule
set(DynamoRIO_VERSION_REQUIRED "10.0.0")
set(DR_install_dir "dynamorio")
set(DynamoRIO_PAGE_SIZE_COMPATIBILITY ON)
set(DynamoRIO_LOG_COMPATIBILITY ON)
if (USER_SPECIFIED_DynamoRIO_DIR)
# i#67: relative dirs are not really supported in find_package: they're
# relative to source dir not build dir, so we change that here.
# we can't do get_filename_component(... ABSOLUTE) b/c it's relative to
# source dir as well.
if ("${DynamoRIO_DIR}" MATCHES "^\\.\\.")
get_filename_component(DynamoRIO_DIR "${PROJECT_BINARY_DIR}/${DynamoRIO_DIR}" ABSOLUTE)
endif ()
# exit if it doesn't exist since very misleading if find_package() goes
# and finds some other version from what was requested
if (NOT EXISTS "${DynamoRIO_DIR}/DynamoRIOConfig.cmake")
message(FATAL_ERROR "${DynamoRIO_DIR}/DynamoRIOConfig.cmake does not exist: invalid DynamoRIO_DIR")
endif ()
if (BUILDING_SUB_PACKAGE)
message(FATAL_ERROR "Sub-package not supported with pre-built DR")
endif ()
message(STATUS "Attempting to use pre-built DynamoRIO: ${DynamoRIO_DIR}")
find_package(DynamoRIO ${DynamoRIO_VERSION_REQUIRED})
if (NOT DynamoRIO_FOUND)
message(FATAL_ERROR "DynamoRIO package required to build")
endif(NOT DynamoRIO_FOUND)
# from here on use what was found, not what was passed in
get_filename_component(DynamoRIO_DIR "${DynamoRIO_CONFIG}" PATH)
# preserve real value in the cache so it's easy to tell
set(DynamoRIO_DIR "${DynamoRIO_DIR}" CACHE PATH "Path to DynamoRIO.")
message(STATUS "DynamoRIO that matches: ${DynamoRIO_VERSION} in ${DynamoRIO_DIR}")
else (USER_SPECIFIED_DynamoRIO_DIR)
# Build from our local copy of the sources, coming from a git submodule: i#74.
set(DynamoRIO_DIR "${LOCAL_DynamoRIO_DIR}" CACHE PATH "Path to DynamoRIO.")
message(STATUS "Building DynamoRIO from local sources ${DynamoRIO_DIR}")
# We include DynamoRIO as a subdir here to make it easy to use the
# DynamoRIOConfig.cmake at configure time: however, that also means we have
# potential conflicts in CMake's global option and target space.
# Ideally, DynamoRIO would prefix all its options and targets with "DR_"
# or something. For now we live w/ the ugliness.
# (An alternative would be to use the ExternalProject feature: but
# then we don't have DynamoRIOConfig.cmake at config time and we'd
# either need a parent build project or to hack our find_package().)
# it seems that we must set these in the cache for the subproj to see them:
set(BUILD_DOCS OFF CACHE BOOL "DynamoRIO option: build client samples")
set(BUILD_SAMPLES OFF CACHE BOOL "DynamoRIO option: build documentation")
# our local DR build matches our own build type
if ("${CMAKE_BUILD_TYPE}" MATCHES "Debug")
set(DEBUG ON CACHE BOOL "DynamoRIO option: debug build")
set(INTERNAL ON CACHE BOOL "DynamoRIO option: internal build")
endif ("${CMAKE_BUILD_TYPE}" MATCHES "Debug")
if (DRM_COPY_TO_DEVICE)
set(DR_COPY_TO_DEVICE ON CACHE BOOL "DynamoRIO option: copy to Android")
get_filename_component(builddir ${PROJECT_BINARY_DIR} NAME)
set(DR_DEVICE_BASEDIR "${DRM_DEVICE_BASEDIR}/${builddir}" CACHE STRING
"DynamoRIO option: Android path")
endif ()
# We do not want DR install, except for the targets we need for our
# multi-export-set install of the DRMF. We need those targets
# even for BUILDING_SUB_PACKAGE.
set(DO_DR_INSTALL OFF)
set(DO_DR_INSTALL_TARGETS ON)
# Stick the binaries somewhere outside of the install dir.
# However, NSIS won't allow an absolute path (i#1099).
# So for an automated package.cmake build via cpack, we use .. which
# is fine in the package dir structure. We don't want .. for a
# user-specified destination of course. We simply don't
# support creating a package manually outside of package.cmake.
if (BUILDING_PACKAGE)
set(DR_INSTALL_TARGETS_DEST ../ignored-installs)
else ()
set(DR_INSTALL_TARGETS_DEST ${PROJECT_BINARY_DIR}/dynamorio/installs)
endif ()
# i#1449: we need cmake to remove the absolute path from the LC_LOAD_DYLIB
# entries, which only happens on install. We can't easily do a two-step
# install b/c subdirs go after the main dir -- so we have DR cooperation.
set(DR_INSTALL_DEPLOY_BIN_DEST ${DR_install_dir}/${BIN_ARCH})
add_subdirectory(dynamorio)
# don't show DR options in drmem cmake list
# to really hide we should mark as INTERNAL but not worth it since would
# have to do for all of DR's many options.
# see comment above about DR prefixing its options.
mark_as_advanced(BUILD_CORE BUILD_DOCS BUILD_SAMPLES BUILD_EXT BUILD_TESTS
BUILD_TOOLS DEBUG INTERNAL)
# do not import dynamorio lib target: we'd end up w/ duplicate
# dynamorio targets
set(DynamoRIO_INTERNAL ON)
# our included DynamoRIO project will set DynamoRIO_SOURCE_DIR in cache
# for us so we'll get proper include dirs for extensions.
find_package(DynamoRIO ${DynamoRIO_VERSION_REQUIRED})
if (NOT DynamoRIO_FOUND OR
# make sure it didn't go find some other pre-built version after
# seeing that the local one is somehow not suitable
NOT "${DynamoRIO_CONFIG}" STREQUAL "${DynamoRIO_DIR}/DynamoRIOConfig.cmake")
message(FATAL_ERROR "Local DynamoRIO mis-configured")
endif ()
# Restore global flags
foreach (config "" ${CMAKE_BUILD_TYPE} ${CMAKE_CONFIGURATION_TYPES})
if ("${config}" STREQUAL "")
set(config_upper "")
else ("${config}" STREQUAL "")
string(TOUPPER "_${config}" config_upper)
endif ("${config}" STREQUAL "")
foreach (var CMAKE_C_FLAGS${config_upper};CMAKE_CXX_FLAGS${config_upper})
set(${var} "${SAVE_${var}}")
endforeach (var)
endforeach (config)
endif (USER_SPECIFIED_DynamoRIO_DIR)
if (USER_SPECIFIED_DynamoRIO_DIR)
# if we're building from our own DR, DR adds this option for us
option(GENERATE_PDBS "generate Windows debug information" ON)
mark_as_advanced(GENERATE_PDBS)
endif (USER_SPECIFIED_DynamoRIO_DIR)
# This must be before any add_library() or add_executable()
# but that means for local DR sources we haven't yet included
# DR's option(), so we check whether defined.
if (DEFINED GENERATE_PDBS AND NOT GENERATE_PDBS)
# Default from cmake in DEBUG and RELWITHDEBINFO has /debug
foreach (var CMAKE_C_FLAGS;CMAKE_CXX_FLAGS;
CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE_UPPER};
CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE_UPPER};
# tests are always built as Debug
CMAKE_C_FLAGS_DEBUG;CMAKE_CXX_FLAGS_DEBUG)
string(REGEX REPLACE "/Zi" "" ${var} "${${var}}")
endforeach ()
foreach (var CMAKE_EXE_LINKER_FLAGS_${CMAKE_BUILD_TYPE_UPPER};
CMAKE_MODULE_LINKER_FLAGS_${CMAKE_BUILD_TYPE_UPPER};
CMAKE_SHARED_LINKER_FLAGS_${CMAKE_BUILD_TYPE_UPPER};
# tests are always built as Debug
CMAKE_EXE_LINKER_FLAGS_DEBUG;
CMAKE_MODULE_LINKER_FLAGS_DEBUG;
CMAKE_SHARED_LINKER_FLAGS_DEBUG)
string(REGEX REPLACE "/debug" "" ${var} "${${var}}")
endforeach ()
endif (DEFINED GENERATE_PDBS AND NOT GENERATE_PDBS)
# Shrink binaries and pdbs (/Gy should already be there)
if (WIN32)
foreach (var CMAKE_EXE_LINKER_FLAGS_${CMAKE_BUILD_TYPE_UPPER};
CMAKE_MODULE_LINKER_FLAGS_${CMAKE_BUILD_TYPE_UPPER};
CMAKE_SHARED_LINKER_FLAGS_${CMAKE_BUILD_TYPE_UPPER})
set(${var} "${${var}} /opt:ref /opt:icf /pdbcompress")
endforeach ()
endif ()
if (APPLE)
# install_name_tool needs write access (i#1372)
set(owner_access OWNER_READ OWNER_WRITE)
else (APPLE)
set(owner_access OWNER_READ)
endif (APPLE)
##################################################
# now that we have ${DynamoRIO_DIR} we can configure docs
find_package(Doxygen)
if (NOT DOXYGEN_FOUND)
# We'd like to require doxygen for Windows pre-commit suite but it's not
# installed on our bots so we live with just Linux catching docs errors.
# Ditto for Mac.
if (TEST_SUITE AND UNIX AND NOT APPLE)
message(FATAL_ERROR "doxygen is required to build the documentation")
else ()
# Non-fatal for a single, un-official build, or on Windows
message(WARNING "doxygen not found: documentation will NOT be built")
endif ()
else ()
add_subdirectory(docs)
endif ()