From 2e89a903ec7b1136995f05f2dc7330e4a56b597f Mon Sep 17 00:00:00 2001 From: Evan Burkey Date: Wed, 8 Sep 2021 11:19:24 -0700 Subject: [PATCH] OS detection through Cmake --- CMakeLists.txt | 12 ++++++++++-- README.md | 4 +++- build.sh | 8 ++++++++ src/input.c | 2 ++ src/main.c | 3 +++ 5 files changed, 26 insertions(+), 3 deletions(-) create mode 100755 build.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index b6e4b4d..0a2048c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,5 +16,13 @@ file(GLOB SRC2020 src/2020/*.c) file(COPY input DESTINATION ${CMAKE_BINARY_DIR}) add_executable(advent ${SRC} ${SRC2015} ${SRC2016} ${SRC2017} ${SRC2018} ${SRC2019} ${SRC2020}) -target_link_libraries(advent PRIVATE bsd flint) -target_include_directories(advent PRIVATE include lib/libflint/include) \ No newline at end of file + +if ((${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD") OR (${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")) + message(WARNING "${CMAKE_SYSTEM_NAME}: Not linking libbsd") + target_link_libraries(advent PRIVATE flint) +else() + message(WARNING "${CMAKE_SYSTEM_NAME}: Linking libbsd") + target_link_libraries(advent PRIVATE bsd flint) +endif() + +target_include_directories(advent PRIVATE include lib/libflint/include) diff --git a/README.md b/README.md index e1f1eb6..91da08e 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Advent Of Code solutions using C99. Be sure to clone the project with its submodules: - git clone --recurse-submodules -j8 https://git.fputs.com/fputs/advent + git clone --recurse-submodules https://git.fputs.com/fputs/advent This project relies on several BSD extensions to the stdlib. BSDs should be able to build the project out of the box. Linux users will need `libbsd` installed. The package is called `libbsd-dev` on Debian-based systems. @@ -17,6 +17,8 @@ Build the project using Cmake: cmake .. make +The supplied `build.sh` script uses `scan-build` to build a compilation database. This is not neccesary for users. + ## Inputs Inputs can be generated from `get_input.sh`. You will need to get your session cookie from the Advent of Code website. The easiest way to do this is to inspect any input page in your browser. diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..1ef627e --- /dev/null +++ b/build.sh @@ -0,0 +1,8 @@ +#! /usr/bin/env sh + +mkdir -p build +cd build +cmake .. +make +cp advent .. +cd .. diff --git a/src/input.c b/src/input.c index 2479740..35bbfd9 100644 --- a/src/input.c +++ b/src/input.c @@ -3,7 +3,9 @@ #include #include +#ifdef __linux__ #include +#endif #include "input.h" diff --git a/src/main.c b/src/main.c index f156c3e..5d47917 100644 --- a/src/main.c +++ b/src/main.c @@ -1,7 +1,10 @@ #include #include #include + +#ifdef __linux__ #include +#endif #include "advent2015.h" #include "advent2016.h"