Skip to content
Open
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
43 changes: 35 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ include(CMakePackageConfigHelpers)

set ( CMAKE_C_STANDARD 99 )
set ( CMAKE_C_STANDARD_REQUIRED ON )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2 -g" )
set ( CMAKE_C_EXTENSIONS OFF )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2 -g -Wall -W" )

add_compile_definitions ( _LARGEFILE64_SOURCE _FILE_OFFSET_BITS=64 )

string(TIMESTAMP BUILD_TIME "%Y%m%d %H:%M:%S")

Expand Down Expand Up @@ -127,6 +130,11 @@ check_function_exists(pthread_kill HAVE_PTHREAD_KILL)
check_function_exists(getopt_long HAVE_GETOPT_LONG)
check_function_exists(setmode HAVE_SETMODE)

find_package(Threads)

include(CheckLibraryExists)
check_library_exists(rt clock_gettime "" NEED_RT_LIB)

set(OS_LINUX 0)
set(SG_LIB_LINUX 0)
set(SG_LIB_ANDROID 0)
Expand Down Expand Up @@ -162,11 +170,13 @@ if (CYGWIN)
set(OS_WIN32 1)
set(SG_LIB_WIN32 1)
set(SG_LIB_CYGWIN 1)
set(HAVE_NVME 1)
elseif (MINGW)
message(STATUS ">> MinGW build")
set(OS_WIN32 1)
set(SG_LIB_WIN32 1)
set(SG_LIB_MINGW 1)
set(HAVE_NVME 1)
elseif (WIN32)
message(STATUS ">> Windows build")
set(OS_WIN32 1)
Expand All @@ -176,6 +186,9 @@ elseif (ANDROID)
set(OS_ANDROID 1)
set(SG_LIB_LINUX 1)
set(SG_LIB_ANDROID 1)
if (HAVE_LINUX_NVME_IOCTL_H)
set(HAVE_NVME 1)
endif ()
elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux")
message(STATUS ">> Linux build")
set(OS_LINUX 1)
Expand All @@ -184,10 +197,14 @@ elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux")
CHECK_INCLUDE_FILE( "linux/types.h" HAVE_LINUX_TYPES_H )
CHECK_INCLUDE_FILE( "linux/bsg.h" HAVE_LINUX_BSG_H )
CHECK_INCLUDE_FILE( "linux/kdev_t.h" HAVE_LINUX_KDEV_T_H )
if (HAVE_LINUX_NVME_IOCTL_H)
set(HAVE_NVME 1)
endif ()
elseif (CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
message(STATUS ">> FreeBSD build")
set(OS_FREEBSD 1)
set(SG_LIB_FREEBSD 1)
set(HAVE_NVME 1)
elseif (CMAKE_SYSTEM_NAME STREQUAL "NetBSD")
message(STATUS ">> NetBSD build")
set(OS_NETBSD 1)
Expand Down Expand Up @@ -262,13 +279,15 @@ set(CPACK_COMPONENTS_GROUPING IGNORE)
#

set(CPACK_DEBIAN_UTILITIES_PACKAGE_NAME "sg3-utils")
set(CPACK_DEBIAN_RUNTIME_PACKAGE_NAME "libsgutils2")
set(CPACK_DEBIAN_RUNTIME_PACKAGE_NAME "libsgutils2-2")
set(CPACK_DEBIAN_DEVELOPMENT_PACKAGE_NAME "libsgutils2-dev")
set(CPACK_DEBIAN_DEVELOPMENT_PACKAGE_DEPENDS
"libsgutils2 (= ${PROJECT_VERSION})")
"libsgutils2-2 (= ${PROJECT_VERSION})")
SET(CPACK_DEBIAN_PACKAGE_DESCRIPTION "SCSI utilities, typically one utility per SCSI command, outputs responses in human readable or JSON form")
SET(CPACK_DEBIAN_PACKAGE_MAINTAINER "Douglas Gilbert")
SET(CPACK_DEBIAN_PACKAGE_SECTION "admin")
set(CPACK_DEBIAN_UTILITIES_PACKAGE_SECTION "admin")
set(CPACK_DEBIAN_RUNTIME_PACKAGE_SECTION "libs")
set(CPACK_DEBIAN_DEVELOPMENT_PACKAGE_SECTION "libdevel")
SET(CPACK_DEBIAN_PACKAGE_DEPENDS " ")
set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)

Expand All @@ -279,11 +298,11 @@ SET(CPACK_DEB_COMPONENT_INSTALL YES)
#

set(CPACK_RPM_UTILITIES_PACKAGE_NAME "sg3_utils")
set(CPACK_RPM_RUNTIME_PACKAGE_NAME "sgutils2-libs")
set(CPACK_RPM_DEVELOPMENT_PACKAGE_NAME "sgutils2-devel")
set(CPACK_RPM_RUNTIME_PACKAGE_NAME "sg3_utils-libs")
set(CPACK_RPM_DEVELOPMENT_PACKAGE_NAME "sg3_utils-devel")
SET(CPACK_RPM_PACKAGE_DESCRIPTION "SCSI utilities, typically one utility per SCSI command, outputs responses in human readable or JSON form")
SET(CPACK_RPM_PACKAGE_DEPENDS " ")
SET(CPACK_RPM_PACKAGE_LICENSE "BSD-2-clause")
SET(CPACK_RPM_PACKAGE_LICENSE "BSD-2-Clause and GPL-2.0-or-later")
SET(CPACK_RPM_PACKAGE_VENDOR "Douglas Gilbert")
set(CPACK_RPM_FILE_NAME RPM-DEFAULT)

