Skip to content
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

cmake: add basic CMakeLists.txt (without modules) #3

Merged
merged 1 commit into from
Sep 7, 2023
Merged
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
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/build*
/dist
*stamp
*.previous
*.gcov

# ctags
tags

# Vim swp files
*.swp

# clangd
.cache
compile_commands.json
144 changes: 144 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
#
# CMakeLists.txt
#
# Copyright (C) 2023 Sebastian Reimers
#

##############################################################################
#
# Project and Versioning
#

cmake_minimum_required(VERSION 3.18)

project(restund VERSION 0.5.0 LANGUAGES C)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake)

##############################################################################
#
# Module/Package Includes
#

include(GNUInstallDirs)
include(CheckIncludeFile)
find_package(RE REQUIRED)


##############################################################################
#
# Compile options
#

if(WIN32)
option(STATIC "Build static" ON)
else()
option(STATIC "Build static" OFF)
endif()

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_EXTENSIONS OFF)

if(MSVC)
add_compile_options("/W3")
else()
add_compile_options(
-Wall
-Wextra
)

set(c_flags
-pedantic
-Wcast-align
-Wbad-function-cast
-Wmissing-declarations
-Wmissing-prototypes
-Wnested-externs
-Wno-strict-aliasing
-Wold-style-definition
-Wshadow -Waggregate-return
-Wstrict-prototypes
-Wuninitialized
-Wvla
)

if(CMAKE_C_COMPILER_ID MATCHES "Clang")
list(APPEND c_flags
-Watomic-implicit-seq-cst
-Wshorten-64-to-32
-Wno-gnu-zero-variadic-macro-arguments
)
endif()

add_compile_options(
"$<$<COMPILE_LANGUAGE:C>:${c_flags}>"
)
endif()

find_package(re CONFIG REQUIRED HINTS ../re/cmake)

list(APPEND RE_DEFINITIONS
-DVERSION="${PROJECT_VERSION}"
)

add_definitions(${RE_DEFINITIONS})

include_directories(
include
src
${RE_INCLUDE_DIRS}
${OPENSSL_INCLUDE_DIR}
)

if(MOD_PATH)
add_definitions(-DMOD_PATH="${MOD_PATH}")
elseif(CMAKE_INSTALL_FULL_LIBDIR)
add_definitions(-DMOD_PATH="${CMAKE_INSTALL_FULL_LIBDIR}/restund/modules")
endif()

if(STATIC)
add_definitions(-DSTATIC)
endif()

##############################################################################
#
# Source section
#

set(SRCS
src/cmd.c
src/db.c
src/dtls.c
src/log.c
src/main.c
src/stun.c
src/tcp.c
src/udp.c
)

##############################################################################
#
# Target executable
#


set(LINKLIBS ${RE_LIBRARIES} Threads::Threads)

if(ZLIB_FOUND)
list(APPEND LINKLIBS ZLIB::ZLIB)
endif()

if(USE_OPENSSL)
list(APPEND LINKLIBS OpenSSL::SSL OpenSSL::Crypto)
endif()

if(WIN32)
list(APPEND LINKLIBS ws2_32 iphlpapi winmm gdi32 crypt32 strmiids
ole32 oleaut32 qwave dbghelp)
else()
list(APPEND LINKLIBS -lm ${RESOLV_LIBRARY})
endif()

add_executable(restund ${SRCS})
target_link_libraries(restund PUBLIC ${LINKLIBS})
131 changes: 0 additions & 131 deletions Makefile

This file was deleted.

17 changes: 17 additions & 0 deletions cmake/FindRE.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
find_package(PkgConfig QUIET)
pkg_check_modules(PC_LIBRE QUIET libre)

find_path(RE_INCLUDE_DIR re.h
HINTS ../re/include ${PC_LIBRE_INCLUDEDIR} ${PC_LIBRE_INCLUDE_DIRS})

find_library(RE_LIBRARY NAMES re libre re-static
HINTS ../re ../re/build ../re/build/Debug
${PC_LIBRE_LIBDIR} ${PC_LIBRE_LIBRARY_DIRS})

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(RE DEFAULT_MSG RE_LIBRARY RE_INCLUDE_DIR)

mark_as_advanced(RE_INCLUDE_DIR RE_LIBRARY)

set(RE_INCLUDE_DIRS ${RE_INCLUDE_DIR})
set(RE_LIBRARIES ${RE_LIBRARY})