-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmakeauto.h
209 lines (177 loc) · 4.56 KB
/
cmakeauto.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#ifndef CMAKEAUTO_H_
#define CMAKEAUTO_H_
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <memory.h>
#include <string.h>
#ifdef _WIN32
#include <Windows.h>
#include <fileapi.h>
#define FILE_MAX_PATH _MAX_PATH
#define FILE_SEPERATOR "\\"
#define FILE_SEPERATOR_CHAR '\\'
typedef void *watchfolderhandle_t;
#elif __linux__
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <dirent.h>
#include <spawn.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/inotify.h>
#ifdef __GNUC__
#define ALIGNAS(TYPE) __attribute__((aligned(__alignof__(TYPE))))
#else
#define ALIGNAS(TYPE) /* empty */
#endif
#define FILE_MAX_PATH PATH_MAX
#define FILE_SEPERATOR "/"
#define FILE_SEPERATOR_CHAR '/'
typedef int watchfolderhandle_t;
#else
#error unsupported platform
#endif
#define GERNERATOR_MAX_LEN 64
#define WATCHFOLDER_MAX_LEN 64
#ifdef __linux__
#define stricmp strcasecmp
bool strcpy_s(
char *_Destination,
unsigned long long _SizeInBytes,
char const *_Source);
bool strcat_s(
char *_Destination,
unsigned long long _SizeInBytes,
char const *_Source);
bool memcpy_s(
void *const _Destination,
unsigned long long const _DestinationSize,
void const *const _Source,
unsigned long long const _SourceSize);
int sprintf_s(
char *const _Buffer,
unsigned long long const _BufferCount,
char const *const _Format,
...);
#endif
typedef enum
{
CMAKE_AUTO_ACTION_UNKNOWN,
CMAKE_AUTO_ACTION_BUILD,
CMAKE_AUTO_ACTION_HELP,
CMAKE_AUTO_ACTION_CONFIGURE,
CMAKE_AUTO_ACTION_TEMPLATE,
} CMakeAutoAction;
typedef enum
{
CMAKE_AUTO_ARCH_UNKONWN,
CMAKE_AUTO_ARCH_X86,
CMAKE_AUTO_ARCH_X64,
} CMakeAutoArchitecture;
typedef enum
{
CMAKE_AUTO_MODE_UNKNOWN,
CMAKE_AUTO_MODE_DEBUG,
CMAKE_AUTO_MODE_RELEASE,
} CMakeAutoMode;
typedef enum
{
CMAKE_AUTO_OPTION_NONE,
CMAKE_AUTO_OPTION_AUTO_RELOAD = (1 << 0),
} CMakeAutoOptions;
typedef struct
{
CMakeAutoAction action;
CMakeAutoArchitecture arch;
CMakeAutoMode mode;
int options;
char builddir[FILE_MAX_PATH];
char srcdir[FILE_MAX_PATH];
char generator[GERNERATOR_MAX_LEN];
char *template;
char *extra_init_args;
char *extra_build_args;
char watchfolders[FILE_MAX_PATH + 1][WATCHFOLDER_MAX_LEN];
unsigned int watchfolders_count;
watchfolderhandle_t *watchfolderhandles;
unsigned int watchfolderhandles_count;
} CMakeAutoConfig;
/**
* @brief Prints this program's usage
*/
void cma_print_usage();
/**
* @brief Gets the absolute path of a path
*
* @param buf
* @param size
* @param path
* @return true if succeeded
* @return false if failed
*/
bool cma_abspath(char *buf, size_t size, const char *path);
bool cma_create_dir_include_existing(const char *path);
bool cma_file_exists(const char *path);
bool cma_folder_exists(const char *path);
bool cma_copy_file(const char *src, const char *dst);
bool cma_get_current_process_absfilepath(char *buf, size_t size);
bool cma_get_workdir(char *buf, size_t size);
void cma_iterate_dir(const char *abspath,
const char *relpath, // default should be "./"
void *userdata,
bool should_iter_sub_folder,
bool (*callback)(const char *abspath, // return false to stop iterating
const char *relpath,
const char *name,
bool isfolder /* 0 = file, 1 = folder */,
void *userdata));
/**
* @brief Creates a process
*
* @param filename
* @param cmdline
* @param workdir
* @param processhandle (optional) (out)
* @param pid (optional) (out)
* @return true if created successfully
* @return false if failed
*/
bool cma_create_process(char *filename,
char *cmdline,
char *posix_args[], // Only used on Linux otherwise NULL
char *workdir,
void **processhandle,
unsigned int *pid);
bool cma_watch_folder_init(CMakeAutoConfig *config);
bool cma_watch_folder_wait_for_next_change(CMakeAutoConfig *config);
bool cma_watch_folder_close(CMakeAutoConfig *config);
/**
* @brief Parses command line arguments
*
* @param argc
* @param argv
* @param config (out)
* @return true if parsed successfully
* @return false if failed
*/
bool cma_parse_args(int argc, char **argv, CMakeAutoConfig *config);
/**
* @brief Initalized Project Files
*
* @param config
* @return true if process created & exited correctly
* @return false if failed
*/
bool cma_init_proj(CMakeAutoConfig *config);
/**
* @brief Builds Project Files
*
* @param config
* @return true if process created & exited correctly
* @return false if failed
*/
bool cma_build(CMakeAutoConfig *config);
#endif // CMAKEAUTO_H_