From 52efefbb7d9d2857388219dd913518931c1a4f3f Mon Sep 17 00:00:00 2001 From: The Tumultuous Unicorn Of Darkness Date: Wed, 10 Jul 2024 20:56:38 +0200 Subject: [PATCH] CMake: harmonizes options --- CMakeLists.txt | 16 ++++---- Readme.md | 10 ++++- drivers/arm/CMakeLists.txt | 4 +- drivers/arm/linux/CMakeLists.txt | 4 +- libcpuid/CMakeLists.txt | 64 +++++++++++++++++--------------- 5 files changed, 58 insertions(+), 40 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 06d3bc5..b343dbe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,9 +17,11 @@ if(MSVC) else() set(LIBCPUID_SHARED ON) endif() -option(BUILD_SHARED_LIBS "Build shared lib" ${LIBCPUID_SHARED}) -option(LIBCPUID_DRIVERS "Enable kernel drivers" ON) -option(LIBCPUID_TESTS "Enable building tests" OFF) + +# Options +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_C_STANDARD 99) @@ -65,9 +67,9 @@ endif(UNIX) # Include subdirectories add_subdirectory(libcpuid) add_subdirectory(cpuid_tool) -if(LIBCPUID_DRIVERS) +if(LIBCPUID_BUILD_DRIVERS) add_subdirectory(drivers) -endif() -if(LIBCPUID_TESTS) +endif(LIBCPUID_BUILD_DRIVERS) +if(LIBCPUID_ENABLE_TESTS) add_subdirectory(tests) -endif() +endif(LIBCPUID_ENABLE_TESTS) diff --git a/Readme.md b/Readme.md index 51e23ea..ecfe01b 100644 --- a/Readme.md +++ b/Readme.md @@ -65,9 +65,17 @@ sources. ##### 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: ```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 --install build # may need administrative privileges, install under /usr/local by default ``` diff --git a/drivers/arm/CMakeLists.txt b/drivers/arm/CMakeLists.txt index 5301e96..08ec576 100644 --- a/drivers/arm/CMakeLists.txt +++ b/drivers/arm/CMakeLists.txt @@ -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) add_definitions(-DLIBCPUID_DRIVER_DEBUG) endif(LIBCPUID_DRIVER_DEBUG) diff --git a/drivers/arm/linux/CMakeLists.txt b/drivers/arm/linux/CMakeLists.txt index 876702c..2025d0d 100644 --- a/drivers/arm/linux/CMakeLists.txt +++ b/drivers/arm/linux/CMakeLists.txt @@ -1,6 +1,8 @@ -set(DRIVER_NAME "cpuid") +# Options 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) message(STATUS "Deploying DKMS configuration for CPUID kernel module...") set(LIBCPUID_SRC_DIR "/usr/src/${CMAKE_PROJECT_NAME}-${PROJECT_VERSION}") diff --git a/libcpuid/CMakeLists.txt b/libcpuid/CMakeLists.txt index 65d7556..09189ef 100644 --- a/libcpuid/CMakeLists.txt +++ b/libcpuid/CMakeLists.txt @@ -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 cpuid_main.c recog_amd.c @@ -21,11 +25,10 @@ if("${MSVC_CXX_ARCHITECTURE_ID}" MATCHES "x64") list(APPEND cpuid_sources masm-x64.asm) endif() -option(SUPPORT_DEPRECATED "Build support of deprecated attributes" ON) -if(NOT SUPPORT_DEPRECATED) +if(NOT LIBCPUID_BUILD_DEPRECATED) message(AUTHOR_WARNING "Deprecated attributes will not be available, the library will be not backward compatible") add_compile_definitions(LIBCPUID_DISABLE_DEPRECATED) -endif(NOT SUPPORT_DEPRECATED) +endif(NOT LIBCPUID_BUILD_DEPRECATED) add_library(cpuid ${cpuid_sources}) 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") # 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) - 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() +if(LIBCPUID_ENABLE_DOCS) + find_package(Doxygen) + if(DOXYGEN_FOUND) + 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(DOXYGEN_FOUND) + add_custom_target( + docs + echo + "Doxygen was not installed when CMake was run. Check that Doxygen is installed and rerun `cmake .`" + VERBATIM) + endif(DOXYGEN_FOUND) +endif(LIBCPUID_ENABLE_DOCS) # Configuration set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")