Skip to content

Commit f8049c8

Browse files
committed
Updated the version for something more sane. Added testing and packaging to CMake.
1 parent 77f368c commit f8049c8

File tree

2 files changed

+76
-7
lines changed

2 files changed

+76
-7
lines changed

CMakeLists.txt

Lines changed: 75 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ endif()
1111
# Options
1212
option(PTK_BUILD_EXAMPLES "Build Protocol Toolkit examples" ${PTK_IS_MAIN_PROJECT})
1313
option(PTK_BUILD_TESTS "Build Protocol Toolkit tests" ${PTK_IS_MAIN_PROJECT})
14+
option(PTK_RUN_TESTS "Run Protocol Toolkit tests" ${PTK_IS_MAIN_PROJECT})
1415
option(PTK_INSTALL "Install Protocol Toolkit files" ${PTK_IS_MAIN_PROJECT})
1516
option(PTK_STATIC_BUILD "Build static libraries only" OFF)
1617
option(PTK_ENABLE_STATIC_ANALYSIS "Enable static analysis tools" OFF)
@@ -23,11 +24,23 @@ option(PTK_ENABLE_TSAN "Enable ThreadSanitizer" OFF)
2324
set(CMAKE_C_STANDARD 11)
2425
set(CMAKE_C_STANDARD_REQUIRED ON)
2526

27+
2628
# Set build type if not specified
2729
if(NOT CMAKE_BUILD_TYPE)
2830
set(CMAKE_BUILD_TYPE Release)
2931
endif()
3032

33+
# =============================
34+
# Versioning from VERSION file
35+
# =============================
36+
file(READ "${CMAKE_SOURCE_DIR}/VERSION" PROJECT_VERSION_STR)
37+
string(STRIP "${PROJECT_VERSION_STR}" PROJECT_VERSION_STR)
38+
string(REPLACE "." ";" VERSION_LIST ${PROJECT_VERSION_STR})
39+
list(GET VERSION_LIST 0 PROJECT_VERSION_MAJOR)
40+
list(GET VERSION_LIST 1 PROJECT_VERSION_MINOR)
41+
list(GET VERSION_LIST 2 PROJECT_VERSION_PATCH)
42+
set(PROJECT_VERSION "${PROJECT_VERSION_STR}")
43+
3144
# Set output directories
3245
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
3346
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
@@ -249,10 +262,13 @@ if(PTK_INSTALL)
249262
)
250263
endif()
251264

265+
266+
267+
252268
# Generate and install CMake config files
253269
write_basic_package_version_file(
254270
PTKConfigVersion.cmake
255-
VERSION 1.0.0
271+
VERSION ${PROJECT_VERSION}
256272
COMPATIBILITY AnyNewerVersion
257273
)
258274

@@ -284,15 +300,68 @@ if(PTK_INSTALL)
284300
endif()
285301
endif()
286302

303+
############################################################
304+
# Packaging (CPack) - always include, not just for install #
305+
############################################################
306+
include(CPack)
307+
set(CPACK_PACKAGE_NAME "protocol-toolkit")
308+
set(CPACK_PACKAGE_VENDOR "libplctag")
309+
set(CPACK_PACKAGE_CONTACT "kyle.hayes@gmail.com")
310+
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Protocol Toolkit: For creating clients and servers for industrial protocols.")
311+
set(CPACK_PACKAGE_VERSION_MAJOR "${PROJECT_VERSION_MAJOR}")
312+
set(CPACK_PACKAGE_VERSION_MINOR "${PROJECT_VERSION_MINOR}")
313+
set(CPACK_PACKAGE_VERSION_PATCH "${PROJECT_VERSION_PATCH}")
314+
set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION}")
315+
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE-1.MPL")
316+
set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/README.md")
317+
318+
# DEB
319+
set(CPACK_GENERATOR "DEB;RPM;TGZ")
320+
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Kyle Hayes")
321+
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= 2.17)")
322+
set(CPACK_DEBIAN_PACKAGE_SECTION "devel")
323+
set(CPACK_DEBIAN_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR})
324+
325+
# RPM
326+
set(CPACK_RPM_PACKAGE_LICENSE "MPL-2.0")
327+
set(CPACK_RPM_PACKAGE_GROUP "Development/Tools")
328+
set(CPACK_RPM_PACKAGE_REQUIRES "libc.so.6")
329+
330+
# Windows MSI/NSIS
331+
if(WIN32)
332+
set(CPACK_GENERATOR "WIX;NSIS")
333+
set(CPACK_WIX_UPGRADE_GUID "de49774c-8210-44be-bb1d-a461a442bdf1")
334+
set(CPACK_PACKAGE_INSTALL_DIRECTORY "Protocol Toolkit")
335+
endif()
336+
337+
# macOS Homebrew: build TGZ, provide formula separately
338+
if(APPLE)
339+
set(CPACK_GENERATOR "TGZ")
340+
endif()
341+
342+
set(CPACK_SOURCE_GENERATOR "TGZ")
343+
set(CPACK_SOURCE_PACKAGE_FILE_NAME "protocol-toolkit-${PROJECT_VERSION}")
344+
set(CPACK_SOURCE_IGNORE_FILES "/build/;/\\.git/;/\\.github/;/external_docs/;/docs/;/ideas/;/tools/attic/")
345+
346+
287347
#=============================================================================
288348
# TESTING
289349
#=============================================================================
290350

291-
# Add test targets
292-
# add_custom_target(test_sockets
293-
# COMMENT "Testing socket implementation"
294-
# DEPENDS test_tcp_echo_abort test_udp_echo_abort
295-
# )
351+
# Run test_harness with all test binaries in build/bin (except test_harness)
352+
if(PTK_BUILD_TESTS AND PTK_RUN_TESTS AND UNIX)
353+
set(TEST_BIN_DIR "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
354+
file(GLOB PTK_TEST_BINARIES RELATIVE "${TEST_BIN_DIR}" "${TEST_BIN_DIR}/test_*")
355+
set(TEST_ARGS "")
356+
foreach(testbin ${PTK_TEST_BINARIES})
357+
if(NOT testbin STREQUAL "test_harness")
358+
list(APPEND TEST_ARGS "${TEST_BIN_DIR}/${testbin}")
359+
endif()
360+
endforeach()
361+
if(EXISTS "${TEST_BIN_DIR}/test_harness")
362+
add_test(NAME run_all_ptk_tests COMMAND "${TEST_BIN_DIR}/test_harness" ${TEST_ARGS})
363+
endif()
364+
endif()
296365

297366
#=============================================================================
298367
# INFORMATION

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.0
1+
0.1.0

0 commit comments

Comments
 (0)