Skip to content

Make libartnet 99% CMake compatible #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
111 changes: 111 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# CMakeLists.txt for libartnet project

cmake_minimum_required(VERSION 3.10)
project(libartnet C)

include(CheckIncludeFiles)
include(CheckFunctionExists)
include(CheckTypeSize)
# include(CheckTypeExists)
include(CheckSymbolExists)
include(CheckCSourceRuns)
include(CheckStructHasMember)

# Check for standard libraries and functions
check_include_files("arpa/inet.h" HAVE_ARPA_INET_H)
check_include_files("dlfcn.h" HAVE_DLFCN_H)
check_function_exists("_doprnt" HAVE_DOPRNT)
check_include_files("endian.h" HAVE_ENDIAN_H)
check_function_exists("getifaddrs" HAVE_GETIFADDRS)
check_function_exists("inet_aton" HAVE_INET_ATON)
check_function_exists("inet_ntoa" HAVE_INET_NTOA)
check_include_files("inttypes.h" HAVE_INTTYPES_H)
check_include_files("linux/if_packet.h" HAVE_LINUX_IF_PACKET_H)
# TODO GNU libc compatible malloc -> HAVE_MALLOC
check_include_files("memory.h" HAVE_MEMORY_H)
check_function_exists("memset" HAVE_MEMSET)
check_include_files("netinet/in.h" HAVE_NETINET_IN_H)
check_include_files("ppc/endian.h" HAVE_PPC_ENDIAN_H)
# TODO GNU libc compatible realloc
check_function_exists("select" HAVE_SELECT)
check_struct_has_member("struct sockaddr" "sa_len" "sys/socket.h" HAVE_SOCKADDR_SA_LEN)
check_function_exists("socket" HAVE_SOCKET)
# TODO C99 stdbool.h -> HAVE_STDBOOL_H
check_include_files("stdint.h" HAVE_STDINT_H)
check_include_files("stdlib.h" HAVE_STDLIB_H)
check_function_exists("strchr" HAVE_STRCHR)
check_function_exists("strdup" HAVE_STRDUP)
check_function_exists("strerror" HAVE_STRERROR)
check_include_files("strings.h" HAVE_STRINGS_H)
check_include_files("string.h" HAVE_STRING_H)
check_include_files("sys/ioctl.h" HAVE_SYS_IOCTL_H)
check_include_files("sys/select.h" HAVE_SYS_SELECT_H)
check_include_files("sys/socket.h" HAVE_SYS_SOCKET_H)
check_include_files("sys/stat.h" HAVE_SYS_STAT_H)
check_include_files("sys/types.h" HAVE_SYS_TYPES_H)
check_include_files("unistd.h" HAVE_UNISTD_H)
check_include_files("unistd.hi" HAVE_UNISTD_HI)
check_function_exists("vprintf" HAVE_VPRINTF)
# check_type_exists("_Bool" HAVE__BOOL)

# IPv6 check
check_c_source_runs("
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
int main() {
int fd = socket(AF_INET6, SOCK_STREAM, 0);
return fd >= 0 ? 0 : 1;
}
" IPV6)

if(IPV6)
add_definitions(-DIPV6)
endif()

# Struct member check
check_type_size("size_t" SIZE_T)


if(HAVE_SOCKADDR_SA_LEN)
add_definitions(-DHAVE_SOCKADDR_SA_LEN)
endif()

# Generate config.h
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/config.h @ONLY)

# Set the C standard
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)

# Add source files
set(SOURCES
artnet/artnet.c
artnet/misc.c
artnet/network.c
artnet/receive.c
artnet/tod.c
artnet/transmit.c
)

# Add header files
set(HEADERS
artnet/artnet.h
artnet/common.h
artnet/misc.h
artnet/packets.h
artnet/private.h
artnet/tod.h
)

# Create a static library
add_library(libartnet STATIC ${SOURCES} ${HEADERS})

