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:
parent
f49e82043c
commit
7179a7b103
4 changed files with 135 additions and 68 deletions
|
@ -1,10 +1,30 @@
|
||||||
cmake_minimum_required(VERSION 3.14)
|
cmake_minimum_required(VERSION 3.14)
|
||||||
|
|
||||||
set(VERSION "0.4.1")
|
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_CXX_STANDARD 11)
|
||||||
set(CMAKE_C_STANDARD 99)
|
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(libcpuid)
|
||||||
add_subdirectory(cpuid_tool)
|
add_subdirectory(cpuid_tool)
|
||||||
|
add_subdirectory(tests)
|
||||||
|
|
|
@ -1,9 +1,16 @@
|
||||||
add_executable(cpuid_tool cpuid_tool.c)
|
add_executable(cpuid_tool cpuid_tool.c)
|
||||||
target_link_libraries(cpuid_tool PRIVATE cpuid)
|
|
||||||
|
|
||||||
install(TARGETS cpuid_tool
|
target_link_libraries(cpuid_tool cpuid)
|
||||||
|
|
||||||
|
if(WIN32)
|
||||||
|
install(
|
||||||
|
TARGETS cpuid_tool
|
||||||
CONFIGURATIONS Debug
|
CONFIGURATIONS Debug
|
||||||
RUNTIME DESTINATION bin/Debug)
|
RUNTIME DESTINATION bin/Debug)
|
||||||
install(TARGETS cpuid_tool
|
install(
|
||||||
|
TARGETS cpuid_tool
|
||||||
CONFIGURATIONS Release
|
CONFIGURATIONS Release
|
||||||
RUNTIME DESTINATION bin/Release)
|
RUNTIME DESTINATION bin/Release)
|
||||||
|
else()
|
||||||
|
install(TARGETS cpuid_tool RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||||
|
endif()
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
set(cpuid_sources cpuid_main.c
|
set(cpuid_sources
|
||||||
|
cpuid_main.c
|
||||||
recog_intel.c
|
recog_intel.c
|
||||||
recog_amd.c
|
recog_amd.c
|
||||||
rdtsc.c
|
rdtsc.c
|
||||||
|
@ -7,43 +8,48 @@ set(cpuid_sources cpuid_main.c
|
||||||
msrdriver.c
|
msrdriver.c
|
||||||
asm-bits.c)
|
asm-bits.c)
|
||||||
|
|
||||||
if ("${MSVC_CXX_ARCHITECTURE_ID}" MATCHES "x64")
|
if(WIN32 AND "${MSVC_CXX_ARCHITECTURE_ID}" MATCHES "x64")
|
||||||
list(APPEND cpuid_sources masm-x64.asm)
|
list(APPEND cpuid_sources masm-x64.asm)
|
||||||
endif ()
|
endif()
|
||||||
|
|
||||||
add_library(cpuid
|
add_library(cpuid SHARED ${cpuid_sources})
|
||||||
${cpuid_sources}
|
|
||||||
)
|
|
||||||
target_include_directories(cpuid SYSTEM PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
|
target_include_directories(cpuid SYSTEM PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
|
||||||
|
|
||||||
target_compile_definitions(cpuid PRIVATE VERSION="${PROJECT_VERSION}")
|
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 VERSION ${PROJECT_VERSION})
|
||||||
set_target_properties(cpuid PROPERTIES
|
set_target_properties(cpuid PROPERTIES SOVERSION ${SOVERSION})
|
||||||
PUBLIC_HEADER "${CPUID_HEADERS}"
|
set_target_properties(cpuid PROPERTIES PUBLIC_HEADER "libcpuid.h;libcpuid_types.h;libcpuid_constants.h")
|
||||||
)
|
|
||||||
|
|
||||||
#Documentation
|
# Documentation
|
||||||
find_package(Doxygen)
|
find_package(Doxygen)
|
||||||
option(ENABLE_DOCS "Enable building documentation." ON)
|
option(ENABLE_DOCS "Enable building documentation." ON)
|
||||||
if (DOXYGEN_FOUND AND ENABLE_DOCS)
|
if(DOXYGEN_FOUND AND ENABLE_DOCS)
|
||||||
set(top_srcdir ${PROJECT_SOURCE_DIR})
|
set(top_srcdir ${PROJECT_SOURCE_DIR})
|
||||||
configure_file(Doxyfile.in
|
configure_file(Doxyfile.in Doxyfile ESCAPE_QUOTES)
|
||||||
Doxyfile
|
add_custom_target(
|
||||||
ESCAPE_QUOTES
|
docs ALL
|
||||||
)
|
|
||||||
add_custom_target(docs
|
|
||||||
ALL
|
|
||||||
${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
|
${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
|
||||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/
|
||||||
COMMENT "Generating API documentation with Doxygen" VERBATIM
|
COMMENT "Generating API documentation with Doxygen"
|
||||||
)
|
VERBATIM)
|
||||||
else ()
|
if(UNIX)
|
||||||
add_custom_target(docs
|
install(
|
||||||
echo "Doxygen was not installed when CMake was run or ENABLE_DOCS was OFF. Check that Doxygen is installed and rerun `cmake .`" VERBATIM
|
DIRECTORY "${CMAKE_SOURCE_DIR}/docs/man/"
|
||||||
)
|
DESTINATION "${CMAKE_INSTALL_MANDIR}"
|
||||||
endif ()
|
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(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
|
||||||
set(config_install_dir "lib/cmake/${PROJECT_NAME}")
|
set(config_install_dir "lib/cmake/${PROJECT_NAME}")
|
||||||
set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake")
|
set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake")
|
||||||
|
@ -53,34 +59,40 @@ set(namespace "${PROJECT_NAME}::")
|
||||||
|
|
||||||
include(CMakePackageConfigHelpers)
|
include(CMakePackageConfigHelpers)
|
||||||
|
|
||||||
# Configure '<PROJECT-NAME>ConfigVersion.cmake'
|
# Configure '<PROJECT-NAME>ConfigVersion.cmake' Use: * PROJECT_VERSION
|
||||||
# Use:
|
write_basic_package_version_file("${version_config}" COMPATIBILITY SameMajorVersion)
|
||||||
# * PROJECT_VERSION
|
|
||||||
write_basic_package_version_file(
|
|
||||||
"${version_config}" COMPATIBILITY SameMajorVersion
|
|
||||||
)
|
|
||||||
|
|
||||||
# Configure '<PROJECT-NAME>Config.cmake'
|
# Configure '<PROJECT-NAME>Config.cmake' Use variables: * TARGETS_EXPORT_NAME * PROJECT_NAME
|
||||||
# Use variables:
|
configure_package_config_file("${CMAKE_MODULE_PATH}/Config.cmake.in" "${project_config}"
|
||||||
# * TARGETS_EXPORT_NAME
|
INSTALL_DESTINATION "${config_install_dir}")
|
||||||
# * PROJECT_NAME
|
|
||||||
configure_package_config_file(
|
# Installation
|
||||||
"${CMAKE_SOURCE_DIR}/cmake/Config.cmake.in"
|
if(WIN32)
|
||||||
"${project_config}"
|
install(
|
||||||
INSTALL_DESTINATION "${config_install_dir}"
|
TARGETS cpuid
|
||||||
)
|
|
||||||
#Installation
|
|
||||||
install(TARGETS cpuid
|
|
||||||
EXPORT "${TARGETS_EXPORT_NAME}"
|
EXPORT "${TARGETS_EXPORT_NAME}"
|
||||||
LIBRARY DESTINATION "lib"
|
LIBRARY DESTINATION "lib"
|
||||||
ARCHIVE DESTINATION "lib"
|
ARCHIVE DESTINATION "lib"
|
||||||
RUNTIME DESTINATION "bin"
|
RUNTIME DESTINATION "bin"
|
||||||
INCLUDES DESTINATION "include")
|
INCLUDES
|
||||||
|
DESTINATION "include")
|
||||||
install(FILES "${project_config}" "${version_config}"
|
install(
|
||||||
DESTINATION "${config_install_dir}"
|
EXPORT "${TARGETS_EXPORT_NAME}"
|
||||||
)
|
|
||||||
install(EXPORT "${TARGETS_EXPORT_NAME}"
|
|
||||||
NAMESPACE "${namespace}"
|
NAMESPACE "${namespace}"
|
||||||
DESTINATION "${config_install_dir}"
|
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
28
tests/CMakeLists.txt
Normal 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)
|
Loading…
Reference in a new issue