From 6f3a1387e7e5adf53da82a805e75b4e85b13676e Mon Sep 17 00:00:00 2001 From: George Constantine Date: Tue, 13 Jul 2021 01:02:09 +1000 Subject: [PATCH] Added library to example --- CMakeLists.txt | 9 +++++++-- lib/CMakeLists.txt | 5 +++++ lib/lib.c | 13 +++++++++++++ lib/lib.h | 6 ++++++ main.c | 12 ++---------- 5 files changed, 33 insertions(+), 12 deletions(-) create mode 100644 lib/CMakeLists.txt create mode 100644 lib/lib.c create mode 100644 lib/lib.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 53be302..7ce2354 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,8 +2,13 @@ cmake_minimum_required(VERSION 3.13) project(cmake-issue VERSION 1.0 DESCRIPTION "Static target issue" LANGUAGES C) +add_subdirectory(lib) + + add_executable(main-dynamic main.c) -target_link_libraries(main-dynamic uuid) +target_link_libraries(main-dynamic uuid libcmake.a) +add_dependencies(main-dynamic libcmake) add_executable(main-static main.c) -target_link_libraries(main-static uuid -static) +target_link_libraries(main-static uuid libcmake.a -static) +add_dependencies(main-static libcmake) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt new file mode 100644 index 0000000..59c936b --- /dev/null +++ b/lib/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_minimum_required(VERSION 3.13) + +project(libcmake VERSION 1.0 DESCRIPTION "Static target issue - Library" LANGUAGES C) + +add_library(libcmake lib.c) diff --git a/lib/lib.c b/lib/lib.c new file mode 100644 index 0000000..355aa73 --- /dev/null +++ b/lib/lib.c @@ -0,0 +1,13 @@ +#include +#include + +void PrintUUID(){ + + uuid_t some_uuid; + char uuid_str[40]; + + uuid_generate(some_uuid); + uuid_unparse(some_uuid, uuid_str); + + printf("UUID: %s\n", uuid_str); +} diff --git a/lib/lib.h b/lib/lib.h new file mode 100644 index 0000000..ca53567 --- /dev/null +++ b/lib/lib.h @@ -0,0 +1,6 @@ +#ifndef LIB_H +#define LIB_H + +void PrintUUID(); + +#endif //LIB_H diff --git a/main.c b/main.c index 8be9219..d763e3f 100644 --- a/main.c +++ b/main.c @@ -1,14 +1,6 @@ -#include -#include - +#include "lib/lib.h" int main(){ - uuid_t some_uuid; - char uuid_str[40]; - - uuid_generate(some_uuid); - uuid_unparse(some_uuid, uuid_str); - - printf("UUID: %s\n", uuid_str); + PrintUUID(); return 0; }