# Include directories
target_include_directories(libartnet PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

# Compiler options (adjust as needed)
target_compile_options(libartnet PRIVATE -Wall -Wextra)

# Optionally link libraries here if needed
# target_link_libraries(libartnet <library_name>)
160 changes: 160 additions & 0 deletions config.h.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
// cGenerated by cmake, do not modify.

// Define to 1 if you have the <arpa/inet.h> header file.
#cmakedefine HAVE_ARPA_INET_H @HAVE_ARPA_INET_H@

// Define to 1 if you have the <dlfcn.h> header file.
#cmakedefine HAVE_DLFCN_H @HAVE_DLFCN_H@

// Define to 1 if you don't have `vprintf' but do have `_doprnt.'
#cmakedefine HAVE_DOPRNT @HAVE_DOPRNT@

// Define to 1 if you have the <endian.h> header file.
#cmakedefine HAVE_ENDIAN_H @HAVE_ENDIAN_H@

// Define to 1 if you have the `getifaddrs' function.
#cmakedefine HAVE_GETIFADDRS @HAVE_GETIFADDRS@

// Define to 1 if you have the `inet_aton' function.
#cmakedefine HAVE_INET_ATON @HAVE_INET_ATON@

// Define to 1 if you have the `inet_ntoa' function.
#cmakedefine HAVE_INET_NTOA @HAVE_INET_NTOA@

// Define to 1 if you have the <inttypes.h> header file.
#cmakedefine HAVE_INTTYPES_H @HAVE_INTTYPES_H@

// Define to 1 if you have the <linux/if_packet.h> header file.
#cmakedefine HAVE_LINUX_IF_PACKET_H @HAVE_LINUX_IF_PACKET_H@

// Define to 1 if your system has a GNU libc compatible `malloc' function, and to 0 otherwise.
#cmakedefine HAVE_MALLOC @HAVE_MALLOC@

// Define to 1 if you have the <memory.h> header file.
#cmakedefine HAVE_MEMORY_H @HAVE_MEMORY_H@

// Define to 1 if you have the `memset' function.
#cmakedefine HAVE_MEMSET @HAVE_MEMSET@

// Define to 1 if you have the <netinet/in.h> header file.
#cmakedefine HAVE_NETINET_IN_H @HAVE_NETINET_IN_H@

// Define to 1 if you have the <ppc/endian.h> header file.
#cmakedefine HAVE_PPC_ENDIAN_H @HAVE_PPC_ENDIAN_H@

// Define to 1 if your system has a GNU libc compatible `realloc' function, and to 0 otherwise.
#cmakedefine HAVE_REALLOC @HAVE_REALLOC@

// Define to 1 if you have the `select' function.
#cmakedefine HAVE_SELECT @HAVE_SELECT@

// define if socket address structures have length fields
#cmakedefine HAVE_SOCKADDR_SA_LEN @HAVE_SOCKADDR_SA_LEN@

// Define to 1 if you have the `socket' function.
#cmakedefine HAVE_SOCKET @HAVE_SOCKET@

// Define to 1 if stdbool.h conforms to C99.
#cmakedefine HAVE_STDBOOL_H @HAVE_STDBOOL_H@

// Define to 1 if you have the <stddef.h> header file.
#cmakedefine HAVE_STDDEF_H @HAVE_STDDEF_H@

// Define to 1 if you have the <stdint.h> header file.
#cmakedefine HAVE_STDINT_H @HAVE_STDINT_H@

// Define to 1 if you have the <stdlib.h> header file.
#cmakedefine HAVE_STDLIB_H @HAVE_STDLIB_H@

// Define to 1 if you have the `strchr' function.
#cmakedefine HAVE_STRCHR @HAVE_STRCHR@

// Define to 1 if you have the `strdup' function.
#cmakedefine HAVE_STRDUP @HAVE_STRDUP@

// Define to 1 if you have the `strerror' function.
#cmakedefine HAVE_STRERROR @HAVE_STRERROR@

// Define to 1 if you have the <strings.h> header file.
#cmakedefine HAVE_STRINGS_H @HAVE_STRINGS_H@

// Define to 1 if you have the <string.h> header file.
#cmakedefine HAVE_STRING_H @HAVE_STRING_H@

// Define to 1 if you have the <sys/ioctl.h> header file.
#cmakedefine HAVE_SYS_IOCTL_H @HAVE_SYS_IOCTL_H@

// Define to 1 if you have the <sys/select.h> header file.
#cmakedefine HAVE_SYS_SELECT_H @HAVE_SYS_SELECT_H@

// Define to 1 if you have the <sys/socket.h> header file.
#cmakedefine HAVE_SYS_SOCKET_H @HAVE_SYS_SOCKET_H@

// Define to 1 if you have the <sys/stat.h> header file.
#cmakedefine HAVE_SYS_STAT_H @HAVE_SYS_STAT_H@

// Define to 1 if you have the <sys/types.h> header file.
#cmakedefine HAVE_SYS_TYPES_H @HAVE_SYS_TYPES_H@

// Define to 1 if you have the <unistd.h> header file.
#cmakedefine HAVE_UNISTD_H @HAVE_UNISTD_H@

// Define to 1 if you have the <unistd.hi> header file.
#cmakedefine HAVE_UNISTD_HI @HAVE_UNISTD_HI@

// Define to 1 if you have the `vprintf' function.
#cmakedefine HAVE_VPRINTF @HAVE_VPRINTF@

// Define to 1 if the system has the type `_Bool'.
#cmakedefine HAVE__BOOL @HAVE__BOOL@

// Define to 1 if the system supports IPv6
#cmakedefine IPV6 @IPV6@

// Name of package
#cmakedefine PACKAGE @PACKAGE@

// Define to the address where bug reports for this package should be sent.
#cmakedefine PACKAGE_BUGREPORT @PACKAGE_BUGREPORT@

// Define to the full name of this package.
#cmakedefine PACKAGE_NAME @PACKAGE_NAME@

// Define to the full name and version of this package.
#cmakedefine PACKAGE_STRING @PACKAGE_STRING@

// Define to the one symbol short name of this package.
#cmakedefine PACKAGE_TARNAME @PACKAGE_TARNAME@

// Define to the version of this package.
#cmakedefine PACKAGE_VERSION @PACKAGE_VERSION@

// Define to the type of arg 1 for `select'.
#cmakedefine SELECT_TYPE_ARG1 @SELECT_TYPE_ARG1@

// Define to the type of args 2, 3 and 4 for `select'.
#cmakedefine SELECT_TYPE_ARG234 @SELECT_TYPE_ARG234@

// Define to the type of arg 5 for `select'.
#cmakedefine SELECT_TYPE_ARG5 @SELECT_TYPE_ARG5@

// Define to 1 if you have the ANSI C header files.
#cmakedefine STDC_HEADERS @STDC_HEADERS@

// Define to 1 if you can safely include both <sys/time.h> and <time.h>.
#cmakedefine TIME_WITH_SYS_TIME @TIME_WITH_SYS_TIME@

// Version number of package
#cmakedefine VERSION @VERSION@

// Define to empty if `const' does not conform to ANSI C.
#cmakedefine const @const@

// Define to rpl_malloc if the replacement function should be used.
#cmakedefine malloc @malloc@

// Define to rpl_realloc if the replacement function should be used.
#cmakedefine realloc @realloc@

// Define to `unsigned int' if <sys/types.h> does not define.
#cmakedefine size_t @SIZE_T@