Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Options prefix add. Executables build option add: #794 #801

Merged
merged 2 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2022, Intel Corporation

cmake_minimum_required(VERSION 3.5)

project(PCM)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
# set(CMAKE_POSITION_INDEPENDENT_CODE ON)


option(PCM_NO_ASAN "Disable address sanitizer" OFF)
option(PCM_FUZZ "Enable fuzzing" OFF)
option(PCM_BUILD_EXECUTABLES "Build PCM utilities" ON)
option(PCM_NO_STATIC_LIBASAN OFF)

if(MSVC)
option(PCM_NO_STATIC_MSVC_RUNTIME_LIBRARY "Disable using static runtime under MSVC" OFF)
endif()

foreach(opt NO_STATIC_MSVC_RUNTIME_LIBRARY;FUZZ;NO_ASAN;NO_STATIC_LIBASAN)
if(${opt})
message(DEPRECATION "Option \"${opt}\" is deprecated and will be removed soon. Please use \"PCM_${opt}\"")
set(PCM_${opt} ${opt})
endif()
endforeach()

include(GNUInstallDirs)

Expand All @@ -19,6 +37,7 @@ foreach(file ${PCM_X_ARTIFACTS})
file(REMOVE ${file})
message(STATUS "Removing old artifact from current source directory : ${file}")
endforeach()

if(PCM_X_ARTIFACTS)
message(WARNING
" Old pcm utilities (.x) were indicated in build folder.\n"
Expand Down Expand Up @@ -82,12 +101,12 @@ if(UNIX) # APPLE, LINUX, FREE_BSD
elseif()
set (PCM_DYNAMIC "")
endif()
if(NO_ASAN)
if(PCM_NO_ASAN)
message(STATUS "AddressSanitizer is disabled")
set(PCM_ASAN "")
else()
message(STATUS "AddressSanitizer is enabled")
message(STATUS "To disable AddressSanitizer, use -DNO_ASAN=1 option")
message(STATUS "To disable AddressSanitizer, use -DPCM_NO_ASAN=1 option")
set(PCM_ASAN "-fsanitize=address")
endif()
set(PCM_HARDENING_FLAGS "-fPIE -fstack-protector -D_FORTIFY_SOURCE=2 -ftrapv ${PCM_ASAN} -fwrapv -fno-delete-null-pointer-checks -fno-strict-overflow -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer")
Expand Down Expand Up @@ -117,12 +136,12 @@ if(UNIX) # APPLE, LINUX, FREE_BSD

endif(UNIX)

if(FUZZ)
if(PCM_FUZZ)
set(FUZZER_OPTIONS "-fsanitize=fuzzer,address -fprofile-instr-generate -fcoverage-mapping")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FUZZER_OPTIONS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FUZZER_OPTIONS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${FUZZER_OPTIONS}")
endif(FUZZ)
endif(PCM_FUZZ)

#######################
# Install
Expand Down
2 changes: 1 addition & 1 deletion pcm.spec
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Intel(r) Performance Counter Monitor (Intel(r) PCM) is an application programmin
%build
mkdir build
cd build
cmake -DNO_STATIC_LIBASAN=1 -DCMAKE_INSTALL_PREFIX=/usr/ -DCMAKE_BUILD_TYPE=RelWithDebInfo ..
cmake -DPCM_NO_STATIC_LIBASAN=ON -DCMAKE_INSTALL_PREFIX=/usr/ -DCMAKE_BUILD_TYPE=RelWithDebInfo ..
make -j

%install
Expand Down
124 changes: 63 additions & 61 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ if (LINUX)
endif()
endif()

if(NOT DEFINED NO_ASAN)
if(NOT PCM_NO_ASAN)
if(OS_ID STREQUAL "centos")
set(NO_STATIC_LIBASAN 1)
set(PCM_NO_STATIC_LIBASAN ON)
message(STATUS "CentOS detected, using dynamic libasan")
endif()
endif()
Expand Down Expand Up @@ -68,19 +68,19 @@ if(UNIX) # LINUX, FREE_BSD, APPLE
$<$<CONFIG:RelWithDebInfo>:PCM_SILENT>
)

