Skip to content

Commit b40aded

Browse files
author
Mauricio
committed
fix: CMake definition for cmake specific files
1 parent f2c4b71 commit b40aded

File tree

5 files changed

+45
-74
lines changed

5 files changed

+45
-74
lines changed

CMakeLists.txt

Lines changed: 24 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ include(GNUInstallDirs REQUIRED)
1111
find_package(PkgConfig REQUIRED)
1212
find_package(Threads REQUIRED)
1313
find_package(ICU COMPONENTS uc)
14+
find_package(LibXml2 REQUIRED)
1415

15-
# pkg_check_modules(DL REQUIRED "libdl" IMPORTED_TARGET)
16-
pkg_check_modules(FUSE REQUIRED "fuse>=2.6.0" IMPORTED_TARGET)
17-
target_compile_definitions(PkgConfig::FUSE INTERFACE _FILE_OFFSET_BITS=64)
16+
add_compile_definitions(_GNU_SOURCE __CMAKE_BUILD)
1817

19-
pkg_check_modules(XML2 REQUIRED "libxml-2.0>=2.6.16" IMPORTED_TARGET)
18+
pkg_check_modules(FUSE REQUIRED "fuse>=2.6.0" IMPORTED_TARGET)
19+
target_compile_definitions(PkgConfig::FUSE INTERFACE
20+
_FILE_OFFSET_BITS=64
21+
)
2022

2123
if(APPLE)
2224
pkg_check_modules(UUID REQUIRED "uuid>=1.6" IMPORTED_TARGET)
@@ -25,84 +27,38 @@ else()
2527
endif()
2628

2729
add_subdirectory(messages)
28-
add_subdirectory(src/libltfs)
2930
add_subdirectory(src)
3031

3132

32-
# Parsing features options
33-
# NOTE: Is this needed? cmake can add this feature using -DUSE_UNORM2
34-
# option(ICU_6X "Force to use ICU6x (unorm2) functions" OFF)
35-
# if(ICU_6X)
36-
# add_definitions(-DUSE_UNORM2)
37-
# endif()
38-
39-
# option(SNMP "Force to use ICU6x (unorm2) functions" OFF)
33+
option(ENABLE_SNMP "Force to use ICU6x (unorm2) functions" OFF)
4034
if(ENABLE_SNMP)
4135
pkg_check_modules(SNMP REQUIRED "net-snmp>=5.3" IMPORTED_TARGET)
42-
endif()
36+
find_program(NETSNMP_CONFIG_BIN net-snmp-config REQUIRED)
37+
if(NETSNMP_CONFIG_BIN)
38+
exec_program(${NETSNMP_CONFIG_BIN} ARGS --cflags OUTPUT_VARIABLE _NETSNMP_CFLAGS)
39+
exec_program(${NETSNMP_CONFIG_BIN} ARGS --libs OUTPUT_VARIABLE _NETSNMP_LIBS)
4340

44-
# # Check libraries exists
45-
# check_library_exists(pthread pthread_create "" HAVE_PTHREAD)
46-
# if(APPLE)
47-
# check_library_exists(rt clock_gettime "" HAVE_RT)
48-
# endif()
41+
string(REGEX REPLACE "[\"\r\n]" " " _NETSNMP_CFLAGS "${_NETSNMP_CFLAGS}")
42+
string(REGEX REPLACE "[\"\r\n]" " " _NETSNMP_LIBS "${_NETSNMP_LIBS}")
43+
set(NETSNMP_CFLAGS ${_NETSNMP_CFLAGS} CACHE STRING "CFLAGS for net-snmp lib")
44+
set(NETSNMP_LIBS ${_NETSNMP_LIBS} CACHE STRING "linker options for net-snmp lib")
45+
set(NETSNMP_FOUND TRUE CACHE BOOL "net-snmp is found")
46+
else()
47+
set (NETSNMP_FOUND FALSE CACHE BOOL "net-snmp is not found")
48+
endif()
49+
endif()
4950

50-
# if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
51-
# check_library_exists(cam cam_open_device "" HAVE_CAM)
52-
# check_library_exists(bsdxml XML_ParserCreate "" HAVE_BSDXML)
53-
# check_library_exists(mt mt_status_free "" HAVE_MT)
54-
# check_library_exists(execinfo backtrace "" HAVE_EXECINFO)
55-
# elseif(CMAKE_SYSTEM_NAME STREQUAL "NetBSD")
56-
# check_library_exists(execinfo backtrace "" HAVE_EXECINFO)
57-
# endif()
5851

