Guillaume Chatelet | 439d371 | 2018-02-01 10:03:09 +0100 | [diff] [blame] | 1 | cmake_minimum_required(VERSION 3.0) |
| 2 | |
| 3 | project(CpuFeatures) |
| 4 | |
Guillaume Chatelet | 3a156da | 2018-02-08 16:59:18 +0100 | [diff] [blame^] | 5 | # Default Build Type to be Release |
| 6 | if(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) |
| 10 | endif(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. |
| 14 | option(BUILD_TESTING "Enable test (depends on googletest)." OFF) |
| 15 | |
Guillaume Chatelet | 439d371 | 2018-02-01 10:03:09 +0100 | [diff] [blame] | 16 | # |
| 17 | # library : cpu_features |
| 18 | # |
| 19 | |
| 20 | add_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 | |
| 47 | target_include_directories(cpu_features PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>) |
| 48 | target_include_directories(cpu_features PRIVATE include/internal) |
| 49 | target_compile_definitions(cpu_features PUBLIC STACK_LINE_READER_BUFFER_SIZE=1024) |
| 50 | target_link_libraries(cpu_features PUBLIC ${CMAKE_DL_LIBS}) |
| 51 | |
| 52 | # |
| 53 | # program : list_cpu_features |
| 54 | # |
| 55 | |
| 56 | add_executable(list_cpu_features src/list_cpu_features.cc) |
| 57 | target_link_libraries(list_cpu_features PRIVATE cpu_features) |
| 58 | target_compile_features(list_cpu_features PRIVATE cxx_range_for) |
| 59 | |
| 60 | # |
| 61 | # tests |
| 62 | # |
| 63 | |
| 64 | include(CTest) |
| 65 | if(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 Chatelet | 3a156da | 2018-02-08 16:59:18 +0100 | [diff] [blame^] | 102 | |
Guillaume Chatelet | 439d371 | 2018-02-01 10:03:09 +0100 | [diff] [blame] | 103 | add_subdirectory(test) |
| 104 | endif() |