if(NO_ASAN)
if(PCM_NO_ASAN)
set(PCM_DYNAMIC_ASAN "")
set(PCM_STATIC_ASAN "")
else()
if(NO_STATIC_LIBASAN)
if(PCM_NO_STATIC_LIBASAN)
message(STATUS "Using dynamic libasan")
set(PCM_DYNAMIC_ASAN "asan")
set(PCM_STATIC_ASAN "")
else()
set(PCM_DYNAMIC_ASAN "")
set(PCM_STATIC_ASAN "-static-libasan")
message(STATUS "Using static libasan")
message(STATUS "To use dynamic libasan, use -DNO_STATIC_LIBASAN=1 option (required for CentOS)")
message(STATUS "To use dynamic libasan, use -DPCM_NO_STATIC_LIBASAN=1 option (required for CentOS)")
endif()
endif()

Expand All @@ -102,7 +102,7 @@ if(MSVC)
file(GLOB WINDOWS_SOURCES winpmem/winpmem.cpp windows/stdafx.cpp freegetopt/getopt.cpp)
add_library(PCM_STATIC STATIC ${COMMON_SOURCES} ${WINDOWS_SOURCES})
target_compile_definitions(PCM_STATIC PRIVATE UNICODE _UNICODE _CONSOLE)
if (NO_STATIC_MSVC_RUNTIME_LIBRARY)
if(PCM_NO_STATIC_MSVC_RUNTIME_LIBRARY)
set(PCM_MSVC_RUNTIME_LIBRARY_OPTIONS "")
else()
set(PCM_MSVC_RUNTIME_LIBRARY_OPTIONS "/MT$<$<CONFIG:Debug>:d>")
Expand Down Expand Up @@ -175,66 +175,68 @@ endif(SIMDJSON_IS_APPLICABLE)
# End of SIMDJSON dependency section
#######################

foreach(PROJECT_NAME ${PROJECT_NAMES})
file(GLOB PROJECT_FILE ${PROJECT_NAME}.cpp)
set(LIBS PCM_STATIC)
if(PCM_BUILD_EXECUTABLES)
foreach(PROJECT_NAME ${PROJECT_NAMES})
file(GLOB PROJECT_FILE ${PROJECT_NAME}.cpp)
set(LIBS PCM_STATIC)

add_executable(${PROJECT_NAME} ${PROJECT_FILE})
add_executable(${PROJECT_NAME} ${PROJECT_FILE})

if(MSVC)
target_compile_options(${PROJECT_NAME} PRIVATE "${PCM_MSVC_RUNTIME_LIBRARY_OPTIONS}")
endif(MSVC)
if(MSVC)
target_compile_options(${PROJECT_NAME} PRIVATE "${PCM_MSVC_RUNTIME_LIBRARY_OPTIONS}")
endif(MSVC)

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "${PCM_STATIC_ASAN}")
endif()

# specific file for pcm-raw project
if(${PROJECT_NAME} STREQUAL pcm-raw)
set(LIBS ${LIBS} PCM_SIMDJSON)
endif(${PROJECT_NAME} STREQUAL pcm-raw)

if(${PROJECT_NAME} STREQUAL pcm-sensor-server)
if(NO_SSL)
message(STATUS "SSL is disabled")
else()
message(STATUS "Compiling with SSL support, requires libssl-dev or openssl-devel or libopenssl-devel or libopenssl-dev package installed")
message(STATUS "To disable SSL support, use -DNO_SSL=1 option")
find_package(OpenSSL ${MINIMUM_OPENSSL_VERSION} QUIET)
if(OPENSSL_FOUND)
message(STATUS "OpenSSL version ${OPENSSL_VERSION} >= ${MINIMUM_OPENSSL_VERSION}, OpenSSL support enabled")
target_compile_options(${PROJECT_NAME} PRIVATE "-DUSE_SSL")
set(LIBS ${LIBS} OpenSSL::SSL OpenSSL::Crypto)
else()
message(STATUS "OpenSSL support has been disabled, the version is less than ${MINIMUM_OPENSSL_VERSION}")
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "${PCM_STATIC_ASAN}")
endif()
endif()
file(READ pcm-sensor-server.service.in SENSOR_SERVICE_IN)
string(REPLACE "@@CMAKE_INSTALL_SBINDIR@@" "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_SBINDIR}" SENSOR_SERVICE "${SENSOR_SERVICE_IN}")
file(WRITE "${CMAKE_BINARY_DIR}/pcm-sensor-server.service" "${SENSOR_SERVICE}")
file(GLOB PROJECT_FILE ${PROJECT_NAME}.cpp pcm-accel-common.h pcm-accel-common.cpp)
target_include_directories(pcm-sensor-server PUBLIC ${CMAKE_SOURCE_DIR})
if(LINUX_SYSTEMD)
install(FILES "${CMAKE_BINARY_DIR}/pcm-sensor-server.service" DESTINATION "${LINUX_SYSTEMD_UNITDIR}")
endif(LINUX_SYSTEMD)
endif(${PROJECT_NAME} STREQUAL pcm-sensor-server)

