]> git.saurik.com Git - apt.git/blob - CMake/FindLFS.cmake
test: Use C locale instead of C.UTF-8
[apt.git] / CMake / FindLFS.cmake
1 # CMake support for large files
2 #
3 # Copyright (C) 2016 Julian Andres Klode <jak@debian.org>.
4 #
5 # Permission is hereby granted, free of charge, to any person
6 # obtaining a copy of this software and associated documentation files
7 # (the "Software"), to deal in the Software without restriction,
8 # including without limitation the rights to use, copy, modify, merge,
9 # publish, distribute, sublicense, and/or sell copies of the Software,
10 # and to permit persons to whom the Software is furnished to do so,
11 # subject to the following conditions:
12 #
13 # The above copyright notice and this permission notice shall be
14 # included in all copies or substantial portions of the Software.
15 #
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 # SOFTWARE.
24 #
25 # This defines the following variables
26 #
27 # LFS_DEFINITIONS - List of definitions to pass to add_definitions()
28 # LFS_COMPILE_OPTIONS - List of definitions to pass to add_compile_options()
29 # LFS_LIBRARIES - List of libraries and linker flags
30 # LFS_FOUND - If there is Large files support
31 #
32
33 include(CheckCXXSourceCompiles)
34 include(FindPackageHandleStandardArgs)
35
36 # Test program to check for LFS. Requires that off_t has at least 8 byte large
37 set(_lfs_test_source
38 "
39 #include <sys/types.h>
40 typedef char my_static_assert[sizeof(off_t) >= 8 ? 1 : -1];
41 int main(void) { return 0; }
42 "
43 )
44
45 # Check if the given options are needed
46 #
47 # This appends to the variables _lfs_cppflags, _lfs_cflags, and _lfs_ldflags,
48 # it also sets LFS_FOUND to 1 if it works.
49 function(_lfs_check_compiler_option var options definitions libraries)
50 set(CMAKE_REQUIRED_QUIET 1)
51 set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS} ${options})
52 set(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} ${definitions})
53 set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_DEFINITIONS} ${libraries})
54
55 message(STATUS "Looking for LFS support using ${options} ${definitions} ${libraries}")
56 check_cxx_source_compiles("${_lfs_test_source}" ${var})
57
58 if(${var})
59 message(STATUS "Looking for LFS support using ${options} ${definitions} ${libraries} - found")
60 set(_lfs_cppflags ${_lfs_cppflags} ${definitions} PARENT_SCOPE)
61 set(_lfs_cflags ${_lfs_cflags} ${options} PARENT_SCOPE)
62 set(_lfs_ldflags ${_lfs_ldflags} ${libraries} PARENT_SCOPE)
63 set(LFS_FOUND TRUE PARENT_SCOPE)
64 else()
65 message(STATUS "Looking for LFS support using ${options} ${definitions} ${libraries} - not found")
66 endif()
67 endfunction()
68
69 # Check for the availability of LFS.
70 # The cases handled are:
71 #
72 # * Native LFS
73 # * Output of getconf LFS_CFLAGS; getconf LFS_LIBS; getconf LFS_LDFLAGS
74 # * Preprocessor flag -D_FILE_OFFSET_BITS=64
75 # * Preprocessor flag -D_LARGE_FILES
76 #
77 function(_lfs_check)
78 set(_lfs_cflags)
79 set(_lfs_cppflags)
80 set(_lfs_ldflags)
81 set(_lfs_libs)
82 set(CMAKE_REQUIRED_QUIET 1)
83 message(STATUS "Looking for native LFS support")
84 check_cxx_source_compiles("${_lfs_test_source}" lfs_native)
85 if (lfs_native)
86 message(STATUS "Looking for native LFS support - found")
87 set(LFS_FOUND TRUE)
88 else()
89 message(STATUS "Looking for native LFS support - not found")
90 endif()
91
92 if (NOT LFS_FOUND)
93 # Check using getconf. If getconf fails, don't worry, the check in
94 # _lfs_check_compiler_option will fail as well.
95 execute_process(COMMAND getconf LFS_CFLAGS
96 OUTPUT_VARIABLE _lfs_cflags_raw
97 OUTPUT_STRIP_TRAILING_WHITESPACE
98 ERROR_QUIET)
99 execute_process(COMMAND getconf LFS_LIBS
100 OUTPUT_VARIABLE _lfs_libs_tmp
101 OUTPUT_STRIP_TRAILING_WHITESPACE
102 ERROR_QUIET)
103 execute_process(COMMAND getconf LFS_LDFLAGS
104 OUTPUT_VARIABLE _lfs_ldflags_tmp
105 OUTPUT_STRIP_TRAILING_WHITESPACE
106 ERROR_QUIET)
107
108 separate_arguments(_lfs_cflags_raw)
109 separate_arguments(_lfs_ldflags_tmp)
110 separate_arguments(_lfs_libs_tmp)
111
112 # Move -D flags to the place they are supposed to be
113 foreach(flag ${_lfs_cflags_raw})
114 if (flag MATCHES "-D.*")
115 list(APPEND _lfs_cppflags_tmp ${flag})
116 else()
117 list(APPEND _lfs_cflags_tmp ${flag})
118 endif()
119 endforeach()
120
121 # Check if the flags we received (if any) produce working LFS support
122 _lfs_check_compiler_option(lfs_getconf_works
123 "${_lfs_cflags_tmp}"
124 "${_lfs_cppflags_tmp}"
125 "${_lfs_libs_tmp};${_lfs_ldflags_tmp}")
126 endif()
127
128 if(NOT LFS_FOUND) # IRIX stuff
129 _lfs_check_compiler_option(lfs_need_n32 "-n32" "" "")
130 endif()
131 if(NOT LFS_FOUND) # Linux and friends
132 _lfs_check_compiler_option(lfs_need_file_offset_bits "" "-D_FILE_OFFSET_BITS=64" "")
133 endif()
134 if(NOT LFS_FOUND) # AIX
135 _lfs_check_compiler_option(lfs_need_large_files "" "-D_LARGE_FILES=1" "")
136 endif()
137
138 set(LFS_DEFINITIONS ${_lfs_cppflags} CACHE STRING "Extra definitions for large file support")
139 set(LFS_COMPILE_OPTIONS ${_lfs_cflags} CACHE STRING "Extra definitions for large file support")
140 set(LFS_LIBRARIES ${_lfs_libs} ${_lfs_ldflags} CACHE STRING "Extra definitions for large file support")
141 set(LFS_FOUND ${LFS_FOUND} CACHE INTERNAL "Found LFS")
142 endfunction()
143
144 if (NOT LFS_FOUND)
145 _lfs_check()
146 endif()
147
148 find_package_handle_standard_args(LFS "Could not find LFS. Set LFS_DEFINITIONS, LFS_COMPILE_OPTIONS, LFS_LIBRARIES." LFS_FOUND)