Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 1 | # |
| 2 | #//===----------------------------------------------------------------------===// |
| 3 | #// |
| 4 | #// The LLVM Compiler Infrastructure |
| 5 | #// |
| 6 | #// This file is dual licensed under the MIT and the University of Illinois Open |
| 7 | #// Source Licenses. See LICENSE.txt for details. |
| 8 | #// |
| 9 | #//===----------------------------------------------------------------------===// |
| 10 | # |
| 11 | |
Jim Cownie | 3b81ce6 | 2014-08-05 09:32:28 +0000 | [diff] [blame] | 12 | # This file holds the common flags independent of compiler |
| 13 | # The flag types are: |
| 14 | # 1) Assembly flags (append_asm_flags_common) |
| 15 | # 2) C/C++ Compiler flags (append_c_and_cxx_flags_common) |
| 16 | # 3) Fortran Compiler flags (append_fort_flags_common) |
| 17 | # 4) Linker flags (append_linker_flags_common) |
| 18 | # 5) Archiver flags (append_archiver_flags_common) |
| 19 | |
| 20 | # These append_* macros all append to the corresponding list variable holding the flags. |
| 21 | macro(append_c_flags new_flag) |
| 22 | list(APPEND local_c_flags "${new_flag}") |
| 23 | endmacro() |
| 24 | |
| 25 | macro(append_cxx_flags new_flag) |
| 26 | list(APPEND local_cxx_flags "${new_flag}") |
| 27 | endmacro() |
| 28 | |
| 29 | macro(append_c_and_cxx_flags new_flag) |
| 30 | append_c_flags("${new_flag}") |
| 31 | append_cxx_flags("${new_flag}") |
| 32 | endmacro() |
| 33 | |
| 34 | macro(append_asm_flags new_flag) |
| 35 | list(APPEND local_asm_flags "${new_flag}") |
| 36 | endmacro() |
| 37 | |
| 38 | macro(append_fort_flags new_flag) |
| 39 | list(APPEND local_fort_flags "${new_flag}") |
| 40 | endmacro() |
| 41 | |
| 42 | # The difference between linker_flags and linker_flags_libs is linker_flags_libs |
| 43 | # is put at the end of the linker command where linking libraries should be done. |
| 44 | macro(append_linker_flags new_flag) |
| 45 | list(APPEND local_ld_flags "${new_flag}") |
| 46 | endmacro() |
| 47 | |
| 48 | macro(append_linker_flags_library new_flag) |
| 49 | list(APPEND local_ld_flags_libs "${new_flag}") |
| 50 | endmacro() |
| 51 | |
| 52 | macro(append_archiver_flags new_flag) |
| 53 | list(APPEND local_ar_flags "${new_flag}") |
| 54 | endmacro() |
| 55 | |
| 56 | ######################################################### |
| 57 | # Global Assembly flags |
| 58 | function(append_asm_flags_common input_asm_flags) |
| 59 | set(local_asm_flags) |
Jonathan Peyton | 7979a07 | 2015-05-20 22:33:24 +0000 | [diff] [blame^] | 60 | set(${input_asm_flags} "${${input_asm_flags}}" "${local_asm_flags}" "${LIBOMP_ASMFLAGS}" PARENT_SCOPE) |
Jim Cownie | 3b81ce6 | 2014-08-05 09:32:28 +0000 | [diff] [blame] | 61 | endfunction() |
| 62 | |
| 63 | ######################################################### |
| 64 | # Global C/C++ Compiler flags |
| 65 | function(append_c_and_cxx_flags_common input_c_flags input_cxx_flags) |
| 66 | set(local_c_flags) |
| 67 | set(local_cxx_flags) |
Jonathan Peyton | 7979a07 | 2015-05-20 22:33:24 +0000 | [diff] [blame^] | 68 | set(${input_c_flags} "${${input_c_flags}}" "${local_c_flags}" "${LIBOMP_CFLAGS}" PARENT_SCOPE) |
| 69 | set(${input_cxx_flags} "${${input_cxx_flags}}" "${local_cxx_flags}" "${LIBOMP_CXXFLAGS}" PARENT_SCOPE) |
Jim Cownie | 3b81ce6 | 2014-08-05 09:32:28 +0000 | [diff] [blame] | 70 | endfunction() |
| 71 | |
| 72 | ######################################################### |
| 73 | # Global Fortran Compiler flags (for creating .mod files) |
| 74 | function(append_fort_flags_common input_fort_flags) |
| 75 | set(local_fort_flags) |
Jonathan Peyton | 7979a07 | 2015-05-20 22:33:24 +0000 | [diff] [blame^] | 76 | set(${input_fort_flags} "${${input_fort_flags}}" "${local_fort_flags}" "${LIBOMP_FFLAGS}" PARENT_SCOPE) |
Jim Cownie | 3b81ce6 | 2014-08-05 09:32:28 +0000 | [diff] [blame] | 77 | endfunction() |
| 78 | |
| 79 | ######################################################### |
| 80 | # Linker flags |
| 81 | function(append_linker_flags_common input_ld_flags input_ld_flags_libs) |
| 82 | set(local_ld_flags) |
| 83 | set(local_ld_flags_libs) |
| 84 | |
Jonathan Peyton | 7979a07 | 2015-05-20 22:33:24 +0000 | [diff] [blame^] | 85 | if(${LIBOMP_USE_PREDEFINED_LINKER_FLAGS}) |
Jim Cownie | 3b81ce6 | 2014-08-05 09:32:28 +0000 | [diff] [blame] | 86 | |
Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 87 | ################################# |
| 88 | # Windows linker flags |
| 89 | if(${WINDOWS}) |
| 90 | |
| 91 | ################## |
| 92 | # MAC linker flags |
| 93 | elseif(${MAC}) |
Jim Cownie | 3b81ce6 | 2014-08-05 09:32:28 +0000 | [diff] [blame] | 94 | append_linker_flags("-single_module") |
Jonathan Peyton | 7979a07 | 2015-05-20 22:33:24 +0000 | [diff] [blame^] | 95 | append_linker_flags("-current_version ${LIBOMP_VERSION}.0") |
| 96 | append_linker_flags("-compatibility_version ${LIBOMP_VERSION}.0") |
Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 97 | ##################################################################################### |
| 98 | # Intel(R) Many Integrated Core Architecture (Intel(R) MIC Architecture) linker flags |
| 99 | elseif(${MIC}) |
Jim Cownie | 3b81ce6 | 2014-08-05 09:32:28 +0000 | [diff] [blame] | 100 | append_linker_flags("-Wl,-x") |
| 101 | append_linker_flags("-Wl,--warn-shared-textrel") # Warn if the linker adds a DT_TEXTREL to a shared object. |
| 102 | append_linker_flags("-Wl,--as-needed") |
| 103 | append_linker_flags("-Wl,--version-script=${src_dir}/exports_so.txt") # Use exports_so.txt as version script to create versioned symbols for ELF libraries |
| 104 | if(NOT ${STUBS_LIBRARY}) |
| 105 | append_linker_flags_library("-pthread") # link in pthread library |
Jim Cownie | 3b81ce6 | 2014-08-05 09:32:28 +0000 | [diff] [blame] | 106 | endif() |
Jonathan Peyton | 7979a07 | 2015-05-20 22:33:24 +0000 | [diff] [blame^] | 107 | if(${LIBOMP_STATS}) |
Jim Cownie | 3b81ce6 | 2014-08-05 09:32:28 +0000 | [diff] [blame] | 108 | append_linker_flags_library("-Wl,-lstdc++") # link in standard c++ library (stats-gathering needs it) |
| 109 | endif() |
Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 110 | ######################### |
| 111 | # Unix based linker flags |
| 112 | else() |
| 113 | # For now, always include --version-script flag on Unix systems. |
| 114 | append_linker_flags("-Wl,--version-script=${src_dir}/exports_so.txt") # Use exports_so.txt as version script to create versioned symbols for ELF libraries |
Jim Cownie | 3b81ce6 | 2014-08-05 09:32:28 +0000 | [diff] [blame] | 115 | append_linker_flags("-Wl,-z,noexecstack") # Marks the object as not requiring executable stack. |
| 116 | append_linker_flags("-Wl,--as-needed") # Only adds library dependencies as they are needed. (if libiomp5 actually uses a function from the library, then add it) |
| 117 | if(NOT ${STUBS_LIBRARY}) |
| 118 | append_linker_flags("-Wl,--warn-shared-textrel") # Warn if the linker adds a DT_TEXTREL to a shared object. |
| 119 | append_linker_flags("-Wl,-fini=__kmp_internal_end_fini") # When creating an ELF executable or shared object, call NAME when the |
| 120 | # executable or shared object is unloaded, by setting DT_FINI to the |
| 121 | # address of the function. By default, the linker uses "_fini" as the function to call. |
| 122 | append_linker_flags_library("-pthread") # link pthread library |
Jim Cownie | 3b81ce6 | 2014-08-05 09:32:28 +0000 | [diff] [blame] | 123 | endif() |
Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 124 | endif() # if(${OPERATING_SYSTEM}) ... |
| 125 | |
Jonathan Peyton | 7979a07 | 2015-05-20 22:33:24 +0000 | [diff] [blame^] | 126 | endif() # LIBOMP_USE_PREDEFINED_LINKER_FLAGS |
Jim Cownie | 3b81ce6 | 2014-08-05 09:32:28 +0000 | [diff] [blame] | 127 | |
Jonathan Peyton | 7979a07 | 2015-05-20 22:33:24 +0000 | [diff] [blame^] | 128 | set(${input_ld_flags} "${${input_ld_flags}}" "${local_ld_flags}" "${LIBOMP_LDFLAGS}" PARENT_SCOPE) |
| 129 | set(${input_ld_flags_libs} "${${input_ld_flags_libs}}" "${local_ld_flags_libs}" "${LIBOMP_LIBFLAGS}" PARENT_SCOPE) |
Jim Cownie | 3b81ce6 | 2014-08-05 09:32:28 +0000 | [diff] [blame] | 130 | endfunction() |
| 131 | |
| 132 | ######################################################### |
| 133 | # Archiver Flags |
| 134 | function(append_archiver_flags_common input_ar_flags) |
| 135 | set(local_ar_flags) |
| 136 | set(${input_ar_flags} "${${input_ar_flags}}" "${local_ar_flags}" PARENT_SCOPE) |
| 137 | endfunction() |
| 138 | |