2
0

CMakeLists.txt 18 KB

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