Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / bolt / runtime / CMakeLists.txt
blob6a65f80fb9079f18258b1c2ce402c0f4bc78581b
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 "${LLVM_LIBRARY_DIR}")
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 "${LLVM_LIBRARY_DIR}")
26 set(BOLT_RT_FLAGS
27   -ffreestanding
28   -fno-exceptions
29   -fno-rtti
30   -fno-stack-protector
31   -fPIC
32   -mgeneral-regs-only)
33 if (CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
34   set(BOLT_RT_FLAGS ${BOLT_RT_FLAGS} "-mno-sse")
35 endif()
36 if (CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64")
37   check_cxx_compiler_flag("-mno-outline-atomics" CXX_SUPPORTS_OUTLINE_ATOMICS)
38   if (CXX_SUPPORTS_OUTLINE_ATOMICS)
39     set(BOLT_RT_FLAGS ${BOLT_RT_FLAGS} "-mno-outline-atomics")
40   endif()
41 endif()
43 # Don't let the compiler think it can create calls to standard libs
44 target_compile_options(bolt_rt_instr PRIVATE ${BOLT_RT_FLAGS})
45 target_include_directories(bolt_rt_instr PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
46 target_compile_options(bolt_rt_hugify PRIVATE ${BOLT_RT_FLAGS})
47 target_include_directories(bolt_rt_hugify PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
49 install(TARGETS bolt_rt_instr DESTINATION "lib${LLVM_LIBDIR_SUFFIX}")
50 install(TARGETS bolt_rt_hugify DESTINATION "lib${LLVM_LIBDIR_SUFFIX}")
52 if (CMAKE_CXX_COMPILER_ID MATCHES ".*Clang.*" AND CMAKE_SYSTEM_NAME STREQUAL "Darwin")
53   add_library(bolt_rt_instr_osx STATIC
54     instr.cpp
55     ${CMAKE_CURRENT_BINARY_DIR}/config.h
56   )
57   set_target_properties(bolt_rt_instr_osx PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${LLVM_LIBRARY_DIR}")
58   target_include_directories(bolt_rt_instr_osx PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
59   target_compile_options(bolt_rt_instr_osx PRIVATE
60     -target x86_64-apple-darwin19.6.0
61     ${BOLT_RT_FLAGS})
62   install(TARGETS bolt_rt_instr_osx DESTINATION "lib${LLVM_LIBDIR_SUFFIX}")
63 endif()