CMakeLists.txt 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. cmake_minimum_required(VERSION 3.10)
  2. project (CHAKRACORE)
  3. set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g")
  4. # Disable expected CMake workflow
  5. option(CHAKRACORE_BUILD_SH "Use build.sh")
  6. set(CCACHE_PROGRAM_NAME_DEFAULT "ccache")
  7. if(NOT CHAKRACORE_BUILD_SH)
  8. option(DISABLE_JIT "Disable JIT compilation" OFF)
  9. option(INTL_ICU "Enable Intl" ON)
  10. option(EMBED_ICU "Build ICU within ChakraCore build" OFF)
  11. option(USE_CCACHE "Build using ccache" OFF)
  12. set(CCACHE_PROGRAM_NAME ${CCACHE_PROGRAM_NAME_DEFAULT} CACHE
  13. STRING "ccache executable")
  14. set(ICU_INCLUDE_PATH "" CACHE STRING "libicu iclude path")
  15. if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
  16. set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Build type" FORCE)
  17. endif (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
  18. else(NOT CHAKRACORE_BUILD_SH)
  19. # Keep CMake from caching static/shared library
  20. # option. Otherwise, CMake fails to update cached
  21. # references
  22. # todo: create a sub cmake file to take care of _SH uncaching...
  23. if(SHARED_LIBRARY_SH)
  24. unset(SHARED_LIBRARY_SH CACHE)
  25. unset(STATIC_LIBRARY_SH CACHE)
  26. unset(STATIC_LIBRARY CACHE)
  27. set(SHARED_LIBRARY 1)
  28. endif()
  29. if(STATIC_LIBRARY_SH)
  30. unset(SHARED_LIBRARY_SH CACHE)
  31. unset(STATIC_LIBRARY_SH CACHE)
  32. unset(SHARED_LIBRARY CACHE)
  33. set(STATIC_LIBRARY 1)
  34. endif()
  35. if(LIBS_ONLY_BUILD_SH)
  36. unset(LIBS_ONLY_BUILD_SH CACHE)
  37. set(CC_LIBS_ONLY_BUILD 1)
  38. endif()
  39. if (CLANG_SANITIZE_SH)
  40. set(CLANG_SANITIZE ${CLANG_SANITIZE_SH})
  41. unset(CLANG_SANITIZE_SH CACHE)
  42. endif()
  43. endif(NOT CHAKRACORE_BUILD_SH)
  44. if(CC_USES_SYSTEM_ARCH_SH OR NOT CHAKRACORE_BUILD_SH)
  45. if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
  46. set(CC_TARGETS_AMD64_SH 1)
  47. elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7l")
  48. set(CC_TARGETS_ARM_SH 1)
  49. elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
  50. set(CC_TARGETS_ARM64_SH 1)
  51. elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
  52. set(CC_TARGETS_ARM64_SH 1)
  53. endif()
  54. unset(CC_USES_SYSTEM_ARCH_SH CACHE)
  55. endif()
  56. if(CC_TARGETS_AMD64_SH)
  57. set(CC_TARGETS_AMD64 1)
  58. elseif(CC_TARGETS_ARM_SH)
  59. set(CC_TARGETS_ARM 1)
  60. add_definitions(-D_ARM_=1)
  61. set(CMAKE_SYSTEM_PROCESSOR "armv7l")
  62. elseif(CC_TARGETS_ARM64_SH)
  63. add_definitions(-D_ARM64_=1)
  64. add_definitions(-D__arm64__=1)
  65. set(CC_TARGETS_ARM64 1)
  66. set(CMAKE_SYSTEM_PROCESSOR "arm64")
  67. elseif(CC_TARGETS_X86_SH)
  68. set(CC_TARGETS_X86 1)
  69. set(CMAKE_SYSTEM_PROCESSOR "i386")
  70. else()
  71. message(FATAL_ERROR "Unsupported target processor: ${CMAKE_SYSTEM_PROCESSOR}")
  72. endif()
  73. unset(CC_TARGETS_ARM_SH CACHE)
  74. unset(CC_TARGETS_X86_SH CACHE)
  75. unset(CC_TARGETS_AMD64_SH CACHE)
  76. if (CHAKRACORE_BUILD_SH)
  77. if(CCACHE_PROGRAM_NAME_SH)
  78. set(USE_CCACHE ON)
  79. set(CCACHE_PROGRAM_NAME ${CCACHE_PROGRAM_NAME_SH})
  80. unset(CCACHE_PROGRAM_NAME_SH CACHE)
  81. else()
  82. set(USE_CCACHE OFF)
  83. set(CCACHE_PROGRAM_NAME ${CCACHE_PROGRAM_NAME_DEFAULT})
  84. endif()
  85. endif()
  86. if(USE_CCACHE)
  87. find_program(CCACHE_PROGRAM ${CCACHE_PROGRAM_NAME} REQUIRED)
  88. set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_PROGRAM})
  89. set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE_PROGRAM})
  90. endif()
  91. if(ENABLE_VALGRIND_SH)
  92. unset(ENABLE_VALGRIND_SH CACHE)
  93. if(NOT CC_TARGETS_X86)
  94. # Enable Valgrind is not needed for x86 builds. Already <= 32Gb address space
  95. set(ENABLE_VALGRIND 1)
  96. add_definitions(-DENABLE_VALGRIND=1)
  97. endif()
  98. endif()
  99. if(ICU_SETTINGS_RESET)
  100. unset(ICU_SETTINGS_RESET CACHE)
  101. unset(ICU_INCLUDE_PATH_SH CACHE)
  102. unset(NO_ICU_SH CACHE)
  103. unset(LOCAL_ICU_SH CACHE)
  104. unset(SYSTEM_ICU_SH CACHE)
  105. unset(EMBED_ICU_SH CACHE)
  106. endif()
  107. if(CC_TARGET_OS_ANDROID_SH)
  108. set(CC_TARGET_OS_ANDROID 1)
  109. set(CMAKE_SYSTEM_NAME Android)
  110. set(ANDROID_NDK "android-toolchain-arm/")
  111. set(ANDROID_ABI armeabi-v7a)
  112. set(CMAKE_SYSTEM_VERSION 21)
  113. set(CMAKE_ANDROID_ARCH_ABI armeabi)
  114. set(ANDROID_TOOLCHAIN_NAME arm-linux-androideabi-clang3.8)
  115. set(ANDROID_STL "c++_static")
  116. unset(CC_TARGET_OS_ANDROID_SH CACHE)
  117. elseif(CMAKE_SYSTEM_NAME STREQUAL Linux)
  118. set(CC_TARGET_OS_LINUX 1)
  119. elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
  120. set(CC_TARGET_OS_OSX 1)
  121. endif()
  122. if (ENABLE_CC_XPLAT_TRACE_SH)
  123. unset(ENABLE_CC_XPLAT_TRACE_SH CACHE)
  124. set(ENABLE_CC_XPLAT_TRACE 1)
  125. if (CC_TARGET_OS_ANDROID)
  126. add_definitions(-DTRACE_OUTPUT_TO_LOGCAT=1)
  127. else()
  128. add_definitions(-DTRACE_OUTPUT_TARGET_FILE=1)
  129. endif()
  130. add_definitions(-DENABLE_CC_XPLAT_TRACE=1)
  131. add_compile_options(-finstrument-functions)
  132. add_compile_options(-g)
  133. add_compile_options(-ggdb)
  134. if(NOT STATIC_LIBRARY)
  135. message(FATAL_ERROR "Trace option is available only for --static builds")
  136. endif()
  137. endif()
  138. if(ICU_INCLUDE_PATH_SH)
  139. set(ICU_INCLUDE_PATH ${ICU_INCLUDE_PATH_SH})
  140. unset(ICU_INCLUDE_PATH_SH CACHE)
  141. endif()
  142. if(NO_ICU_SH)
  143. set(NO_ICU 1)
  144. unset(NO_ICU_SH CACHE)
  145. endif()
  146. if(SYSTEM_ICU_SH)
  147. set(SYSTEM_ICU 1)
  148. unset(SYSTEM_ICU_SH CACHE)
  149. endif()
  150. if(CHAKRACORE_BUILD_SH)
  151. if(INTL_ICU_SH)
  152. unset(INTL_ICU_SH CACHE)
  153. set(INTL_ICU 1)
  154. else()
  155. unset(INTL_ICU_SH CACHE)
  156. set(INTL_ICU 0)
  157. endif()
  158. endif(CHAKRACORE_BUILD_SH)
  159. if(EMBED_ICU_SH)
  160. set(EMBED_ICU 1)
  161. unset(EMBED_ICU_SH CACHE)
  162. endif()
  163. if(EMBED_ICU AND ICU_INCLUDE_PATH)
  164. message(FATAL_ERROR "Embedded ICU and ICU include path cannot be set at the same time")
  165. endif()
  166. if(EMBED_ICU)
  167. # Keep consistent with what ICU download script used to print
  168. message("Note: ICU installation and use is subject to it's publisher's licensing terms")
  169. set(ICU_PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/deps/thirdparty/icu)
  170. set(ICU_DOWNLOAD_DIR ${ICU_PREFIX}/download)
  171. set(ICU_SOURCE_DIR ${ICU_PREFIX}/stage)
  172. set(EMBEDDED_ICU_TARGET icu4c)
  173. set(ICU_INCLUDE_PATH ${ICU_PREFIX}/include)
  174. set(ICU_LIBRARY_PATH ${ICU_PREFIX}/lib)
  175. add_definitions(-DHAS_REAL_ICU=1)
  176. add_definitions(-DHAS_ICU)
  177. add_definitions(-DINTL_ICU=1)
  178. set(ICU_LIBRARIES
  179. ${ICU_LIBRARY_PATH}/libicuuc.a
  180. ${ICU_LIBRARY_PATH}/libicui18n.a
  181. ${ICU_LIBRARY_PATH}/libicudata.a
  182. )
  183. include(ExternalProject)
  184. ExternalProject_Add(${EMBEDDED_ICU_TARGET}
  185. PREFIX ${ICU_PREFIX}
  186. DOWNLOAD_DIR ${ICU_DOWNLOAD_DIR}
  187. SOURCE_DIR ${ICU_SOURCE_DIR}
  188. URL https://github.com/unicode-org/icu/releases/download/release-63-2/icu4c-63_2-src.tgz
  189. URL_HASH SHA512=5fa9092efd8d6da6dfc8d498e4026167fda43423eaafc754d1789cf8fd4f6e76377878ebcaa32e14f314836136b764873511a93bfbcc5419b758841cc6df8f32
  190. CONFIGURE_COMMAND ${ICU_SOURCE_DIR}/source/configure --prefix=${ICU_PREFIX} --with-data-packaging=static --enable-static --disable-shared --with-library-bits=64 --disable-icuio --disable-layout --disable-tests --disable-samples
  191. BUILD_COMMAND make STATICCFLAGS="-fPIC" STATICCXXFLAGS="-fPIC" STATICCPPFLAGS="-DPIC"
  192. INSTALL_COMMAND make install
  193. BYPRODUCTS ${ICU_LIBRARIES}
  194. )
  195. elseif(ICU_INCLUDE_PATH)
  196. add_definitions(-DHAS_REAL_ICU=1)
  197. add_definitions(-DHAS_ICU)
  198. set(ICU_LIBRARY_PATH "${ICU_INCLUDE_PATH}/../lib/")
  199. find_library(ICUUC icuuc PATHS ${ICU_LIBRARY_PATH} NO_DEFAULT_PATH)
  200. if(INTL_ICU)
  201. add_definitions(-DINTL_ICU=1)
  202. find_library(ICUIN icui18n PATHS ${ICU_LIBRARY_PATH} NO_DEFAULT_PATH)
  203. # In a default install, ICU header files are all in ICU_ROOT/include
  204. # However, for Node, the include/ folder is never generated, so we have to look
  205. # in NODE/deps/icu/source/{common|i18n} for headers
  206. set(ICU_INCLUDE_PATH
  207. "${ICU_INCLUDE_PATH}"
  208. "${ICU_INCLUDE_PATH}/../i18n/"
  209. )
  210. endif()
  211. if(ICUUC)
  212. message("-- found ICU libs: ${ICU_LIBRARY_PATH}")
  213. find_library(ICUDATA icudata PATHS ${ICU_LIBRARY_PATH} NO_DEFAULT_PATH)
  214. if (NOT ICUDATA)
  215. set(ICUDATA "")
  216. endif()
  217. set(ICU_LIBRARIES
  218. ${ICUUC}
  219. ${ICUIN}
  220. ${ICUDATA}
  221. )
  222. endif()
  223. endif()
  224. if(CC_TARGET_OS_LINUX OR CC_TARGET_OS_ANDROID)
  225. if(SYSTEM_ICU OR (NOT ICU_INCLUDE_PATH AND NOT NO_ICU))
  226. set(ICU_LIBRARIES "icuuc")
  227. if(INTL_ICU)
  228. add_definitions(-DINTL_ICU=1)
  229. set(ICU_LIBRARIES
  230. ${ICU_LIBRARIES}
  231. icui18n
  232. )
  233. endif()
  234. add_definitions(-DHAS_REAL_ICU=1)
  235. add_definitions(-DHAS_ICU)
  236. endif()
  237. elseif(CC_TARGET_OS_OSX)
  238. # in case ICU path was given but it doesn't exist, build script will fail.
  239. # so, fallback only if ICU path wasn't given
  240. if(NOT ICU_INCLUDE_PATH)
  241. set(NO_ICU 1)
  242. message("-- Couldn't find ICU. Falling back to --no-icu build")
  243. endif()
  244. endif()
  245. set(CLR_CMAKE_PLATFORM_XPLAT 1)
  246. if(CC_TARGETS_AMD64)
  247. add_definitions(-DTARGET_64)
  248. add_compile_options(-msse4.2)
  249. if(NOT CMAKE_BUILD_TYPE STREQUAL Release)
  250. set(CAN_BUILD_WABT 1)
  251. endif()
  252. elseif(CC_TARGETS_X86)
  253. add_definitions(-D__i686__)
  254. add_definitions(-DTARGET_32)
  255. add_compile_options(-arch i386)
  256. add_compile_options(-msse3)
  257. set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} \
  258. -m32"
  259. )
  260. elseif(CC_TARGETS_ARM)
  261. add_definitions(-D__arm__)
  262. add_definitions(-DTARGET_32)
  263. add_definitions(-D_M_ARM32_OR_ARM64)
  264. if(CC_TARGET_OS_OSX)
  265. add_compile_options(-arch arm)
  266. elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
  267. # reduce link time memory usage
  268. set(LINKER_REDUCED_MEMORY "-Xlinker --no-keep-memory")
  269. endif()
  270. elseif(CC_TARGETS_ARM64)
  271. add_definitions(-D__aarch64__)
  272. add_definitions(-DTARGET_64)
  273. add_definitions(-D_M_ARM32_OR_ARM64)
  274. if(CC_TARGET_OS_OSX)
  275. add_compile_options(-arch arm64)
  276. endif()
  277. if (CC_TARGET_OS_LINUX)
  278. # arm64 .S mostly use ; comments, not accepted by GNU assembler.
  279. # In lieu of converting them all, just strip these comments during build.
  280. set(CMAKE_ASM_COMPILE_OBJECT
  281. "sed -e 's/\;.*//g' <SOURCE> > <OBJECT_DIR>/$$(basename <SOURCE>)"
  282. "<CMAKE_ASM_COMPILER> <DEFINES> <INCLUDES> -I $$(dirname <SOURCE>) <FLAGS> -o <OBJECT> -c <OBJECT_DIR>/$$(basename <SOURCE>)"
  283. )
  284. endif()
  285. else()
  286. message(FATAL_ERROR "Only AMD64, ARM, ARM64 and I386 are supported")
  287. endif()
  288. if(CAN_BUILD_WABT)
  289. add_definitions(-DCAN_BUILD_WABT)
  290. endif()
  291. if(CC_TARGET_OS_LINUX OR CC_TARGET_OS_ANDROID)
  292. set(CLR_CMAKE_PLATFORM_LINUX 1)
  293. # OSX 10.12 Clang deprecates libstdc++ [See GH #1599]
  294. # So, -Werror is linux only for now
  295. # + Android ARM ABI shows ld warnings
  296. # xplat-todo: Do we need this ?
  297. if (NOT CC_TARGET_OS_ANDROID)
  298. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
  299. -Werror"
  300. )
  301. endif()
  302. elseif(CC_TARGET_OS_OSX)
  303. add_definitions(
  304. -DPLATFORM_UNIX
  305. )
  306. if(NOT CC_XCODE_PROJECT)
  307. set(OSX_DEPLOYMENT_TARGET "$ENV{MACOSX_DEPLOYMENT_TARGET} CC")
  308. if (${OSX_DEPLOYMENT_TARGET} STREQUAL " CC")
  309. set(OSX_DEPLOYMENT_TARGET "10.9")
  310. add_compile_options(-mmacosx-version-min=10.9)
  311. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} \
  312. -mmacosx-version-min=10.9 -std=gnu99")
  313. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
  314. -mmacosx-version-min=10.9 -std=gnu++11")
  315. else()
  316. set(OSX_DEPLOYMENT_TARGET "$ENV{MACOSX_DEPLOYMENT_TARGET}")
  317. message(WARNING "-- !! macOS Deployment Target was set to $ENV{MACOSX_DEPLOYMENT_TARGET}. Using it as is.")
  318. endif()
  319. endif()
  320. else()
  321. message(FATAL_ERROR "Unsupported OS: ${CMAKE_SYSTEM_NAME}")
  322. endif()
  323. if (CMAKE_CXX_COMPILER_ID STREQUAL AppleClang
  324. OR CMAKE_CXX_COMPILER_ID STREQUAL Clang
  325. OR CMAKE_CXX_COMPILER_ID STREQUAL GNU)
  326. # Color diagnostics for g++ and clang++
  327. add_definitions("-fdiagnostics-color=always")
  328. endif()
  329. if(STATIC_LIBRARY)
  330. add_definitions(-DCHAKRA_STATIC_LIBRARY=1)
  331. endif()
  332. if(CLR_CMAKE_PLATFORM_XPLAT)
  333. add_definitions(-D_CHAKRACOREBUILD)
  334. add_definitions(-DFEATURE_PAL)
  335. add_definitions(-DPLATFORM_UNIX=1)
  336. if(CLR_CMAKE_PLATFORM_LINUX)
  337. add_definitions(-D__LINUX__=1)
  338. if(CC_TARGETS_AMD64)
  339. add_definitions(-DLINUX64)
  340. endif(CC_TARGETS_AMD64)
  341. endif(CLR_CMAKE_PLATFORM_LINUX)
  342. if(CC_TARGETS_AMD64)
  343. set(IS_64BIT_BUILD 1)
  344. add_definitions(-D_M_X64 -D_M_AMD64 -D_AMD64_)
  345. elseif(CC_TARGETS_ARM64)
  346. set(IS_64BIT_BUILD 1)
  347. add_definitions(-D_M_ARM64 -D_ARM64_)
  348. endif()
  349. add_definitions(
  350. -DUNICODE
  351. -D_SAFECRT_USE_CPP_OVERLOADS=1
  352. -D__STDC_WANT_LIB_EXT1__=1
  353. )
  354. set(CMAKE_CXX_STANDARD 17)
  355. set(CMAKE_CXX_STANDARD_REQUIRED On)
  356. # todo: fix general visibility of the interface
  357. # do not set to `fvisibility=hidden` as it is going to
  358. # prevent the required interface is being exported
  359. # clang by default sets fvisibility=default
  360. # Allow ch to export `OnChakraCoreLoadedEntry`
  361. set(CMAKE_ENABLE_EXPORTS ON)
  362. # CXX WARNING FLAGS
  363. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
  364. -Wno-ignored-attributes\
  365. -Wno-parentheses-equality\
  366. -Wno-reorder\
  367. -Wno-microsoft\
  368. -Wno-unused-value\
  369. -Wno-int-to-void-pointer-cast\
  370. -Wno-invalid-offsetof\
  371. -Wno-undefined-inline\
  372. -Wno-inconsistent-missing-override\
  373. -Wno-macro-redefined\
  374. -Wno-pragmas\
  375. -Wno-invalid-token-paste\
  376. -Wno-format\
  377. -Wno-invalid-noreturn\
  378. -Wno-null-arithmetic\
  379. -Wno-tautological-constant-out-of-range-compare\
  380. -Wno-tautological-undefined-compare\
  381. -Wno-address-of-temporary\
  382. -Wno-null-conversion\
  383. -Wno-return-type\
  384. -Wno-switch\
  385. -Wno-int-to-pointer-cast\
  386. -Wno-tautological-constant-compare\
  387. -Wno-enum-compare-switch\
  388. -Wno-unknown-warning-option"
  389. )
  390. # notes..
  391. # -Wno-address-of-temporary # vtinfo.h, VirtualTableInfo<T>::RegisterVirtualTable
  392. # -Wno-null-conversion # Check shmemory.cpp and cs.cpp here...
  393. # -Wno-return-type # switch unreachable code
  394. # -Wno-switch # switch values not handled
  395. # -W-enum-compare-switch # throws warning on enum1 == enum2 where both
  396. # enums represent same value but do not share the type. ie. we use both AsmJsType
  397. # and AsmJsRetType interchangably and filter things out by `default:` case.
  398. # -W-tautological-constant-compare throws warning for checks known at compile time.
  399. # Some of those checks are optimized out during compile / lto time, and others
  400. # are platform / compiler dependent.
  401. # -Wno-unknown-warning-option ... well, some of the new switches are not
  402. # recognized by older compilers and they fail. So, put this one and not fail
  403. include(Build/CMakeFeatureDetect.cmake)
  404. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
  405. ${CXX_DO_NOT_OPTIMIZE_SIBLING_CALLS} \
  406. -fno-omit-frame-pointer \
  407. -fdelayed-template-parsing"
  408. )
  409. # CXX / CC COMPILER FLAGS
  410. add_compile_options(
  411. -fasm-blocks
  412. -fms-extensions
  413. -fwrapv # Treat signed integer overflow as two's complement
  414. )
  415. # Only disable RTTI in release builds so that TrackAlloc works for debug and test builds
  416. # Also disable RTTI when building a shared library
  417. # TODO: why does the shared library break with rtti disabled?
  418. if(CMAKE_BUILD_TYPE STREQUAL Release)
  419. if(STATIC_LIBRARY)
  420. add_compile_options(-fno-rtti)
  421. endif()
  422. endif()
  423. endif(CLR_CMAKE_PLATFORM_XPLAT)
  424. if (ENABLE_FULL_LTO_SH OR ENABLE_THIN_LTO_SH)
  425. if (CC_TARGET_OS_LINUX)
  426. set(CC_LTO_ENABLED -use-gold-plugin)
  427. set(CC_LTO_ENABLED_C -c)
  428. endif()
  429. if (ENABLE_FULL_LTO_SH)
  430. unset(DENABLE_FULL_LTO_SH CACHE)
  431. add_compile_options(-flto ${CC_LTO_ENABLED_C})
  432. if (CC_LTO_ENABLED)
  433. set(CC_LTO_ENABLED "${CC_LTO_ENABLED} -flto")
  434. endif()
  435. elseif (ENABLE_THIN_LTO_SH)
  436. unset(ENABLE_THIN_LTO_SH CACHE)
  437. add_compile_options(-flto=thin)
  438. if (CC_LTO_ENABLED)
  439. set(CC_LTO_ENABLED "${CC_LTO_ENABLED} -flto=thin")
  440. endif()
  441. endif()
  442. endif()
  443. if(CMAKE_BUILD_TYPE STREQUAL Debug)
  444. add_definitions(
  445. -DDBG=1
  446. -DDEBUG=1
  447. -D_DEBUG=1 # for PAL
  448. -DDBG_DUMP=1
  449. )
  450. elseif(CMAKE_BUILD_TYPE STREQUAL RelWithDebInfo)
  451. add_definitions(
  452. -DENABLE_DEBUG_CONFIG_OPTIONS=1
  453. )
  454. endif(CMAKE_BUILD_TYPE STREQUAL Debug)
  455. if(IS_64BIT_BUILD)
  456. add_definitions(
  457. -DBIT64=1
  458. -DSTACK_ALIGN=16
  459. )
  460. endif(IS_64BIT_BUILD)
  461. if(NO_JIT_SH)
  462. unset(NO_JIT_SH CACHE) # don't cache
  463. unset(BuildJIT CACHE) # also clear it just in case
  464. add_definitions(-DDISABLE_JIT=1)
  465. elseif(DISABLE_JIT)
  466. set(BuildJIT 0)
  467. add_definitions(-DDISABLE_JIT=1)
  468. else()
  469. set(BuildJIT 1)
  470. endif()
  471. if(WITHOUT_FEATURES_SH)
  472. add_definitions(${WITHOUT_FEATURES_SH})
  473. unset(WITHOUT_FEATURES_SH CACHE) # don't cache
  474. endif(WITHOUT_FEATURES_SH)
  475. if(EXTRA_DEFINES_SH)
  476. add_definitions(${EXTRA_DEFINES_SH})
  477. unset(EXTRA_DEFINES_SH CACHE) #don't cache
  478. endif(EXTRA_DEFINES_SH)
  479. enable_language(ASM)
  480. if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
  481. set(DYN_LIB_EXT "dylib")
  482. else()
  483. set(DYN_LIB_EXT "so")
  484. endif()
  485. if(CC_TARGETS_ARM64)
  486. if(CC_TARGET_OS_LINUX)
  487. message(WARNING "ARM64 linux build has not yet been tested, this build is unsupported.")
  488. endif()
  489. if(BuildJIT)
  490. message(WARNING "ARM64 Jit not yet functional on platforms other than windows.")
  491. message(WARNING "For use rather than development please build with Jit disabled --no-jit with ./build.sh or -DDISABLE_JIT=1 if using CMake directly")
  492. endif()
  493. endif()
  494. ################# Write-barrier check/analyze ##################
  495. if (WB_CHECK_SH OR WB_ANALYZE_SH)
  496. add_definitions(
  497. -Xclang -load
  498. -Xclang ${CMAKE_CURRENT_SOURCE_DIR}/tools/RecyclerChecker/Build/libclangRecyclerChecker.${DYN_LIB_EXT}
  499. )
  500. endif()
  501. if (WB_CHECK_SH)
  502. unset(WB_CHECK_SH CACHE) # don't cache
  503. add_definitions(
  504. -Xclang -add-plugin
  505. -Xclang check-recycler
  506. )
  507. endif()
  508. if (WB_ANALYZE_SH)
  509. unset(WB_ANALYZE_SH CACHE) # don't cache
  510. add_definitions(
  511. -Xclang -analyze
  512. -Xclang -analyzer-checker=chakra.RecyclerChecker
  513. )
  514. endif()
  515. if (WB_ARGS_SH)
  516. foreach(wb_arg IN LISTS WB_ARGS_SH)
  517. add_definitions(
  518. -Xclang -plugin-arg-check-recycler
  519. -Xclang ${wb_arg}
  520. )
  521. endforeach(wb_arg)
  522. unset(WB_ARGS_SH CACHE) # don't cache
  523. endif()
  524. include_directories(
  525. .
  526. lib/Common
  527. lib/Common/PlaceHolder
  528. pal
  529. pal/inc
  530. pal/inc/rt
  531. ${ICU_INCLUDE_PATH}
  532. )
  533. if(ICU_INCLUDE_PATH)
  534. if(NOT HAVE_LIBICU_UCHAR_H)
  535. set(HAVE_LIBICU_UCHAR_H 1)
  536. endif()
  537. endif()
  538. # detect features
  539. include_directories(SYSTEM /usr/local/include)
  540. include(pal/src/configure.cmake)
  541. # Clang sanitizer support, this should be after `detect feature` to not to
  542. # affect feature detection
  543. if (CLANG_SANITIZE)
  544. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=${CLANG_SANITIZE_SH}")
  545. set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -fsanitize=${CLANG_SANITIZE_SH}")
  546. endif()
  547. add_subdirectory (pal)
  548. # build the rest with NO_PAL_MINMAX and PAL_STDCPP_COMPAT
  549. add_definitions(
  550. -DNO_PAL_MINMAX
  551. -DPAL_STDCPP_COMPAT
  552. )
  553. if (ENABLE_JS_LTTNG_SH)
  554. unset(ENABLE_JS_LTTNG_SH CACHE)
  555. include_directories (
  556. ${CMAKE_CURRENT_SOURCE_DIR}/out/lttng
  557. )
  558. add_subdirectory ($ENV{TARGET_PATH}/lttng ${CMAKE_CURRENT_BINARY_DIR}/lttng)
  559. add_definitions(
  560. -DENABLE_JS_ETW
  561. -DENABLE_JS_LTTNG
  562. )
  563. set(USE_LTTNG "1")
  564. endif()
  565. add_subdirectory (lib)
  566. add_subdirectory (bin)
  567. add_subdirectory(test)