CMakeLists.txt (28237B)
1 # AsmJit 2 # ====== 3 4 # To consume asmjit as a dependency, use asmjit::asmjit alias. 5 6 cmake_minimum_required(VERSION 3.24 FATAL_ERROR) 7 8 # Don't create a project if it was already created by another CMakeLists.txt. This makes 9 # it possible to support both add_subdirectory() and include() ways of using AsmJit as a 10 # dependency. 11 if (NOT CMAKE_PROJECT_NAME OR "${CMAKE_PROJECT_NAME}" STREQUAL "asmjit") 12 project(asmjit 13 LANGUAGES CXX 14 DESCRIPTION "Low-latency machine code generation" 15 HOMEPAGE_URL "https://asmjit.com") 16 endif() 17 18 include(CheckCXXCompilerFlag) 19 include(CheckCXXSourceCompiles) 20 include(GNUInstallDirs) 21 22 # AsmJit - Configuration - Build 23 # ============================== 24 25 if (NOT DEFINED ASMJIT_TEST) 26 set(ASMJIT_TEST FALSE) 27 endif() 28 29 if (NOT DEFINED ASMJIT_EMBED) 30 set(ASMJIT_EMBED FALSE) 31 endif() 32 33 if (NOT DEFINED ASMJIT_STATIC) 34 set(ASMJIT_STATIC ${ASMJIT_EMBED}) 35 endif() 36 37 if (NOT DEFINED ASMJIT_SANITIZE) 38 set(ASMJIT_SANITIZE FALSE) 39 endif() 40 41 if (NOT DEFINED ASMJIT_NO_CUSTOM_FLAGS) 42 set(ASMJIT_NO_CUSTOM_FLAGS FALSE) 43 endif() 44 45 if (NOT DEFINED ASMJIT_NO_NATVIS) 46 set(ASMJIT_NO_NATVIS FALSE) 47 endif() 48 49 # EMBED implies STATIC. 50 if (ASMJIT_EMBED AND NOT ASMJIT_STATIC) 51 set(ASMJIT_STATIC TRUE) 52 endif() 53 54 if (NOT DEFINED ASMJIT_NO_DEPRECATED) 55 set(ASMJIT_NO_DEPRECATED FALSE) 56 endif() 57 58 if (NOT DEFINED ASMJIT_NO_ABI_NAMESPACE) 59 set(ASMJIT_NO_ABI_NAMESPACE FALSE) 60 endif() 61 62 # AsmJit - Configuration - Backend 63 # ================================ 64 65 if (NOT DEFINED ASMJIT_NO_X86) 66 set(ASMJIT_NO_X86 FALSE) 67 endif() 68 69 if (NOT DEFINED ASMJIT_NO_AARCH64) 70 set(ASMJIT_NO_AARCH64 FALSE) 71 endif() 72 73 if (NOT DEFINED ASMJIT_NO_FOREIGN) 74 set(ASMJIT_NO_FOREIGN FALSE) 75 endif() 76 77 # AsmJit - Configuration - Features 78 # ================================= 79 80 if (NOT DEFINED ASMJIT_NO_SHM_OPEN) 81 set(ASMJIT_NO_SHM_OPEN FALSE) 82 endif() 83 84 if (NOT DEFINED ASMJIT_NO_JIT) 85 set(ASMJIT_NO_JIT FALSE) 86 endif() 87 88 if (NOT DEFINED ASMJIT_NO_TEXT) 89 set(ASMJIT_NO_TEXT FALSE) 90 endif() 91 92 if (NOT DEFINED ASMJIT_NO_LOGGING) 93 set(ASMJIT_NO_LOGGING ${ASMJIT_NO_TEXT}) 94 endif() 95 96 if (NOT DEFINED ASMJIT_NO_VALIDATION) 97 set(ASMJIT_NO_VALIDATION FALSE) 98 endif() 99 100 if (NOT DEFINED ASMJIT_NO_INTROSPECTION) 101 set(ASMJIT_NO_INTROSPECTION FALSE) 102 endif() 103 104 if (NOT DEFINED ASMJIT_NO_BUILDER) 105 set(ASMJIT_NO_BUILDER FALSE) 106 endif() 107 108 if (NOT DEFINED ASMJIT_NO_COMPILER) 109 if (ASMJIT_NO_BUILDER OR ASMJIT_NO_INTROSPECTION) 110 set(ASMJIT_NO_COMPILER TRUE) 111 else() 112 set(ASMJIT_NO_COMPILER FALSE) 113 endif() 114 endif() 115 116 if (NOT DEFINED ASMJIT_NO_UJIT) 117 if (ASMJIT_NO_COMPILER) 118 set(ASMJIT_NO_UJIT TRUE) 119 else() 120 set(ASMJIT_NO_UJIT FALSE) 121 endif() 122 endif() 123 124 # AsmJit - Configuration - CMake Introspection 125 # ============================================ 126 127 set(ASMJIT_DIR "${CMAKE_CURRENT_LIST_DIR}" CACHE PATH "Location of 'asmjit'") 128 set(ASMJIT_TEST "${ASMJIT_TEST}" CACHE BOOL "Build 'asmjit' test applications") 129 set(ASMJIT_EMBED "${ASMJIT_EMBED}" CACHE BOOL "Embed 'asmjit' library (no targets)") 130 set(ASMJIT_STATIC "${ASMJIT_STATIC}" CACHE BOOL "Build 'asmjit' library as static") 131 set(ASMJIT_SANITIZE "${ASMJIT_SANITIZE}" CACHE STRING "Build with sanitizers: 'address', 'undefined', etc...") 132 set(ASMJIT_NO_NATVIS "${ASMJIT_NO_NATVIS}" CACHE BOOL "Disable natvis support (embedding asmjit.natvis in PDB)") 133 set(ASMJIT_NO_CUSTOM_FLAGS "${ASMJIT_NO_CUSTOM_FLAGS}" CACHE BOOL "Disable extra compilation flags added by AsmJit to its targets") 134 135 set(ASMJIT_NO_X86 "${ASMJIT_NO_X86}" CACHE BOOL "Disable X86/X64 backend") 136 set(ASMJIT_NO_AARCH64 "${ASMJIT_NO_AARCH64}" CACHE BOOL "Disable AArch64 backend") 137 set(ASMJIT_NO_FOREIGN "${ASMJIT_NO_FOREIGN}" CACHE BOOL "Disable all foreign architectures (enables only a target architecture)") 138 139 set(ASMJIT_NO_DEPRECATED "${ASMJIT_NO_DEPRECATED}" CACHE BOOL "Disable deprecated API at build time") 140 set(ASMJIT_NO_ABI_NAMESPACE "${ASMJIT_NO_ABI_NAMESPACE}" CACHE BOOL "Disable the use of ABI namespace (inline namespace in {asmjit} adding ABI version)") 141 142 set(ASMJIT_NO_SHM_OPEN "${ASMJIT_NO_SHM_OPEN}" CACHE BOOL "Disable the use of shm_open() even on platforms where it's supported") 143 set(ASMJIT_NO_JIT "${ASMJIT_NO_JIT}" CACHE BOOL "Disable VirtMem, JitAllocator, and JitRuntime at build time") 144 set(ASMJIT_NO_TEXT "${ASMJIT_NO_TEXT}" CACHE BOOL "Disable textual representation of instructions, enums, cpu features, ...") 145 set(ASMJIT_NO_LOGGING "${ASMJIT_NO_LOGGING}" CACHE BOOL "Disable logging features at build time") 146 set(ASMJIT_NO_VALIDATION "${ASMJIT_NO_VALIDATION}" CACHE BOOL "Disable instruction validation API at build time") 147 set(ASMJIT_NO_INTROSPECTION "${ASMJIT_NO_INTROSPECTION}" CACHE BOOL "Disable instruction introspection API at build time") 148 set(ASMJIT_NO_BUILDER "${ASMJIT_NO_BUILDER}" CACHE BOOL "Disable Builder at build time") 149 set(ASMJIT_NO_COMPILER "${ASMJIT_NO_COMPILER}" CACHE BOOL "Disable Compiler at build time") 150 set(ASMJIT_NO_UJIT "${ASMJIT_NO_UJIT}" CACHE BOOL "Disable UniCompiler at build time") 151 152 # AsmJit - Project 153 # ================ 154 155 set(ASMJIT_INCLUDE_DIRS "${ASMJIT_DIR}/src") # Include directory is the same as source dir. 156 set(ASMJIT_DEPS "") # AsmJit dependencies (libraries) for the linker. 157 set(ASMJIT_LIBS "") # Dependencies of libs/apps that want to use AsmJit. 158 set(ASMJIT_CFLAGS "") # Public compiler flags. 159 set(ASMJIT_PRIVATE_CFLAGS "") # Private compiler flags independent of build type. 160 set(ASMJIT_PRIVATE_CFLAGS_DBG "") # Private compiler flags used by debug builds. 161 set(ASMJIT_PRIVATE_CFLAGS_REL "") # Private compiler flags used by release builds. 162 set(ASMJIT_SANITIZE_CFLAGS "") # Compiler flags required by currently enabled sanitizers. 163 set(ASMJIT_SANITIZE_LFLAGS "") # Linker flags required by currently enabled sanitizers. 164 165 # AsmJit - Utilities 166 # ================== 167 168 function(asmjit_detect_cflags out) 169 set(out_array ${${out}}) 170 foreach(flag ${ARGN}) 171 string(REGEX REPLACE "[+]" "x" flag_signature "${flag}") 172 string(REGEX REPLACE "[-=:;/.\]" "_" flag_signature "${flag_signature}") 173 check_cxx_compiler_flag(${flag} "__CxxFlag_${flag_signature}") 174 if (${__CxxFlag_${flag_signature}}) 175 list(APPEND out_array "${flag}") 176 endif() 177 endforeach() 178 set(${out} "${out_array}" PARENT_SCOPE) 179 endfunction() 180 181 # Support for various sanitizers provided by C/C++ compilers. 182 function(asmjit_detect_sanitizers out) 183 set(_out_array ${${out}}) 184 set(_flags "") 185 186 foreach(_arg ${ARGN}) 187 string(REPLACE "," ";" _arg "${_arg}") 188 list(APPEND _flags ${_arg}) 189 endforeach() 190 191 foreach(_flag ${_flags}) 192 if (NOT "${_flag}" MATCHES "^-fsanitize=") 193 SET(_flag "-fsanitize=${_flag}") 194 endif() 195 196 # Sanitizers also require link flags, see CMAKE_REQUIRED_FLAGS. 197 set(CMAKE_REQUIRED_FLAGS "${_flag}") 198 asmjit_detect_cflags(_out_array ${_flag}) 199 unset(CMAKE_REQUIRED_FLAGS) 200 endforeach() 201 202 set(${out} "${_out_array}" PARENT_SCOPE) 203 endfunction() 204 205 function(asmjit_addapp target target_type) 206 set(single_val "") 207 set(multi_val SOURCES LIBRARIES CFLAGS CFLAGS_DBG CFLAGS_REL) 208 cmake_parse_arguments("X" "" "${single_val}" "${multi_val}" ${ARGN}) 209 210 if ("${target_type}" MATCHES "^(EXECUTABLE|TEST)$") 211 add_executable(${target} ${X_SOURCES}) 212 else() 213 add_library(${target} ${target_type} ${X_SOURCES}) 214 endif() 215 216 set_target_properties(${target} 217 PROPERTIES 218 DEFINE_SYMBOL "" 219 CXX_VISIBILITY_PRESET hidden) 220 target_compile_options(${target} PRIVATE ${X_CFLAGS} ${ASMJIT_SANITIZE_CFLAGS} $<$<CONFIG:Debug>:${X_CFLAGS_DBG}> $<$<NOT:$<CONFIG:Debug>>:${X_CFLAGS_REL}>) 221 target_compile_features(${target} PUBLIC cxx_std_17) 222 target_link_options(${target} PRIVATE ${ASMJIT_PRIVATE_LFLAGS}) 223 target_link_libraries(${target} PRIVATE ${X_LIBRARIES}) 224 225 if ("${target_type}" STREQUAL "TEST") 226 add_test(NAME ${target} COMMAND ${target}) 227 endif() 228 endfunction() 229 230 # AsmJit - Compiler Support 231 # ========================= 232 233 # We will have to keep this most likely forever as some users may still be using it. 234 set(ASMJIT_INCLUDE_DIR "${ASMJIT_INCLUDE_DIRS}") 235 236 if (NOT ASMJIT_NO_CUSTOM_FLAGS) 237 if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" OR "x${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}" STREQUAL "xMSVC") 238 list(APPEND ASMJIT_PRIVATE_CFLAGS -W4) # [+] Warning level 4. 239 240 list(APPEND ASMJIT_PRIVATE_CFLAGS -MP) # [+] Multi-Process Compilation. 241 list(APPEND ASMJIT_PRIVATE_CFLAGS -GF) # [+] Eliminate duplicate strings. 242 list(APPEND ASMJIT_PRIVATE_CFLAGS -Zc:__cplusplus) # [+] Conforming __cplusplus definition. 243 list(APPEND ASMJIT_PRIVATE_CFLAGS -Zc:inline) # [+] Remove unreferenced COMDAT. 244 list(APPEND ASMJIT_PRIVATE_CFLAGS -Zc:strictStrings) # [+] Strict const qualification of string literals. 245 list(APPEND ASMJIT_PRIVATE_CFLAGS -Zc:threadSafeInit-) # [-] Thread-safe statics. 246 247 list(APPEND ASMJIT_PRIVATE_CFLAGS_DBG -GS) # [+] Buffer security-check. 248 list(APPEND ASMJIT_PRIVATE_CFLAGS_REL -GS-) # [-] Buffer security-check. 249 list(APPEND ASMJIT_PRIVATE_CFLAGS_REL -O2) # [+] Favor speed over size. 250 list(APPEND ASMJIT_PRIVATE_CFLAGS_REL -Oi) # [+] Generate intrinsic functions. 251 elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU|Clang") 252 list(APPEND ASMJIT_PRIVATE_CFLAGS -Wall -Wextra -Wconversion) # [+] Add baseline warnings that can be used safely even with system headers. 253 asmjit_detect_cflags(ASMJIT_PRIVATE_CFLAGS -Wdouble-promotion) # [+] Warn about double promotions. 254 asmjit_detect_cflags(ASMJIT_PRIVATE_CFLAGS -Wduplicated-cond) # [+] Warn about duplicate conditions. 255 asmjit_detect_cflags(ASMJIT_PRIVATE_CFLAGS -Wduplicated-branches) # [+] Warn about duplicate branches. 256 asmjit_detect_cflags(ASMJIT_PRIVATE_CFLAGS -Wlogical-op) # [+] Warn about suspicious uses of logical operators in expressions. 257 asmjit_detect_cflags(ASMJIT_PRIVATE_CFLAGS -Wlogical-not-parentheses) # [+] Warn about logical not used on the left hand side operand of a comparison. 258 asmjit_detect_cflags(ASMJIT_PRIVATE_CFLAGS -Wrestrict) 259 260 list(APPEND ASMJIT_PRIVATE_CFLAGS -fno-math-errno) # [-] Disable math functions setting errno (performance reasons). 261 list(APPEND ASMJIT_PRIVATE_CFLAGS -fno-threadsafe-statics) # [-] Don't add guards when initializing statics (we don't need it). 262 list(APPEND ASMJIT_PRIVATE_CFLAGS_REL -O2) # [+] Compiling with -O2 in release mode is what we generally want. 263 list(APPEND ASMJIT_PRIVATE_CFLAGS_REL -fmerge-all-constants) # [+] We don't need unique address per constant (merging improves library size). 264 265 # -fno-semantic-interposition is not available on apple - the compiler issues a warning, which is not detected. 266 if (NOT APPLE) 267 asmjit_detect_cflags(ASMJIT_PRIVATE_CFLAGS -fno-semantic-interposition) 268 endif() 269 270 if (NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "iOS") 271 asmjit_detect_cflags(ASMJIT_PRIVATE_CFLAGS_REL -fno-enforce-eh-specs) # [-] Don't enforce termination if noexcept function throws. 272 endif() 273 endif() 274 endif() 275 276 # Support for sanitizers. 277 if (ASMJIT_SANITIZE) 278 asmjit_detect_sanitizers(ASMJIT_SANITIZE_CFLAGS ${ASMJIT_SANITIZE}) 279 if (ASMJIT_SANITIZE_CFLAGS) 280 message("-- Enabling sanitizers: '${ASMJIT_SANITIZE_CFLAGS}'") 281 282 # Linker must receive the same flags as the compiler when it comes to sanitizers. 283 set(ASMJIT_SANITIZE_LFLAGS ${ASMJIT_SANITIZE_CFLAGS}) 284 285 # Don't omit frame pointer if sanitizers are enabled. 286 if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" OR "x${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}" STREQUAL "xMSVC") 287 list(APPEND ASMJIT_SANITIZE_CFLAGS -Oy-) 288 else() 289 list(APPEND ASMJIT_SANITIZE_CFLAGS -fno-omit-frame-pointer -g) 290 endif() 291 292 list(APPEND ASMJIT_PRIVATE_CFLAGS ${ASMJIT_SANITIZE_CFLAGS}) 293 list(APPEND ASMJIT_PRIVATE_LFLAGS ${ASMJIT_SANITIZE_LFLAGS}) 294 endif() 295 endif() 296 297 if (WIN32) 298 # Dependency: nothing extra at the moment. 299 elseif ("${CMAKE_SYSTEM_NAME}" STREQUAL "Android") 300 # Dependency: libc is the only required library on Android as it also provides libthread. 301 message("-- Dependency: adding libc (Android target detected)") 302 list(APPEND ASMJIT_DEPS c) 303 elseif ("${CMAKE_SYSTEM_NAME}" STREQUAL "Haiku") 304 # Dependency: libroot is used by Haiku instead of libc, so link to libroot and libpthread. 305 message("-- Dependency: adding libroot and libpthread (Haiku target detected)") 306 list(APPEND ASMJIT_DEPS root pthread) 307 else() 308 # Dependency: libc is always required. 309 message("-- Dependency: adding libc (Linux, BSD, or other UNIX/POSIX environment)") 310 list(APPEND ASMJIT_DEPS c) 311 312 # Dependency: pthread (required so AsmJit can use pthread_lock). 313 check_cxx_source_compiles(" 314 #include <pthread.h> 315 int main() { 316 pthread_mutex_t m; 317 pthread_mutex_init(&m, nullptr); 318 return pthread_mutex_destroy(&m); 319 } 320 " ASMJIT_LIBC_HAS_LIBPTHREAD) 321 if (ASMJIT_LIBC_HAS_LIBPTHREAD) 322 message("-- Dependency: libpthread provided by libc (not linking to libpthread)") 323 else() 324 message("-- Dependency: libpthread not provided by libc, linking to libpthread") 325 list(APPEND ASMJIT_DEPS pthread) 326 endif() 327 328 # Dependency: shm_open (required so AsmJit can use shm_open on supported platforms). 329 if ("${CMAKE_SYSTEM_NAME}" MATCHES "^(Linux|NetBSD)$" AND NOT ASMJIT_NO_SHM_OPEN) 330 check_cxx_source_compiles(" 331 #include <sys/mman.h> 332 int main() { 333 const char file_name[1] {}; 334 return shm_open(file_name, 0, 0); 335 } 336 " ASMJIT_LIBC_HAS_LIBRT) 337 if (ASMJIT_LIBC_HAS_LIBRT) 338 message("-- Dependency: shm_open provided by libc (not linking to librt)") 339 else() 340 message("-- Dependency: shm_open not provided by libc, linking to librt") 341 list(APPEND ASMJIT_DEPS rt) 342 endif() 343 endif() 344 endif() 345 346 set(ASMJIT_LIBS ${ASMJIT_DEPS}) 347 if (NOT ASMJIT_EMBED) 348 list(INSERT ASMJIT_LIBS 0 asmjit) 349 endif() 350 351 if (ASMJIT_EMBED) 352 set(ASMJIT_TARGET_TYPE "EMBED") 353 elseif (ASMJIT_STATIC) 354 set(ASMJIT_TARGET_TYPE "STATIC") 355 else() 356 set(ASMJIT_TARGET_TYPE "SHARED") 357 endif() 358 359 foreach(build_option # AsmJit build options. 360 ASMJIT_STATIC 361 ASMJIT_NO_DEPRECATED 362 ASMJIT_NO_ABI_NAMESPACE 363 # AsmJit backends selection. 364 ASMJIT_NO_X86 365 ASMJIT_NO_AARCH64 366 ASMJIT_NO_FOREIGN 367 # AsmJit features selection. 368 ASMJIT_NO_SHM_OPEN 369 ASMJIT_NO_JIT 370 ASMJIT_NO_TEXT 371 ASMJIT_NO_LOGGING 372 ASMJIT_NO_INTROSPECTION 373 ASMJIT_NO_VALIDATION 374 ASMJIT_NO_BUILDER 375 ASMJIT_NO_COMPILER 376 ASMJIT_NO_UJIT) 377 if (${build_option}) 378 List(APPEND ASMJIT_CFLAGS "-D${build_option}") 379 List(APPEND ASMJIT_PRIVATE_CFLAGS "-D${build_option}") 380 endif() 381 endforeach() 382 383 # AsmJit - Linker Support 384 # ======================= 385 386 if (WIN32) 387 if (CMAKE_LINKER MATCHES "link\\.exe" OR CMAKE_LINKER MATCHES "lld-link\\.exe") 388 set(ASMJIT_LINKER_SUPPORTS_NATVIS TRUE) 389 endif() 390 endif() 391 392 # AsmJit - Source 393 # =============== 394 395 set(ASMJIT_SRC_LIST 396 asmjit/asmjit.h 397 asmjit/asmjit-scope-begin.h 398 asmjit/asmjit-scope-end.h 399 400 asmjit/core.h 401 asmjit/core/api-build_p.h 402 asmjit/core/api-config.h 403 asmjit/core/arena.cpp 404 asmjit/core/arena.h 405 asmjit/core/arenabitset.cpp 406 asmjit/core/arenabitset_p.h 407 asmjit/core/arenahash.cpp 408 asmjit/core/arenahash.h 409 asmjit/core/arenalist.cpp 410 asmjit/core/arenalist.h 411 asmjit/core/arenapool.h 412 asmjit/core/arenastring.h 413 asmjit/core/arenatree.cpp 414 asmjit/core/arenatree.h 415 asmjit/core/arenavector.cpp 416 asmjit/core/arenavector.h 417 asmjit/core/archtraits.cpp 418 asmjit/core/archtraits.h 419 asmjit/core/archcommons.h 420 asmjit/core/assembler.cpp 421 asmjit/core/assembler.h 422 asmjit/core/builder.cpp 423 asmjit/core/builder.h 424 asmjit/core/codebuffer.h 425 asmjit/core/codeholder.cpp 426 asmjit/core/codeholder.h 427 asmjit/core/codewriter.cpp 428 asmjit/core/codewriter_p.h 429 asmjit/core/compiler.cpp 430 asmjit/core/compiler.h 431 asmjit/core/compilerdefs.h 432 asmjit/core/constpool.cpp 433 asmjit/core/constpool.h 434 asmjit/core/cpuinfo.cpp 435 asmjit/core/cpuinfo.h 436 asmjit/core/emithelper.cpp 437 asmjit/core/emithelper_p.h 438 asmjit/core/emitter.cpp 439 asmjit/core/emitter.h 440 asmjit/core/emitterutils.cpp 441 asmjit/core/emitterutils_p.h 442 asmjit/core/environment.cpp 443 asmjit/core/environment.h 444 asmjit/core/errorhandler.cpp 445 asmjit/core/errorhandler.h 446 asmjit/core/fixup.h 447 asmjit/core/formatter.cpp 448 asmjit/core/formatter.h 449 asmjit/core/func.cpp 450 asmjit/core/func.h 451 asmjit/core/funcargscontext.cpp 452 asmjit/core/funcargscontext_p.h 453 asmjit/core/globals.cpp 454 asmjit/core/globals.h 455 asmjit/core/inst.cpp 456 asmjit/core/inst.h 457 asmjit/core/instdb.cpp 458 asmjit/core/instdb_p.h 459 asmjit/core/jitallocator.cpp 460 asmjit/core/jitallocator.h 461 asmjit/core/jitruntime.cpp 462 asmjit/core/jitruntime.h 463 asmjit/core/logger.cpp 464 asmjit/core/logger.h 465 asmjit/core/misc_p.h 466 asmjit/core/operand.cpp 467 asmjit/core/operand.h 468 asmjit/core/osutils.cpp 469 asmjit/core/osutils.h 470 asmjit/core/osutils_p.h 471 asmjit/core/raassignment_p.h 472 asmjit/core/racfgblock_p.h 473 asmjit/core/racfgbuilder_p.h 474 asmjit/core/raconstraints_p.h 475 asmjit/core/radefs_p.h 476 asmjit/core/rainst_p.h 477 asmjit/core/ralocal.cpp 478 asmjit/core/ralocal_p.h 479 asmjit/core/rapass.cpp 480 asmjit/core/rapass_p.h 481 asmjit/core/rastack.cpp 482 asmjit/core/rastack_p.h 483 asmjit/core/span.h 484 asmjit/core/string.cpp 485 asmjit/core/string.h 486 asmjit/core/support.cpp 487 asmjit/core/support.h 488 asmjit/core/target.cpp 489 asmjit/core/target.h 490 asmjit/core/type.cpp 491 asmjit/core/type.h 492 asmjit/core/virtmem.cpp 493 asmjit/core/virtmem.h 494 495 asmjit/a64.h 496 asmjit/arm.h 497 asmjit/arm/armformatter.cpp 498 asmjit/arm/armformatter_p.h 499 asmjit/arm/armglobals.h 500 asmjit/arm/armutils.h 501 asmjit/arm/a64archtraits_p.h 502 asmjit/arm/a64assembler.cpp 503 asmjit/arm/a64assembler.h 504 asmjit/arm/a64builder.cpp 505 asmjit/arm/a64builder.h 506 asmjit/arm/a64compiler.cpp 507 asmjit/arm/a64compiler.h 508 asmjit/arm/a64emithelper.cpp 509 asmjit/arm/a64emithelper_p.h 510 asmjit/arm/a64emitter.h 511 asmjit/arm/a64formatter.cpp 512 asmjit/arm/a64formatter_p.h 513 asmjit/arm/a64func.cpp 514 asmjit/arm/a64func_p.h 515 asmjit/arm/a64globals.h 516 asmjit/arm/a64instapi.cpp 517 asmjit/arm/a64instapi_p.h 518 asmjit/arm/a64instdb.cpp 519 asmjit/arm/a64instdb.h 520 asmjit/arm/a64operand.cpp 521 asmjit/arm/a64operand.h 522 asmjit/arm/a64rapass.cpp 523 asmjit/arm/a64rapass_p.h 524 525 asmjit/x86.h 526 asmjit/x86/x86archtraits_p.h 527 asmjit/x86/x86assembler.cpp 528 asmjit/x86/x86assembler.h 529 asmjit/x86/x86builder.cpp 530 asmjit/x86/x86builder.h 531 asmjit/x86/x86compiler.cpp 532 asmjit/x86/x86compiler.h 533 asmjit/x86/x86emithelper.cpp 534 asmjit/x86/x86emithelper_p.h 535 asmjit/x86/x86emitter.h 536 asmjit/x86/x86formatter.cpp 537 asmjit/x86/x86formatter_p.h 538 asmjit/x86/x86func.cpp 539 asmjit/x86/x86func_p.h 540 asmjit/x86/x86globals.h 541 asmjit/x86/x86instdb.cpp 542 asmjit/x86/x86instdb.h 543 asmjit/x86/x86instdb_p.h 544 asmjit/x86/x86instapi.cpp 545 asmjit/x86/x86instapi_p.h 546 asmjit/x86/x86operand.cpp 547 asmjit/x86/x86operand.h 548 asmjit/x86/x86rapass.cpp 549 asmjit/x86/x86rapass_p.h 550 551 asmjit/ujit/ujitbase.h 552 asmjit/ujit/unicompiler.h 553 asmjit/ujit/unicompiler_a64.cpp 554 asmjit/ujit/unicompiler_x86.cpp 555 asmjit/ujit/unicompiler_utils_p.h 556 asmjit/ujit/uniop.h 557 asmjit/ujit/vecconsttable.cpp 558 asmjit/ujit/vecconsttable.h 559 ) 560 561 if (MSVC AND NOT ASMJIT_NO_NATVIS) 562 list(APPEND ASMJIT_SRC_LIST asmjit.natvis) 563 endif() 564 565 set(ASMJIT_SRC "") 566 foreach(src_file ${ASMJIT_SRC_LIST}) 567 set(src_file "${ASMJIT_DIR}/src/${src_file}") 568 list(APPEND ASMJIT_SRC ${src_file}) 569 570 if ("${src_file}" MATCHES "\\.natvis") 571 if (ASMJIT_LINKER_SUPPORTS_NATVIS) 572 list(APPEND ASMJIT_PRIVATE_LFLAGS "-natvis:${src_file}") 573 endif() 574 endif() 575 endforeach() 576 577 source_group(TREE "${ASMJIT_DIR}" FILES ${ASMJIT_SRC}) 578 579 # AsmJit - Summary 580 # ================ 581 582 message("** AsmJit Summary **") 583 message(" ASMJIT_DIR=${ASMJIT_DIR}") 584 message(" ASMJIT_TEST=${ASMJIT_TEST}") 585 message(" ASMJIT_TARGET_TYPE=${ASMJIT_TARGET_TYPE}") 586 message(" ASMJIT_DEPS=${ASMJIT_DEPS}") 587 message(" ASMJIT_LIBS=${ASMJIT_LIBS}") 588 message(" ASMJIT_CFLAGS=${ASMJIT_CFLAGS}") 589 message(" ASMJIT_PRIVATE_CFLAGS=${ASMJIT_PRIVATE_CFLAGS}") 590 message(" ASMJIT_PRIVATE_CFLAGS_DBG=${ASMJIT_PRIVATE_CFLAGS_DBG}") 591 message(" ASMJIT_PRIVATE_CFLAGS_REL=${ASMJIT_PRIVATE_CFLAGS_REL}") 592 593 # AsmJit - Targets 594 # ================ 595 596 if (NOT ASMJIT_EMBED) 597 # Add AsmJit target. 598 asmjit_addapp(asmjit "${ASMJIT_TARGET_TYPE}" 599 SOURCES ${ASMJIT_SRC} 600 LIBRARIES ${ASMJIT_DEPS} 601 CFLAGS ${ASMJIT_PRIVATE_CFLAGS} 602 CFLAGS_DBG ${ASMJIT_PRIVATE_CFLAGS_DBG} 603 CFLAGS_REL ${ASMJIT_PRIVATE_CFLAGS_REL}) 604 605 target_compile_options(asmjit INTERFACE ${ASMJIT_CFLAGS}) 606 target_include_directories(asmjit BEFORE INTERFACE 607 $<BUILD_INTERFACE:${ASMJIT_INCLUDE_DIRS}> 608 $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>) 609 610 # Create an asmjit::asmjit alias. 611 add_library(asmjit::asmjit ALIAS asmjit) 612 613 # Add AsmJit install instructions (library and public headers). 614 if (NOT ASMJIT_NO_INSTALL) 615 install(TARGETS asmjit 616 EXPORT asmjit-config 617 RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" 618 ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" 619 LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" 620 INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") 621 install(EXPORT asmjit-config 622 NAMESPACE asmjit:: 623 DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/asmjit") 624 625 foreach(_src_file ${ASMJIT_SRC_LIST}) 626 if ("${_src_file}" MATCHES "\\.h$" AND NOT "${_src_file}" MATCHES "_p\\.h$") 627 get_filename_component(_src_dir ${_src_file} PATH) 628 install(FILES "${ASMJIT_DIR}/src/${_src_file}" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${_src_dir}") 629 endif() 630 endforeach() 631 endif() 632 633 # Add AsmJit tests. 634 if (ASMJIT_TEST) 635 enable_testing() 636 637 # Special target that always uses embedded AsmJit. 638 asmjit_addapp(asmjit_test_runner TEST 639 SOURCES ${ASMJIT_SRC} 640 testing/tests/asmjit_test_runner.cpp 641 testing/tests/broken.cpp 642 testing/tests/broken.h 643 LIBRARIES ${ASMJIT_DEPS} 644 CFLAGS ${ASMJIT_PRIVATE_CFLAGS} 645 -DASMJIT_TEST 646 -DASMJIT_STATIC 647 CFLAGS_DBG ${ASMJIT_PRIVATE_CFLAGS_DBG} 648 CFLAGS_REL ${ASMJIT_PRIVATE_CFLAGS_REL}) 649 target_include_directories(asmjit_test_runner BEFORE PRIVATE ${ASMJIT_INCLUDE_DIRS}) 650 651 asmjit_addapp(asmjit_test_assembler TEST 652 SOURCES testing/tests/asmjit_test_assembler.cpp 653 testing/tests/asmjit_test_assembler.h 654 testing/tests/asmjit_test_assembler_a64.cpp 655 testing/tests/asmjit_test_assembler_x64.cpp 656 testing/tests/asmjit_test_assembler_x86.cpp 657 LIBRARIES asmjit::asmjit 658 CFLAGS ${ASMJIT_PRIVATE_CFLAGS} 659 CFLAGS_DBG ${ASMJIT_PRIVATE_CFLAGS_DBG} 660 CFLAGS_REL ${ASMJIT_PRIVATE_CFLAGS_REL}) 661 662 foreach(app asmjit_test_environment asmjit_test_emitters asmjit_test_x86_sections) 663 asmjit_addapp(${app} TEST 664 SOURCES testing/tests/${app}.cpp 665 LIBRARIES asmjit::asmjit 666 CFLAGS ${ASMJIT_PRIVATE_CFLAGS} 667 CFLAGS_DBG ${ASMJIT_PRIVATE_CFLAGS_DBG} 668 CFLAGS_REL ${ASMJIT_PRIVATE_CFLAGS_REL}) 669 endforeach() 670 671 if (NOT ASMJIT_NO_INTROSPECTION) 672 asmjit_addapp(asmjit_test_instinfo TEST 673 SOURCES testing/tests/asmjit_test_instinfo.cpp 674 LIBRARIES asmjit::asmjit 675 CFLAGS ${ASMJIT_PRIVATE_CFLAGS} 676 CFLAGS_DBG ${ASMJIT_PRIVATE_CFLAGS_DBG} 677 CFLAGS_REL ${ASMJIT_PRIVATE_CFLAGS_REL}) 678 endif() 679 680 if (NOT (ASMJIT_NO_BUILDER OR ASMJIT_NO_COMPILER)) 681 # Vectorcall tests and XMM tests require at least SSE2 in 32-bit mode (in 64-bit mode it's implicit). 682 # Some compilers don't like passing -msse2 for 64-bit targets, and some compilers targeting non-x86 683 # would pass "-msse2" compile flag check, but with a warning not detected by CMake. Thus, verify that 684 # our target is really 32-bit X86 and only use -msse2 or -arch:SSE2 flags when necessary. 685 set(ASMJIT_SSE2_CFLAGS "") 686 687 check_cxx_source_compiles(" 688 #if defined(_M_X64) || defined(__x86_64__) 689 // Skip... 690 #elif defined(_M_IX86) || defined(__X86__) || defined(__i386__) 691 int target_arch_is_x86() { return 1; } 692 #endif 693 int main() { return target_arch_is_x86(); } 694 " ASMJIT_TARGET_ARCH_X86) 695 696 check_cxx_source_compiles(" 697 #if defined(_M_X64) || defined(__x86_64__) 698 int target_arch_is_x86_64() { return 1; } 699 #endif 700 int main() { return target_arch_is_x86_64(); } 701 " ASMJIT_TARGET_ARCH_X86_64) 702 703 if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" OR "x${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}" STREQUAL "xMSVC") 704 if (ASMJIT_TARGET_ARCH_X86) 705 asmjit_detect_cflags(ASMJIT_SSE2_CFLAGS -arch:SSE2) 706 endif() 707 if (ASMJIT_TARGET_ARCH_X86 OR ASMJIT_TARGET_ARCH_X86_64) 708 asmjit_detect_cflags(ASMJIT_AVX2FMA_CFLAGS -arch:AVX2) 709 endif() 710 else() 711 if (ASMJIT_TARGET_ARCH_X86) 712 asmjit_detect_cflags(ASMJIT_SSE2_CFLAGS -msse2) 713 endif() 714 if (ASMJIT_TARGET_ARCH_X86 OR ASMJIT_TARGET_ARCH_X86_64) 715 asmjit_detect_cflags(ASMJIT_AVX2FMA_CFLAGS -mavx2 -mfma) 716 endif() 717 endif() 718 719 asmjit_addapp(asmjit_test_compiler TEST 720 SOURCES testing/tests/asmjit_test_compiler.cpp 721 testing/tests/asmjit_test_compiler.h 722 testing/tests/asmjit_test_compiler_a64.cpp 723 testing/tests/asmjit_test_compiler_x86.cpp 724 LIBRARIES asmjit::asmjit 725 CFLAGS ${ASMJIT_PRIVATE_CFLAGS} ${ASMJIT_SSE2_CFLAGS} 726 CFLAGS_DBG ${ASMJIT_PRIVATE_CFLAGS_DBG} 727 CFLAGS_REL ${ASMJIT_PRIVATE_CFLAGS_REL}) 728 endif() 729 730 if (NOT ASMJIT_NO_UJIT) 731 asmjit_addapp(asmjit_test_unicompiler TEST 732 SOURCES testing/tests/asmjit_test_unicompiler.cpp 733 testing/tests/asmjit_test_unicompiler_sse2.cpp 734 testing/tests/asmjit_test_unicompiler_avx2fma.cpp 735 testing/tests/broken.cpp 736 LIBRARIES asmjit::asmjit 737 CFLAGS ${ASMJIT_PRIVATE_CFLAGS} ${ASMJIT_SSE2_CFLAGS} 738 CFLAGS_DBG ${ASMJIT_PRIVATE_CFLAGS_DBG} 739 CFLAGS_REL ${ASMJIT_PRIVATE_CFLAGS_REL}) 740 set_property(SOURCE testing/tests/asmjit_test_unicompiler_avx2fma.cpp APPEND PROPERTY COMPILE_OPTIONS ${ASMJIT_AVX2FMA_CFLAGS}) 741 endif() 742 743 asmjit_addapp(asmjit_bench_codegen EXECUTABLE 744 SOURCES testing/bench/asmjit_bench_codegen.cpp 745 testing/bench/asmjit_bench_codegen_a64.cpp 746 testing/bench/asmjit_bench_codegen_x86.cpp 747 SOURCES testing/bench/asmjit_bench_codegen.h 748 LIBRARIES asmjit::asmjit 749 CFLAGS ${ASMJIT_PRIVATE_CFLAGS} 750 CFLAGS_DBG ${ASMJIT_PRIVATE_CFLAGS_DBG} 751 CFLAGS_REL ${ASMJIT_PRIVATE_CFLAGS_REL}) 752 753 foreach(app asmjit_bench_overhead asmjit_bench_regalloc) 754 asmjit_addapp(${app} TEST 755 SOURCES testing/bench/${app}.cpp 756 LIBRARIES asmjit::asmjit 757 CFLAGS ${ASMJIT_PRIVATE_CFLAGS} 758 CFLAGS_DBG ${ASMJIT_PRIVATE_CFLAGS_DBG} 759 CFLAGS_REL ${ASMJIT_PRIVATE_CFLAGS_REL}) 760 endforeach() 761 762 endif() 763 endif()