From 12de298ff7740b5ceffc729c292b0bf418f10a96 Mon Sep 17 00:00:00 2001 From: kreuzerkrieg Date: Thu, 6 Feb 2020 08:02:51 +0200 Subject: [PATCH] Add CMake --- CMakeLists.txt | 10 +++++ cmake/Config.cmake.in | 4 ++ cpuid_tool/CMakeLists.txt | 9 +++++ libcpuid/CMakeLists.txt | 80 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 103 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 cmake/Config.cmake.in create mode 100644 cpuid_tool/CMakeLists.txt create mode 100644 libcpuid/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..80cb2b7 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,10 @@ +cmake_minimum_required(VERSION 3.14) + +set(VERSION "0.4.1") +project(cpuid LANGUAGES C CXX ASM VERSION ${VERSION}) + +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_C_STANDARD 11) + +add_subdirectory(libcpuid) +add_subdirectory(cpuid_tool) \ No newline at end of file diff --git a/cmake/Config.cmake.in b/cmake/Config.cmake.in new file mode 100644 index 0000000..38bbde7 --- /dev/null +++ b/cmake/Config.cmake.in @@ -0,0 +1,4 @@ +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/@TARGETS_EXPORT_NAME@.cmake") +check_required_components("@PROJECT_NAME@") diff --git a/cpuid_tool/CMakeLists.txt b/cpuid_tool/CMakeLists.txt new file mode 100644 index 0000000..b7f4430 --- /dev/null +++ b/cpuid_tool/CMakeLists.txt @@ -0,0 +1,9 @@ +add_executable(cpuid_tool cpuid_tool.c) +target_link_libraries(cpuid_tool PRIVATE cpuid) + +install(TARGETS cpuid_tool + CONFIGURATIONS Debug + RUNTIME DESTINATION bin/Debug) +install(TARGETS cpuid_tool + CONFIGURATIONS Release + RUNTIME DESTINATION bin/Release) \ No newline at end of file diff --git a/libcpuid/CMakeLists.txt b/libcpuid/CMakeLists.txt new file mode 100644 index 0000000..48cadd6 --- /dev/null +++ b/libcpuid/CMakeLists.txt @@ -0,0 +1,80 @@ +add_library(cpuid + cpuid_main.c + recog_intel.c + recog_amd.c + rdtsc.c + asm-bits.c + libcpuid_util.c + rdmsr.c + msrdriver.c + ) +target_include_directories(cpuid SYSTEM PUBLIC $) + +target_compile_definitions(cpuid PRIVATE VERSION="${PROJECT_VERSION}") +set(CPUID_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/libcpuid.h ${CMAKE_CURRENT_SOURCE_DIR}/libcpuid_constants.h ${CMAKE_CURRENT_SOURCE_DIR}/libcpuid_types.h) +set_target_properties(cpuid PROPERTIES + PUBLIC_HEADER "${CPUID_HEADERS}" + ) + +#Documentation +find_package(Doxygen) +option(ENABLE_DOCS "Enable building documentation." ON) +if (DOXYGEN_FOUND AND ENABLE_DOCS) + set(top_srcdir ${PROJECT_SOURCE_DIR}) + configure_file(Doxyfile.in + Doxyfile + ESCAPE_QUOTES + ) + add_custom_target(docs + ALL + ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/ + COMMENT "Generating API documentation with Doxygen" VERBATIM + ) +else () + add_custom_target(docs + echo "Doxygen was not installed when CMake was run or ENABLE_DOCS was OFF. Check that Doxygen is installed and rerun `cmake .`" VERBATIM + ) +endif () + +#Configuration +set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated") +set(config_install_dir "lib/cmake/${PROJECT_NAME}") +set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake") +set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake") +set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets") +set(namespace "${PROJECT_NAME}::") + +include(CMakePackageConfigHelpers) + +# Configure 'ConfigVersion.cmake' +# Use: +# * PROJECT_VERSION +write_basic_package_version_file( + "${version_config}" COMPATIBILITY SameMajorVersion +) + +# Configure 'Config.cmake' +# Use variables: +# * TARGETS_EXPORT_NAME +# * PROJECT_NAME +configure_package_config_file( + "${CMAKE_SOURCE_DIR}/cmake/Config.cmake.in" + "${project_config}" + INSTALL_DESTINATION "${config_install_dir}" +) +#Installation +install(TARGETS cpuid + EXPORT "${TARGETS_EXPORT_NAME}" + LIBRARY DESTINATION "lib" + ARCHIVE DESTINATION "lib" + RUNTIME DESTINATION "bin" + INCLUDES DESTINATION "include") + +install(FILES "${project_config}" "${version_config}" + DESTINATION "${config_install_dir}" + ) +install(EXPORT "${TARGETS_EXPORT_NAME}" + NAMESPACE "${namespace}" + DESTINATION "${config_install_dir}" + ) \ No newline at end of file