-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
1744 lines (1620 loc) · 74 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-2013 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.
# We need 2.8.10 for multi-export-set support for DRMF.
# (For Visual Studio generators, we also need >= 2.8.2 for output dir name control.)
# (For Linux, we also need 2.6.4+ for cmake bug #8639 (asm support broken).)
cmake_minimum_required(VERSION 2.8.10)
# 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 "Release" 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)
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 ()
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)
option(BUILD_VISUALIZER "build Dr. Heapstat visualizer (requires Flex SDK and Java)")
if (BUILD_VISUALIZER)
# Flex building is done only for Dr. HeapStat visualization tool. So Java
# is needed only for that too.
if (NOT DEFINED JAVA) # Not using toolchain then
set(Java_FIND_QUIETLY ON) # avoid errors about missing javac
include(FindJava)
if (JAVA_RUNTIME)
set(JAVA "${JAVA_RUNTIME}")
message(STATUS "Found Java interpreter ${JAVA}")
else (JAVA_RUNTIME)
message(FATAL_ERROR "Can't find Java interpreter: please set JAVA var")
endif (JAVA_RUNTIME)
endif (NOT DEFINED JAVA)
# There is no standard install path so the user must tell us where they
# installed the Flex SDK, either via env var FLEXROOT or FLEX_SDK CMake var.
set(FLEX_SDK "$ENV{FLEXROOT}" CACHE PATH "Path to Flex SDK.")
set(FLEX_MXMLC "${FLEX_SDK}/lib/mxmlc.jar"
CACHE FILEPATH "Path to Flex MXML compiler.")
if (NOT EXISTS "${FLEX_MXMLC}")
message(FATAL_ERROR "Flex compiler ${FLEX_MXMLC} not found: set FLEX_SDK var or FLEXROOT env var")
endif ()
message(STATUS "Found Flex MXML compiler ${FLEX_MXMLC}")
set(FLEX_FRAMEWORKS "${FLEX_SDK}/frameworks"
CACHE PATH "Path to Flex frameworks, i.e., standard libraries.")
if (NOT EXISTS "${FLEX_FRAMEWORKS}")
message(FATAL_ERROR "Flex frameworks path ${FLEX_FRAMEWORKS} not found.")
endif ()
endif (BUILD_VISUALIZER)
# 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).
set(DRSYMS_DEFAULT ON)
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)
set(DRSYMS_DEFAULT ON)
endif (TOOL_DR_HEAPSTAT)
# i#83: use svn revision of last commit as patchlevel ver# to distinguish
# mid-release builds.
# XXX: if we later switch to a non-linear version control system we'll
# want to switch to a date or something, but be aware of timezone issues
# so we may want a cron job that updates an official date in the sources.
set(VERSION_NUMBER_PATCHLEVEL 0)
# for now using a hack of running svn or git to get the ver#,
# rather than having it stored in the sources and auto-updated
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)
execute_process(COMMAND ${GIT} log
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
RESULT_VARIABLE git_result
ERROR_VARIABLE git_err
OUTPUT_VARIABLE git_out)
if (git_result OR git_err)
message(FATAL_ERROR "*** ${GIT} show failed: ***\n${git_err}")
endif (git_result OR git_err)
# look for first commit with git-svn-id
string(REGEX MATCH "git-svn-id: http[^@]*@[0-9]+" git_out "${git_out}")
string(REGEX REPLACE "git-svn-id: http[^@]*@" "" git_out "${git_out}")
set(VERSION_NUMBER_PATCHLEVEL "${git_out}")
endif (GIT)
endif (EXISTS "${PROJECT_SOURCE_DIR}/.git")
endif (EXISTS "${PROJECT_SOURCE_DIR}/.svn")
# XXX: for windows should we have a real .rc file?
set(VERSION_NUMBER_DEFAULT "1.5.${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)")
set(DEFINES ${DEFINES}
-DBUILD_NUMBER=${TOOL_BUILD_NUMBER}
-DVERSION_NUMBER=${TOOL_VERSION_NUMBER}
-DVERSION_STRING="${TOOL_VERSION_NUMBER}")
# i#44/PR 243532: online symbol access
option(USE_DRSYMS "use drsyms DR Extension online symbols instead of post-processing"
${DRSYMS_DEFAULT})
if (USE_DRSYMS)
set(DEFINES ${DEFINES} -DUSE_DRSYMS)
endif (USE_DRSYMS)
if (WIN32)
# With the new drinjectlib-based front end we do not use perl or perl2exe
# at all on Windows (xref i#265/PR 486139)
if (OFF) # disabling
# For portability we convert our perl scripts to executables,
# if the 'pp' tool is available.
# For most portable results, use a native windows perl (e.g.,
# strawberry perl) rather than cygwin perl.
set(PERL_PATH "" CACHE PATH "directory where perl binaries are located")
if (PERL_PATH AND EXISTS "${PERL_PATH}/perl.exe")
set(PERL_EXECUTABLE "${PERL_PATH}/perl.exe")
else ()
# we only look for perl if user doesn't specify (on windows it's common
# to have several perls installed)
include(FindPerl)
if (PERL_FOUND)
get_filename_component(PERL_PATH "${PERL_EXECUTABLE}" PATH)
endif (PERL_FOUND)
endif ()
if (EXISTS "${PERL_PATH}/pp")
set(PERL_PP "${PERL_PATH}/pp" CACHE FILEPATH
"Path to perl PAR module's perl-to-executable tool 'pp'")
else ()
find_file(PERL_PP pp HINTS "${PERL_PATH}"
DOC "Path to perl PAR module's perl-to-executable tool 'pp'")
endif ()
if (PERL_PP-NOTFOUND OR NOT EXISTS "${PERL_PP}")
message(STATUS "Did not find pp: will not convert perl scripts to executables")
set(PERL_TO_EXE OFF)
else (PERL_PP-NOTFOUND OR NOT EXISTS "${PERL_PP}")
message(STATUS "Found pp: ${PERL_PP}")
set(PERL_TO_EXE ON)
endif (PERL_PP-NOTFOUND OR NOT EXISTS "${PERL_PP}")
else (OFF)
set(PERL_TO_EXE OFF)
endif (OFF)
endif (WIN32)
# i#889: Dr. Memory pattern mode supports 64-bit
# FIXME i#111, i#217: 64-bit is only supported in pattern mode
set(SUPPORT_64BIT ON)
if (CMAKE_C_SIZEOF_DATA_PTR EQUAL 8 OR CMAKE_CXX_SIZEOF_DATA_PTR EQUAL 8)
if (NOT SUPPORT_64BIT)
message(FATAL_ERROR "64-bit not supported (on Linux, set CFLAGS=-m32 CXXFLAGS=-m32)")
endif (NOT SUPPORT_64BIT)
set(X64 ON)
set(LIB_ARCH "lib64")
set(BIN_ARCH "bin64")
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 ()
if (UNIX)
# has enough debug info
set(CMAKE_BUILD_TYPE "Release")
else (UNIX)
# we want pdb for release build
set(CMAKE_BUILD_TYPE "RelWithDebInfo")
endif (UNIX)
set(DEBUG_BUILD OFF)
endif ()
string(TOUPPER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_UPPER)
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")
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 ()
set(EXTRA_FLAGS "")
endif ()
set(CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE_UPPER} "${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE_UPPER}} ${ARCH_CFLAGS} ${WARN} ${EXTRA_FLAGS}")
else (UNIX)
# FIXME: 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}}")
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")
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)
include(CheckIncludeFiles)
check_include_files("asm-i386/stat.h" HAVE_ASM_I386)
if (HAVE_ASM_I386)
# see comments abouve about adding configure.h
set(DEFINES ${DEFINES} -DHAVE_ASM_I386)
endif (HAVE_ASM_I386)
if (UNIX)
# We don't want our instrument_init() pre-empted by debug-internal DynamoRIO
# that has visible internal routines.
# Check for -fvisibility: code from DynamoRIO's CMakeLists.txt
# I tried cmake's CheckCCompilerFlag but it doesn't seem to work
execute_process(COMMAND
${CMAKE_C_COMPILER} -v --help
RESULT_VARIABLE gcc_result
ERROR_QUIET
OUTPUT_VARIABLE gcc_out)
if (gcc_result)
message(FATAL_ERROR "*** ${CMAKE_C_COMPILER} failed to run ***\n")
endif (gcc_result)
string(REGEX MATCH "fvisibility" flag_present "${gcc_out}")
if (NOT flag_present)
message("${CMAKE_C_COMPILER} missing flag -fvisibility, using linker script instead")
set(HAVE_FVISIBILITY OFF)
else (NOT flag_present)
set(HAVE_FVISIBILITY ON)
endif (NOT flag_present)
if (HAVE_FVISIBILITY)
# Only export functions so marked via attributes
set(CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE_UPPER}
"${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE_UPPER}} -fvisibility=internal")
endif (HAVE_FVISIBILITY)
endif (UNIX)
if (WIN32)
# 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.
if (X64)
set(PROGFILES "$ENV{PROGRAMW6432}") # cmake is 32-bit
set(PROGFILES32 "$ENV{PROGRAMFILES}")
set(ARCH_SFX "x64")
set(DDK_SFX "amd64")
else (X64)
set(PROGFILES "$ENV{PROGRAMFILES}")
set(PROGFILES32 "$ENV{PROGRAMFILES}")
set(ARCH_SFX "x86")
set(DDK_SFX "i386")
endif (X64)
# 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
"${DDK_ROOT}/bin/${ARCH_SFX}/dbghelp.dll"
"${DDK_ROOT}/tools/tracing/${DDK_SFX}/dbghelp.dll"
"${PROGFILES}/Microsoft Visual Studio */Common7/IDE/Remote Debugger/${ARCH_SFX}/dbghelp.dll"
"${PROGFILES32}/Windows Kits/*/Debuggers/${ARCH_SFX}/dbghelp.dll"
# Putting this last mainly b/c only older versions (like my 6.3) are here.
"${PROGFILES}/Debugging Tools for Windows/dbghelp.dll")
if (NOT X64)
set(dbghelp_paths ${dbghelp_paths}
"${PROGFILES}/Microsoft Visual Studio */Common7/IDE/dbghelp.dll")
endif (NOT 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)
list(GET dbghelp_hint 0 dbghelp_default)
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 ()
set(symsrv_paths
"${PROGFILES}/Debugging Tools for Windows/symsrv.dll"
"${PROGFILES}/Microsoft Visual Studio */Common7/IDE/Remote Debugger/${ARCH_SFX}/symsrv.dll"
"${PROGFILES32}/Windows Kits/*/Debuggers/${ARCH_SFX}/symsrv.dll")
if (NOT X64)
set(symsrv_paths ${symsrv_paths}
"${PROGFILES}/Microsoft Visual Studio */Common7/IDE/symsrv.dll")
endif (NOT X64)
file(GLOB symsrv_hint ${symsrv_paths})
if (symsrv_hint)
list(GET symsrv_hint 0 symsrv_default)
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)
# 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 USE_DRSYMS AND TOOL_DR_MEMORY)
set(INSTALL_BIN_PREFIX ".")
set(BUILD_BIN_PREFIX ".")
elseif (PERL_TO_EXE)
# We are only releasing Dr. Memory so no toolnames: would need to create
# shortcut or .bat file to run from right dir
if (X64)
set(INSTALL_BIN_PREFIX "bin64")
set(BUILD_BIN_PREFIX "bin64")
else (X64)
set(INSTALL_BIN_PREFIX "bin")
set(BUILD_BIN_PREFIX "bin")
endif (X64)
else (PERL_TO_EXE)
# When installed we now use a bin dir for scripts
if (X64)
set(INSTALL_BIN_PREFIX "${toolname}/bin64")
set(BUILD_BIN_PREFIX "bin64")
else (X64)
set(INSTALL_BIN_PREFIX "${toolname}/bin")
set(BUILD_BIN_PREFIX "bin")
endif (X64)
endif (WIN32 AND USE_DRSYMS AND TOOL_DR_MEMORY)
if (WIN32 AND USE_DRSYMS AND TOOL_DR_MEMORY)
# 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)
else (WIN32 AND USE_DRSYMS AND TOOL_DR_MEMORY)
set(INSTALL_BIN "${INSTALL_BIN_PREFIX}/${BIN_ARCH}")
set(BUILD_BIN "${BUILD_BIN_PREFIX}/${BIN_ARCH}")
endif (WIN32 AND USE_DRSYMS AND TOOL_DR_MEMORY)
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)
if (UNIX)
# "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 cpp HINTS "${compiler_path}" DOC "path to C preprocessor")
if (cpp-NOTFOUND OR NOT EXISTS "${CMAKE_CPP}")
message(FATAL_ERROR "cpp is required to build")
endif (cpp-NOTFOUND OR NOT EXISTS "${CMAKE_CPP}")
mark_as_advanced(CMAKE_CPP)
set(CPP_NO_LINENUM -P)
else (UNIX)
set(CMAKE_CPP ${CMAKE_C_COMPILER})
set(CPP_NO_LINENUM /EP)
endif (UNIX)
# I would share this name w/ drmemory.pl but it's a pain to configure_file
# or generate the perl script as we also have to compile it for pp.
set(options_for_perl "${PROJECT_BINARY_DIR}/${BUILD_BIN_PREFIX}/options-perl.pl")
add_custom_target(options_perl ALL DEPENDS "${options_for_perl}")
add_custom_command(
OUTPUT "${options_for_perl}"
DEPENDS "${PROJECT_SOURCE_DIR}/common/options-perl.c"
"${PROJECT_SOURCE_DIR}/${tooldir}/optionsx.h"
COMMAND ${CMAKE_CPP}
ARGS -E ${CPP_NO_LINENUM} "${PROJECT_SOURCE_DIR}/common/options-perl.c"
-I${PROJECT_SOURCE_DIR}/${tooldir} ${DEFINES} > "${options_for_perl}"
VERBATIM)
# 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 svn:externals prop on trunk/
set(DynamoRIO_VERSION_REQUIRED "3.0.0")
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 ()
# ensure was built w/ static ext libs
if (UNIX)
set(LIB_EXT "so")
set(LIB_PFX "lib")
else (UNIX)
set(LIB_EXT "dll")
set(LIB_PFX "")
endif (UNIX)
if (EXISTS "${DynamoRIO_DIR}/../ext/${LIB_ARCH}/${build_type}/${LIB_PFX}drwrap.${LIB_EXT}" OR
EXISTS "${DynamoRIO_DIR}/../ext/${LIB_ARCH}/${build_type}/${LIB_PFX}drutil.${LIB_EXT}" OR
EXISTS "${DynamoRIO_DIR}/../ext/${LIB_ARCH}/${build_type}/${LIB_PFX}drmgr.${LIB_EXT}")
message(FATAL_ERROR "${DynamoRIO_DIR} was built with dynamic extensions: please re-build with static extension libraries")
endif ()
if (STATIC_DRSYMS AND EXISTS "${DynamoRIO_DIR}/../ext/${LIB_ARCH}/${build_type}/${LIB_PFX}drsyms.${LIB_EXT}")
message(FATAL_ERROR "${DynamoRIO_DIR} was built with dynamic drsyms: please re-build with static drsyms")
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 an svn external: 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")
# for efficiency, have all our extensions be static. we have the same
# LGPL license as drutil and drwrap so it works out.
set(DR_EXT_DRWRAP_STATIC ON CACHE BOOL "static drwrap")
set(DR_EXT_DRUTIL_STATIC ON CACHE BOOL "static drutil")
set(DR_EXT_DRMGR_STATIC ON CACHE BOOL "static drmgr")
if (STATIC_DRSYMS)
# N.B.: static drsyms gives us kernel32 imports from elftoolchain
# libc use. If we end up needing late kernel32 use for early
# injection we may want to go back to dynamic drsyms (and delayed
# dr_enable_console_printing()).
set(DR_EXT_DRSYMS_STATIC ON CACHE BOOL "static drsyms")
endif (STATIC_DRSYMS)
# We do not want DR install, except for the targets we need for our
# multi-export-set install of the DRMF.
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 ()
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)
##################################################
# now that we have ${DynamoRIO_DIR} we can configure docs
find_package(Doxygen)
if (NOT DOXYGEN_FOUND)
message("doxygen is required to build the documentation")
else ()
add_subdirectory(docs)
endif ()
##################################################
# assembly support
# set up assembly support and CMAKE_CPP
include(${DynamoRIO_DIR}/cpp2asm_support.cmake)
if (UNIX)
if (NOT CMAKE_ASM_SUPPORTS_INTEL_SYNTAX)
message(FATAL_ERROR "${CMAKE_ASM_COMPILER} does not support required flags")
endif (NOT CMAKE_ASM_SUPPORTS_INTEL_SYNTAX)
endif (UNIX)
# for cpp2asm_defines.h
include_directories(${DynamoRIO_DIR})
# XXX: even if we went to a configure.h, we wouldn't have the DR platform
# defines there unless we duplicated them.
if (UNIX)
set(DEFINES ${DEFINES} -DASSEMBLE_WITH_GAS)
else (UNIX)
set(DEFINES ${DEFINES} -DASSEMBLE_WITH_MASM)
endif (UNIX)
get_DynamoRIO_defines(DR_DEFINES OFF)
# We need defines to be a list to pass as separate args to custom command.
# We assume none have spaces inside them which seems reasonable.
string(REPLACE " " ";" DR_DEFINES "${DR_DEFINES}")
set(asm_defs ${DR_DEFINES} ${DEFINES} -I "${DynamoRIO_DIR}")
set(asm_deps "${DynamoRIO_DIR}/cpp2asm_defines.h")
add_asm_target(common/asm_utils.asm asm_utils_src asm_utils_tgt ""
"${asm_defs}" "${asm_deps}")
##################################################
if (WIN32)
set(FLAG_DISABLE_FPO "/Oy-")
else (WIN32)
set(FLAG_DISABLE_FPO "-fno-omit-frame-pointer")
endif (WIN32)
function(append_src_compile_flags srcfile new_flags)
get_source_file_property(cur_flags ${srcfile} COMPILE_FLAGS)
# XXX: if we require cmake 2.8.6 we can simply use APPEND_STRING
if (NOT cur_flags)
set(cur_flags "")
endif (NOT cur_flags)
set_source_files_properties(${srcfile} PROPERTIES
COMPILE_FLAGS "${cur_flags} ${new_flags}")
endfunction(append_src_compile_flags)
# new set_property() doesn't want -D but our cpp invocation above does
string(REGEX REPLACE "-D" "" DEFINES_NO_D "${DEFINES}")
string(REGEX REPLACE "-D" "" DR_DEFINES_NO_D "${DR_DEFINES}")
option(BUILD_TOOL_TESTS "build Dr. Memory/Dr. Heapstat tests" ON)
if (TOOL_DR_HEAPSTAT)
# Dr. Heapstat
set(srcs
drheapstat/drheapstat.c
drheapstat/staleness.c
common/alloc.c
common/alloc_unopt.c
common/alloc_replace.c
common/heap.c
common/callstack.c
common/utils.c
${asm_utils_src}
common/redblack.c
common/crypto.c
# For leak checking we need stack.c but it pulls in the inter-dependent
# readwrite, fastpath, and shadow: we'll want those for staleness anyway.
# Looking more and more like Dr. Memory!
drmemory/annotations.c
drmemory/leak.c
drmemory/options.c
drmemory/stack.c
drmemory/readwrite.c
drmemory/fastpath.c
drmemory/shadow.c
drmemory/perturb.c)
else (TOOL_DR_HEAPSTAT)
# Dr. Memory
set(srcs
drmemory/annotations.c
drmemory/drmemory.c
drmemory/readwrite.c
drmemory/fastpath.c
drmemory/stack.c
drmemory/shadow.c
drmemory/options.c
drmemory/pattern.c
common/alloc.c
common/alloc_unopt.c
common/alloc_replace.c
common/heap.c
common/callstack.c
drmemory/alloc_drmem.c
drmemory/syscall.c
drmemory/report.c
drmemory/replace.c
drmemory/leak.c
drmemory/perturb.c
common/utils.c
${asm_utils_src}
common/redblack.c
common/crypto.c)
if (UNIX)
set(srcs ${srcs} drmemory/syscall_linux.c)
else (UNIX)
set(srcs ${srcs} drmemory/syscall_windows.c)
set(srcs ${srcs} drmemory/syscall_wingdi.c)
set(srcs ${srcs} drmemory/gdicheck.c)
set(srcs ${srcs} drmemory/handlecheck.c)
endif (UNIX)
endif (TOOL_DR_HEAPSTAT)
set(scripts ${toolname}.pl)
if (NOT USE_DRSYMS)
set(scripts ${scripts} postprocess.pl)
endif (NOT USE_DRSYMS)
if (USE_DRSYMS)
set(srcs ${srcs} common/symcache.c)
endif (USE_DRSYMS)
if (WIN32 AND USE_DRSYMS AND TOOL_DR_MEMORY)
# front-end needs to be name drmemory.exe and thus has drmemory.pdb, so
# we rename client lib (plus cmake best w/o same-name targets)
set(client_target "${toolname}lib")
# assuming only DrMem for now
add_executable(${toolname} drmemory/frontend.c)
target_link_libraries(${toolname} dbghelp)
else (WIN32 AND USE_DRSYMS AND TOOL_DR_MEMORY)
set(client_target ${toolname})
endif (WIN32 AND USE_DRSYMS AND TOOL_DR_MEMORY)
add_library(${client_target} SHARED ${srcs})
set_target_properties(${client_target} PROPERTIES
VERSION ${TOOL_VERSION_NUMBER})
set_property(TARGET ${client_target} PROPERTY COMPILE_DEFINITIONS ${DEFINES_NO_D})
if ("${CMAKE_GENERATOR}" MATCHES "Visual Studio")
# ensure race-free parallel builds
add_dependencies(${client_target} ${asm_utils_tgt})
endif ("${CMAKE_GENERATOR}" MATCHES "Visual Studio")
# We require frames in our replacement routines in order to reliably include
# the allocator routines in the callstack for i#639. Xref i#958.
append_src_compile_flags(common/alloc_replace.c ${FLAG_DISABLE_FPO})
if (WIN32)
# our addr2line for Windows
add_executable(winsyms tools/winsyms.c)
target_link_libraries(winsyms dbghelp)
# configure_DynamoRIO_client clears global flags so add as additional
# request static libc to avoid manifest files and libc portability issues
string(REGEX REPLACE "/MD" "/MT" CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE_UPPER}
"${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE_UPPER}}")
set_source_files_properties(tools/winsyms.c PROPERTIES
COMPILE_FLAGS "${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE_UPPER}}")
endif (WIN32)
# we want a preferred base to avoid patching pcaches
set(DynamoRIO_SET_PREFERRED_BASE ON)
set(PREFERRED_BASE 0x73800000)
set(DynamoRIO_REG_COMPATIBILITY ON)
if (STATIC_DRSYMS)
set(DynamoRIO_USE_LIBC ON)
endif (STATIC_DRSYMS)
configure_DynamoRIO_client(${client_target})
# i#277/PR 540817: features split into DynamoRIO Extensions
use_DynamoRIO_extension(${client_target} drcontainers)
use_DynamoRIO_extension(${client_target} drmgr)
use_DynamoRIO_extension(${client_target} drutil)
use_DynamoRIO_extension(${client_target} drwrap)
set_target_properties(${client_target} PROPERTIES
# dlls are put in runtime dir but we want lib dir
RUNTIME_OUTPUT_DIRECTORY${location_suffix} "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
if (WIN32)
# annoying to have ASLR and not on module list
# plus, now we require the same base for pcache
set(new_flags "/dynamicbase:no")
if (NOT DEFINED GENERATE_PDBS OR GENERATE_PDBS)
set(new_flags "${new_flags} /debug")
endif ()
get_target_property(cur_flags ${client_target} LINK_FLAGS)
if (NOT cur_flags)
set(cur_flags "")
endif (NOT cur_flags)
set_target_properties(${client_target} PROPERTIES
LINK_FLAGS "${cur_flags} ${new_flags}")
endif (WIN32)
if (WIN32 AND USE_DRSYMS AND TOOL_DR_MEMORY)
configure_DynamoRIO_standalone(${toolname})
target_link_libraries(${toolname} drinjectlib drconfiglib)
set_target_properties(${toolname} PROPERTIES
VERSION ${TOOL_VERSION_NUMBER})
set_property(TARGET ${toolname} PROPERTY COMPILE_DEFINITIONS ${DEFINES_NO_D})
endif (WIN32 AND USE_DRSYMS AND TOOL_DR_MEMORY)
if (USE_DRSYMS)
use_DynamoRIO_extension(${client_target} drsyms)
endif (USE_DRSYMS)
if (WIN32)