summaryrefslogtreecommitdiffstats
path: root/Modules/CMakeCommonLanguageInclude.cmake
blob: 5511930fd0cd0d8fa0acbf8162c38ad5d9ad7f76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.


# this file has flags that are shared across languages and sets
# cache values that can be initialized in the platform-compiler.cmake file
# it may be included by more than one language.

string(APPEND CMAKE_EXE_LINKER_FLAGS_INIT " $ENV{LDFLAGS}")
string(APPEND CMAKE_SHARED_LINKER_FLAGS_INIT " $ENV{LDFLAGS}")
string(APPEND CMAKE_MODULE_LINKER_FLAGS_INIT " $ENV{LDFLAGS}")

cmake_initialize_per_config_variable(CMAKE_EXE_LINKER_FLAGS    "Flags used by the linker")
cmake_initialize_per_config_variable(CMAKE_SHARED_LINKER_FLAGS "Flags used by the linker during the creation of shared libraries")
cmake_initialize_per_config_variable(CMAKE_MODULE_LINKER_FLAGS "Flags used by the linker during the creation of modules")
cmake_initialize_per_config_variable(CMAKE_STATIC_LINKER_FLAGS "Flags used by the linker during the creation of static libraries")

# Alias the build tool variable for backward compatibility.
set(CMAKE_BUILD_TOOL ${CMAKE_MAKE_PROGRAM})

mark_as_advanced(
CMAKE_VERBOSE_MAKEFILE
)

