1
0
Fork 0
mirror of https://github.com/anrieff/libcpuid synced 2024-12-16 16:35:45 +00:00

CMake: harmonizes options

This commit is contained in:
The Tumultuous Unicorn Of Darkness 2024-07-10 20:56:38 +02:00
parent 4d6cc787fe
commit 52efefbb7d
No known key found for this signature in database
GPG key ID: 1E55EE2EFF18BC1A
5 changed files with 58 additions and 40 deletions

View file

@ -17,9 +17,11 @@ if(MSVC)
else() else()
set(LIBCPUID_SHARED ON) set(LIBCPUID_SHARED ON)
endif() endif()
option(BUILD_SHARED_LIBS "Build shared lib" ${LIBCPUID_SHARED})
option(LIBCPUID_DRIVERS "Enable kernel drivers" ON) # Options
option(LIBCPUID_TESTS "Enable building tests" OFF) option(BUILD_SHARED_LIBS "Build building shared libraries" ${LIBCPUID_SHARED})
option(LIBCPUID_BUILD_DRIVERS "Enable building kernel drivers" ON)
option(LIBCPUID_ENABLE_TESTS "Enable tests targets" OFF)
set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD 11)
set(CMAKE_C_STANDARD 99) set(CMAKE_C_STANDARD 99)
@ -65,9 +67,9 @@ endif(UNIX)
# Include subdirectories # Include subdirectories
add_subdirectory(libcpuid) add_subdirectory(libcpuid)
add_subdirectory(cpuid_tool) add_subdirectory(cpuid_tool)
if(LIBCPUID_DRIVERS) if(LIBCPUID_BUILD_DRIVERS)
add_subdirectory(drivers) add_subdirectory(drivers)
endif() endif(LIBCPUID_BUILD_DRIVERS)
if(LIBCPUID_TESTS) if(LIBCPUID_ENABLE_TESTS)
add_subdirectory(tests) add_subdirectory(tests)
endif() endif(LIBCPUID_ENABLE_TESTS)

View file

@ -65,9 +65,17 @@ sources.
##### By using CMake ##### By using CMake
CMake options for libcpuid (use `cmake -LH` to list all options):
- `LIBCPUID_ENABLE_DOCS`: enable building documentation by using Doxyen (**ON** by default)
- `LIBCPUID_ENABLE_TESTS`: enable tests targets, like `test-fast`, `test-old` and `fix-tests` (**OFF** by default)
- `LIBCPUID_BUILD_DEPRECATED`: build support of deprecated attributes (**ON** by default to guarantee backward compatibility)
- `LIBCPUID_BUILD_DRIVERS`: enable building kernel drivers (**ON** by default)
- `LIBCPUID_DRIVER_DEBUG`: enable debug mode flr kernel drivers (**OFF** by default)
- `LIBCPUID_DRIVER_ARM_LINUX_DKMS`: use DKMS for CPUID Linux kernel module for ARM (**ON** by default), switch off to build the kernel module in the `build` directory
Basic example to build and install libcpuid by using CMake: Basic example to build and install libcpuid by using CMake:
```shell ```shell
cmake -S . -B build -DCMAKE_BUILD_TYPE=RelWithDebInfo cmake -S . -B build -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLIBCPUID_ENABLE_TESTS=ON
cmake --build build cmake --build build
cmake --install build # may need administrative privileges, install under /usr/local by default cmake --install build # may need administrative privileges, install under /usr/local by default
``` ```

View file

@ -1,4 +1,6 @@
option(LIBCPUID_DRIVER_DEBUG "Debug kernel module" OFF) # Options
option(LIBCPUID_DRIVER_DEBUG "Debug kernel driver" OFF)
if(LIBCPUID_DRIVER_DEBUG) if(LIBCPUID_DRIVER_DEBUG)
add_definitions(-DLIBCPUID_DRIVER_DEBUG) add_definitions(-DLIBCPUID_DRIVER_DEBUG)
endif(LIBCPUID_DRIVER_DEBUG) endif(LIBCPUID_DRIVER_DEBUG)

View file