Expand All @@ -299,7 +318,15 @@ set(CPACK_FREEBSD_PACKAGE_MAINTAINER "dgilbert@interlog.com")
set(CPACK_FREEBSD_PACKAGE_WWW "https://doug-gilbert.github.io/sg3_utils.html")

if ( SG_LIB_LINUX )
SET(CPACK_GENERATOR "DEB;RPM")
set(CPACK_GENERATOR "")
find_program(DPKG_EXECUTABLE dpkg)
if (DPKG_EXECUTABLE)
list(APPEND CPACK_GENERATOR "DEB")
endif ()
find_program(RPMBUILD_EXECUTABLE rpmbuild)
if (RPMBUILD_EXECUTABLE)
list(APPEND CPACK_GENERATOR "RPM")
endif ()
elseif ( SG_LIB_FREEBSD )
SET(CPACK_GENERATOR "FREEBSD")
endif ( SG_LIB_LINUX )
Expand Down
1 change: 1 addition & 0 deletions config.h.in.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#cmakedefine HAVE_LINUX_BSG_H 1
#cmakedefine HAVE_LINUX_KDEV_T_H 1
#cmakedefine HAVE_LINUX_NVME_IOCTL_H 1
#cmakedefine HAVE_NVME 1
#cmakedefine HAVE_SYS_TYPES_H 1
#cmakedefine IGNORE_NVME 1
#cmakedefine IGNORE_LINUX_SGV4 1
Expand Down
6 changes: 3 additions & 3 deletions doc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ foreach(util ${SG3_UTILS})

file(ARCHIVE_CREATE
OUTPUT ${CMAKE_BINARY_DIR}/doc/${util}.8.gz
PATHS doc/${util}.8
PATHS ${CMAKE_SOURCE_DIR}/doc/${util}.8
FORMAT raw
COMPRESSION GZip
)
Expand All @@ -109,7 +109,7 @@ endforeach()
if (OS_LINUX)
file(ARCHIVE_CREATE
OUTPUT ${CMAKE_BINARY_DIR}/doc/sg_scan.8.gz
PATHS doc/sg_scan.8.linux
PATHS ${CMAKE_SOURCE_DIR}/doc/sg_scan.8.linux
FORMAT raw
COMPRESSION GZip
)
Expand All @@ -122,7 +122,7 @@ endif (OS_LINUX)
if (SG_LIB_WIN32)
file(ARCHIVE_CREATE
OUTPUT ${CMAKE_BINARY_DIR}/doc/sg_scan.8.gz
PATHS doc/sg_scan.8.win32
PATHS ${CMAKE_SOURCE_DIR}/doc/sg_scan.8.win32
FORMAT raw
COMPRESSION GZip
)
Expand Down
2 changes: 1 addition & 1 deletion include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ install(
sg_pt_linux_missing.h
sg_unaligned.h
DESTINATION
${CMAKE_INSTALL_INCLUDEDIR}
${CMAKE_INSTALL_INCLUDEDIR}/scsi
COMPONENT development
)

Expand Down
20 changes: 16 additions & 4 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ endif ( ENABLE_DEBUG )
target_include_directories(sgutils2
PUBLIC
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

target_include_directories(sgutils2 PRIVATE ${CMAKE_BINARY_DIR})
Expand All @@ -91,8 +91,9 @@ target_include_directories(sgutils2 PRIVATE ${CMAKE_BINARY_DIR})
# target_compile_features(sgutils2 PUBLIC c_std_99)

set_target_properties(sgutils2 PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION 1
OUTPUT_NAME "sgutils2-${PROJECT_VERSION}"
VERSION 2.0.0
SOVERSION 2
)

#
Expand All @@ -104,8 +105,19 @@ install(TARGETS sgutils2

LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT runtime
NAMELINK_SKIP
)

NAMELINK_COMPONENT development
# Match the autotools -release convention: the development symlink is the
# plain libsgutils2.so name (without the release version embedded).
# Create the directory first so this works when CPack stages components
# into separate trees.
install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${CMAKE_INSTALL_FULL_LIBDIR}\")
file(CREATE_LINK
\"libsgutils2-${PROJECT_VERSION}.so.2\"
\"\$ENV{DESTDIR}${CMAKE_INSTALL_FULL_LIBDIR}/libsgutils2.so\"
SYMBOLIC)"
COMPONENT development
)

write_basic_package_version_file(
Expand Down
16 changes: 15 additions & 1 deletion scripts/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@

MESSAGE( STATUS ">> Entering scripts/CMakeLists.txt" )

install(FILES ${CMAKE_SOURCE_DIR}/scripts/rescan-scsi-bus.sh
set(SG3_UTILS_SCRIPTS
rescan-scsi-bus.sh
scsi_logging_level
scsi_mandat
scsi_readcap
scsi_ready
scsi_satl
scsi_start
scsi_stop
scsi_temperature
)

foreach(script ${SG3_UTILS_SCRIPTS})
install(FILES ${CMAKE_SOURCE_DIR}/scripts/${script}
PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ
DESTINATION "${CMAKE_INSTALL_BINDIR}"
COMPONENT utilities)
endforeach()
13 changes: 13 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,16 @@ elseif (SG_LIB_WIN32)
endif (NOT PT_DUMMY)
endif (SG_LIB_LINUX)

# Per-utility link dependencies matching autotools (src/Makefile.am):
# sgp_dd needs pthread, sg_seek and sg_turs need rt (for clock_gettime)
if (SG_LIB_LINUX AND NOT PT_DUMMY)
if (Threads_FOUND)
target_link_libraries(sgp_dd PRIVATE Threads::Threads)
endif ()
endif ()

if (NEED_RT_LIB)
target_link_libraries(sg_seek PRIVATE rt)
target_link_libraries(sg_turs PRIVATE rt)
endif ()

Loading