Merge topic 'cuda_add_12.8_new_sm_support'
[kiteware-cmake.git] / Modules / CMakeCInformation.cmake
blob977e51a3ece79c6af265ac82007024db947f2a15
1 # Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2 # file Copyright.txt or https://cmake.org/licensing for details.
5 # This file sets the basic flags for the C language in CMake.
6 # It also loads the available platform file for the system-compiler
7 # if it exists.
8 # It also loads a system - compiler - processor (or target hardware)
9 # specific file, which is mainly useful for crosscompiling and embedded systems.
11 include(CMakeLanguageInformation)
13 # some compilers use different extensions (e.g. sdcc uses .rel)
14 # so set the extension here first so it can be overridden by the compiler specific file
15 if(UNIX)
16   set(CMAKE_C_OUTPUT_EXTENSION .o)
17 else()
18   set(CMAKE_C_OUTPUT_EXTENSION .obj)
19 endif()
21 set(_INCLUDED_FILE 0)
23 # Load compiler-specific information.
24 if(CMAKE_C_COMPILER_ID)
25   include(Compiler/${CMAKE_C_COMPILER_ID}-C OPTIONAL)
26 endif()
28 set(CMAKE_BASE_NAME)
29 get_filename_component(CMAKE_BASE_NAME "${CMAKE_C_COMPILER}" NAME_WE)
30 if(CMAKE_COMPILER_IS_GNUCC)
31   set(CMAKE_BASE_NAME gcc)
32 endif()
35 # load a hardware specific file, mostly useful for embedded compilers
36 if(CMAKE_SYSTEM_PROCESSOR)
37   if(CMAKE_C_COMPILER_ID)
38     include(Platform/${CMAKE_EFFECTIVE_SYSTEM_NAME}-${CMAKE_C_COMPILER_ID}-C-${CMAKE_SYSTEM_PROCESSOR} OPTIONAL RESULT_VARIABLE _INCLUDED_FILE)
39   endif()
40   if (NOT _INCLUDED_FILE)
41     include(Platform/${CMAKE_EFFECTIVE_SYSTEM_NAME}-${CMAKE_BASE_NAME}-${CMAKE_SYSTEM_PROCESSOR} OPTIONAL)
42   endif ()
43 endif()
46 # load the system- and compiler specific files
47 if(CMAKE_C_COMPILER_ID)
48   include(Platform/${CMAKE_EFFECTIVE_SYSTEM_NAME}-${CMAKE_C_COMPILER_ID}-C
49     OPTIONAL RESULT_VARIABLE _INCLUDED_FILE)
50 endif()
51 if (NOT _INCLUDED_FILE)
52   include(Platform/${CMAKE_EFFECTIVE_SYSTEM_NAME}-${CMAKE_BASE_NAME}
53     OPTIONAL RESULT_VARIABLE _INCLUDED_FILE)
54 endif ()
56 # load any compiler-wrapper specific information
57 if (CMAKE_C_COMPILER_WRAPPER)
58   __cmake_include_compiler_wrapper(C)
59 endif ()
61 # We specify the compiler information in the system file for some
62 # platforms, but this language may not have been enabled when the file
63 # was first included.  Include it again to get the language info.
64 # Remove this when all compiler info is removed from system files.
65 if (NOT _INCLUDED_FILE)
66   include(Platform/${CMAKE_SYSTEM_NAME} OPTIONAL)
67 endif ()
69 if(CMAKE_C_SIZEOF_DATA_PTR)
70   foreach(f IN LISTS CMAKE_C_ABI_FILES)
71     include(${f})
72   endforeach()
73   unset(CMAKE_C_ABI_FILES)
74 endif()
76 # This should be included before the _INIT variables are
77 # used to initialize the cache.  Since the rule variables
78 # have if blocks on them, users can still define them here.
79 # But, it should still be after the platform file so changes can
80 # be made to those values.
82 if(CMAKE_USER_MAKE_RULES_OVERRIDE)
83   # Save the full path of the file so try_compile can use it.
84   include(${CMAKE_USER_MAKE_RULES_OVERRIDE} RESULT_VARIABLE _override)
85   set(CMAKE_USER_MAKE_RULES_OVERRIDE "${_override}")
86 endif()
88 if(CMAKE_USER_MAKE_RULES_OVERRIDE_C)
89   # Save the full path of the file so try_compile can use it.
90   include(${CMAKE_USER_MAKE_RULES_OVERRIDE_C} RESULT_VARIABLE _override)
91   set(CMAKE_USER_MAKE_RULES_OVERRIDE_C "${_override}")
92 endif()
94 set(CMAKE_C_FLAGS_INIT "$ENV{CFLAGS} ${CMAKE_C_FLAGS_INIT}")
96 cmake_initialize_per_config_variable(CMAKE_C_FLAGS "Flags used by the C compiler")
98 if(CMAKE_C_STANDARD_LIBRARIES_INIT)
99   set(CMAKE_C_STANDARD_LIBRARIES "${CMAKE_C_STANDARD_LIBRARIES_INIT}"
100     CACHE STRING "Libraries linked by default with all C applications.")
101   mark_as_advanced(CMAKE_C_STANDARD_LIBRARIES)
102 endif()
104 if(NOT CMAKE_C_COMPILER_LAUNCHER AND DEFINED ENV{CMAKE_C_COMPILER_LAUNCHER})
105   set(CMAKE_C_COMPILER_LAUNCHER "$ENV{CMAKE_C_COMPILER_LAUNCHER}"
106     CACHE STRING "Compiler launcher for C.")
107 endif()
109 if(NOT CMAKE_C_LINKER_LAUNCHER AND DEFINED ENV{CMAKE_C_LINKER_LAUNCHER})
110   set(CMAKE_C_LINKER_LAUNCHER "$ENV{CMAKE_C_LINKER_LAUNCHER}"
111     CACHE STRING "Linker launcher for C.")
112 endif()
114 include(CMakeCommonLanguageInclude)
115 _cmake_common_language_platform_flags(C)
117 # now define the following rule variables
119 # CMAKE_C_CREATE_SHARED_LIBRARY
120 # CMAKE_C_CREATE_SHARED_MODULE
121 # CMAKE_C_COMPILE_OBJECT
122 # CMAKE_C_LINK_EXECUTABLE
124 # variables supplied by the generator at use time
125 # <TARGET>
126 # <TARGET_BASE> the target without the suffix
127 # <OBJECTS>
128 # <OBJECT>
129 # <LINK_LIBRARIES>
130 # <FLAGS>
131 # <LINK_FLAGS>
133 # C compiler information
134 # <CMAKE_C_COMPILER>
135 # <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS>
136 # <CMAKE_SHARED_MODULE_CREATE_C_FLAGS>
137 # <CMAKE_C_LINK_FLAGS>
139 # Static library tools
140 # <CMAKE_AR>
141 # <CMAKE_RANLIB>
144 # create a C shared library
145 if(NOT CMAKE_C_CREATE_SHARED_LIBRARY)
146   set(CMAKE_C_CREATE_SHARED_LIBRARY
147       "<CMAKE_C_COMPILER> <CMAKE_SHARED_LIBRARY_C_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS> <SONAME_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
148 endif()
150 # create a C shared module just copy the shared library rule
151 if(NOT CMAKE_C_CREATE_SHARED_MODULE)
152   set(CMAKE_C_CREATE_SHARED_MODULE ${CMAKE_C_CREATE_SHARED_LIBRARY})
153 endif()
155 # Create a static archive incrementally for large object file counts.
156 # If CMAKE_C_CREATE_STATIC_LIBRARY is set it will override these.
157 if(NOT DEFINED CMAKE_C_ARCHIVE_CREATE)
158   set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> qc <TARGET> <LINK_FLAGS> <OBJECTS>")
159 endif()
160 if(NOT DEFINED CMAKE_C_ARCHIVE_APPEND)
161   set(CMAKE_C_ARCHIVE_APPEND "<CMAKE_AR> q <TARGET> <LINK_FLAGS> <OBJECTS>")
162 endif()
163 if(NOT DEFINED CMAKE_C_ARCHIVE_FINISH)
164   set(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> <TARGET>")
165 endif()
167 # compile a C file into an object file
168 if(NOT CMAKE_C_COMPILE_OBJECT)
169   set(CMAKE_C_COMPILE_OBJECT
170     "<CMAKE_C_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> -c <SOURCE>")
171 endif()
173 if(NOT CMAKE_C_LINK_EXECUTABLE)
174   set(CMAKE_C_LINK_EXECUTABLE
175     "<CMAKE_C_COMPILER> <FLAGS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
176 endif()
178 set(CMAKE_C_USE_LINKER_INFORMATION TRUE)
180 set(CMAKE_C_INFORMATION_LOADED 1)