2023-08-01 03:22:17 +02:00
|
|
|
cmake_minimum_required (VERSION 3.0...3.27)
|
2023-07-07 12:25:14 +02:00
|
|
|
project (liberty C CXX)
|
2015-02-28 19:53:23 +01:00
|
|
|
|
|
|
|
# Moar warnings
|
2024-12-04 17:44:30 +01:00
|
|
|
set (CMAKE_CXX_STANDARD 11)
|
2017-07-24 03:46:06 +02:00
|
|
|
if ("${CMAKE_C_COMPILER_ID}" MATCHES "GNU" OR CMAKE_COMPILER_IS_GNUCC)
|
2015-02-28 19:53:23 +01:00
|
|
|
# -Wunused-function is pretty annoying here, as everything is static
|
2020-10-26 18:23:14 +01:00
|
|
|
set (wdisabled "-Wno-unused-function")
|
2017-06-22 18:14:49 +02:00
|
|
|
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -Wall -Wextra ${wdisabled}")
|
2020-10-29 15:32:26 +01:00
|
|
|
endif ()
|
2015-02-28 19:53:23 +01:00
|
|
|
|
|
|
|
# Dependencies
|
2016-01-04 00:47:12 +01:00
|
|
|
set (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
|
|
|
|
include (AddThreads)
|
|
|
|
|
2015-02-28 19:53:23 +01:00
|
|
|
find_package (PkgConfig REQUIRED)
|
|
|
|
pkg_check_modules (libssl REQUIRED libssl libcrypto)
|
|
|
|
|
2016-01-04 00:47:12 +01:00
|
|
|
if ("${CMAKE_SYSTEM_NAME}" MATCHES "BSD")
|
|
|
|
# Our POSIX version macros make these undefined
|
|
|
|
add_definitions (-D__BSD_VISIBLE=1 -D_BSD_SOURCE=1)
|
2020-10-29 15:32:26 +01:00
|
|
|
endif ()
|
2016-01-01 19:15:18 +01:00
|
|
|
|
2016-01-04 00:47:12 +01:00
|
|
|
set (common_libraries ${libssl_LIBRARIES})
|
2015-02-28 19:53:23 +01:00
|
|
|
include_directories (${libssl_INCLUDE_DIRS})
|
|
|
|
link_directories (${libssl_LIBRARY_DIRS})
|
|
|
|
|
2016-01-04 00:47:12 +01:00
|
|
|
# -lrt is only for glibc < 2.17
|
|
|
|
# -liconv may or may not be a part of libc
|
|
|
|
foreach (extra iconv rt)
|
|
|
|
find_library (extra_lib_${extra} ${extra})
|
|
|
|
if (extra_lib_${extra})
|
2023-07-04 08:08:25 +02:00
|
|
|
list (APPEND common_libraries ${extra_lib_${extra}})
|
2020-10-29 15:32:26 +01:00
|
|
|
endif ()
|
|
|
|
endforeach ()
|
2016-01-04 00:47:12 +01:00
|
|
|
|
2015-02-28 19:53:23 +01:00
|
|
|
# Build some unit tests
|
2017-06-14 23:28:30 +02:00
|
|
|
include_directories (${PROJECT_SOURCE_DIR})
|
2015-02-28 19:53:23 +01:00
|
|
|
enable_testing ()
|
2024-02-10 12:15:21 +01:00
|
|
|
set (tests liberty proto xdg)
|
2021-11-07 15:37:21 +01:00
|
|
|
|
|
|
|
pkg_check_modules (libpulse libpulse)
|
|
|
|
if (libpulse_FOUND)
|
|
|
|
list (APPEND tests pulse)
|
|
|
|
list (APPEND common_libraries ${libpulse_LIBRARIES})
|
|
|
|
include_directories (${libpulse_INCLUDE_DIRS})
|
|
|
|
link_directories (${libpulse_LIBRARY_DIRS})
|
|
|
|
endif ()
|
|
|
|
|
|
|
|
foreach (name ${tests})
|
2015-02-28 19:53:23 +01:00
|
|
|
add_executable (test-${name} tests/${name}.c ${common_sources})
|
2016-01-01 19:15:18 +01:00
|
|
|
add_threads (test-${name})
|
2015-02-28 19:53:23 +01:00
|
|
|
target_link_libraries (test-${name} ${common_libraries})
|
2015-12-09 00:57:00 +01:00
|
|
|
add_test (NAME test-${name} COMMAND test-${name})
|
2020-10-29 15:32:26 +01:00
|
|
|
endforeach ()
|
2022-09-27 17:13:45 +02:00
|
|
|
|
2022-09-30 03:09:04 +02:00
|
|
|
# --- Tools --------------------------------------------------------------------
|
|
|
|
|
|
|
|
# Test the AsciiDoc manual page generator for a successful parse
|
|
|
|
set (ASCIIMAN ${PROJECT_SOURCE_DIR}/tools/asciiman.awk)
|
|
|
|
add_custom_command (OUTPUT libertyxdr.7
|
|
|
|
COMMAND env LC_ALL=C awk -f ${ASCIIMAN}
|
|
|
|
"${PROJECT_SOURCE_DIR}/libertyxdr.adoc" > libertyxdr.7
|
|
|
|
DEPENDS libertyxdr.adoc ${ASCIIMAN}
|
|
|
|
COMMENT "Generating man page for libertyxdr" VERBATIM)
|
|
|
|
add_custom_target (docs ALL DEPENDS libertyxdr.7)
|
|
|
|
|
2022-09-29 21:06:46 +02:00
|
|
|
# Test CMake script parsing
|
2022-09-27 17:13:45 +02:00
|
|
|
add_test (test-cmake-parser
|
|
|
|
env LC_ALL=C awk -f ${PROJECT_SOURCE_DIR}/tools/cmake-parser.awk
|
|
|
|
-f ${PROJECT_SOURCE_DIR}/tools/cmake-dump.awk ${CMAKE_CURRENT_LIST_FILE})
|
2022-09-29 21:06:46 +02:00
|
|
|
|
|
|
|
# Test protocol code generation
|
|
|
|
set (lxdrgen_outputs)
|
|
|
|
set (lxdrgen_base "${PROJECT_BINARY_DIR}/lxdrgen.lxdr")
|
2023-07-07 12:25:14 +02:00
|
|
|
foreach (backend c cpp go mjs swift)
|
2022-09-29 21:06:46 +02:00
|
|
|
list (APPEND lxdrgen_outputs ${lxdrgen_base}.${backend})
|
|
|
|
add_custom_command (OUTPUT ${lxdrgen_base}.${backend}
|
|
|
|
COMMAND env LC_ALL=C awk
|
|
|
|
-f ${PROJECT_SOURCE_DIR}/tools/lxdrgen.awk
|
|
|
|
-f ${PROJECT_SOURCE_DIR}/tools/lxdrgen-${backend}.awk
|
|
|
|
-v PrefixCamel=ProtoGen
|
|
|
|
${PROJECT_SOURCE_DIR}/tests/lxdrgen.lxdr
|
|
|
|
> ${lxdrgen_base}.${backend}
|
|
|
|
DEPENDS
|
|
|
|
${PROJECT_SOURCE_DIR}/tools/lxdrgen.awk
|
|
|
|
${PROJECT_SOURCE_DIR}/tools/lxdrgen-${backend}.awk
|
|
|
|
${PROJECT_SOURCE_DIR}/tests/lxdrgen.lxdr
|
|
|
|
COMMENT "Generating test protocol code (${backend})" VERBATIM)
|
|
|
|
endforeach ()
|
|
|
|
add_custom_target (test-lxdrgen-outputs ALL DEPENDS ${lxdrgen_outputs})
|
|
|
|
|
|
|
|
set_source_files_properties (${lxdrgen_base}.c
|
|
|
|
PROPERTIES HEADER_FILE_ONLY TRUE)
|
2023-07-07 12:25:14 +02:00
|
|
|
add_executable (test-lxdrgen-c tests/lxdrgen.c ${lxdrgen_base}.c)
|
|
|
|
target_include_directories (test-lxdrgen-c PUBLIC ${PROJECT_BINARY_DIR})
|
|
|
|
add_test (NAME test-lxdrgen-c COMMAND test-lxdrgen-c)
|
|
|
|
|
|
|
|
set_source_files_properties (${lxdrgen_base}.cpp
|
|
|
|
PROPERTIES HEADER_FILE_ONLY TRUE)
|
|
|
|
if (WIN32)
|
|
|
|
add_executable (test-lxdrgen-cpp tests/lxdrgen.cpp
|
|
|
|
${lxdrgen_base}.cpp tools/lxdrgen-cpp-win32.cpp)
|
|
|
|
else ()
|
|
|
|
add_executable (test-lxdrgen-cpp tests/lxdrgen.cpp
|
|
|
|
${lxdrgen_base}.cpp tools/lxdrgen-cpp-posix.cpp)
|
|
|
|
endif ()
|
2024-12-04 17:44:30 +01:00
|
|
|
target_link_libraries (test-lxdrgen-cpp ${common_libraries})
|
2023-07-07 12:25:14 +02:00
|
|
|
target_include_directories (test-lxdrgen-cpp PUBLIC ${PROJECT_BINARY_DIR})
|
|
|
|
add_test (NAME test-lxdrgen-cpp COMMAND test-lxdrgen-cpp)
|
2022-09-29 21:06:46 +02:00
|
|
|
|
|
|
|
find_program (GO_EXECUTABLE go)
|
|
|
|
if (GO_EXECUTABLE)
|
|
|
|
add_test (test-lxdrgen-go ${GO_EXECUTABLE} vet ${lxdrgen_base}.go)
|
|
|
|
else ()
|
|
|
|
message (WARNING "Cannot test generated protocol code for Go")
|
|
|
|
endif ()
|
|
|
|
|
|
|
|
find_program (NODE_EXECUTABLE node)
|
|
|
|
if (NODE_EXECUTABLE)
|
|
|
|
add_test (test-lxdrgen-mjs ${NODE_EXECUTABLE} -c ${lxdrgen_base}.mjs)
|
|
|
|
else ()
|
|
|
|
message (WARNING "Cannot test generated protocol code for Javascript")
|
|
|
|
endif ()
|
2023-06-15 09:42:06 +02:00
|
|
|
|
|
|
|
find_program (SWIFTC_EXECUTABLE swiftc)
|
|
|
|
if (SWIFTC_EXECUTABLE)
|
|
|
|
add_test (test-lxdrgen-swift
|
|
|
|
${SWIFTC_EXECUTABLE} -typecheck ${lxdrgen_base}.swift)
|
|
|
|
else ()
|
|
|
|
message (WARNING "Cannot test generated protocol code for Swift")
|
|
|
|
endif ()
|