CMakeLists.txt 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. cmake_minimum_required(VERSION 3.2)
  2. project (CHAKRACORE)
  3. # Keep CMake from caching static/shared library
  4. # option. Otherwise, CMake fails to update cached
  5. # references
  6. if(SHARED_LIBRARY_SH)
  7. unset(SHARED_LIBRARY_SH CACHE)
  8. unset(STATIC_LIBRARY_SH CACHE)
  9. unset(STATIC_LIBRARY CACHE)
  10. set(SHARED_LIBRARY 1)
  11. endif()
  12. if(STATIC_LIBRARY_SH)
  13. unset(SHARED_LIBRARY_SH CACHE)
  14. unset(STATIC_LIBRARY_SH CACHE)
  15. unset(SHARED_LIBRARY CACHE)
  16. set(STATIC_LIBRARY 1)
  17. endif()
  18. if(CC_TARGETS_AMD64_SH)
  19. unset(CC_TARGETS_X86 CACHE)
  20. unset(CC_TARGETS_X86_SH CACHE)
  21. unset(CC_TARGETS_AMD64_SH CACHE)
  22. set(CC_TARGETS_AMD64 1)
  23. endif()
  24. if(CC_TARGETS_X86_SH)
  25. unset(CC_TARGETS_X86_SH CACHE)
  26. unset(CC_TARGETS_AMD64_SH CACHE)
  27. unset(CC_TARGETS_AMD64 CACHE)
  28. set(CC_TARGETS_X86 1)
  29. set(CMAKE_SYSTEM_PROCESSOR "i386")
  30. endif()
  31. if(ICU_SETTINGS_RESET)
  32. unset(ICU_SETTINGS_RESET CACHE)
  33. unset(ICU_INCLUDE_PATH CACHE)
  34. unset(ICU_INCLUDE_PATH_SH CACHE)
  35. unset(NO_ICU_PATH_GIVEN_SH CACHE)
  36. unset(NO_ICU_PATH_GIVEN CACHE)
  37. unset(CC_EMBED_ICU_SH CACHE)
  38. endif()
  39. if(CC_EMBED_ICU_SH)
  40. unset(CC_EMBED_ICU_SH CACHE)
  41. set(CC_EMBED_ICU 1)
  42. set(ICU_INCLUDE_PATH "deps/icu/source/output/include/")
  43. add_definitions(-DU_STATIC_IMPLEMENTATION)
  44. endif()
  45. if(ICU_INCLUDE_PATH_SH)
  46. set(ICU_INCLUDE_PATH ${ICU_INCLUDE_PATH_SH})
  47. unset(NO_ICU_PATH_GIVEN_SH CACHE)
  48. unset(NO_ICU_PATH_GIVEN CACHE)
  49. unset(ICU_INCLUDE_PATH_SH CACHE)
  50. endif()
  51. if(NO_ICU_PATH_GIVEN_SH)
  52. set(NO_ICU_PATH_GIVEN ${NO_ICU_PATH_GIVEN_SH})
  53. unset(NO_ICU_PATH_GIVEN_SH CACHE)
  54. unset(ICU_INCLUDE_PATH_SH CACHE)
  55. unset(ICU_INCLUDE_PATH CACHE)
  56. endif()
  57. function(clr_unknown_arch)
  58. if (WIN32)
  59. message(FATAL_ERROR "Only AMD64, ARM and I386 are supported")
  60. else()
  61. message(FATAL_ERROR "Only AMD64 and I386 are supported")
  62. endif()
  63. endfunction()
  64. if(ICU_INCLUDE_PATH)
  65. add_definitions(-DHAS_REAL_ICU=1)
  66. set(ICU_CC_PATH "${ICU_INCLUDE_PATH}/../lib/")
  67. find_library(ICUUC icuuc PATHS ${ICU_CC_PATH} NO_DEFAULT_PATH)
  68. find_library(ICU18 icui18n PATHS ${ICU_CC_PATH} NO_DEFAULT_PATH)
  69. find_library(ICUDATA icudata PATHS ${ICU_CC_PATH} NO_DEFAULT_PATH)
  70. if(ICUUC)
  71. message("found libraries on ${ICU_CC_PATH}")
  72. set(ICULIB
  73. ${ICUUC}
  74. ${ICU18}
  75. ${ICUDATA}
  76. )
  77. endif()
  78. elseif(CC_EMBED_ICU)
  79. set(ICU_CC_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../deps/icu/source/output/lib/")
  80. find_library(ICUUC icuuc PATHS ${ICU_CC_PATH} NO_DEFAULT_PATH)
  81. find_library(ICU18 icui18n PATHS ${ICU_CC_PATH} NO_DEFAULT_PATH)
  82. find_library(ICUDATA icudata PATHS ${ICU_CC_PATH} NO_DEFAULT_PATH)
  83. set(ICULIB
  84. ${ICUUC}
  85. ${ICU18}
  86. ${ICUDATA}
  87. )
  88. endif()
  89. set(CLR_CMAKE_PLATFORM_XPLAT 1)
  90. if(CC_TARGETS_AMD64)
  91. add_definitions(-D_M_X64_OR_ARM64)
  92. add_compile_options(-msse4.2)
  93. elseif(CC_TARGETS_X86)
  94. add_definitions(-D__i686__)
  95. add_definitions(-D_M_IX86_OR_ARM32)
  96. add_compile_options(-arch i386)
  97. add_compile_options(-msse3)
  98. set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} \
  99. -m32"
  100. )
  101. else()
  102. clr_unknown_arch()
  103. endif()
  104. if(CMAKE_SYSTEM_NAME STREQUAL Linux)
  105. if(NOT ICULIB)
  106. if(NOT NO_ICU_PATH_GIVEN)
  107. if(NOT CC_EMBED_ICU)
  108. set(ICULIB "icuuc")
  109. endif()
  110. add_definitions(-DHAS_REAL_ICU=1)
  111. endif()
  112. endif()
  113. set(CLR_CMAKE_PLATFORM_LINUX 1)
  114. # OSX 10.12 Clang deprecates libstdc++ [See GH #1599]
  115. # So, -Werror is linux only for now
  116. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
  117. -Werror"
  118. )
  119. elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
  120. add_definitions(
  121. -DPLATFORM_UNIX
  122. )
  123. if(NOT ICULIB)
  124. if(NOT NO_ICU_PATH_GIVEN)
  125. add_definitions(-DHAS_REAL_ICU=1)
  126. if(NOT CC_EMBED_ICU)
  127. set(ICULIB "icucore")
  128. add_definitions(
  129. -DU_DISABLE_RENAMING=1 #in case we link against to an older binary of icu
  130. )
  131. endif()
  132. message("using ICU from system default: ${ICULIB}")
  133. endif()
  134. endif()
  135. if(NOT CC_XCODE_PROJECT)
  136. set(CLR_CMAKE_PLATFORM_DARWIN 1)
  137. add_compile_options(-mmacosx-version-min=10.7)
  138. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} \
  139. -mmacosx-version-min=10.7")
  140. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
  141. -mmacosx-version-min=10.7")
  142. endif()
  143. else()
  144. message(FATAL_ERROR "This OS is not supported")
  145. endif()
  146. if (CMAKE_CXX_COMPILER_ID STREQUAL AppleClang
  147. OR CMAKE_CXX_COMPILER_ID STREQUAL Clang
  148. OR CMAKE_CXX_COMPILER_ID STREQUAL GNU)
  149. # Color diagnostics for g++ and clang++
  150. add_definitions("-fdiagnostics-color=always")
  151. endif()
  152. if(STATIC_LIBRARY)
  153. add_definitions(-DCHAKRA_STATIC_LIBRARY=1)
  154. endif()
  155. if(CLR_CMAKE_PLATFORM_XPLAT)
  156. add_definitions(-DPLATFORM_UNIX=1)
  157. if(CLR_CMAKE_PLATFORM_LINUX)
  158. add_definitions(-D__LINUX__=1)
  159. if(CC_TARGETS_AMD64)
  160. add_definitions(-DLINUX64)
  161. endif(CC_TARGETS_AMD64)
  162. endif(CLR_CMAKE_PLATFORM_LINUX)
  163. if(CC_TARGETS_AMD64)
  164. set(IS_64BIT_BUILD 1)
  165. add_definitions(-D_M_X64 -D_M_AMD64 -D_AMD64_)
  166. endif(CC_TARGETS_AMD64)
  167. add_definitions(
  168. -DUNICODE
  169. -D_SAFECRT_USE_CPP_OVERLOADS=1
  170. -D__STDC_WANT_LIB_EXT1__=1
  171. )
  172. set(CMAKE_CXX_STANDARD 11)
  173. # CC WARNING FLAGS
  174. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} \
  175. -Wno-implicit-function-declaration"
  176. )
  177. # todo: fix general visibility of the interface
  178. # do not set to `fvisibility=hidden` as it is going to
  179. # prevent the required interface is being exported
  180. # clang by default sets fvisibility=default
  181. # CXX WARNING FLAGS
  182. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
  183. -Wno-ignored-attributes\
  184. -Wno-deprecated-declarations\
  185. -Wno-parentheses-equality\
  186. -Wno-missing-braces\
  187. -Wno-reorder\
  188. -Wno-microsoft\
  189. -Wno-unused-value\
  190. -Wno-int-to-void-pointer-cast\
  191. -Wno-invalid-offsetof\
  192. -Wno-undefined-inline\
  193. -Wno-inconsistent-missing-override\
  194. -Wno-c++14-extensions\
  195. -Wno-macro-redefined\
  196. -Wno-pragmas\
  197. -Wno-invalid-token-paste\
  198. -Wno-format\
  199. -Wno-invalid-noreturn\
  200. -Wno-null-arithmetic\
  201. -Wno-tautological-constant-out-of-range-compare\
  202. -Wno-tautological-undefined-compare\
  203. -Wno-address-of-temporary\
  204. -Wno-null-conversion\
  205. -Wno-return-type\
  206. -Wno-switch\
  207. -Wno-int-to-pointer-cast"
  208. )
  209. # notes..
  210. # -Wno-address-of-temporary # vtinfo.h, VirtualTableInfo<T>::RegisterVirtualTable
  211. # -Wno-null-conversion # Check shmemory.cpp and cs.cpp here...
  212. # -Wno-return-type # switch unreachable code
  213. # -Wno-switch # switch values not handled
  214. # xplat-todo for release build
  215. # -fno-inline.... -> -mno-omit.... are needed for more accurate stack inf.
  216. # Release Builds: Not sure if this has to be as strict as the debug/test?
  217. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
  218. -fdelayed-template-parsing\
  219. -fno-omit-frame-pointer\
  220. -fno-optimize-sibling-calls\
  221. -mno-omit-leaf-frame-pointer" # this is for compat reasons. i.e. It is a noop with gcc
  222. )
  223. # CXX / CC COMPILER FLAGS
  224. add_compile_options(
  225. -fasm-blocks
  226. -fms-extensions
  227. -fwrapv # Treat signed integer overflow as two's complement
  228. )
  229. # Clang -fsanitize.
  230. if (CLANG_SANITIZE_SH)
  231. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=${CLANG_SANITIZE_SH}")
  232. set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -fsanitize=${CLANG_SANITIZE_SH}")
  233. unset(CLANG_SANITIZE_SH CACHE) # don't cache
  234. endif()
  235. endif(CLR_CMAKE_PLATFORM_XPLAT)
  236. if(ENABLE_FULL_LTO_SH)
  237. unset(DENABLE_FULL_LTO_SH CACHE)
  238. add_compile_options(-flto)
  239. elseif(ENABLE_THIN_LTO_SH)
  240. unset(ENABLE_THIN_LTO_SH CACHE)
  241. add_compile_options(-flto=thin)
  242. endif()
  243. if(CMAKE_BUILD_TYPE STREQUAL Debug)
  244. add_definitions(
  245. -DDBG=1
  246. -DDEBUG=1
  247. -D_DEBUG=1 # for PAL
  248. -DDBG_DUMP=1
  249. )
  250. elseif(CMAKE_BUILD_TYPE STREQUAL Test)
  251. add_definitions(
  252. -DENABLE_DEBUG_CONFIG_OPTIONS=1
  253. )
  254. endif(CMAKE_BUILD_TYPE STREQUAL Debug)
  255. if(NOT CMAKE_BUILD_TYPE STREQUAL Debug)
  256. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
  257. -O3"
  258. )
  259. endif(NOT CMAKE_BUILD_TYPE STREQUAL Debug)
  260. if(IS_64BIT_BUILD)
  261. add_definitions(
  262. -DBIT64=1
  263. -DSTACK_ALIGN=16
  264. )
  265. endif(IS_64BIT_BUILD)
  266. if(CLR_CMAKE_PLATFORM_XPLAT)
  267. add_definitions(-DFEATURE_PAL)
  268. endif(CLR_CMAKE_PLATFORM_XPLAT)
  269. if(NO_JIT_SH)
  270. unset(NO_JIT_SH CACHE) # don't cache
  271. unset(BuildJIT CACHE) # also clear it just in case
  272. add_definitions(-DDISABLE_JIT=1)
  273. else()
  274. set(BuildJIT 1)
  275. endif()
  276. if(WITHOUT_FEATURES_SH)
  277. unset(WITHOUT_FEATURES_SH CACHE) # don't cache
  278. add_definitions(${WITHOUT_FEATURES_SH})
  279. endif(WITHOUT_FEATURES_SH)
  280. enable_language(ASM)
  281. include_directories(
  282. .
  283. lib/Common
  284. lib/Common/PlaceHolder
  285. pal
  286. pal/inc
  287. pal/inc/rt
  288. ${ICU_INCLUDE_PATH}
  289. )
  290. if(ICU_INCLUDE_PATH)
  291. if(NOT HAVE_LIBICU_UCHAR_H)
  292. set(HAVE_LIBICU_UCHAR_H "1")
  293. endif()
  294. endif()
  295. add_subdirectory (pal)
  296. # build the rest with NO_PAL_MINMAX and PAL_STDCPP_COMPAT
  297. add_definitions(
  298. -DNO_PAL_MINMAX
  299. -DPAL_STDCPP_COMPAT
  300. )
  301. add_subdirectory (lib)
  302. add_subdirectory (bin)