forked from DynamoRIO/dynamorio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
2077 lines (1921 loc) · 82.6 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-2022 Google, Inc. All rights reserved.
# Copyright (c) 2009-2010 VMware, Inc. All rights reserved.
# Copyright (c) 2018 Arm Limited 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 DRstats a subproject to support with different compiler from libutil
# 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#70: symbol store support in core/Makefile and tools/Makefile
# 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
###########################################################################
# Visual Studio 2017 requires 3.7.
cmake_minimum_required(VERSION 3.7)
include(make/policies.cmake NO_POLICY_SCOPE)
# for non-makefile-based generators (i.e., Visual Studio) there is no
# CMAKE_BUILD_TYPE and instead there are multiple configs.
# note that we would love cmake to support multi-config for makefiles too,
# but given that it doesn't, and that we don't have full control
# over the output dir names (until cmake 2.8.4), I'm collapsing
# the VS generator configs to a single choice to match the makefiles.
# this must be done prior to the project() command and the var
# must be set in the cache.
if ("${CMAKE_GENERATOR}" MATCHES "Visual Studio")
# Workaround for https://gitlab.kitware.com/cmake/cmake/issues/17992
set(CMAKE_SYSTEM_VERSION_TEMP $ENV{WindowsSDKVersion})
string(REGEX REPLACE "([0-9.]+).*" "\\1" CMAKE_SYSTEM_VERSION_TEMP "${CMAKE_SYSTEM_VERSION_TEMP}")
if (CMAKE_SYSTEM_VERSION_TEMP)
set(CMAKE_SYSTEM_VERSION ${CMAKE_SYSTEM_VERSION_TEMP} CACHE INTERNAL "")
endif()
if (DEBUG)
set(CMAKE_CONFIGURATION_TYPES "Debug" CACHE STRING "" FORCE)
else (DEBUG)
set(CMAKE_CONFIGURATION_TYPES "RelWithDebInfo" CACHE STRING "" FORCE)
endif (DEBUG)
# we want to use the <VAR>_<config> variants of config-dependent properties
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)
# 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})
# Don't use the default-Debug build type set for the try-compiles
set(specified_build_type "${CMAKE_BUILD_TYPE}")
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 ()
# We have some Find*.cmake modules of our own
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/make/modules")
enable_language(C)
enable_language(CXX)
if ("${CMAKE_GENERATOR}" MATCHES "Ninja")
# i#1040: Ninja sets the type to Debug if it's not in the cache
set(CMAKE_BUILD_TYPE "${specified_build_type}" CACHE STRING
"Choose the type of build: Debug or Release" FORCE)
else ()
set(CMAKE_BUILD_TYPE "${specified_build_type}")
endif ()
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
###########################################################################
# utility functions
include(make/utils.cmake)
if (UNIX)
set(LIB_PFX "lib")
if (APPLE)
set(LIB_EXT ".dylib")
else ()
set(LIB_EXT ".so")
endif ()
else (UNIX)
set(LIB_PFX "")
set(LIB_EXT ".dll")
endif (UNIX)
###########################################################################
# configuration options
# many are core-specific
# whether this build of DynamoRIO is meant for distribution, in which case
# glibc should not have any too-recent imports. See core/CMake_readelf.cmake
# for more information. This is off by default, but gets set by
# make/package.cmake.
option(BUILD_PACKAGE "build DynamoRIO for packaging purposes by performing glibc checks" OFF)
# configurations that also have defines
option(DRSTATS_DEMO "build DRstats without the no-longer-supported Run, etc. controls" ON)
# we honor CMAKE_BUILD_TYPE since many cmake users are used to it
if ("${CMAKE_BUILD_TYPE}" MATCHES "Debug")
set(DEBUG_DEFAULT ON)
else ()
set(DEBUG_DEFAULT OFF)
endif ()
set(DEBUG_DESCR "Build with asserts and logging enabled (also controlled by CMAKE_BUILD_TYPE=Debug)")
option(DEBUG ${DEBUG_DESCR} ${DEBUG_DEFAULT})
# support later changes
if ("${CMAKE_BUILD_TYPE}" MATCHES "Debug")
set(DEBUG ON CACHE BOOL ${DEBUG_DESCR} FORCE)
elseif (NOT "${CMAKE_BUILD_TYPE}" STREQUAL "")
set(DEBUG OFF CACHE BOOL ${DEBUG_DESCR} FORCE)
endif ()
# INTERNAL option now matches DEBUG
if (DEBUG)
set(INTERNAL_DEFAULT ON)
else (DEBUG)
set(INTERNAL_DEFAULT OFF)
endif (DEBUG)
set(INTERNAL "" CACHE STRING "for developer use: ON or OFF overrides default")
if ("${INTERNAL}" STREQUAL "")
set(INTERNAL ${INTERNAL_DEFAULT})
endif()
# The target OS:
if (APPLE)
set(MACOS 1)
# Ensure our binaries can run on older OSX but only as far back as is
# officially supported by Apple.
set(OLDEST_OSX_SUPPPORTED "11.7")
elseif (UNIX)
set(LINUX 1)
endif (APPLE)
if (WIN32)
set(WINDOWS 1)
endif (WIN32)
# Assuming we cross compile on a Linux system and UNIX is set by CMake.
# ANDROID is not mutually exclusive with LINUX or UNIX.
if (CMAKE_SYSTEM_NAME MATCHES "^Android")
set(ANDROID 1)
# We prefix new options with DR_ to make it easier for containing projects including
# DR to avoid name conflicts and to separate options.
set(DR_DEVICE_BASEDIR "/data/local/tmp" CACHE STRING "base dir for Android binaries")
option(DR_COPY_TO_DEVICE "copy cross-compiled binaries to DR_DEVICE_BASEDIR" OFF)
if (DR_COPY_TO_DEVICE)
find_program(ADB adb DOC "adb Android utility")
if (NOT ADB)
message(FATAL_ERROR "Unable to find adb for DR_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 DR_COPY_TO_DEVICE")
endif ()
endif ()
endif ()
endif ()
# The target architecture.
# For cross-compilation this should still work as you're supposed to set this var.
# X64 mean 64-bit generically, whether AMD64 or AARCH64.
set(TARGET_ARCH "${CMAKE_SYSTEM_PROCESSOR}" CACHE STRING "Target architecture")
if (TARGET_ARCH MATCHES "^arm64" OR TARGET_ARCH MATCHES "^aarch64")
set(AARCH64 1)
set(X64 1)
message(STATUS "Building for AArch64")
elseif (TARGET_ARCH MATCHES "^arm")
set(ARM 1) # This means AArch32.
set(X64 OFF)
message(STATUS "Building for ARM")
elseif (TARGET_ARCH MATCHES "^riscv64")
set(RISCV64 1)
set(X64 1)
message(STATUS "Building for riscv64")
else ()
set(X86 1) # This means IA-32 or AMD64
message(STATUS "Building for x86")
# 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.)
# For target!=host, we still need the host compiler to match the target,
# so we do not support differing bitwidths.
if (CMAKE_C_SIZEOF_DATA_PTR EQUAL 8)
set(X64 ON)
else ()
set(X64 OFF)
endif ()
endif ()
if (X86)
set(ARCH_NAME x86)
elseif (ARM)
set(ARCH_NAME arm)
elseif (AARCH64)
set(ARCH_NAME aarch64)
elseif (RISCV64)
set(ARCH_NAME riscv64)
else ()
message(FATAL_ERROR "Unknown architecture target")
endif ()
if (ARM OR AARCH64)
set(AARCHXX 1)
set(ARCH_NAME_SHARED aarchxx)
else ()
set(ARCH_NAME_SHARED ${ARCH_NAME})
endif ()
# The execution architecture, which might differ from the target for building
# an AArch64 decoder to execute on x86 machines (i#1684).
if (CMAKE_SYSTEM_PROCESSOR MATCHES "^aarch64" OR CMAKE_SYSTEM_PROCESSOR MATCHES "^arm64")
set(DR_HOST_AARCH64 1)
set(DR_HOST_ARCH_NAME "aarch64")
set(DR_HOST_AARCHXX 1)
set(DR_HOST_ARCH_NAME_SHARED aarchxx)
set(DR_HOST_X64 1)
elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "^arm")
set(DR_HOST_ARM 1)
set(DR_HOST_ARCH_NAME "arm")
set(DR_HOST_AARCHXX 1)
set(DR_HOST_ARCH_NAME_SHARED aarchxx)
elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "^riscv64")
set(DR_HOST_RISCV64 1)
set(DR_HOST_ARCH_NAME "riscv64")
set(DR_HOST_ARCH_NAME_SHARED ${DR_HOST_ARCH_NAME})
set(DR_HOST_X64 1)
elseif (CMAKE_C_SIZEOF_DATA_PTR EQUAL 8)
set(DR_HOST_X86 1)
set(DR_HOST_ARCH_NAME "x86")
set(DR_HOST_ARCH_NAME_SHARED ${DR_HOST_ARCH_NAME})
set(DR_HOST_X64 1)
else ()
set(DR_HOST_X86 1)
set(DR_HOST_ARCH_NAME "x86")
set(DR_HOST_ARCH_NAME_SHARED ${DR_HOST_ARCH_NAME})
endif ()
if (NOT "${TARGET_ARCH}" STREQUAL "${CMAKE_SYSTEM_PROCESSOR}")
set(DR_HOST_NOT_TARGET 1)
if (WIN32)
# TODO i#1684: Fix Windows compiler warnings for AArch64 on x86.
message(FATAL_ERROR "Host != target is not yet supported on Windows")
endif ()
if ((DR_HOST_X64 AND NOT X64) OR (NOT DR_HOST_X64 AND X64))
# XXX i#1345: We need to resolve the hardcoded ELF bitwidth types.
# We likely also have general C type issues if the host is 32-bit.
message(FATAL_ERROR "Different-bitwidth host-vs-target not supported: i#1345.")
endif ()
if (ARM)
# TODO i#1684: We don't have full support for targeting arm in i386 yet.
message(FATAL_ERROR "Targeting ARM on i386 is not yet supported: i#1684.")
endif ()
if (RISCV64)
# TODO #1684: We don't have full support for targeting RISC-V in i386 yet.
message(FATAL_ERROR "Targeting riscv64 on i386 is not yet supported.")
endif ()
endif ()
# Support for running cross-compiled tests under emulation.
if (CMAKE_CROSSCOMPILING AND DEFINED CMAKE_FIND_ROOT_PATH)
find_program(QEMU_BINARY qemu-${CMAKE_SYSTEM_PROCESSOR} DOC "QEMU emulation tool")
if (NOT QEMU_BINARY)
message(STATUS "Did not find qemu-${CMAKE_SYSTEM_PROCESSOR}: tests will not run")
else ()
message(STATUS "Found qemu-${CMAKE_SYSTEM_PROCESSOR} for tests under emulation")
endif ()
endif ()
option(VMKERNEL "target VMkernel (not officially supported yet)")
# We no longer support building without a client interface: it is always enabled.
# TODO i#4819: Remove {DR_}APP_EXPORTS and replace with a runtime option.
# We'll still need something to swap DR_APP_API from import to export and
# set that for static DR, but the rest of the defines can go.
set(APP_EXPORTS 1)
# TODO: Consider removing these no-longer-maintained options:
# - VMKERNEL
# - PROGRAM_SHEPHERDING
# - PROCESS_CONTROL
# - GBOP
# TODO: Revive HOT_PATCHING_INTERFACE and combine with PROBE.
option(PROBE "enable not-yet-supported Probe API")
mark_as_advanced(PROBE)
if (PROBE)
set(HOT_PATCHING_INTERFACE 1)
endif (PROBE)
option(TEST_SUITE "we are running a series of builds for official purposes")
# 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)
# 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()
option(CALLPROF "internal caller profiling support")
option(PROFILE "profiling build: disables FPO and tweaks other flags" OFF)
if (UNIX)
option(RECORD_MEMQUERY "generate test cases for memquery_library_bounds_by_iterator")
endif ()
if (X86)
set(ANNOTATIONS_DEFAULT ON)
else ()
# TODO i#1672: Add annotation support to AArchXX.
set(ANNOTATIONS_DEFAULT OFF)
endif ()
# TODO i#4819: Remove the define and replace with a runtime option.
option(ANNOTATIONS "annotations" ${ANNOTATIONS_DEFAULT})
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")
elseif (APPLE AND X64)
# Set to higher than _PAGEZERO which is [0..0x1'00000000).
set(preferred_base "0x171000000" CACHE STRING "Preferred library base address")
else ()
set(preferred_base "0x71000000" CACHE STRING "Preferred library base address")
endif ()
# 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
# for 32-bit Linux: we put dynamorio at top of address space so little chance
# of conflict with app for early injection.
# there should be no noticeable perf hit from this (b/c no relocations for DR lib)
# so it's ok to be on for non-early injection
set(SET_PREFERRED_BASE 1)
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(
PROGRAM_SHEPHERDING
PROCESS_CONTROL
GBOP
VMKERNEL
KSTATS
CALLPROF
PROFILE
SET_PREFERRED_BASE
preferred_base
GENERATE_PDBS
DRSTATS_DEMO
)
# we clear both base and build-type cflags and then use just base.
# XXX: could use CMAKE_USER_MAKE_RULES_OVERRIDE to set these but not any cleaner
#
# i#919: Ninja generator does not leave CMAKE_BUILD_TYPE blank, and that affects
# the exported target files, so we set it here. This shouldn't hurt containing
# tools as they should set our DEBUG to match the incoming CMAKE_BUILD_TYPE.
if ("${CMAKE_BUILD_TYPE}" STREQUAL "")
if (DEBUG)
set(CMAKE_BUILD_TYPE "Debug")
else (DEBUG)
set(CMAKE_BUILD_TYPE "RelWithDebInfo")
endif (DEBUG)
endif ()
string(TOUPPER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_UPPER)
foreach (config ${CMAKE_BUILD_TYPE} ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER "${config}" config_upper)
foreach (var
CMAKE_C_FLAGS_${config_upper};
CMAKE_CXX_FLAGS_${config_upper};
CMAKE_EXE_LINKER_FLAGS_${config_upper};
CMAKE_MODULE_LINKER_FLAGS_${config_upper};
CMAKE_SHARED_LINKER_FLAGS_${config_upper})
set(${var} " ") # if "" defaults come back
endforeach ()
endforeach ()
foreach (var CMAKE_C_FLAGS;CMAKE_CXX_FLAGS)
set(${var} " ") # if "" defaults come back
endforeach ()
if (APPLE)
# Enable @rpath for all shared library install names.
set(CMAKE_MACOSX_RPATH 1)
endif ()
##################################################
# resources when packaging
# We use a monotonically increasing integer that's larger than any bugfix
# release version as the patchlevel ver# to distinguish
# mid-release builds.
# 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 i#1565 and use a date.
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_ver "${svn_out}")
string(REGEX REPLACE "Revision: " "" svn_ver "${svn_ver}")
if ("${svn_ver}" STREQUAL "")
# could be another language (xref i#401) so look just for number
# which will rule out URL and UUID fields
string(REGEX MATCH ": [0-9]+\r?\n" svn_ver "${svn_out}")
string(REGEX REPLACE ": ([0-9]+)\r?\n" "\\1" svn_ver "${svn_ver}")
endif ("${svn_ver}" STREQUAL "")
if ("${svn_ver}" STREQUAL "")
# indicate we failed w/ impossible ver#
message(STATUS "WARNING: Unable to obtain actual revision number")
set(VERSION_NUMBER_PATCHLEVEL "42")
else ("${svn_ver}" STREQUAL "")
set(VERSION_NUMBER_PATCHLEVEL "${svn_ver}")
endif ("${svn_ver}" STREQUAL "")
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 i#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 i#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")
# N.B.: when updating this, update the default version in ci-package.yml.
# We should find a way to share (xref i#1565).
set(VERSION_NUMBER_DEFAULT "9.90.${VERSION_NUMBER_PATCHLEVEL}")
# 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}")
message(STATUS "Version number: ${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")
set(PACKAGE_PLATFORM "" CACHE STRING "Platform for package name (should have trailing -)")
set(PACKAGE_SUBSYS "" CACHE STRING
"Platform for sub-system name (should have leading -: e.g., -EABIHF")
mark_as_advanced(
VERSION_NUMBER
VERSION_COMMA_DELIMITED
BUILD_NUMBER
UNIQUE_BUILD_NUMBER
CUSTOM_PRODUCT_NAME
PACKAGE_PLATFORM
PACKAGE_SUBSYS
)
# 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
# Figure out avx flags before asm setup, which requires it.
set(proc_supports_avx OFF)
set(proc_supports_avx2 OFF)
set(proc_supports_avx512 OFF)
if (X86 AND UNIX)
set(CFLAGS_AVX "-mavx")
# BMI2 instructions are typically also supported on AVX2 processors.
set(CFLAGS_AVX2 "-mavx2 -mbmi2")
set(CFLAGS_AVX512 "-mavx512f")
check_avx_processor_and_compiler_support(proc_supports_avx)
check_avx2_processor_and_compiler_support(proc_supports_avx2)
check_avx512_processor_and_compiler_support(proc_supports_avx512)
endif ()
# Ensure that _AMD64_ or _X86_ are defined on Microsoft Windows, as otherwise
# um/winnt.h provided since Windows 10.0.22000 will error.
if (NOT UNIX)
if (X64)
add_definitions(-D_AMD64_)
else (X64)
add_definitions(-D_X86_)
endif (X64)
endif (NOT UNIX)
if (UNIX)
# Ensure we can export dr_stat_syscall() from drlibc and get everyone to agree
# that struct stat64 is the stat struct.
add_definitions(-D_LARGEFILE64_SOURCE)
endif ()
# Set up assembly support and CMAKE_CPP.
# Note that in cmake < 2.6.4, 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 top of top-level CMakeLists.txt for our workaround.
if (NOT UNIX)
get_filename_component(cl_path ${CMAKE_C_COMPILER} PATH)
endif (NOT UNIX)
set(cpp2asm_newline_script_path "${PROJECT_SOURCE_DIR}/make/CMake_asm.cmake")
include(make/cpp2asm_support.cmake)
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)
if (NOT CMAKE_ASM_SUPPORTS_INTEL_SYNTAX)
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 CMAKE_ASM_SUPPORTS_INTEL_SYNTAX)
endif (UNIX)
if (UNIX)
identify_clang(CMAKE_COMPILER_IS_CLANG)
if (CMAKE_COMPILER_IS_CLANG)
set(CLANG 1)
endif (CMAKE_COMPILER_IS_CLANG)
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)
check_if_linker_is_gnu_gold(LINKER_IS_GNU_GOLD)
# FIXME i#2949: static 32-bit release-build linking with gcc 7.3.1 fails when
# static C++ clients like drmemtrace or drmemtrace_raw2trace are linked in.
# For now we disable those builds.
if (UNIX AND NOT X64 AND NOT DEBUG AND NOT CLANG AND
"${CMAKE_C_COMPILER_VERSION}" VERSION_GREATER "7.3")
message(STATUS "gcc 7.3+ non-debug 32-bit detected: disabling static C++ client "
"tests to work around i#2949")
set(DISABLE_FOR_BUG_2949 ON)
else ()
set(DISABLE_FOR_BUG_2949 OFF)
endif ()
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")
# cmake has CMAKE_RC_COMPILER, but no message compiler
if ("${CMAKE_GENERATOR}" MATCHES "Visual Studio")
# First checks for the Windows SDK through Windows Kits.
get_filename_component(kits_dir "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots;KitsRoot10]" REALPATH)
if (EXISTS ${kits_dir})
if (X64)
set(sdk_bindir "${kits_dir}/bin/${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}/x64")
else (X64)
set(sdk_bindir "${kits_dir}/bin/${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}/x86")
endif (X64)
else (EXISTS ${kits_dir})
# this path is only present for 2008+, but we currently require PATH to
# be set up anyway
get_filename_component(sdk_dir "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows;CurrentInstallFolder]" REALPATH)
if (X64)
set(sdk_bindir "${sdk_dir}/bin/x64")
else (X64)
set(sdk_bindir "${sdk_dir}/bin")
endif (X64)
endif (EXISTS ${kits_dir})
endif ()
if (NOT ("${CMAKE_GENERATOR}" MATCHES "MSYS Makefiles"))
# For MinGW (MSYS Makefiles) we do not have a message compiler.
# We build without it (which means we can't use the Windows event log).
find_program(CMAKE_MC_COMPILER mc.exe HINTS "${sdk_bindir}"
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)
endif ()
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
if (DR_DO_NOT_DEFINE_bool)
# i#488: ensure bool compatibility with C++
if (NOT ${DR_DO_NOT_DEFINE_bool} EQUAL 1)
message(FATAL_ERROR "incompatible pre-defined \"bool\" type is larger than 1 byte")
endif (NOT ${DR_DO_NOT_DEFINE_bool} EQUAL 1)
endif (DR_DO_NOT_DEFINE_bool)
CHECK_TYPE_SIZE(_Bool DR__Bool_EXISTS)
if (DR__Bool_EXISTS)
if (NOT ${DR__Bool_EXISTS} EQUAL 1)
message(FATAL_ERROR "incompatible \"_Bool\" type is larger than 1 byte")
endif (NOT ${DR__Bool_EXISTS} EQUAL 1)
endif (DR__Bool_EXISTS)
endif (UNIX)
###########################################################################
# basic build rules and flags
# i#1781: cmake 2.8.12+ fails to create static lib pdb by default
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()
# compiler flags
# BASE_CFLAGS applies to both C and C++.
# BASE_CONLY_FLAGS applies to just C.
# BASE_CXXONLY_FLAGS applies to just C++.
set(BASE_CFLAGS "")
set(BASE_CONLY_FLAGS "")
set(BASE_CXXONLY_FLAGS "")
CHECK_CXX_COMPILER_FLAG("-std=c++17" cxx17_available)
if (UNIX)
set(BASE_CXXONLY_FLAGS "${BASE_CXXONLY_FLAGS} -std=c++11")
# -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_CONLY_FLAGS "${BASE_CONLY_FLAGS} -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")
# Ensure DR is interoperable with other toolchains: do not assume char is signed
# (see i#1034 where this caused problems in the past).
set(BASE_CFLAGS "${BASE_CFLAGS} -funsigned-char")
# Ubuntu defaults to -fstack-protector these days, which depends on app TLS.
CHECK_C_COMPILER_FLAG("-fno-stack-protector" no_stack_protector_avail)
if (no_stack_protector_avail)
set(BASE_CFLAGS "${BASE_CFLAGS} -fno-stack-protector")
endif (no_stack_protector_avail)
# Prefer the new 'override' keyword.
CHECK_CXX_COMPILER_FLAG("-Wsuggest-override" suggest_override_avail)
if (suggest_override_avail)
set(BASE_CXXONLY_FLAGS "${BASE_CXXONLY_FLAGS} -Wsuggest-override")
endif ()
# Try to support users setting -m32 in CMAKE_C_FLAGS rather than the
# CFLAGS env var.
if (X86)
if (X64)
set(BASE_CFLAGS "-m64 ${BASE_CFLAGS}")
set(LD_FLAGS "-melf_x86_64")
else (X64)
set(BASE_CFLAGS "-m32 ${BASE_CFLAGS}")
set(LD_FLAGS "-melf_i386")
endif (X64)
elseif (ARM)
# i#1551: add necessary flags for ARM build.
if (X64)
else (X64)
# On newer gcc versions such as 11.2 we need an explicit +fp to denote our
# gnueablihf hardware-fp-capabilities target.
CHECK_C_COMPILER_FLAG("-march=armv7-a+fp" armv7_fp_available)
if (armv7_fp_available)
set(BASE_CFLAGS "-mthumb -march=armv7-a+fp ${BASE_CFLAGS}")
else ()
set(BASE_CFLAGS "-mthumb -march=armv7-a ${BASE_CFLAGS}")
endif ()
set(LD_FLAGS "-marmelf_linux_eabi")
if (ANDROID OR CMAKE_C_LIBRARY_ARCHITECTURE MATCHES "gnueabi$")
# We use eabihf by default for ARM build.
# According to https://developer.android.com/ndk/guides/abis.html#v7a,
# we need extra flags to use eabihf for Android build, i.e.,:
# TARGET_CFLAGS += -mhard-float -D_NDK_MATH_NO_SOFTFP=1
# TARGET_LDFLAGS += -Wl,--no-warn-mismatch -lm_hard
# so we use softfp for Android build instead.
# We also need to add softfp for the gnueabi target.
set(BASE_CFLAGS "-mfloat-abi=softfp ${BASE_CFLAGS}")
endif ()
endif (X64)
endif ()
if (APPLE AND CMAKE_COMPILER_IS_CLANG)
set(BASE_CFLAGS "${BASE_CFLAGS} -mmacosx-version-min=${OLDEST_OSX_SUPPPORTED}")
endif ()
if (APPLE)
set(ld_entry_flag "-e")
else ()
set(ld_entry_flag "--entry")
endif ()
# there's no cmake warning control so we hardcode it
set(WARN "-Wall -Werror -Wwrite-strings -Wvla")
if (NOT CMAKE_COMPILER_IS_CLANG)
# Old gcc's ignore unknown -W flags, but -Wall -Werror causes clang to
# complain that it doesn't recognize it.
# Actually this is not true: gcc 4.1.2 aborts on unknown -W so we check
CHECK_C_COMPILER_FLAG("-Wno-unused-but-set-variable" nounused_avail)
if (nounused_avail)
set(WARN "${WARN} -Wno-unused-but-set-variable")
endif (nounused_avail)
# XXX i#3792: DynamoRIO manages '\0' termination and error states itself in
# too many places. In order to activate this warning, this code needs to get
# re-factored for no good reason.
CHECK_C_COMPILER_FLAG("-Wstringop-truncation" stringop_truncation_avail)
if (stringop_truncation_avail)
set(WARN "${WARN} -Wno-stringop-truncation")
endif (stringop_truncation_avail)
# XXX i#3792: see comment above.
CHECK_C_COMPILER_FLAG("-Wformat-truncation" format_truncation_avail)
if (format_truncation_avail)
set(WARN "${WARN} -Wno-format-truncation")
endif (format_truncation_avail)
# XXX i#3792: see comment above.
CHECK_C_COMPILER_FLAG("-Wstringop-overflow" stringop_overflow_avail)
if (stringop_overflow_avail)
set(WARN "${WARN} -Wno-stringop-overflow")
endif (stringop_overflow_avail)
CHECK_C_COMPILER_FLAG("-Wtype-limits" HAVE_TYPELIMITS_CONTROL)
else (NOT CMAKE_COMPILER_IS_CLANG)
# clang turns off color when it's writing to a pipe, but the user may still
# wish to force color if it eventually goes to a terminal.
option(CLANG_COLOR_DIAGNOSTICS "force colored clang diagnostics" OFF)
set(clang_args "")
if (CLANG_COLOR_DIAGNOSTICS)
set(clang_args "-fcolor-diagnostics ${clang_args}")
endif (CLANG_COLOR_DIAGNOSTICS)
set(BASE_CFLAGS "${clang_args} ${BASE_CFLAGS}")
endif (NOT CMAKE_COMPILER_IS_CLANG)
set(DBG "-g3")
# gcc doesn't change its optimizations based on -g
set(OPT "-O3 ${DBG}")
if (PROFILE)
set(OPT "${OPT} -fno-omit-frame-pointer")
endif ()
# Omit unwind tables in optimized mode.
if (NOT DEBUG)
set(BASE_CONLY_FLAGS "${BASE_CONLY_FLAGS} -fno-unwind-tables")
endif ()
if (NOT APPLE AND NOT ANDROID) # no .gnu.hash support on Android
# Generate the .hash section in addition to .gnu.hash for every target, to
# avoid SIGFPE when running our binaries on old systems:
foreach (config ${CMAKE_BUILD_TYPE} ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER "${config}" config_upper)
foreach (var
CMAKE_EXE_LINKER_FLAGS_${config_upper};
CMAKE_MODULE_LINKER_FLAGS_${config_upper};
CMAKE_SHARED_LINKER_FLAGS_${config_upper})
set(${var} "-Wl,--hash-style=both")
endforeach ()
endforeach ()
endif ()
# XXX: core-specific: move to core/CMakeLists.txt?
#
# XXX: i#374: we used to use -O to avoid stack overflow in debug
# build (makes a huge difference by having locals/temps share stack
# slots) and had -fno-omit-frame-pointer to keep things more easily
# debuggable (though gcc claims only omits when debuggable), but
# even then many locals were optimized away, and utils.c's first
# statsx.h expansion took over a minute to compile with some
# versions of gcc, so removing the -O (can't repro the stack
# overflows now anyway). If we hit the overflows again, we should
# use -O0 and optimize attributes on the few funcs that need higher
# opt.
set(DBG_OPT "-fno-omit-frame-pointer")
# We disable strcmp intrinsic to avoid stack overflow in
# set_dynamo_options(): case 7853.
if (NOT CMAKE_COMPILER_IS_CLANG)
set(DBG_OPT "${DBG_OPT} -fno-builtin-strcmp")
endif ()
set(LINK_EXTRA_FLAGS "")
else (UNIX)
# FIXME: why isn't ${CMAKE_CL_NOLOGO} set?
set(BASE_CFLAGS "${BASE_CFLAGS} /nologo")
# 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(BASE_CFLAGS "${BASE_CFLAGS} /MP")
# read-only string pooling
set(BASE_CFLAGS "${BASE_CFLAGS} /GF")
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(BASE_CFLAGS "${BASE_CFLAGS} /FS")
endif()
# FIXME case 191729: we should try to enable this.
# Currently we get "unresolved external symbol ___security_cookie"
set(BASE_CFLAGS "${BASE_CFLAGS} /GS-")
# VS2010 has /MD as the default (and does declspec(dllimport) for
# libc routines) so make sure we explicitly request /MT
if (DEBUG)
set(BASE_CFLAGS "${BASE_CFLAGS} /MTd")
else ()
set(BASE_CFLAGS "${BASE_CFLAGS} /MT")
endif ()
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}")
# Shrink binaries and pdbs (/Gy should already be there)
set(LINK_EXTRA_FLAGS "/opt:ref /opt:icf /pdbcompress")
if (GENERATE_PDBS)
set(DBG "/Zi")
set(LINK_EXTRA_FLAGS "${LINK_EXTRA_FLAGS} /debug")
else (GENERATE_PDBS)
# xref PR 192750 - runregression uses this to avoid over-ssh pdb issues
set(DBG "")
set(LINK_EXTRA_FLAGS "")
# 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)
# i#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}")