diff options
| author | Xavier Del Campo Romero <xavi92@disroot.org> | 2025-09-09 03:14:50 +0200 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi92@disroot.org> | 2025-09-18 01:08:14 +0200 |
| commit | c11cb04929f28853142b14339b66f561ca028f36 (patch) | |
| tree | a77a3ddcc1d01028e4077cb295b9b41f594c5d52 /CMakeLists.txt | |
Diffstat (limited to 'CMakeLists.txt')
| -rw-r--r-- | CMakeLists.txt | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..648f8b2 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,61 @@ +# wip, a small TCP/IP stack. +# Copyright (C) 2025 Xavier Del Campo Romero +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at https://mozilla.org/MPL/2.0/. + +cmake_minimum_required(VERSION 3.19) +project(wip LANGUAGES C VERSION 0.0.0) +option(WIP_LOG "Enables logging to stderr") +option(WIP_LOG_CUSTOM "Allows user code to define wip_log. Enables WIP_LOG") +add_library(${PROJECT_NAME}) +target_include_directories(${PROJECT_NAME} PUBLIC include + PRIVATE private_include) + +set(compilers + "GNU" + "Clang" + "TinyCC" +) + +if(WIP_LOG_CUSTOM) + set(WIP_LOG ON) +endif() + +foreach(c ${compilers}) + if(CMAKE_C_COMPILER_ID STREQUAL ${c}) + set(cflags_np + -pedantic + -Wall + ) + + if(CMAKE_BUILD_TYPE STREQUAL "Debug") + set(cflags_np ${cflags_np} -Og -g) + else() + set(cflags_np ${cflags_np} -Os) + endif() + + break() + endif() +endforeach() + +include(CheckCompilerFlag) + +foreach(f ${cflags_np}) + string(REPLACE "-" "_" var supported_${f}) + check_compiler_flag(C ${f} ${var}) + + if(${var}) + set(sup_cflags ${sup_cflags} ${f}) + endif() +endforeach() + +if(WIP_LOG) + target_compile_definitions(${PROJECT_NAME} PRIVATE WIP_LOG) +endif() + +target_compile_options(${PROJECT_NAME} PRIVATE ${sup_cflags}) +set_target_properties(${PROJECT_NAME} PROPERTIES C_STANDARD 90 C_EXTENSIONS OFF) +add_subdirectory(src) +install(TARGETS ${PROJECT_NAME}) |