# The Platform/* modules set a bunch of platform-specific flags expressed
# for the C toolchain.  Other languages call this to copy them as defaults.
macro(_cmake_common_language_platform_flags lang)
  if(NOT DEFINED CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS)
    set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS})
  endif()

  if(NOT DEFINED CMAKE_${lang}_COMPILE_OPTIONS_PIC)
    set(CMAKE_${lang}_COMPILE_OPTIONS_PIC ${CMAKE_C_COMPILE_OPTIONS_PIC})
  endif()

  if(NOT DEFINED CMAKE_${lang}_COMPILE_OPTIONS_PIE)
    set(CMAKE_${lang}_COMPILE_OPTIONS_PIE ${CMAKE_C_COMPILE_OPTIONS_PIE})
  endif()
  if(NOT DEFINED CMAKE_${lang}_LINK_OPTIONS_PIE)
    set(CMAKE_${lang}_LINK_OPTIONS_PIE ${CMAKE_C_LINK_OPTIONS_PIE})
  endif()
  if(NOT DEFINED CMAKE_${lang}_LINK_OPTIONS_NO_PIE)
    set(CMAKE_${lang}_LINK_OPTIONS_NO_PIE ${CMAKE_C_LINK_OPTIONS_NO_PIE})
  endif()

  if(NOT DEFINED CMAKE_${lang}_COMPILE_OPTIONS_DLL)
    set(CMAKE_${lang}_COMPILE_OPTIONS_DLL ${CMAKE_C_COMPILE_OPTIONS_DLL})
  endif()

  if(NOT DEFINED CMAKE_SHARED_LIBRARY_${lang}_FLAGS)
    set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS ${CMAKE_SHARED_LIBRARY_C_FLAGS})
  endif()

  if(NOT DEFINED CMAKE_SHARED_LIBRARY_LINK_${lang}_FLAGS)
    set(CMAKE_SHARED_LIBRARY_LINK_${lang}_FLAGS ${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS})
  endif()

  if(NOT DEFINED CMAKE_SHARED_LIBRARY_RUNTIME_${lang}_FLAG)
    set(CMAKE_SHARED_LIBRARY_RUNTIME_${lang}_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG})
  endif()

  if(NOT DEFINED CMAKE_SHARED_LIBRARY_RUNTIME_${lang}_FLAG_SEP)
    set(CMAKE_SHARED_LIBRARY_RUNTIME_${lang}_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP})
  endif()

  if(NOT DEFINED CMAKE_SHARED_LIBRARY_RPATH_LINK_${lang}_FLAG)
    set(CMAKE_SHARED_LIBRARY_RPATH_LINK_${lang}_FLAG ${CMAKE_SHARED_LIBRARY_RPATH_LINK_C_FLAG})
  endif()

  if(NOT DEFINED CMAKE_EXE_EXPORTS_${lang}_FLAG)
    set(CMAKE_EXE_EXPORTS_${lang}_FLAG ${CMAKE_EXE_EXPORTS_C_FLAG})
  endif()

  if(NOT DEFINED CMAKE_SHARED_LIBRARY_SONAME_${lang}_FLAG)
    set(CMAKE_SHARED_LIBRARY_SONAME_${lang}_FLAG ${CMAKE_SHARED_LIBRARY_SONAME_C_FLAG})
  endif()

  if(NOT DEFINED CMAKE_EXECUTABLE_RUNTIME_${lang}_FLAG)
    set(CMAKE_EXECUTABLE_RUNTIME_${lang}_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_${lang}_FLAG})
  endif()

  if(NOT DEFINED CMAKE_EXECUTABLE_RUNTIME_${lang}_FLAG_SEP)
    set(CMAKE_EXECUTABLE_RUNTIME_${lang}_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_${lang}_FLAG_SEP})
  endif()

  if(NOT DEFINED CMAKE_EXECUTABLE_RPATH_LINK_${lang}_FLAG)
    set(CMAKE_EXECUTABLE_RPATH_LINK_${lang}_FLAG ${CMAKE_SHARED_LIBRARY_RPATH_LINK_${lang}_FLAG})
  endif()

  if(NOT DEFINED CMAKE_SHARED_LIBRARY_LINK_${lang}_WITH_RUNTIME_PATH)
    set(CMAKE_SHARED_LIBRARY_LINK_${lang}_WITH_RUNTIME_PATH ${CMAKE_SHARED_LIBRARY_LINK_C_WITH_RUNTIME_PATH})
  endif()

  if(NOT DEFINED CMAKE_INCLUDE_FLAG_${lang})
    set(CMAKE_INCLUDE_FLAG_${lang} ${CMAKE_INCLUDE_FLAG_C})
  endif()

  # for most systems a module is the same as a shared library
  # so unless the variable CMAKE_MODULE_EXISTS is set just
  # copy the values from the LIBRARY variables
  if(NOT CMAKE_MODULE_EXISTS)
    set(CMAKE_SHARED_MODULE_${lang}_FLAGS ${CMAKE_SHARED_LIBRARY_${lang}_FLAGS})
    set(CMAKE_SHARED_MODULE_CREATE_${lang}_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS})
  endif()

  if(NOT DEFINED CMAKE_SHARED_MODULE_CREATE_${lang}_FLAGS)
    set(CMAKE_SHARED_MODULE_CREATE_${lang}_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS})
  endif()
  if(NOT DEFINED CMAKE_SHARED_MODULE_${lang}_FLAGS)
    set(CMAKE_SHARED_MODULE_${lang}_FLAGS ${CMAKE_SHARED_LIBRARY_C_FLAGS})
  endif()

  foreach(type IN ITEMS SHARED_LIBRARY SHARED_MODULE EXE)
    if(NOT DEFINED CMAKE_${type}_LINK_STATIC_${lang}_FLAGS)
      set(CMAKE_${type}_LINK_STATIC_${lang}_FLAGS
        ${CMAKE_${type}_LINK_STATIC_C_FLAGS})
    endif()
    if(NOT DEFINED CMAKE_${type}_LINK_DYNAMIC_${lang}_FLAGS)
      set(CMAKE_${type}_LINK_DYNAMIC_${lang}_FLAGS
        ${CMAKE_${type}_LINK_DYNAMIC_C_FLAGS})
    endif()
  endforeach()

  if(CMAKE_EXECUTABLE_FORMAT STREQUAL "ELF")
    if(NOT DEFINED CMAKE_${lang}_LINK_WHAT_YOU_USE_FLAG)
      set(CMAKE_${lang}_LINK_WHAT_YOU_USE_FLAG "LINKER:--no-as-needed")
    endif()
    if(NOT DEFINED CMAKE_LINK_WHAT_YOU_USE_CHECK)
      set(CMAKE_LINK_WHAT_YOU_USE_CHECK ldd -u -r)
    endif()
  endif()
endmacro()