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