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