diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2021-05-05 22:45:35 -0400 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2021-05-05 22:45:35 -0400 |
commit | bf8a03e4867a019ab66c34832c3d93108c89c840 (patch) | |
tree | 58ff2b64f93355957686c528ca28a6d554861d50 | |
parent | 70c312779ecad328a8003b93ebe253c4598b6980 (diff) | |
download | cleanpath-bf8a03e4867a019ab66c34832c3d93108c89c840.tar.gz |
Implement header detection
-rw-r--r-- | CMakeLists.txt | 14 | ||||
-rw-r--r-- | config.h.in | 7 | ||||
-rw-r--r-- | lib/cleanpath.c | 5 |
3 files changed, 24 insertions, 2 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 71de6df..04e6239 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,13 +1,23 @@ cmake_minimum_required(VERSION 3.0) project(clean_path) +include(CheckIncludeFile) + set(CMAKE_C_STANDARD 99) -include_directories(${CMAKE_SOURCE_DIR}/include) set(LIB_SOURCES lib/cleanpath.c) set(MAIN_SOURCES src/main.c) set(INCLUDES include/cleanpath.h) -include (CTest) +CHECK_INCLUDE_FILE(sys/limits.h HAVE_SYS_LIMIT_H) +CHECK_INCLUDE_FILE(linux/limits.h HAVE_LINUX_LIMIT_H) + +configure_file ("${PROJECT_SOURCE_DIR}/config.h.in" + "${PROJECT_BINARY_DIR}/include/config.h") + +include_directories(${PROJECT_BINARY_DIR}/include) +include_directories(${CMAKE_SOURCE_DIR}/include) + +include(CTest) enable_testing() add_subdirectory(tests) diff --git a/config.h.in b/config.h.in new file mode 100644 index 0000000..f8a0396 --- /dev/null +++ b/config.h.in @@ -0,0 +1,7 @@ +#ifndef CLEAN_PATH_CONFIG_H +#define CLEAN_PATH_CONFIG_H + +#cmakedefine HAVE_SYS_LIMIT_H @HAVE_SYS_LIMIT_H@ +#cmakedefine HAVE_LINUX_LIMIT_H @HAVE_LINUX_LIMIT_H@ + +#endif
\ No newline at end of file diff --git a/lib/cleanpath.c b/lib/cleanpath.c index d7f207d..038e300 100644 --- a/lib/cleanpath.c +++ b/lib/cleanpath.c @@ -3,10 +3,15 @@ #include <limits.h> #include <regex.h> #include "cleanpath.h" +#include "config.h" #if OS_LINUX +#ifdef HAVE_SYS_LIMIT_H +#include <sys/limits.h> +#elif HAVE_LINUX_LIMIT_H #include <linux/limits.h> #endif +#endif /** * Split path into parts by sep |