Skip to content

Commit

Permalink
build: add packaging rules
Browse files Browse the repository at this point in the history
Signed-off-by: Eduardo Silva <[email protected]>
  • Loading branch information
edsiper committed Aug 3, 2022
1 parent 6a882a3 commit c5547f2
Show file tree
Hide file tree
Showing 4 changed files with 194 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
build/*
include/cfl/cfl_info.h
include/cfl/cfl_version.h
cfl.sublime*

188 changes: 185 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ project(cfl C)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# CMetrics Version
# C Floppy Version
set(CFL_VERSION_MAJOR 0)
set(CFL_VERSION_MINOR 1)
set(CFL_VERSION_PATCH 0)
set(CFL_VERSION_STR "${CTR_VERSION_MAJOR}.${CTR_VERSION_MINOR}.${CTR_VERSION_PATCH}")
set(CFL_VERSION_STR "${CFL_VERSION_MAJOR}.${CFL_VERSION_MINOR}.${CFL_VERSION_PATCH}")

# Configuration options
option(CFL_DEV "Enable development mode" No)

if(CTR_DEV)
if(CFL_DEV)
set(CMAKE_BUILD_TYPE Debug)
endif()

Expand All @@ -21,6 +21,66 @@ include(cmake/macros.cmake)
include(CheckCSourceCompiles)
include(GNUInstallDirs)

# Define macro to identify Windows system (without Cygwin)
if(CMAKE_SYSTEM_NAME MATCHES "Windows")
set(CFL_SYSTEM_WINDOWS On)
add_definitions(-DCFL_SYSTEM_WINDOWS)
endif()

# Define macro to identify macOS system
if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
set(CFL_SYSTEM_MACOS On)
add_definitions(-DCFL_SYSTEM_MACOS)
endif()

if(NOT MSVC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
endif()

# Define __FILENAME__ consistently across Operating Systems
if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D__FILENAME__='\"$(subst ${CMAKE_SOURCE_DIR}/,,$(abspath $<))\"'")
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D__FILENAME__=__FILE__")
endif()



# timespec_get() support
check_c_source_compiles("
#include <time.h>
int main() {
struct tm tm;
return timespec_get(&tm, TIME_UTC);
}" CFL_HAVE_TIMESPEC_GET)
if(CFL_HAVE_TIMESPEC_GET)
CFL_DEFINITION(CFL_HAVE_TIMESPEC_GET)
endif()

# gmtime_r() support
check_c_source_compiles("
#include <time.h>
int main() {
struct tm tm;
struct timespec tms;
return gmtime_r(&tms.tv_sec, &tm);
}" CFL_HAVE_GMTIME_R)
if(CFL_HAVE_GMTIME_R)
CFL_DEFINITION(CFL_HAVE_GMTIME_R)
endif()

# gmtime_s() support
check_c_source_compiles("
#include <time.h>
int main() {
struct tm tm;
struct timespec tms;
return gmtime_s(&tm, &tms.tv_sec);
}" CFL_HAVE_GMTIME_S)
if(CFL_HAVE_GMTIME_S)
CFL_DEFINITION(CFL_HAVE_GMTIME_S)
endif()

# clock_get_time() support for macOS.
check_c_source_compiles("
#include <mach/clock.h>
Expand Down Expand Up @@ -53,3 +113,125 @@ include_directories(

add_subdirectory(src)




# Installer Generation (Cpack)
# ============================

set(CPACK_PACKAGE_VERSION ${CFL_VERSION_STR})
set(CPACK_PACKAGE_NAME "cfl")
set(CPACK_PACKAGE_RELEASE 1)
set(CPACK_PACKAGE_CONTACT "Eduardo Silva <[email protected]>")
set(CPACK_PACKAGE_VENDOR "Calyptia")
set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
set(CPACK_PACKAGING_INSTALL_PREFIX "/")

set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_PACKAGE_RELEASE}.${CMAKE_SYSTEM_PROCESSOR}")

if(CFL_SYSTEM_WINDOWS)
set(CPACK_GENERATOR "ZIP")

if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-win64")
else()
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-win32")
endif()
endif()


# Enable components
set(CPACK_DEB_COMPONENT_INSTALL ON)
set(CPACK_RPM_COMPONENT_INSTALL ON)
set(CPACK_productbuild_COMPONENT_INSTALL ON)
set(CPACK_COMPONENTS_ALL ${CPACK_COMPONENTS_ALL} binary library headers)
set(CPACK_COMPONENTS_GROUPING "ONE_PER_GROUP")

set(CPACK_COMPONENT_BINARY_GROUP "RUNTIME")
set(CPACK_COMPONENT_LIBRARY_GROUP "RUNTIME")

# Debian package setup and name sanitizer
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)

find_program(DPKG_PROGRAM dpkg DOC "dpkg program of Debian-based systems")
if(DPKG_PROGRAM)
execute_process(
COMMAND ${DPKG_PROGRAM} --print-architecture
OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE
OUTPUT_STRIP_TRAILING_WHITESPACE
)

set(CPACK_DEBIAN_HEADERS_FILE_NAME "${CPACK_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}-headers.deb")
set(CPACK_DEBIAN_RUNTIME_PACKAGE_NAME "${CPACK_PACKAGE_NAME}")
set(CPACK_DEBIAN_RUNTIME_FILE_NAME "${CPACK_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}.deb")
set(CPACK_DEBIAN_RUNTIME_PACKAGE_CONTROL_EXTRA
${CMAKE_CURRENT_SOURCE_DIR}/debian/conffiles
)
endif()

# RPM Generation information
set(CPACK_RPM_PACKAGE_GROUP "System Environment/Daemons")
set(CPACK_RPM_PACKAGE_LICENSE "Apache v2.0")
set(CPACK_RPM_PACKAGE_RELEASE ${CPACK_PACKAGE_RELEASE})
set(CPACK_PACKAGE_DESCRIPTION_FILE "${PROJECT_SOURCE_DIR}/cpack/description")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "C Traces Library")
set(CPACK_RPM_SPEC_MORE_DEFINE "%define ignore \#")
set(CPACK_RPM_USER_FILELIST
"%ignore /lib"
"%ignore /lib64"
"%ignore /lib64/pkgconfig"
"%ignore /usr/local"
"%ignore /usr/local/bin")

set(CPACK_RPM_PACKAGE_AUTOREQ ON)
set(CPACK_RPM_RUNTIME_PACKAGE_NAME "${CPACK_PACKAGE_NAME}")
set(CPACK_RPM_HEADERS_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_PACKAGE_RELEASE}.${CMAKE_SYSTEM_PROCESSOR}-headers.rpm")
set(CPACK_RPM_RUNTIME_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_PACKAGE_RELEASE}.${CMAKE_SYSTEM_PROCESSOR}.rpm")

# CPack: DEB
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)

# CPack: Windows System
if(CPACK_GENERATOR MATCHES "ZIP")
set(CPACK_MONOLITHIC_INSTALL 1)
set(CPACK_PACKAGE_INSTALL_DIRECTORY "cfl")
endif()

# CPack: macOS w/ productbuild
if(CFL_SYSTEM_MACOS)
# Determine the platform suffix
execute_process(
COMMAND uname -m
RESULT_VARIABLE UNAME_M_RESULT
OUTPUT_VARIABLE UNAME_ARCH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (UNAME_M_RESULT EQUAL 0 AND UNAME_ARCH STREQUAL "arm64")
set(CFL_PKG ${CMAKE_CURRENT_BINARY_DIR}/${CPACK_PACKAGE_NAME}-${CFL_VERSION_STR}-apple)
elseif(UNAME_M_RESULT EQUAL 0 AND UNAME_ARCH STREQUAL "x86_64")
set(CFL_PKG ${CMAKE_CURRENT_BINARY_DIR}/${CPACK_PACKAGE_NAME}-${CFL_VERSION_STR}-intel)
else()
set(CFL_PKG ${CMAKE_CURRENT_BINARY_DIR}/${CPACK_PACKAGE_NAME}-${CFL_VERSION_STR}-${UNAME_ARCH})
endif()

if (CPACK_GENERATOR MATCHES "productbuild")
set(CPACK_SET_DESTDIR "ON")
configure_file(cpack/macos/welcome.txt.cmakein ${CMAKE_CURRENT_BINARY_DIR}/welcome.txt)
configure_file(LICENSE ${CMAKE_CURRENT_BINARY_DIR}/LICENSE.txt)
find_program(CONVERTER textutil)
if (NOT CONVERTER)
message(FATAL_ERROR "textutil not found.")
endif()
if (CONVERTER)
execute_process(COMMAND ${CONVERTER} -convert html "${CMAKE_SOURCE_DIR}/README.md" -output "${CMAKE_BINARY_DIR}/README.html")
endif()
set(CPACK_PACKAGE_FILE_NAME "${CFL_PKG}")
set(CPACK_RESOURCE_FILE_WELCOME ${CMAKE_CURRENT_BINARY_DIR}/welcome.txt)
set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_BINARY_DIR}/LICENSE.txt)
set(CPACK_RESOURCE_FILE_README ${CMAKE_CURRENT_BINARY_DIR}/README.html)
set(CPACK_PRODUCTBUILD_IDENTIFIER "com.calyptia.${CPACK_PACKAGE_NAME}")
endif()
endif()

include(CPack)

1 change: 1 addition & 0 deletions cpack/description
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Tiny library for data structures, call it C Floppy ;)
6 changes: 6 additions & 0 deletions cpack/macos/welcome.txt.cmakein
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
This will install @CPACK_PACKAGE_NAME@ on your Mac.

--------------------------------------------------

Thank you for trying @CPACK_PACKAGE_NAME@! Have a fantastic day!

0 comments on commit c5547f2

Please sign in to comment.