if(LINUX OR FREE_BSD)
set(LIBS ${LIBS} Threads::Threads)
install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_SBINDIR})
endif(LINUX OR FREE_BSD)

if(APPLE)
set(LIBS ${LIBS} Threads::Threads PcmMsr)
install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_SBINDIR})
endif(APPLE)

if(MSVC)
target_compile_definitions(${PROJECT_NAME} PRIVATE _UNICODE UNICODE _CONSOLE) # for all, except pcm-lib and pcm-service
endif(MSVC)

target_link_libraries(${PROJECT_NAME} PRIVATE ${LIBS})
endforeach(PROJECT_NAME ${PROJECT_NAMES})
# specific file for pcm-raw project
if(${PROJECT_NAME} STREQUAL pcm-raw)
set(LIBS ${LIBS} PCM_SIMDJSON)
endif(${PROJECT_NAME} STREQUAL pcm-raw)

if(${PROJECT_NAME} STREQUAL pcm-sensor-server)
if(NO_SSL)
message(STATUS "SSL is disabled")
else()
message(STATUS "Compiling with SSL support, requires libssl-dev or openssl-devel or libopenssl-devel or libopenssl-dev package installed")
message(STATUS "To disable SSL support, use -DNO_SSL=1 option")
find_package(OpenSSL ${MINIMUM_OPENSSL_VERSION} QUIET)
if(OPENSSL_FOUND)
message(STATUS "OpenSSL version ${OPENSSL_VERSION} >= ${MINIMUM_OPENSSL_VERSION}, OpenSSL support enabled")
target_compile_options(${PROJECT_NAME} PRIVATE "-DUSE_SSL")
set(LIBS ${LIBS} OpenSSL::SSL OpenSSL::Crypto)
else()
message(STATUS "OpenSSL support has been disabled, the version is less than ${MINIMUM_OPENSSL_VERSION}")
endif()
endif()
file(READ pcm-sensor-server.service.in SENSOR_SERVICE_IN)
string(REPLACE "@@CMAKE_INSTALL_SBINDIR@@" "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_SBINDIR}" SENSOR_SERVICE "${SENSOR_SERVICE_IN}")
file(WRITE "${CMAKE_BINARY_DIR}/pcm-sensor-server.service" "${SENSOR_SERVICE}")
file(GLOB PROJECT_FILE ${PROJECT_NAME}.cpp pcm-accel-common.h pcm-accel-common.cpp)
target_include_directories(pcm-sensor-server PUBLIC ${CMAKE_SOURCE_DIR})
if(LINUX_SYSTEMD)
install(FILES "${CMAKE_BINARY_DIR}/pcm-sensor-server.service" DESTINATION "${LINUX_SYSTEMD_UNITDIR}")
endif(LINUX_SYSTEMD)
endif(${PROJECT_NAME} STREQUAL pcm-sensor-server)

if(LINUX OR FREE_BSD)
set(LIBS ${LIBS} Threads::Threads)
install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_SBINDIR})
endif(LINUX OR FREE_BSD)

if(APPLE)
set(LIBS ${LIBS} Threads::Threads PcmMsr)
install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_SBINDIR})
endif(APPLE)

if(MSVC)
target_compile_definitions(${PROJECT_NAME} PRIVATE _UNICODE UNICODE _CONSOLE) # for all, except pcm-lib and pcm-service
endif(MSVC)

target_link_libraries(${PROJECT_NAME} PRIVATE ${LIBS})
endforeach(PROJECT_NAME ${PROJECT_NAMES})
endif(PCM_BUILD_EXECUTABLES)

#######################
# Install
Expand Down