1
0
Fork 0
mirror of https://github.com/anrieff/libcpuid synced 2024-11-10 22:59:13 +00:00

CMake: fix Unix install and format

This commit is contained in:
Xorg 2020-05-21 18:43:34 +02:00
parent f49e82043c
commit 7179a7b103
No known key found for this signature in database
GPG key ID: 1E55EE2EFF18BC1A
4 changed files with 135 additions and 68 deletions

View file

@ -1,10 +1,30 @@
cmake_minimum_required(VERSION 3.14)
set(VERSION "0.4.1")
project(cpuid LANGUAGES C CXX ASM_MASM VERSION ${VERSION})
set(SOVERSION 14)
project(
cpuid
LANGUAGES C CXX ASM_MASM
VERSION ${VERSION})
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_C_STANDARD 99)
# Global variables
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
if(UNIX)
include(GNUInstallDirs)
set(prefix "${CMAKE_INSTALL_PREFIX}")
set(exec_prefix "\${prefix}")
set(libdir "\${exec_prefix}/lib")
set(includedir "\${prefix}/include")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/libcpuid.pc.in" "${CMAKE_CURRENT_BINARY_DIR}/libcpuid.pc" ESCAPE_QUOTES
@ONLY)
install(FILES "${PROJECT_BINARY_DIR}/libcpuid.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
endif(UNIX)
# Include subdirectories
add_subdirectory(libcpuid)
add_subdirectory(cpuid_tool)
add_subdirectory(tests)

View file

@ -1,9 +1,16 @@
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)
target_link_libraries(cpuid_tool cpuid)
if(WIN32)
install(
TARGETS cpuid_tool
CONFIGURATIONS Debug
RUNTIME DESTINATION bin/Debug)
install(
TARGETS cpuid_tool
CONFIGURATIONS Release
RUNTIME DESTINATION bin/Release)
else()
install(TARGETS cpuid_tool RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()

View file

@ -1,4 +1,5 @@
set(cpuid_sources cpuid_main.c
set(cpuid_sources
cpuid_main.c
recog_intel.c
recog_amd.c
rdtsc.c
@ -7,43 +8,48 @@ set(cpuid_sources cpuid_main.c
msrdriver.c
asm-bits.c)
if ("${MSVC_CXX_ARCHITECTURE_ID}" MATCHES "x64")
list(APPEND cpuid_sources masm-x64.asm)
endif ()
if(WIN32 AND "${MSVC_CXX_ARCHITECTURE_ID}" MATCHES "x64")
list(APPEND cpuid_sources masm-x64.asm)
endif()
add_library(cpuid
${cpuid_sources}
)
add_library(cpuid SHARED ${cpuid_sources})
target_include_directories(cpuid SYSTEM PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
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}"
)
set_target_properties(cpuid PROPERTIES VERSION ${PROJECT_VERSION})
set_target_properties(cpuid PROPERTIES SOVERSION ${SOVERSION})
set_target_properties(cpuid PROPERTIES PUBLIC_HEADER "libcpuid.h;libcpuid_types.h;libcpuid_constants.h")
#Documentation
# 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 ()
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)
if(UNIX)
install(
DIRECTORY "${CMAKE_SOURCE_DIR}/docs/man/"
DESTINATION "${CMAKE_INSTALL_MANDIR}"
FILES_MATCHING
PATTERN "cpu_*_t.3"
PATTERN "libcpuid.3"
PATTERN "cpuid_tool.3")
endif(UNIX)
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
# 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")
@ -53,34 +59,40 @@ set(namespace "${PROJECT_NAME}::")
include(CMakePackageConfigHelpers)
# Configure '<PROJECT-NAME>ConfigVersion.cmake'
# Use:
# * PROJECT_VERSION
write_basic_package_version_file(
"${version_config}" COMPATIBILITY SameMajorVersion
)
# Configure '<PROJECT-NAME>ConfigVersion.cmake' Use: * PROJECT_VERSION
write_basic_package_version_file("${version_config}" COMPATIBILITY SameMajorVersion)
# Configure '<PROJECT-NAME>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")
# Configure '<PROJECT-NAME>Config.cmake' Use variables: * TARGETS_EXPORT_NAME * PROJECT_NAME
configure_package_config_file("${CMAKE_MODULE_PATH}/Config.cmake.in" "${project_config}"
INSTALL_DESTINATION "${config_install_dir}")
install(FILES "${project_config}" "${version_config}"
DESTINATION "${config_install_dir}"
)
install(EXPORT "${TARGETS_EXPORT_NAME}"
NAMESPACE "${namespace}"
DESTINATION "${config_install_dir}"
)
# Installation
if(WIN32)
install(
TARGETS cpuid
EXPORT "${TARGETS_EXPORT_NAME}"
LIBRARY DESTINATION "lib"
ARCHIVE DESTINATION "lib"
RUNTIME DESTINATION "bin"
INCLUDES
DESTINATION "include")
install(
EXPORT "${TARGETS_EXPORT_NAME}"
NAMESPACE "${namespace}"
DESTINATION "${config_install_dir}")
else()
install(
TARGETS cpuid
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
endif()
install(FILES "${project_config}" "${version_config}" DESTINATION "${config_install_dir}")
add_custom_target(
consistency
COMMAND "./check-consistency.py" "./"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/
COMMENT "Run tests (fast mode)"
VERBATIM)

28
tests/CMakeLists.txt Normal file
View file

@ -0,0 +1,28 @@
add_executable(convert_instlatx64 convert_instlatx64.c)
target_link_libraries(convert_instlatx64 PUBLIC cpuid)
add_custom_target(test DEPENDS test-fast)
add_custom_target(
test-fast
COMMAND ${CMAKE_COMMAND} -E env "LD_LD_PRELOAD=${CMAKE_BINARY_DIR}/libcpuid" ./run_tests.py
"${CMAKE_BINARY_DIR}/cpuid_tool/cpuid_tool" "." --show-test-fast-warning
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/
COMMENT "Run tests (fast mode)"
VERBATIM)
add_custom_target(
test-old
COMMAND ${CMAKE_COMMAND} -E env "LD_LD_PRELOAD=${CMAKE_BINARY_DIR}/libcpuid" ./run_tests.py
"${CMAKE_BINARY_DIR}/cpuid_tool/cpuid_tool" "."
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/
COMMENT "Run tests (old mode)"
VERBATIM)
add_custom_target(
fix-tests
COMMAND ${CMAKE_COMMAND} -E env "LD_LD_PRELOAD=${CMAKE_BINARY_DIR}/libcpuid" ./run_tests.py
"${CMAKE_BINARY_DIR}/cpuid_tool/cpuid_tool" "." --fix
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/
COMMENT "Fix tests"
VERBATIM)