TYPE3
[iec.git] / src / type3_AndroidCloud / anbox-master / external / cpu_features / CMakeLists.txt
1 cmake_minimum_required(VERSION 3.0)
2
3 project(CpuFeatures VERSION 0.1.0)
4
5 # ANBOX allow to build in our more strict build environment
6 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-error=switch-default -Wno-error=unused-parameter -Wno-error=overflow")
7
8 if("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
9   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-error=cast-align")
10 endif()
11
12 # Default Build Type to be Release
13 if(NOT CMAKE_BUILD_TYPE)
14   set(CMAKE_BUILD_TYPE "Release" CACHE STRING
15       "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
16       FORCE)
17 endif(NOT CMAKE_BUILD_TYPE)
18
19 # BUILD_TESTING is a standard CMake variable, but we declare it here to make it
20 # prominent in the GUI.
21 option(BUILD_TESTING "Enable test (depends on googletest)." OFF)
22 # BUILD_SHARED_LIBS is a standard CMake variable, but we declare it here to make
23 # it prominent in the GUI.
24 option(BUILD_SHARED_LIBS "Build library as shared." OFF)
25
26 #
27 # library : cpu_features
28 #
29
30 set(_HDRS
31   include/cpuinfo_aarch64.h
32   include/cpuinfo_arm.h
33   include/cpuinfo_mips.h
34   include/cpuinfo_ppc.h
35   include/cpuinfo_x86.h
36   include/cpu_features_macros.h
37 )
38
39 add_library(cpu_features
40   ${_HDRS}
41   include/internal/bit_utils.h
42   include/internal/linux_features_aggregator.h
43   include/internal/cpuid_x86.h
44   include/internal/filesystem.h
45   include/internal/hwcaps.h
46   include/internal/stack_line_reader.h
47   include/internal/string_view.h
48   include/cpu_features_macros.h
49   src/linux_features_aggregator.c
50   src/cpuid_x86_clang_gcc.c
51   src/cpuid_x86_msvc.c
52   src/cpuinfo_aarch64.c
53   src/cpuinfo_arm.c
54   src/cpuinfo_mips.c
55   src/cpuinfo_ppc.c
56   src/cpuinfo_x86.c
57   src/filesystem.c
58   src/hwcaps.c
59   src/stack_line_reader.c
60   src/string_view.c
61 )
62
63 target_include_directories(cpu_features
64   PUBLIC
65   $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
66   $<INSTALL_INTERFACE:include/cpu_features>
67   PRIVATE
68   include/internal
69 )
70 set_target_properties(cpu_features PROPERTIES PUBLIC_HEADER "${_HDRS}")
71 target_compile_definitions(cpu_features
72   PUBLIC STACK_LINE_READER_BUFFER_SIZE=1024)
73 target_link_libraries(cpu_features PUBLIC ${CMAKE_DL_LIBS})
74
75 # The use of shared libraries is discouraged.
76 # For API / ABI compatibility reasons, it is recommended to build and use
77 # cpu_features in a subdirectory of your project or as an embedded dependency.
78 if(BUILD_SHARED_LIBS)
79   set_property(TARGET cpu_features PROPERTY POSITION_INDEPENDENT_CODE ON)
80 endif()
81 add_library(CpuFeature::cpu_features ALIAS cpu_features)
82
83 #
84 # program : list_cpu_features
85 #
86
87 add_executable(list_cpu_features src/utils/list_cpu_features.c)
88 target_link_libraries(list_cpu_features PRIVATE cpu_features)
89 add_executable(CpuFeature::list_cpu_features ALIAS list_cpu_features)
90
91 #
92 # tests
93 #
94
95 include(CTest)
96 # ANBOX: disable building tests
97 set(BUILD_TESTING OFF)
98 if(BUILD_TESTING)
99   # Automatically incorporate googletest into the CMake Project if target not
100   # found.
101   if(NOT TARGET gtest OR NOT TARGET gmock_main)
102     # Download and unpack googletest at configure time.
103     configure_file(
104       cmake/googletest.CMakeLists.txt.in
105       googletest-download/CMakeLists.txt
106     )
107
108     execute_process(
109       COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
110       RESULT_VARIABLE result
111       WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download)
112
113     if(result)
114       message(FATAL_ERROR "CMake step for googletest failed: ${result}")
115     endif()
116
117     execute_process(
118       COMMAND ${CMAKE_COMMAND} --build .
119       RESULT_VARIABLE result
120       WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download)
121
122     if(result)
123       message(FATAL_ERROR "Build step for googletest failed: ${result}")
124     endif()
125
126     # Prevent overriding the parent project's compiler/linker settings on
127     # Windows.
128     set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
129
130     # Add googletest directly to our build. This defines the gtest and
131     # gtest_main targets.
132     add_subdirectory(${CMAKE_BINARY_DIR}/googletest-src
133                      ${CMAKE_BINARY_DIR}/googletest-build
134                      EXCLUDE_FROM_ALL)
135   endif()
136
137   add_subdirectory(test)
138 endif()
139
140 #
141 # Install
142 #
143
144 include(GNUInstallDirs)
145 install(TARGETS cpu_features list_cpu_features
146   EXPORT CpuFeaturesTargets
147   PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/cpu_features
148   ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
149   LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
150   RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
151 )
152 install(EXPORT CpuFeaturesTargets
153   NAMESPACE CpuFeatures::
154   DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/CpuFeatures
155   COMPONENT Devel
156 )
157 include(CMakePackageConfigHelpers)
158 configure_package_config_file(cmake/CpuFeaturesConfig.cmake.in
159   "${PROJECT_BINARY_DIR}/CpuFeaturesConfig.cmake"
160   INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/CpuFeatures"
161   NO_SET_AND_CHECK_MACRO
162   NO_CHECK_REQUIRED_COMPONENTS_MACRO
163 )
164 write_basic_package_version_file(
165   "${PROJECT_BINARY_DIR}/CpuFeaturesConfigVersion.cmake"
166   COMPATIBILITY SameMajorVersion
167 )
168 install(
169   FILES
170   "${PROJECT_BINARY_DIR}/CpuFeaturesConfig.cmake"
171   "${PROJECT_BINARY_DIR}/CpuFeaturesConfigVersion.cmake"
172   DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/CpuFeatures"
173   COMPONENT Devel
174 )