From 47c849cc98cab3cbd366ee935f079bb7c07466d9 Mon Sep 17 00:00:00 2001 From: Alex Denes Date: Tue, 22 Sep 2020 22:33:20 +0200 Subject: [PATCH] Improve cmake list and link against built lib instead of existing lib to prevent linker errors --- CMakeLists.txt | 27 +++++++++++++++++++-------- tests/CMakeLists.txt | 23 +++++++++++------------ tests/tagassm.c | 3 --- tests/tagtok.c | 3 --- 4 files changed, 30 insertions(+), 26 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cfb2dd5..f793c9d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,36 +1,47 @@ cmake_minimum_required(VERSION 3.16) project(microirc LANGUAGES C) -# NOTE: Do these seem too annoying? Try writing good code then. -# Code that triggers these warnings will not be accepted unless it has a good reason to trigger them. -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -pedantic -Werror -Wformat-overflow=2 -Wformat-security -Winit-self -Wstrict-overflow=2 -Wstringop-overflow=2 -Walloc-zero -Wduplicated-branches -Wduplicated-cond -Wtrampolines -Wfloat-equal -Wshadow -Wunsafe-loop-optimizations -Wparentheses -fanalyzer -fstack-protector") +if (CMAKE_C_COMPILER_ID STREQUAL "GNU") + add_compile_options(-Wall -Wextra -Werror -Wformat-overflow=2 -Wformat-security -Winit-self -Wstrict-overflow=2 -Wstringop-overflow=2 -Walloc-zero -Wduplicated-branches -Wduplicated-cond -Wtrampolines -Wfloat-equal -Wshadow -Wunsafe-loop-optimizations -Wparentheses -fanalyzer -fstack-check) +elseif (CMAKE_C_COMPILER_ID STREQUAL "Clang") + add_compile_options(-Weverything) +endif() + if (NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Debug) endif() if ( BUILD_IRCV3 ) - add_definitions(-DUIRC_IRCV3) -endif() -if ( BUILD_TESTS ) - enable_testing() - add_subdirectory(tests) + message("IRCv3 capabilities are going to be built.") + add_compile_definitions(UIRC_IRCV3) endif() + set(build_FILES src/assemblers.c src/misc.c src/tokenizers.c src/validators.c ) + if ( BUILD_HELPERS ) message("Helper functions are going to be built.") set(build_FILES ${build_FILES} src/helpers.c src/taghelpers.c) endif() + add_library(uirc SHARED ${build_FILES}) set_property(TARGET uirc PROPERTY C_STANDARD 99) +# NOTE: Do these seem too annoying? Try writing good code then. +# Code that triggers these warnings will not be accepted unless it has a good reason to trigger them. install(DIRECTORY "${CMAKE_SOURCE_DIR}/include/" DESTINATION "include/uirc" FILES_MATCHING PATTERN "*.h" ) install(TARGETS uirc DESTINATION ${CMAKE_INSTALL_BINDIR}) + +if ( BUILD_TESTS ) + message("Tests are going to be built.") + enable_testing() + add_subdirectory(tests) +endif() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index cd5ae40..fdc01d6 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,5 +1,4 @@ cmake_minimum_required(VERSION 3.16) -find_library(UIRC_PATH NAMES uirc libuirc REQUIRED) add_executable(tokenizer tokenizer.c) add_executable(overflow overflow.c) @@ -10,14 +9,14 @@ add_executable(notrail notrail.c) add_executable(spacedargs spacedargs.c) add_executable(strtokmr strtokmr.c) -target_link_libraries(tokenizer ${UIRC_PATH}) -target_link_libraries(overflow ${UIRC_PATH}) -target_link_libraries(prefixassm ${UIRC_PATH}) -target_link_libraries(msgassm ${UIRC_PATH}) -target_link_libraries(numericmds ${UIRC_PATH}) -target_link_libraries(notrail ${UIRC_PATH}) -target_link_libraries(spacedargs ${UIRC_PATH}) -target_link_libraries(strtokmr ${UIRC_PATH}) +target_link_libraries(tokenizer uirc) +target_link_libraries(overflow uirc) +target_link_libraries(prefixassm uirc) +target_link_libraries(msgassm uirc) +target_link_libraries(numericmds uirc) +target_link_libraries(notrail uirc) +target_link_libraries(spacedargs uirc) +target_link_libraries(strtokmr uirc) add_test(NAME Tokenizer COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/tokenizer) add_test(NAME Overflow COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/overflow) @@ -35,10 +34,10 @@ if ( BUILD_HELPERS ) add_executable(timestamp timestamp.c) endif() -target_link_libraries(tagtok ${UIRC_PATH}) -target_link_libraries(tagassm ${UIRC_PATH}) +target_link_libraries(tagtok uirc) +target_link_libraries(tagassm uirc) if ( BUILD_HELPERS ) -target_link_libraries(timestamp ${UIRC_PATH}) +target_link_libraries(timestamp uirc) endif() add_test(NAME TagParser COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/tagtok) diff --git a/tests/tagassm.c b/tests/tagassm.c index 4f703da..b9c7e94 100644 --- a/tests/tagassm.c +++ b/tests/tagassm.c @@ -1,6 +1,3 @@ -#ifndef UIRC_IRCV3 -#define UIRC_IRCV3 -#endif #include "../include/uirc.h" #include #include diff --git a/tests/tagtok.c b/tests/tagtok.c index 779cc72..ef2b2a2 100644 --- a/tests/tagtok.c +++ b/tests/tagtok.c @@ -1,6 +1,3 @@ -#ifndef UIRC_IRCV3 -#define UIRC_IRCV3 -#endif #include "../include/uirc.h" #include #include