[AArch64] Improve mull generation (#114997)
[llvm-project.git] / bolt / runtime / CMakeLists.txt
blob40f4fbc9f30d545f6e91465af065d41717ac3bc6
1 cmake_minimum_required(VERSION 3.20.0)
2 include(CheckCXXCompilerFlag)
3 include(CheckIncludeFiles)
4 include(GNUInstallDirs)
6 set(CMAKE_CXX_EXTENSIONS OFF)
7 set(CMAKE_CXX_STANDARD 17)
9 project(libbolt_rt_project)
11 check_include_files(elf.h HAVE_ELF_H)
12 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in
13                ${CMAKE_CURRENT_BINARY_DIR}/config.h)
15 add_library(bolt_rt_instr STATIC
16   instr.cpp
17   ${CMAKE_CURRENT_BINARY_DIR}/config.h
18   )
19 set_target_properties(bolt_rt_instr PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}")
20 add_library(bolt_rt_hugify STATIC
21   hugify.cpp
22   ${CMAKE_CURRENT_BINARY_DIR}/config.h
23   )
24 set_target_properties(bolt_rt_hugify PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}")
26 if(NOT BOLT_BUILT_STANDALONE)
27   add_custom_command(TARGET bolt_rt_instr POST_BUILD
28     COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_BINARY_DIR}/lib/libbolt_rt_instr.a" "${LLVM_LIBRARY_DIR}")
29   add_custom_command(TARGET bolt_rt_hugify POST_BUILD
30     COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_BINARY_DIR}/lib/libbolt_rt_hugify.a" "${LLVM_LIBRARY_DIR}")
31 endif()
33 set(BOLT_RT_FLAGS
34   -ffreestanding
35   -fno-exceptions
36   -fno-rtti
37   -fno-stack-protector
38   -fPIC
39   -mgeneral-regs-only)
40 if (CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
41   set(BOLT_RT_FLAGS ${BOLT_RT_FLAGS} "-mno-sse")
42 endif()
43 if (CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64")
44   check_cxx_compiler_flag("-mno-outline-atomics" CXX_SUPPORTS_OUTLINE_ATOMICS)
45   if (CXX_SUPPORTS_OUTLINE_ATOMICS)
46     set(BOLT_RT_FLAGS ${BOLT_RT_FLAGS} "-mno-outline-atomics")
47   endif()
48 endif()
50 # Don't let the compiler think it can create calls to standard libs
51 target_compile_options(bolt_rt_instr PRIVATE ${BOLT_RT_FLAGS})
52 target_include_directories(bolt_rt_instr PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
53 target_compile_options(bolt_rt_hugify PRIVATE ${BOLT_RT_FLAGS})
54 target_include_directories(bolt_rt_hugify PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
56 install(TARGETS bolt_rt_instr DESTINATION "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}")
57 install(TARGETS bolt_rt_hugify DESTINATION "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}")
59 if (CMAKE_CXX_COMPILER_ID MATCHES ".*Clang.*" AND CMAKE_SYSTEM_NAME STREQUAL "Darwin")
60   add_library(bolt_rt_instr_osx STATIC
61     instr.cpp
62     ${CMAKE_CURRENT_BINARY_DIR}/config.h
63   )
64   set_target_properties(bolt_rt_instr_osx PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}")
65   target_include_directories(bolt_rt_instr_osx PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
66   target_compile_options(bolt_rt_instr_osx PRIVATE
67     -target x86_64-apple-darwin19.6.0
68     ${BOLT_RT_FLAGS})
69   install(TARGETS bolt_rt_instr_osx DESTINATION "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}")
71   if(NOT BOLT_BUILT_STANDALONE)
72     add_custom_command(TARGET bolt_rt_instr_osx POST_BUILD
73       COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_BINARY_DIR}/lib/libbolt_rt_instr_osx.a" "${LLVM_LIBRARY_DIR}")
74   endif()
75 endif()