-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an option to use a package manager
Projects can now also be generated to use a package manager (Conan or vcpkg). The -p flag accepts a "conan" or "vcpkg" argument to select either. Omit the flag to generate projects without dependencies already setup.
- Loading branch information
1 parent
47cde57
commit 05bfbfb
Showing
39 changed files
with
610 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,63 @@ | ||
#include "lib.h" | ||
#include "lib.h"{% if pm %} | ||
|
||
#include <json-c/json_object.h> | ||
#include <json-c/json_tokener.h> | ||
#include <stddef.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
static const char json[] = "{\"name\":\"{= name =}\"}";{% end %} | ||
|
||
library create_library() | ||
{ | ||
library lib; | ||
lib.name = "{= name =}"; | ||
library lib;{% if pm %} | ||
struct json_tokener* tokener = NULL; | ||
struct json_object* object = NULL; | ||
struct json_object* name_object = NULL; | ||
const char* json_name = NULL; | ||
size_t name_size = 0; | ||
char* name = NULL; | ||
|
||
tokener = json_tokener_new(); | ||
if (tokener == NULL) { | ||
goto exit; | ||
} | ||
|
||
object = json_tokener_parse_ex(tokener, json, sizeof(json)); | ||
if (object == NULL) { | ||
goto cleanup_tokener; | ||
} | ||
|
||
if (json_object_object_get_ex(object, "name", &name_object) == 0) { | ||
goto cleanup_object; | ||
} | ||
|
||
json_name = json_object_get_string(name_object); | ||
if (json_name == NULL) { | ||
goto cleanup_object; | ||
} | ||
|
||
name_size = strlen(json_name) + 1; | ||
name = malloc(name_size); | ||
if (name == NULL) { | ||
goto cleanup_object; | ||
} | ||
|
||
(void)memcpy(name, json_name, name_size); | ||
|
||
cleanup_object: | ||
(void)json_object_put(object); | ||
|
||
cleanup_tokener: | ||
json_tokener_free(tokener); | ||
|
||
exit: | ||
lib.name = name;{% else %} | ||
lib.name = "{= name =}";{% end %} | ||
return lib; | ||
} | ||
}{% if pm %} | ||
|
||
void destroy_library(library* lib) | ||
{ | ||
free((void*)lib->name); | ||
}{% end %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,21 @@ | ||
#include <stdio.h> | ||
{% if pm %}#include <stddef.h> | ||
{% end %}#include <stdio.h> | ||
|
||
#include "lib.h" | ||
|
||
int main(int argc, const char* argv[]) | ||
{ | ||
library lib = create_library(); | ||
|
||
(void)argc; | ||
(void)argv; | ||
|
||
library lib = create_library(); | ||
printf("Hello from %%s!", lib.name); | ||
{% if not pm %} | ||
(void)printf("Hello from %s!", lib.name);{% else %} | ||
if (lib.name == NULL) { | ||
(void)puts("Hello from unknown! (JSON parsing failed in library)"); | ||
} else { | ||
(void)printf("Hello from %s!", lib.name); | ||
} | ||
destroy_library(&lib);{% end %} | ||
return 0; | ||
} |
This file was deleted.
Oops, something went wrong.
34 changes: 29 additions & 5 deletions
34
cmake-init/templates/c/executable/test/source/__name___test.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,37 @@ | ||
#include <string.h> | ||
{% if pm %}#include <memory> | ||
#include <string> | ||
|
||
#include "lib.h" | ||
#include <catch2/catch.hpp>{% else %}#include <string.h>{% end %} | ||
|
||
{% if pm %}extern "C" { | ||
{% end %}#include "lib.h" | ||
{% if pm %}} | ||
|
||
namespace { | ||
|
||
struct library_delete | ||
{ | ||
void operator()(void* p) const | ||
{ | ||
destroy_library(static_cast<library*>(p)); | ||
} | ||
}; | ||
|
||
} // namespace | ||
|
||
TEST_CASE("Name is {= name =}", "[library]") | ||
{ | ||
library lib = create_library(); | ||
auto ptr = std::unique_ptr<library, library_delete>(&lib, {}); | ||
|
||
REQUIRE(std::string("{= name =}") == lib.name); | ||
}{% else %} | ||
int main(int argc, const char* argv[]) | ||
{ | ||
library lib = create_library(); | ||
|
||
(void)argc; | ||
(void)argv; | ||
|
||
library lib = create_library(); | ||
|
||
return strcmp(lib.name, "{= name =}") == 0 ? 0 : 1; | ||
} | ||
}{% end %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.