59-
# # Compilation requirements
60-
# # NOTE: Checking for standard headers is really needed?
61-
# set(
62-
# STD_HEADERS
63-
# "fcntl.h"
64-
# "limits.h"
65-
# "stddef.h"
66-
# "stdint.h"
67-
# "stdlib.h"
68-
# "stdbool.h"
69-
# "string.h"
70-
# "sys/ioctl.h"
71-
# "sys/mount.h"
72-
# "sys/time.h"
73-
# "termios.h"
74-
# "unistd.h"
75-
# "sys/sysctl.h"
76-
# )
77-
# check_include_files("${STD_HEADERS}" HAVE_STD_HEADERS)
7852
# check_type_size(mode_t MODE_T)
7953
# check_type_size(off_t OFF_T)
8054
# check_type_size(size_t SIZE_T)
8155
# check_type_size(ssize_t SSIZE_T)
82-
# check_type_size(time_t TIME_T)
56+
check_type_size(time_t SIZEOF_TIME_T)
57+
add_compile_definitions(
58+
SIZEOF_TIME_T=${SIZEOF_TIME_T}
59+
)
8360
# check_type_size(uint8_t UINT8_T)
8461
# check_type_size(uint16_t UINT16_T)
8562
# check_type_size(uint32_t UINT32_T)
8663
# check_type_size(uint64_t UINT64_T)
8764
# check_type_size(uint64_t UINT64_T)
88-
# check_symbol_exists(malloc "stdlib.h" HAVE_MALLOC)
89-
# check_symbol_exists(strlen "string.h" HAVE_STRLEN)
90-
# check_symbol_exists(bzero "string.h" HAVE_BZERO)
91-
# check_symbol_exists(memchr "string.h" HAVE_MEMCHR)
92-
# check_symbol_exists(memset "string.h" HAVE_MEMSET)
93-
# check_symbol_exists(strcasecmp "string.h" HAVE_STRCASECMP)
94-
# check_symbol_exists(strdup "string.h" HAVE_STRDUP)
95-
# check_symbol_exists(strerror "string.h" HAVE_STRERROR)
96-
# check_symbol_exists(strndup "string.h" HAVE_STRNDUP)
97-
# check_symbol_exists(strrchr "string.h" HAVE_STRRCHR)
98-
# check_symbol_exists(strstr "string.h" HAVE_STRSTR)
99-
# check_symbol_exists(mkdir "sys/stat.h" HAVE_MKDIR)
100-
# check_symbol_exists(rmdir "unistd.h" HAVE_RMDIR)
101-
102-
103-
# check_library_exists(xml2 xmlTextReaderSetup "" HAVE_XML_TEXT_READER_SETUP)
104-
# if(HAVE_XML_TEXT_READER_SETUP)
105-
# # TODO: Add add macro definitions
106-
# endif()
107-
108-
# # check_symbol_exists(xmlTextReaderSetup "" HAVE_XML_TEXT_READER_SETUP)

src/CMakeLists.txt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,26 @@ add_executable(ltfs main.c ltfs_fuse.c)
33
target_link_libraries(ltfs
44
Threads::Threads
55
PkgConfig::FUSE
6-
PkgConfig::XML2
6+
LibXml2::LibXml2
77
PkgConfig::UUID
88
ICU::uc
99
libltfs
1010
)
1111
target_include_directories(ltfs BEFORE PUBLIC "." )
1212
target_compile_definitions(ltfs PRIVATE
13-
_GNU_SOURCE
1413
LTFS_CONFIG_FILE="${SYSCONFDIR}/ltfs.conf"
1514
LTFS_BASE_DIR="${CMAKE_INSTALL_PREFIX}"
1615
PACKAGE_VERSION="${PROJECT_VERSION}"
1716
PACKAGE_NAME="${PROJECT_NAME}"
1817
)
18+
19+
add_subdirectory(libltfs)
20+
21+
# NOTE: Is this needed? cmake can add this feature using -DUSE_UNORM2
22+
option(ICU_6X "Force to use ICU6x (unorm2) functions" OFF)
23+
string(REPLACE "." ";" ICU_VERSION_ARRAY ${ICU_VERSION})
24+
list(GET ICU_VERSION_ARRAY 0 ICU_VERSION_MAJOR)
25+
if(ICU_6X OR ICU_VERSION_MAJOR GREATER_EQUAL "56")
26+
add_compile_definitions(USE_UNORM2)
27+
message(STATUS "Using ICU6x funtions")
28+
endif()

src/libltfs/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,18 @@ target_include_directories(libltfs BEFORE PUBLIC ".." )
1010
target_link_libraries(libltfs
1111
Threads::Threads
1212
PkgConfig::FUSE
13-
PkgConfig::XML2
13+
LibXml2::LibXml2
1414
PkgConfig::UUID
1515
libbin_ltfs
1616
liblibltfs
1717
libinternal_error
1818
libtape_common
1919
)
2020

21+
if(ENABLE_SNMP)
22+
target_link_libraries(libltfs PkgConfig::SNMP)
23+
endif()
24+
2125
target_compile_definitions(libltfs PRIVATE
2226
_GNU_SOURCE
2327
LTFS_CONFIG_FILE="${SYSCONFDIR}/ltfs.conf"

src/libltfs/arch/time_internal.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,15 @@
5656
#include "libltfs/ltfslogging.h"
5757
#include "libltfs/arch/time_internal.h"
5858

59-
#ifdef __APPLE__
59+
// TODO: Fix definition of SIZEOF_TIME_T in cmake
60+
#if defined(__APPLE__) || defined(__CMAKE_BUILD)
6061
/*
6162
* In OSX environment time_t is always 64-bit width.
6263
* It is specified by compile option of Makefile.osx because autoconf architecture is
6364
* not used under OSX.
6465
*/
6566
#define SIZEOF_TIME_T (8)
66-
#else
67+
#elif !defined(__CMAKE_BUILD)
6768
#include "config.h"
6869
#endif
6970

src/libltfs/ltfs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ enum ltfs_index_type {
184184

185185
#define LTFS_NO_BARCODE "NO_BARCODE"
186186

187-
#ifndef __APPLE_MAKEFILE__
187+
#if !defined(__APPLE_MAKEFILE__) && !defined(__CMAKE_BUILD)
188188
#include "config.h"
189189
#endif
190190

0 commit comments

Comments
 (0)