-
Notifications
You must be signed in to change notification settings - Fork 17
/
CMakeLists.txt
1117 lines (1031 loc) · 45.5 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) 2009-2010 VMware, Inc. 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 VMware, Inc. 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 VMWARE, INC. 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.
###########################################################################
# Missing features:
# i#77: make DRgui a subproject to support with different compiler from libutil
# i#73: provide automatic suport for locating ml64.exe when using Vista SDK+WDK
# i#79: custom build number or label for non-release builds
# i#84: nmake adds space before 1st / in 1st arg to a command invoked with quotes
# i#74: create source tarball via 'make package_source'
# i#68: replace perl with cmake scripts and CTest
# i#69: re-add support for core unit tests and standalone build rules
# i#70: symbol store support in core/Makefile and tools/Makefile
# i#75: convert clients/standalone/Makefile to CMake
# i#72: RHEL3 linker script has no __executable_start
# i#60: re-add libutil/ unit tests
#
# Not filed:
# * move info like "build core solely from DDK" from make/compiler.mk into
# HowToBuild.wiki
###########################################################################
cmake_minimum_required(VERSION 2.6)
set(cmake_ver_string
"${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_RELEASE_VERSION}")
if ("${cmake_ver_string}" STRLESS "2.6.4")
# Workaround for cmake bug #8639 where CMAKE_ASM_SOURCE_FILE_EXTENSIONS
# is not set and our asm files are not built (should be fixed in 2.6.4).
# We can simply set the var ahead of time, luckily, since noone clears it:
# Alternative workarounds:
# - Use ASM-ATT instead of ASM: should work
# - I tried puting a patched CMakeASMInformation.cmake ahead of share/Modules
# but enable_language() seems to not use the CMAKE_MODULE_PATH
set(CMAKE_ASM_SOURCE_FILE_EXTENSIONS s;S;asm)
endif ("${cmake_ver_string}" STRLESS "2.6.4")
# 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)
# Allow users to set -m32 in just CFLAGS and have it apply to CXXFLAGS as well.
# CMake puts such flags in various variables early on and we'd have to go
# manually add to CMAKE_SHARED_LIBRARY_CXX_FLAGS or something to fix later.
if (NOT DEFINED ENV{CXXFLAGS})
set(ENV{CXXFLAGS} "$ENV{CFLAGS}")
endif (NOT DEFINED ENV{CXXFLAGS})
project(DynamoRIO NONE)
if (DEFINED GENERATE_PDBS AND NOT GENERATE_PDBS)
# i#310: support building over cygwin ssh where we cannot build pdbs.
# 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)
###########################################################################
# configuration options
# many are core-specific
# configurations that also have defines
option(DEBUG "build with asserts and logging enabled")
option(INTERNAL "for developer use")
option(DRGUI_DEMO "build DRgui with a giant font for projecting")
# target
if (UNIX)
set(LINUX 1)
endif (UNIX)
if (WIN32)
set(WINDOWS 1)
endif (WIN32)
# Whether 64-bit is expected to be selected by user setting up compiler
# prior to invoking CMake: it has to be that way for Windows, and for
# Linux the user should set CFLAGS to -m32 or -m64
# to override gcc's default. To simplify matters we only look at
# CMAKE_C_SIZEOF_DATA_PTR, controlled by CFLAGS, so the user doesn't
# have to also set CXXFLAGS (CMAKE_SIZEOF_VOID_P happens
# to come from CXXFLAGS). (CMAKE_C_SIZEOF_DATA_PTR can be relied on
# to be set in all CMake versions we support.)
if (CMAKE_C_SIZEOF_DATA_PTR EQUAL 8)
set(X64 ON)
else(CMAKE_C_SIZEOF_DATA_PTR EQUAL 8)
set(X64 OFF)
endif (CMAKE_C_SIZEOF_DATA_PTR EQUAL 8)
option(VMKERNEL "target VMkernel (not officially supported yet)")
option(MACOS "target MacOS (not officially supported yet)")
# high-level configurations
option(VMAP "client support" ON)
option(VPS "security support but no client support")
option(VMSAFE "client support including security API")
if (VMAP)
set(CLIENT_INTERFACE 1)
set(APP_EXPORTS 1)
endif (VMAP)
if (VMSAFE)
set(PROGRAM_SHEPHERDING 1)
set(CLIENT_INTERFACE 1)
set(APP_EXPORTS 1)
set(HOT_PATCHING_INTERFACE 1)
endif (VMSAFE)
if (VPS)
set(PROGRAM_SHEPHERDING 1)
set(HOT_PATCHING_INTERFACE 1)
set(PROCESS_CONTROL 1)
if (WIN32)
set(GBOP 1)
endif (WIN32)
endif (VPS)
# temporary: once build+support issues fixed, remove and add HOT_PATCHING_INTERFACE
# to VMAP by default
option(PROBE "enable not-yet-supported Probe API")
mark_as_advanced(PROBE)
if (PROBE)
set(HOT_PATCHING_INTERFACE 1)
endif (PROBE)
# For developers
# CMake note: never set option vars as it prevents override by cache var:
# instead set default value in separate var and use that to initialize option.
# For a dependent option, use a string var and only set it if the string is ""
# (xref i#170 and see below).
if (INTERNAL OR DEBUG)
set(KSTATS_DEFAULT ON)
else (INTERNAL OR DEBUG)
set(KSTATS_DEFAULT 0FF)
endif (INTERNAL OR DEBUG)
# PR 403006 - We want to keep symbols to get glibc backtrace for DR errors, but
# that causes a collision of app and dr symbols on visor (DR's crc32() was
# linked to imports of crc32() in libz.so in hostd). So, we just keep symbol
# support for glibc backtrace only on linux - hope we don't run into any
# collisions on linux! Longer term we do our own backtrace with symbols.
#
if (INTERNAL AND DEBUG AND NOT VMKERNEL)
set(KEEP_SYMBOLS_DEFAULT ON)
else (INTERNAL AND DEBUG AND NOT VMKERNEL)
set(KEEP_SYMBOLS_DEFAULT OFF)
endif (INTERNAL AND DEBUG AND NOT VMKERNEL)
# no KSTATS for caller profiling: we want to be as close to release
# build as we can, but w/o optimizations
if (CALLPROF)
set(KSTATS_DEFAULT 0FF)
endif (CALLPROF)
set(KSTATS "" CACHE STRING "internal kstat profiling: ON or OFF overrides default")
# FIXME i#170: once CMake 2.8 is released we can detect whether 2.8 is
# in use, and if so use a value-enum to get drop-down of possible values, like so:
# set_property(CACHE KSTATS PROPERTY STRINGS "" "ON" "OFF")
if ("${KSTATS}" STREQUAL "")
set(KSTATS ${KSTATS_DEFAULT})
endif()
set(KEEP_SYMBOLS_FOR_LIBC_BACKTRACE "" CACHE STRING
"keep internal symbols exported: ON or OFF overrides default")
# FIXME i#170: ditto
if ("${KEEP_SYMBOLS_FOR_LIBC_BACKTRACE}" STREQUAL "")
set(KEEP_SYMBOLS_FOR_LIBC_BACKTRACE ${KEEP_SYMBOLS_DEFAULT})
endif ()
option(CALLPROF "internal caller profiling support")
option(LINKCOUNT "internal linkcount profiling")
option(STANDALONE_UNIT_TEST "internal unit tests")
if (WIN32)
# xref PR 192750 - runregression uses this to avoid over-ssh pdb issues
option(GENERATE_PDBS "generate Windows debug information" ON)
# instead of config files use registry like in the old days
# (i#85/PR 212034 and i#265/PR 486139 switched DR to config files)
option(PARAMS_IN_REGISTRY "parameters from registry instead of config files")
endif (WIN32)
# for users
option(DISABLE_WARNINGS "disable warnings")
option(SET_PREFERRED_BASE "set a preferred library base address")
if (WIN32 AND DEBUG)
# apparently no numeric type so we use STRING
set(preferred_base "0x15000000" CACHE STRING "Preferred library base address")
else (WIN32 AND DEBUG)
set(preferred_base "0x71000000" CACHE STRING "Preferred library base address")
endif (WIN32 AND DEBUG)
if (WIN32 OR X64)
# for x64: PR 253624: we need our library to be next to our heap
# for win32: not PIC so need a base
# we studied existing exe + dll bases and tried to pick non-conflicting addresses
set(SET_PREFERRED_BASE 1)
endif (WIN32 OR X64)
if (VMKERNEL)
# we end up with the default executable base (0x08*) so go back to 0 base
# (else we fail to load on esx)
set(SET_PREFERRED_BASE 1)
set(preferred_base "0x00000000")
endif (VMKERNEL)
# we do not support most users choosing these
mark_as_advanced(
VMKERNEL
MACOS
VMAP
VMSAFE
VPS
KSTATS
CALLPROF
LINKCOUNT
STANDALONE_UNIT_TEST
KEEP_SYMBOLS_FOR_LIBC_BACKTRACE
SET_PREFERRED_BASE
preferred_base
GENERATE_PDBS
DRGUI_DEMO
)
# replaced by our own DEBUG, INTERNAL, etc.
# FIXME: or should we support and map these to ours?
# if we do support we'll need to remove flags like /MD coming from
# the CMAKE_C_FLAGS_*, which are added to the base CMAKE_C_FLAGS.
set(CMAKE_BUILD_TYPE "" CACHE INTERNAL
"build type: unused" FORCE)
# resources when packaging
# N.B.: once VERSION_NUMBER crosses 3.x we'll need to update the
# symlink loop in core/CMakeLists.txt
set(VERSION_NUMBER_DEFAULT "2.0.0")
# do not store the default VERSION_NUMBER in the cache to prevent a stale one
# from preventing future version updates in a pre-existing build dir
set(VERSION_NUMBER "" CACHE STRING "Version number: leave empty for default")
if ("${VERSION_NUMBER}" STREQUAL "")
set(VERSION_NUMBER ${VERSION_NUMBER_DEFAULT})
endif()
string(REGEX REPLACE "\\." "," VERSION_COMMA_DELIMITED "${VERSION_NUMBER}")
set(BUILD_NUMBER "0" CACHE STRING "Build number (must be <64K)")
set(UNIQUE_BUILD_NUMBER "0" CACHE STRING "Unique build number")
set(CUSTOM_PRODUCT_NAME "" CACHE STRING "Custom product name")
mark_as_advanced(
VERSION_NUMBER
VERSION_COMMA_DELIMITED
BUILD_NUMBER
UNIQUE_BUILD_NUMBER
CUSTOM_PRODUCT_NAME
)
# This is hardcoded in globals_shared.h: going to leave it that way, but
# adding indirection within cmake files
set(PRODUCT_NAME "DynamoRIO")
if (install_override)
set(CMAKE_INSTALL_PREFIX "${PROJECT_SOURCE_DIR}/exports"
CACHE PATH "install path" FORCE)
endif (install_override)
# for historical reasons we have a separate mirror var
set(INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
###########################################################################
# toolchain
if (UNIX)
if (CYGWIN)
message(FATAL_ERROR "building using gcc within cygwin is not supported")
endif (CYGWIN)
if (NOT CMAKE_COMPILER_IS_GNUCC)
# we use gcc extensions
message(FATAL_ERROR "gcc is required to build")
endif (NOT CMAKE_COMPILER_IS_GNUCC)
# "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 (NOT CMAKE_CPP)
message(FATAL_ERROR "cpp is required to build")
endif (NOT CMAKE_CPP)
mark_as_advanced(CMAKE_CPP)
else (UNIX)
if (NOT ${COMPILER_BASE_NAME} STREQUAL "cl")
# we use cl pragmas and intrinsics
message(FATAL_ERROR "cl (Microsoft C++ compiler) is required to build")
endif (NOT ${COMPILER_BASE_NAME} STREQUAL "cl")
set(CMAKE_CPP ${CMAKE_C_COMPILER})
# CMake older than 2.6.3 does not automatically look for ml or ml64
get_filename_component(cl_path ${CMAKE_C_COMPILER} PATH)
if (X64)
find_program(CMAKE_ASM_COMPILER ml64.exe HINTS "${cl_path}" DOC "path to assembler")
else (X64)
find_program(CMAKE_ASM_COMPILER ml.exe HINTS "${cl_path}" DOC "path to assembler")
endif (X64)
if (NOT CMAKE_ASM_COMPILER)
message(FATAL_ERROR "assembler not found: required to build")
endif (NOT CMAKE_ASM_COMPILER)
# cmake has CMAKE_RC_COMPILER, but no message compiler
find_program(CMAKE_MC_COMPILER mc.exe DOC "path to message compiler")
if (NOT CMAKE_MC_COMPILER)
message(FATAL_ERROR "message compiler not found: required to build")
endif (NOT CMAKE_MC_COMPILER)
message(STATUS "Found message compiler: ${CMAKE_MC_COMPILER}")
mark_as_advanced(CMAKE_MC_COMPILER)
# DDKROOT env var is recommended method in our docs
if (NOT "$ENV{DDKROOT}" STREQUAL "")
set(DDK_ROOT "$ENV{DDKROOT}")
# Check default install path
elseif (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 (NOT "$ENV{DDKROOT}" STREQUAL "")
# Note that we want the oldest ntdll.lib for maximum compatibility.
# The 2003 DDK (3790.1830) or Vista WDK (6000) both have these paths:
if (X64)
set(NTDLL_LIB_SUBPATH lib/wnet/amd64)
else (X64)
# Newer WDK (7600.16385.1) does not have w2k so use wxp: if using
# that WDK, won't be able to run on 2K or NT.
if (EXISTS "${DDK_ROOT}/w2k/i386")
set(NTDLL_LIB_SUBPATH lib/w2k/i386)
else (EXISTS "${DDK_ROOT}/w2k/i386")
message(STATUS "DDK/WDK is too recent: no support for Windows 2000 or earlier")
set(NTDLL_LIB_SUBPATH lib/wxp/i386)
endif (EXISTS "${DDK_ROOT}/w2k/i386")
endif (X64)
# Use find_library() and not find_path() in case on LIB env var or sthg
find_library(NTDLL_LIBPATH ntdll.lib HINTS "${DDK_ROOT}/${NTDLL_LIB_SUBPATH}"
DOC "Path to ntdll.lib from either 2003 DDK (3790.1830) or Vista WDK (6000)")
if (NOT NTDLL_LIBPATH)
message(FATAL_ERROR "ntdll.lib not found: required to build")
endif (NOT NTDLL_LIBPATH)
message(STATUS "Found ntdll.lib: ${NTDLL_LIBPATH}")
get_filename_component(NTDLL_LIBPATH "${NTDLL_LIBPATH}" PATH)
link_directories(${NTDLL_LIBPATH})
endif (UNIX)
find_package(Perl)
if (NOT PERL_FOUND)
message(FATAL_ERROR "perl is required to build")
endif (NOT PERL_FOUND)
if (UNIX) # unlikely to be an issue on Windows
# Check for uint, etc. typedef conflicts like on rhel3 (i#18)
# and set DR_DO_NOT_DEFINE_*
# Note that for later gcc uint and ushort seem to be "soft typedefs":
# defined, but overridable: ?!?
include(CheckTypeSize)
CHECK_TYPE_SIZE(uint DR_DO_NOT_DEFINE_uint)
CHECK_TYPE_SIZE(ushort DR_DO_NOT_DEFINE_ushort)
CHECK_TYPE_SIZE(bool DR_DO_NOT_DEFINE_bool)
CHECK_TYPE_SIZE(byte DR_DO_NOT_DEFINE_byte)
CHECK_TYPE_SIZE(sbyte DR_DO_NOT_DEFINE_sbyte)
CHECK_TYPE_SIZE(uint32 DR_DO_NOT_DEFINE_uint32)
CHECK_TYPE_SIZE(uint64 DR_DO_NOT_DEFINE_uint64)
CHECK_TYPE_SIZE(int32 DR_DO_NOT_DEFINE_int32)
CHECK_TYPE_SIZE(int64 DR_DO_NOT_DEFINE_int64)
# we could do CHECK_SYMBOL_EXISTS for MAX and MIN but they're not
# in standard headers so up to user to define if an issue
endif (UNIX)
###########################################################################
# basic build rules and flags
# compiler flags
if (UNIX)
# -std=c99 doesn't quite work
# FIXME case 191480: we used to pass -pedantic just to cpp;
# now w/ no separate cpp step we should eliminate the
# warnings and pass -pedantic to main gcc
set(BASE_CFLAGS "-std=gnu99")
# disable strict aliasing opt in gcc 3.3.3 -- gives warnings and makes bad assumptions
set(BASE_CFLAGS "${BASE_CFLAGS} -fno-strict-aliasing")
set(ASM_FLAGS "-mmnemonic=intel -msyntax=intel -mnaked-reg --noexecstack")
# now that the user must set non-default -mNN we don't nec. need these:
if (X64)
set(BASE_CFLAGS "-m64 ${BASE_CFLAGS}")
set(BASE_CXXFLAGS "-m64")
set(ASM_FLAGS "${ASM_FLAGS} --64")
set(LD_FLAGS "-melf_x86_64")
else (X64)
set(BASE_CFLAGS "-m32 ${BASE_CFLAGS}")
set(BASE_CXXFLAGS "-m32")
# putting --32 last so we fail on -mmnemonic=intel on older as, not --32
set(ASM_FLAGS "${ASM_FLAGS} --32")
set(LD_FLAGS "-melf_i386")
endif (X64)
# there's no cmake warning control so we hardcode it
set(WARN "-Wall -Werror")
set(DBG "-g3")
# gcc doesn't change its optimizations based on -g
set(OPT "-O3 ${DBG}")
# FIXME: core-specific: move to core/CMakeLists.txt?
# We use -O to avoid stack overflow in debug build (makes a huge difference by
# having locals/temps share stack slots) but we use -fno-omit-frame-pointer to
# keep things more easily debuggable (though gcc claims only omits when
# debuggable).
# We disable strcmp intrinsic to avoid stack overflow in
# set_dynamo_options(): case 7853.
# FIXME: now that we have -O we may not need -fno-builtin-strcmp
# FIXME: actually -O is making it annoying to debug: need better solution!
set(DBG_OPT "-O -fno-omit-frame-pointer -fno-builtin-strcmp")
set(CPP_KEEP_COMMENTS -C)
set(CPP_NO_LINENUM -P)
set(CMAKE_CPP_FLAGS "")
else (UNIX)
# FIXME: why isn't ${CMAKE_CL_NOLOGO} set?
set(BASE_CFLAGS "/nologo")
# read-only string pooling
set(BASE_CFLAGS "${BASE_CFLAGS} /GF")
# FIXME case 191729: we should try to enable this.
# Currently we get "unresolved external symbol ___security_cookie"
set(BASE_CFLAGS "${BASE_CFLAGS} /GS-")
set(WARN "/W4 /WX")
# Default from cmake has /W3 so remove to avoid warning about overriding
string(REGEX REPLACE "/W[0-9]" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
string(REGEX REPLACE "/W[0-9]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
if (GENERATE_PDBS)
set(DBG "/Zi")
set(LINK_DBG "/debug")
else (GENERATE_PDBS)
# xref PR 192750 - runregression uses this to avoid over-ssh pdb issues
set(DBG "")
set(LINK_DBG "")
# Default from cmake in DEBUG and RELWITHDEBINFO has /debug
string(REGEX REPLACE "/debug" "" CMAKE_EXE_LINKER_FLAGS
"${CMAKE_EXE_LINKER_FLAGS}")
string(REGEX REPLACE "/debug" "" CMAKE_MODULE_LINKER_FLAGS
"${CMAKE_MODULE_LINKER_FLAGS}")
string(REGEX REPLACE "/debug" "" CMAKE_SHARED_LINKER_FLAGS
"${CMAKE_SHARED_LINKER_FLAGS}")
endif (GENERATE_PDBS)
# w/ cl, using DBG here won't mess up the optimizations, debug line number info
# gets a little messed up, but is better than nothing
set(OPT "/O2 ${DBG}")
# do not use /O2 on windows, it messes up debug info!
set(DBG_OPT "")
set(CPP_KEEP_COMMENTS /C)
set(CPP_NO_LINENUM /EP)
set(CMAKE_CPP_FLAGS "/nologo")
set(ASM_FLAGS "/nologo")
set(BASE_CXXFLAGS "${BASE_CFLAGS}")
endif (UNIX)
enable_language(ASM)
# note that I had to fix a bug in /usr/share/cmake/Modules/CMakeASMInformation.cmake
# where @VAR@ expansion was used, which only works for configure_file()
# now fixed in CMake/Modules/CMakeASMInformation.cmake:1.5
# see above for our workaround
if (UNIX)
# we used to have ".ifdef FOO" and to not have it turn into ".ifdef 1" we'd say
# "-DFOO=FOO", but we now use exclusively preprocessor defines, which is good
# since our defines are mostly in configure.h where we can't as easily tweak them
# (update: I do have top-level defines gathered up in ${defines}.
# so, we don't bother transforming -DFOO into -DFOO=FOO, nor with setting
# up the --defsym args.
set(CMAKE_ASM_COMPILE_OBJECT
"${CMAKE_CPP} ${CMAKE_CPP_FLAGS} <FLAGS> <DEFINES> -E <SOURCE> -o <OBJECT>.s"
"<CMAKE_COMMAND> -Dfile=<OBJECT>.s -P \"${PROJECT_SOURCE_DIR}/make/CMake_asm.cmake\""
# not using <FLAGS> b/c of cmake bug #8107 where -Ddynamorio_EXPORTS
# is passed in: we don't need the include dirs b/c of the cpp step.
# update: Brad fixed bug #8107: moved -Ddynamorio_EXPORTS from <FLAGS> to <DEFINES>
# in CMake/Source/cmMakefileTargetGenerator.cxx:1.115 (will be in 2.6.4).
#
# we also aren't passing any <DEFINES> since for one thing
# there's no way to transform to --defsym: luckily we don't need them
# since using cpp now (see above).
# FIXME: I tried setting CMAKE_ASM_DEFINE_FLAG to "--defsym " (not clear
# how to get =1 in there :should verify it's needed) but <DEFINES>
# comes up empty for me.
"<CMAKE_ASM_COMPILER> ${ASM_FLAGS} -o <OBJECT> <OBJECT>.s"
)
else (UNIX)
# Even if we didn't preprocess we'd need our own rule since cmake doesn't
# support ml.
set(CMAKE_ASM_COMPILE_OBJECT
# There's no way to specify a non-default name with /P: writes to
# cwd/sourcebase.i. Could copy with "cmake -E copy" but no way to
# run get_filename_component on a tag var. So going with
# redirection operator which should work in all supported shells.
#
# ml can't handle line number markers so using ${CPP_NO_LINENUM}.
"<CMAKE_C_COMPILER> ${CMAKE_CPP_FLAGS} <FLAGS> <DEFINES> -E ${CPP_NO_LINENUM} <SOURCE> > <OBJECT>.s"
# cmake does add quotes in custom commands, etc. but not in this rule so we add
# them to handle paths with spaces:
"<CMAKE_COMMAND> -Dfile=<OBJECT>.s -P \"${PROJECT_SOURCE_DIR}/make/CMake_asm.cmake\""
"<CMAKE_ASM_COMPILER> ${ASM_FLAGS} /c /Fo<OBJECT> <OBJECT>.s"
)
endif (UNIX)
if (UNIX)
# We require gas >= 2.18.50 for --32, --64, and the new -msyntax=intel, etc.
# Since this is pretty recent we include a copy (built vs as old a glibc
# as was convenient)
execute_process(COMMAND
${CMAKE_ASM_COMPILER} --help
RESULT_VARIABLE asm_result
ERROR_VARIABLE asm_error
OUTPUT_VARIABLE asm_out)
if (asm_result OR asm_error)
message(FATAL_ERROR "*** ${CMAKE_ASM_COMPILER} failed: ***\n${asm_error}")
endif (asm_result OR asm_error)
# turn the flags into a vector
string(REGEX REPLACE " " ";" flags_needed "${ASM_FLAGS}")
# we want "-mmnemonic=intel" to match "-mmnemonic=[att|intel]"
string(REGEX REPLACE "=" ".*" flags_needed "${flags_needed}")
set(flag_present 1)
foreach (flag ${flags_needed})
if (flag_present)
string(REGEX MATCH "${flag}" flag_present "${asm_out}")
if (NOT flag_present)
message("${CMAKE_ASM_COMPILER} missing flag \"${flag}\"")
endif (NOT flag_present)
endif (flag_present)
endforeach (flag)
if (NOT flag_present)
message("${CMAKE_ASM_COMPILER} too old: using ${PROJECT_SOURCE_DIR}/make/as-2.18.50")
set(CMAKE_ASM_COMPILER "${PROJECT_SOURCE_DIR}/make/as-2.18.50")
endif (NOT flag_present)
# Check for -fvisibility
include(CheckCCompilerFlag)
CHECK_C_COMPILER_FLAG("-fvisibility=internal" HAVE_FVISIBILITY)
if (NOT HAVE_FVISIBILITY)
message("${CMAKE_C_COMPILER} missing flag -fvisibility, using linker script instead")
endif (NOT HAVE_FVISIBILITY)
# For INTERNAL builds we keep our symbols visible, for better libc backtraces
if (HAVE_FVISIBILITY AND NOT KEEP_SYMBOLS_FOR_LIBC_BACKTRACE)
# PR 262458: for gcc >= 3.4 we can use -fvisibility instead of a
# linker version script. Note that we're still using a linker
# script to set our preferred base (PR 253624) and will need to
# for section ordering as well (PR 208267) but those are separate
# scripts.
# Only export functions so marked via attributes
# (For older gcc we use an ugly linker script and an auto-generated export list)
# Using "internal" instead of "hidden" b/c we don't need any indirect
# calls to our non-exported functions
set(BASE_CFLAGS "${BASE_CFLAGS} -fvisibility=internal")
set(BASE_CXXFLAGS "${BASE_CXXFLAGS} -fvisibility=internal")
endif (HAVE_FVISIBILITY AND NOT KEEP_SYMBOLS_FOR_LIBC_BACKTRACE)
# Better to use -dT when passing linker options through gcc, but ld
# prior to 2.18 only supports -T
# FIXME: should we duplicate this in DynamoRIOConfig.cmake?
execute_process(COMMAND
${CMAKE_LINKER} --help
RESULT_VARIABLE ld_result
ERROR_VARIABLE ld_error
OUTPUT_VARIABLE ld_out)
if (ld_result OR ld_error)
message(FATAL_ERROR "*** ${CMAKE_LINKER} failed: ***\n${ld_error}")
endif (ld_result OR ld_error)
string(REGEX MATCH "dT" flag_present "${ld_out}")
if (NOT flag_present)
message("${CMAKE_LINKER} missing flag -dT, using -T instead")
set(ld_script_option "-T")
else (NOT flag_present)
set(ld_script_option "-dT")
endif (NOT flag_present)
# We want separate .debug files for all shared libraries
if (NOT DEFINED CMAKE_OBJCOPY)
find_package(BinUtils)
endif (NOT DEFINED CMAKE_OBJCOPY)
if (EXISTS ${CMAKE_OBJCOPY} AND EXISTS ${CMAKE_STRIP})
# Check for --only-keep-debug support: added ~2.15
execute_process(COMMAND
${CMAKE_OBJCOPY} --help
RESULT_VARIABLE objcopy_result
ERROR_QUIET
OUTPUT_VARIABLE objcopy_out)
if (objcopy_result)
message(FATAL_ERROR "*** ${CMAKE_OBJCOPY} failed to run ***\n")
endif (objcopy_result)
string(REGEX MATCH "only-keep-debug" flag_present "${objcopy_out}")
if (NOT flag_present)
message("${CMAKE_OBJCOPY} missing flag --only-keep-debug: leaving debug info in .so files")
else (NOT flag_present)
set(CMAKE_C_CREATE_SHARED_LIBRARY
# standard rule
"<CMAKE_C_COMPILER> <CMAKE_SHARED_LIBRARY_C_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS> <CMAKE_SHARED_LIBRARY_SONAME_C_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>"
# now create a .debug copy
"${CMAKE_OBJCOPY} --only-keep-debug <TARGET> <TARGET>.debug"
# link original to point at .debug copy
# directory components are removed, so "../lib/" is fine
"${CMAKE_OBJCOPY} --add-gnu-debuglink=<TARGET>.debug <TARGET>"
# We can't strip everything since a client's _USES_DR_VERSION_ will be
# removed, so we only strip debug (-g) and local (-x), and preserve
# file attributes (-p):
"${CMAKE_STRIP} -g -x -p <TARGET>"
)
SET(CMAKE_C_LINK_EXECUTABLE
"<CMAKE_C_COMPILER> <FLAGS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>"
"${CMAKE_OBJCOPY} --only-keep-debug <TARGET> <TARGET>.debug"
"${CMAKE_OBJCOPY} --add-gnu-debuglink=<TARGET>.debug <TARGET>"
"${CMAKE_STRIP} -g -x -p <TARGET>"
)
set(CMAKE_CXX_CREATE_SHARED_LIBRARY
# standard rule
"<CMAKE_CXX_COMPILER> <CMAKE_SHARED_LIBRARY_CXX_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> <CMAKE_SHARED_LIBRARY_SONAME_CXX_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>"
# now create a .debug copy
"${CMAKE_OBJCOPY} --only-keep-debug <TARGET> <TARGET>.debug"
# link original to point at .debug copy
# directory components are removed, so "../lib/" is fine
"${CMAKE_OBJCOPY} --add-gnu-debuglink=<TARGET>.debug <TARGET>"
# We can't strip everything since a client's _USES_DR_VERSION_ will be
# removed, so we only strip debug (-g) and local (-x), and preserve
# file attributes (-p):
"${CMAKE_STRIP} -g -x -p <TARGET>"
)
SET(CMAKE_CXX_LINK_EXECUTABLE
"<CMAKE_CXX_COMPILER> <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>"
"${CMAKE_OBJCOPY} --only-keep-debug <TARGET> <TARGET>.debug"
"${CMAKE_OBJCOPY} --add-gnu-debuglink=<TARGET>.debug <TARGET>"
"${CMAKE_STRIP} -g -x -p <TARGET>"
)
endif (NOT flag_present)
endif (EXISTS ${CMAKE_OBJCOPY} AND EXISTS ${CMAKE_STRIP})
endif (UNIX)
# Should we be using fewer of these and using cmake's Debug vs Release?
# Release => -O3 -NDEBUG
# Right now we only support gcc and cl but could change in future
if (DEBUG)
set(CMAKE_C_FLAGS "${BASE_CFLAGS} ${DBG} ${DBG_OPT}")
set(CMAKE_CXX_FLAGS "${BASE_CXXFLAGS} ${DBG} ${DBG_OPT}")
else (DEBUG)
if (CALLPROF)
# no opts -- we need to avoid messing up call frame walking
# FIXME: just disable frame ptr elim opt: but /Oy- ran into some issues
set (OPT "")
endif (CALLPROF)
set(CMAKE_C_FLAGS "${BASE_CFLAGS} ${OPT}")
set(CMAKE_CXX_FLAGS "${BASE_CXXFLAGS} ${OPT}")
endif (DEBUG)
if (NOT DISABLE_WARNINGS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARN}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARN}")
endif (NOT DISABLE_WARNINGS)
###########################################################################
# use a single path for easier installation of pdbs
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
# if drinjectlib is built before any exe target this dir won't exist
# and the "cmake -E copy" will fail (PR 549174)
file(MAKE_DIRECTORY "${EXECUTABLE_OUTPUT_PATH}")
# Issue 20: cross-arch execve depends on these being distinct and not
# subsets of each other (e.g., not "lib" and "lib64") and on the
# release package using these same names.
set(INSTALL_LIB_X64 lib64)
set(INSTALL_LIB_X86 lib32)
if (X64)
set(INSTALL_LIB_BASE ${INSTALL_LIB_X64})
set(INSTALL_BIN bin64)
else (X64)
set(INSTALL_LIB_BASE ${INSTALL_LIB_X86})
set(INSTALL_BIN bin32)
endif (X64)
if (DEBUG)
set(INSTALL_LIB ${INSTALL_LIB_BASE}/debug)
else (DEBUG)
set(INSTALL_LIB ${INSTALL_LIB_BASE}/release)
endif (DEBUG)
set(INSTALL_INCLUDE include)
set(INSTALL_DOCS docs)
# samples are installed via api/samples/ separate CMake project
set(INSTALL_CMAKE cmake)
set(BUILD_INCLUDE ${PROJECT_BINARY_DIR}/${INSTALL_INCLUDE})
# set var needed by configure.cmake.h
string(REGEX REPLACE
"^([0-9]+)\\..*" "\\1" VERSION_NUMBER_MAJOR "${VERSION_NUMBER}")
string(REGEX REPLACE
"^[0-9]+\\.([0-9]+)\\..*" "\\1" VERSION_NUMBER_MINOR "${VERSION_NUMBER}")
math(EXPR VERSION_NUMBER_INTEGER
"${VERSION_NUMBER_MAJOR}*100 + ${VERSION_NUMBER_MINOR}")
# This does a copy-if-different, so it won't trigger recompilation of
# every single source file if no changes
configure_file(
${PROJECT_SOURCE_DIR}/make/configure.cmake.h
${PROJECT_BINARY_DIR}/configure.h
)
# We want a define that's set to all the options for the C code,
# and a var set to all the options for genapi.pl.
# Something like cpp -dN but we need it on Windows and want only defines.
# Strategy: add -D<define> token after each #define, and then run
# cpp => left with just the -D<define> that are defined.
# If we append this to configure.h we'll trigger recompilation of
# everything, so we generate a separate header file.
file(READ ${PROJECT_BINARY_DIR}/configure.h configure_h)
string(REGEX REPLACE
"(# *define *)([^_][^ \r\n]+)( *\r?\n)"
"\\1\\2\\3-D\\2\n" configure_h_mod "${configure_h}")
set(defines_tmpfile ${PROJECT_BINARY_DIR}/configure_temp.h)
# we do NOT add ${defines_tmpfile} to set_directory_properties
# ADDITIONAL_MAKE_CLEAN_FILES b/c it's built at configure time:
# would be part of "make distclean" but cmake does not have that.
file(WRITE ${defines_tmpfile} "${configure_h_mod}")
# No way to get cmdline defines from cmake: but shouldn't be any, all
# in configure.h, except the -Ddynamorio_EXPORTS that cmake defines.
# Note: cpp w/ no 2nd filename prints to stdout (explicit "-" => pause at end)
execute_process(COMMAND
${CMAKE_CPP} ${CMAKE_CPP_FLAGS} -E ${CPP_NO_LINENUM} ${defines_tmpfile}
RESULT_VARIABLE cpp_result
ERROR_VARIABLE cpp_err
OUTPUT_VARIABLE cpp_out
)
if (WIN32)
# cl prints out name of file: no way to quiet it
get_filename_component(tmpfile_nm ${defines_tmpfile} NAME)
string(REGEX REPLACE "${tmpfile_nm}[ \r\n]*" "" cpp_err "${cpp_err}")
string(STRIP "${cpp_err}" cpp_err)
endif (WIN32)
if (cpp_result OR cpp_err)
message(FATAL_ERROR "*** ${CMAKE_CPP} failed: ***\n${cpp_err}")
endif (cpp_result OR cpp_err)
string(REGEX MATCHALL
"-D[^ \r\n]+" defines "${cpp_out}")
string(REGEX REPLACE
";"
" " defines "${defines}")
set(defines_tofile
"#ifndef _CONFIGDEFS_\n#define _CONFIGDEFS_ 1\n\n#define DYNAMORIO_DEFINES \"${defines}\"\n\n#endif /* _CONFIGDEFS_ */\n")
# Try to avoid triggering re-compilation if no changes
set(defines_file ${PROJECT_BINARY_DIR}/configure_defines.h)
if (EXISTS ${defines_file})
file(READ ${defines_file} defines_fromfile)
if (NOT "${defines_fromfile}" STREQUAL "${defines_tofile}")
file(WRITE ${defines_file} "${defines_tofile}")
endif (NOT "${defines_fromfile}" STREQUAL "${defines_tofile}")
else (EXISTS ${defines_file})
file(WRITE ${defines_file} "${defines_tofile}")
endif (EXISTS ${defines_file})
include_directories(BEFORE
${PROJECT_BINARY_DIR} # for configure.h and configure_defines.h
)
# Export targets for importing by clients.
# We include DynamoRIO and all Extensions in the same file for simplicity,
# since the Extensions depend on DynamoRIO and in some cases each other
# and so need to be locatable as a group.
# To support packaging both together we need different names
# FIXME: should we also append Debug, and have an optional param
# to DynamoRIOConfig.cmake to link to it (only really makes sense
# if using rpath)? If we did that we'd need to set the debug
# param for our internal builds.
if (X64)
set(exported_targets_name "DynamoRIOTarget64")
else (X64)
set(exported_targets_name "DynamoRIOTarget32")
endif (X64)
###########################################################################
# Let user pick which components to build. This is especially
# important b/c w/o 64-bit tools they must configure two different
# build dirs for 64-bit windows: one for 64-bit core and one for
# 32-bit tools.
if (WIN32)
option(BUILD_CORE "build core library and drinject tool" ON)
else (WIN32)
option(BUILD_CORE "build core library" ON)
endif (WIN32)
option(BUILD_TOOLS "build tools" ON)
if (WIN32 AND NOT X64)
# FIXME i#62: port DRgui to 64-bit
option(BUILD_DRGUI "build DRgui statistics viewer (requires MFC)" ON)
endif (WIN32 AND NOT X64)
option(BUILD_EXT "build Extension libraries" ON)
option(BUILD_DOCS "build documentation" ON)
if (VMSAFE)
# I did not preserve VMSAFE docs building: to reactivate it, need to
# add the missing transformations mentioned in api/docs/CMakeLists.txt
# and fix genapi.pl on lib/dr_config.h to handle the outer ifdef WINDOWS
# (ends up keeping 1st endif in 1st enum).
set(BUILD_DOCS OFF)
endif (VMSAFE)
# should we disallow selecting samples when core is not built?
# right now the samples build will just fail
option(BUILD_SAMPLES "build client samples" ON)
if (NOT CLIENT_INTERFACE)
set(BUILD_SAMPLES OFF)
set(BUILD_EXT OFF)
endif (NOT CLIENT_INTERFACE)
# We include all tests and build them at configure time if requested.
# An alternative is to keep them in separate projects and only build
# when we run them via --build-and-test.
option(BUILD_TESTS "build tests" OFF)
if (BUILD_TESTS)
# Tests require tools
# FIXME i#65 NOT YET COMPLETED: what about x64 Windows: we need 32-bit drdeploy.exe!
set(BUILD_TOOLS ON)
endif (BUILD_TESTS)
if (BUILD_CORE)
add_subdirectory(core)
endif (BUILD_CORE)
if (BUILD_TOOLS OR BUILD_DRGUI)
if (WIN32)
add_subdirectory(libutil)
endif (WIN32)
endif (BUILD_TOOLS OR BUILD_DRGUI)
if (BUILD_TOOLS)
add_subdirectory(tools)
endif (BUILD_TOOLS)
if (BUILD_DRGUI)
add_subdirectory(tools/DRgui)
endif (BUILD_DRGUI)
###########################################################################
# used by docs, samples, and tests, so here instead of in core/CMakeLists.txt
if (CLIENT_INTERFACE OR APP_EXPORTS)
# set VERSION_NUMBER_INTEGER in dr_api.h
configure_file(${PROJECT_SOURCE_DIR}/core/lib/dr_api.h
${BUILD_INCLUDE}/dr_api.h)
add_custom_target(api_headers
DEPENDS ${BUILD_INCLUDE}/dr_app.h
${BUILD_INCLUDE}/dr_api.h)
file(MAKE_DIRECTORY ${BUILD_INCLUDE})
# technically only the headers in the genapi.pl list
file(GLOB header_files core/*.h core/*/*.h libutil/*.h core/hotpatch.c)
add_custom_command(
OUTPUT ${BUILD_INCLUDE}/dr_app.h # among other files
DEPENDS ${PROJECT_SOURCE_DIR}/core/lib/genapi.pl
${header_files}
COMMAND ${PERL_EXECUTABLE}
ARGS ${PROJECT_SOURCE_DIR}/core/lib/genapi.pl
-header ${BUILD_INCLUDE} "${defines} -DAPI_EXPORT_ONLY"
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/core
VERBATIM # recommended: p260
)
install(DIRECTORY ${BUILD_INCLUDE} DESTINATION .)
endif (CLIENT_INTERFACE OR APP_EXPORTS)
if (CLIENT_INTERFACE OR APP_EXPORTS)
if (BUILD_DOCS)
find_package(ImageMagick COMPONENTS mogrify)
if (NOT ImageMagick_mogrify_FOUND)
# cmake 2.6.0 does not set the _FOUND vars, just the exec path,
# and it uses all caps
if (EXISTS ${IMAGEMAGICK_MOGRIFY_EXECUTABLE})
set(ImageMagick_mogrify_EXECUTABLE ${IMAGEMAGICK_MOGRIFY_EXECUTABLE})
else (EXISTS ${IMAGEMAGICK_MOGRIFY_EXECUTABLE})
message("ImageMagick is required to build the documentation")
set(BUILD_DOCS OFF)
endif (EXISTS ${IMAGEMAGICK_MOGRIFY_EXECUTABLE})
endif (NOT ImageMagick_mogrify_FOUND)
mark_as_advanced(ImageMagick_EXECUTABLE_DIR)
find_package(Doxygen)
if (NOT DOXYGEN_FOUND)
message("doxygen is required to build the documentation")
set(BUILD_DOCS OFF)
endif (NOT DOXYGEN_FOUND)
include(${PROJECT_SOURCE_DIR}/make/FindFig2Dev.cmake)
if (NOT FIG2DEV_FOUND)
message("fig2dev (from transfig) is required to build the documentation")
set(BUILD_DOCS OFF)
endif (NOT FIG2DEV_FOUND)
# fig2dev needs ghostscript to produce tiff files (not to produce eps)
include(${PROJECT_SOURCE_DIR}/make/FindGhostscript.cmake)
if (NOT GHOSTSCRIPT_FOUND)
message("ghostscript is required to build the documentation")
set(BUILD_DOCS OFF)
else (NOT GHOSTSCRIPT_FOUND)
# must be on path. we can't just literally check the path
# b/c of cygwin issues: c:/cygwin/bin vs /usr/bin, etc.
get_filename_component(gs_name ${GHOSTSCRIPT_EXECUTABLE} NAME)
find_program(GHOSTSCRIPT_ON_PATH ${gs_name} PATHS ENV PATH NO_DEFAULT_PATH)
if (NOT GHOSTSCRIPT_ON_PATH)
message("ghostscript is installed, but must be on PATH for fig2dev to find it")
set(BUILD_DOCS OFF)
endif (NOT GHOSTSCRIPT_ON_PATH)
mark_as_advanced(GHOSTSCRIPT_ON_PATH)
endif (NOT GHOSTSCRIPT_FOUND)
if (BUILD_DOCS)
add_subdirectory(api/docs)
else (BUILD_DOCS)
message("*** NOT building documentation *** (must re-enable BUILD_DOCS manually if fix up the component paths)")
# Note the difference between cache vars and live vars in CMake.
# The cache var indicates "would like to build docs" and the live var
# "capable of building docs." The problem is that if we FORCE the
# cache var OFF as further confirmation of the warning message, the
# user must not only fix up the paths in the required component vars
# but also re-enable BUILD_DOCS before re-configuring due to our
# guard above. An alternative is to add an option BUILD_DOCS_CAPABLE
# as an informational message that is peristent and right next to the
# real option, but I think forcing the user to re-enable BUILD_DOCS
# is actually simpler and reasonable.
set(BUILD_DOCS OFF CACHE BOOL "build documentation" FORCE)
endif (BUILD_DOCS)
endif (BUILD_DOCS)
else (CLIENT_INTERFACE OR APP_EXPORTS)
message("no documentation will be built for this target")
endif (CLIENT_INTERFACE OR APP_EXPORTS)
###########################################################################
install(FILES
${PROJECT_SOURCE_DIR}/README
${PROJECT_SOURCE_DIR}/License.txt
${PROJECT_SOURCE_DIR}/ACKNOWLEDGEMENTS
DESTINATION .)
# We put all our libs and exes in common dirs, making it easier
# to copy our symbols. It's a pain to construct the pdb name
# counterparts for targets, so we use the install(DIRECTORY) commands
# where we can use wildcards.
# Slightly ugly to have hardcoded names: long-term CMake should
# support auto-installing pdb files.
install(DIRECTORY ${LIBRARY_OUTPUT_PATH}/
DESTINATION ${INSTALL_LIB_BASE}
FILE_PERMISSIONS OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE
FILES_MATCHING
PATTERN "*.debug"
PATTERN "*.pdb"
PATTERN "dynamorio.pdb" EXCLUDE # in ${INSTALL_LIB}
PATTERN "libdynamorio.so.*debug" EXCLUDE # in ${INSTALL_LIB}
PATTERN "libdrpreload.so.debug" EXCLUDE # in ${INSTALL_LIB}
PATTERN "policy_static.pdb" EXCLUDE
)
install(DIRECTORY ${LIBRARY_OUTPUT_PATH}/
DESTINATION ${INSTALL_LIB}
FILE_PERMISSIONS OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE
FILES_MATCHING
PATTERN "dynamorio.pdb"
PATTERN "libdynamorio.so.*debug"
PATTERN "libdrpreload.so.debug"
)
if (BUILD_TOOLS OR WIN32)
install(DIRECTORY ${EXECUTABLE_OUTPUT_PATH}/
DESTINATION ${INSTALL_BIN}
FILE_PERMISSIONS OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE
FILES_MATCHING
PATTERN "*.debug"
PATTERN "*.pdb"
PATTERN "runstats.debug" EXCLUDE # since not installing tool
PATTERN "run_in_bg.debug" EXCLUDE # since not installing tool
)