blob: 0c03b7b92e2e5796289e376e6e32ee249265bcfb [file] [log] [blame]
Guillaume Chatelet439d3712018-02-01 10:03:09 +01001cmake_minimum_required(VERSION 3.0)
2
3project(CpuFeatures)
4
Guillaume Chatelet3a156da2018-02-08 16:59:18 +01005# Default Build Type to be Release
6if(NOT CMAKE_BUILD_TYPE)
7 set(CMAKE_BUILD_TYPE "Release" CACHE STRING
8 "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
9 FORCE)
10endif(NOT CMAKE_BUILD_TYPE)
11
12# BUILD_TESTING is a standard CMake variable, but we declare it here to make it
13# prominent in the GUI.
14option(BUILD_TESTING "Enable test (depends on googletest)." OFF)
15
Guillaume Chatelet439d3712018-02-01 10:03:09 +010016#
17# library : cpu_features
18#
19
20add_library(cpu_features
21 include/cpuinfo_aarch64.h
22 include/cpuinfo_arm.h
23 include/cpuinfo_mips.h
24 include/cpuinfo_x86.h
25 include/internal/bit_utils.h
26 include/internal/linux_features_aggregator.h
27 include/internal/cpuid_x86.h
28 include/internal/filesystem.h
29 include/internal/hwcaps.h
30 include/internal/stack_line_reader.h
31 include/internal/string_view.h
32 include/cpu_features_macros.h
33 src/linux_features_aggregator.c
34 src/cpuid_x86_clang.c
35 src/cpuid_x86_gcc.c
36 src/cpuid_x86_msvc.c
37 src/cpuinfo_aarch64.c
38 src/cpuinfo_arm.c
39 src/cpuinfo_mips.c
40 src/cpuinfo_x86.c
41 src/filesystem.c
42 src/hwcaps.c
43 src/stack_line_reader.c
44 src/string_view.c
45)
46
47target_include_directories(cpu_features PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>)
48target_include_directories(cpu_features PRIVATE include/internal)
49target_compile_definitions(cpu_features PUBLIC STACK_LINE_READER_BUFFER_SIZE=1024)
50target_link_libraries(cpu_features PUBLIC ${CMAKE_DL_LIBS})
51
52#
53# program : list_cpu_features
54#
55
56add_executable(list_cpu_features src/list_cpu_features.cc)
57target_link_libraries(list_cpu_features PRIVATE cpu_features)
58target_compile_features(list_cpu_features PRIVATE cxx_range_for)
59
60#
61# tests
62#
63
64include(CTest)
65if(BUILD_TESTING)
66 # Download and unpack googletest at configure time.
67 configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt)
68
69 execute_process(
70 COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
71 RESULT_VARIABLE result
72 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download )
73
74 if(result)
75 message(FATAL_ERROR "CMake step for googletest failed: ${result}")
76 endif()
77
78 execute_process(
79 COMMAND ${CMAKE_COMMAND} --build .
80 RESULT_VARIABLE result
81 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download )
82
83 if(result)
84 message(FATAL_ERROR "Build step for googletest failed: ${result}")
85 endif()
86
87 # Prevent overriding the parent project's compiler/linker settings on Windows.
88 set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
89
90 # Add googletest directly to our build. This defines the gtest and gtest_main
91 # targets.
92 add_subdirectory(${CMAKE_BINARY_DIR}/googletest-src
93 ${CMAKE_BINARY_DIR}/googletest-build
94 EXCLUDE_FROM_ALL)
95
96 # The gtest/gtest_main targets carry header search path dependencies
97 # automatically when using CMake 2.8.11 or later. Otherwise we have to add
98 # them here ourselves.
99 if (CMAKE_VERSION VERSION_LESS 2.8.11)
100 include_directories("${gtest_SOURCE_DIR}/include")
101 endif()
Guillaume Chatelet3a156da2018-02-08 16:59:18 +0100102
Guillaume Chatelet439d3712018-02-01 10:03:09 +0100103 add_subdirectory(test)
104endif()