@ -1,6 +1,8 @@
set(DRIVER_NAME "cpuid") # Options
option(LIBCPUID_DRIVER_ARM_LINUX_DKMS "Use DKMS for CPUID kernel module for ARM" ON) option(LIBCPUID_DRIVER_ARM_LINUX_DKMS "Use DKMS for CPUID kernel module for ARM" ON)
set(DRIVER_NAME "cpuid")
if(LIBCPUID_DRIVER_ARM_LINUX_DKMS) if(LIBCPUID_DRIVER_ARM_LINUX_DKMS)
message(STATUS "Deploying DKMS configuration for CPUID kernel module...") message(STATUS "Deploying DKMS configuration for CPUID kernel module...")
set(LIBCPUID_SRC_DIR "/usr/src/${CMAKE_PROJECT_NAME}-${PROJECT_VERSION}") set(LIBCPUID_SRC_DIR "/usr/src/${CMAKE_PROJECT_NAME}-${PROJECT_VERSION}")

View file

@ -1,3 +1,7 @@
# Options
option(LIBCPUID_BUILD_DEPRECATED "Build support of deprecated attributes" ON)
option(LIBCPUID_ENABLE_DOCS "Enable building documentation" ON)
set(cpuid_sources set(cpuid_sources
cpuid_main.c cpuid_main.c
recog_amd.c recog_amd.c
@ -21,11 +25,10 @@ if("${MSVC_CXX_ARCHITECTURE_ID}" MATCHES "x64")
list(APPEND cpuid_sources masm-x64.asm) list(APPEND cpuid_sources masm-x64.asm)
endif() endif()
option(SUPPORT_DEPRECATED "Build support of deprecated attributes" ON) if(NOT LIBCPUID_BUILD_DEPRECATED)
if(NOT SUPPORT_DEPRECATED)
message(AUTHOR_WARNING "Deprecated attributes will not be available, the library will be not backward compatible") message(AUTHOR_WARNING "Deprecated attributes will not be available, the library will be not backward compatible")
add_compile_definitions(LIBCPUID_DISABLE_DEPRECATED) add_compile_definitions(LIBCPUID_DISABLE_DEPRECATED)
endif(NOT SUPPORT_DEPRECATED) endif(NOT LIBCPUID_BUILD_DEPRECATED)
add_library(cpuid ${cpuid_sources}) add_library(cpuid ${cpuid_sources})
set_property(TARGET cpuid PROPERTY WINDOWS_EXPORT_ALL_SYMBOLS ON) set_property(TARGET cpuid PROPERTY WINDOWS_EXPORT_ALL_SYMBOLS ON)
@ -38,33 +41,34 @@ set_target_properties(cpuid PROPERTIES SOVERSION "${LIBCPUID_CURRENT}")
set_target_properties(cpuid PROPERTIES PUBLIC_HEADER "libcpuid.h;libcpuid_types.h;libcpuid_constants.h") set_target_properties(cpuid PROPERTIES PUBLIC_HEADER "libcpuid.h;libcpuid_types.h;libcpuid_constants.h")
# Documentation # Documentation
find_package(Doxygen) if(LIBCPUID_ENABLE_DOCS)
option(ENABLE_DOCS "Enable building documentation." ON) find_package(Doxygen)
if(DOXYGEN_FOUND AND ENABLE_DOCS) if(DOXYGEN_FOUND)
set(top_srcdir ${PROJECT_SOURCE_DIR}) set(top_srcdir ${PROJECT_SOURCE_DIR})
configure_file(Doxyfile.in Doxyfile ESCAPE_QUOTES) configure_file(Doxyfile.in Doxyfile ESCAPE_QUOTES)
add_custom_target( add_custom_target(
docs ALL 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" COMMENT "Generating API documentation with Doxygen"
VERBATIM) VERBATIM)
if(UNIX) if(UNIX)
install( install(
DIRECTORY "${CMAKE_SOURCE_DIR}/docs/man/" DIRECTORY "${CMAKE_SOURCE_DIR}/docs/man/"
DESTINATION "${CMAKE_INSTALL_MANDIR}" DESTINATION "${CMAKE_INSTALL_MANDIR}"
FILES_MATCHING FILES_MATCHING
PATTERN "cpu_*_t.3" PATTERN "cpu_*_t.3"
PATTERN "libcpuid.3" PATTERN "libcpuid.3"
PATTERN "cpuid_tool.3") PATTERN "cpuid_tool.3")
endif(UNIX) endif(UNIX)
else() else(DOXYGEN_FOUND)
add_custom_target( add_custom_target(
docs docs
echo echo
"Doxygen was not installed when CMake was run or ENABLE_DOCS was OFF. Check that Doxygen is installed and rerun `cmake .`" "Doxygen was not installed when CMake was run. Check that Doxygen is installed and rerun `cmake .`"
VERBATIM) VERBATIM)
endif() endif(DOXYGEN_FOUND)
endif(LIBCPUID_ENABLE_DOCS)
# Configuration # Configuration
set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated") set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")