blob: 6ac98b8c7976bfb10f909fad5b9c83db87a2cb09 [file] [log] [blame]
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001#
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 Cownie3b81ce62014-08-05 09:32:28 +000012# 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.
21macro(append_c_flags new_flag)
22 list(APPEND local_c_flags "${new_flag}")
23endmacro()
24
25macro(append_cxx_flags new_flag)
26 list(APPEND local_cxx_flags "${new_flag}")
27endmacro()
28
29macro(append_c_and_cxx_flags new_flag)
30 append_c_flags("${new_flag}")
31 append_cxx_flags("${new_flag}")
32endmacro()
33
34macro(append_asm_flags new_flag)
35 list(APPEND local_asm_flags "${new_flag}")
36endmacro()
37
38macro(append_fort_flags new_flag)
39 list(APPEND local_fort_flags "${new_flag}")
40endmacro()
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.
44macro(append_linker_flags new_flag)
45 list(APPEND local_ld_flags "${new_flag}")
46endmacro()
47
48macro(append_linker_flags_library new_flag)
49 list(APPEND local_ld_flags_libs "${new_flag}")
50endmacro()
51
52macro(append_archiver_flags new_flag)
53 list(APPEND local_ar_flags "${new_flag}")
54endmacro()
55
56#########################################################
57# Global Assembly flags
58function(append_asm_flags_common input_asm_flags)
59 set(local_asm_flags)
Jonathan Peyton7979a072015-05-20 22:33:24 +000060 set(${input_asm_flags} "${${input_asm_flags}}" "${local_asm_flags}" "${LIBOMP_ASMFLAGS}" PARENT_SCOPE)
Jim Cownie3b81ce62014-08-05 09:32:28 +000061endfunction()
62
63#########################################################
64# Global C/C++ Compiler flags
65function(append_c_and_cxx_flags_common input_c_flags input_cxx_flags)
66 set(local_c_flags)
67 set(local_cxx_flags)
Jonathan Peyton7979a072015-05-20 22:33:24 +000068 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 Cownie3b81ce62014-08-05 09:32:28 +000070endfunction()
71
72#########################################################
73# Global Fortran Compiler flags (for creating .mod files)
74function(append_fort_flags_common input_fort_flags)
75 set(local_fort_flags)
Jonathan Peyton7979a072015-05-20 22:33:24 +000076 set(${input_fort_flags} "${${input_fort_flags}}" "${local_fort_flags}" "${LIBOMP_FFLAGS}" PARENT_SCOPE)
Jim Cownie3b81ce62014-08-05 09:32:28 +000077endfunction()
78
79#########################################################
80# Linker flags
81function(append_linker_flags_common input_ld_flags input_ld_flags_libs)
82 set(local_ld_flags)
83 set(local_ld_flags_libs)
84
Jonathan Peyton7979a072015-05-20 22:33:24 +000085 if(${LIBOMP_USE_PREDEFINED_LINKER_FLAGS})
Jim Cownie3b81ce62014-08-05 09:32:28 +000086
Jim Cownie4cc4bb42014-10-07 16:25:50 +000087 #################################
88 # Windows linker flags
89 if(${WINDOWS})
90
91 ##################
92 # MAC linker flags
93 elseif(${MAC})
Jim Cownie3b81ce62014-08-05 09:32:28 +000094 append_linker_flags("-single_module")
Jonathan Peyton7979a072015-05-20 22:33:24 +000095 append_linker_flags("-current_version ${LIBOMP_VERSION}.0")
96 append_linker_flags("-compatibility_version ${LIBOMP_VERSION}.0")
Jim Cownie4cc4bb42014-10-07 16:25:50 +000097 #####################################################################################
98 # Intel(R) Many Integrated Core Architecture (Intel(R) MIC Architecture) linker flags
99 elseif(${MIC})
Jim Cownie3b81ce62014-08-05 09:32:28 +0000100 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 Cownie3b81ce62014-08-05 09:32:28 +0000106 endif()
Jonathan Peyton7979a072015-05-20 22:33:24 +0000107 if(${LIBOMP_STATS})
Jim Cownie3b81ce62014-08-05 09:32:28 +0000108 append_linker_flags_library("-Wl,-lstdc++") # link in standard c++ library (stats-gathering needs it)
109 endif()
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000110 #########################
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 Cownie3b81ce62014-08-05 09:32:28 +0000115 append_linker_flags("-Wl,-z,noexecstack") # Marks the object as not requiring executable stack.
Jonathan Peyton227e1ae2015-06-01 03:05:13 +0000116 append_linker_flags("-Wl,--as-needed") # Only adds library dependencies as they are needed. (if libomp actually uses a function from the library, then add it)
Jim Cownie3b81ce62014-08-05 09:32:28 +0000117 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 Cownie3b81ce62014-08-05 09:32:28 +0000123 endif()
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000124 endif() # if(${OPERATING_SYSTEM}) ...
125
Jonathan Peyton7979a072015-05-20 22:33:24 +0000126 endif() # LIBOMP_USE_PREDEFINED_LINKER_FLAGS
Jim Cownie3b81ce62014-08-05 09:32:28 +0000127
Jonathan Peyton7979a072015-05-20 22:33:24 +0000128 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 Cownie3b81ce62014-08-05 09:32:28 +0000130endfunction()
131
132#########################################################
133# Archiver Flags
134function(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)
137endfunction()
138