Commit b4ea1dfe authored by platypro's avatar platypro

Compile now works on windows. Some DLLS need to be copied if compiled with MinGW

parent 6155e42c
......@@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.0)
project(quizgrind C)
option(QUIZGRIND_BUILD_PDF "PDF Support" ON)
option(QUIZGRIND_BUILD_DAEMON "HTTP Daemon Support" ON)
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_C_FLAGS "-Wall -O0")
......@@ -11,5 +12,10 @@ include(GNUInstallDirs)
set(APP_DATA_PATH ${CMAKE_INSTALL_FULL_DATAROOTDIR}/${CMAKE_PROJECT_NAME})
set(APP_VAR_PATH ${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/${CMAKE_PROJECT_NAME})
if(MINGW AND QUIZGRIND_BUILD_DAEMON)
message("HTTP Daemon not supported on windows. Not building.")
set(QUIZGRIND_BUILD_DAEMON OFF CACHE BOOL "" FORCE)
endif()
add_subdirectory(deps)
add_subdirectory(src)
......@@ -2,31 +2,34 @@ add_subdirectory(lua EXCLUDE_FROM_ALL)
#libpmustache build settings
if(QUIZGRIND_BUILD_PDF)
SET(PMUSTACHE_BUILD_GIO true)
SET(PMUSTACHE_BUILD_GIO true CACHE BOOL "")
endif()
add_subdirectory(libpmustache EXCLUDE_FROM_ALL)
#WJElement build settings
SET(WJE_BUILD_CLI false)
SET(WJE_STATIC_LIB true)
SET(WJE_BUILD_CLI OFF CACHE BOOL "")
SET(WJE_STATIC_LIB true CACHE BOOL "")
add_subdirectory(wjelement EXCLUDE_FROM_ALL)
if(QUIZGRIND_BUILD_DAEMON)
# Onion build settings
SET(ONION_USE_SSL false)
SET(ONION_USE_PAM false)
SET(ONION_USE_SSL OFF CACHE BOOL "")
SET(ONION_USE_PAM OFF CACHE BOOL "")
SET(ONION_USE_PTHREADS true)
SET(ONION_USE_PNG false)
SET(ONION_USE_JPEG false)
SET(ONION_USE_XML2 false)
SET(ONION_USE_SYSTEMD false)
SET(ONION_USE_SQLITE3 false)
SET(ONION_USE_REDIS false)
SET(ONION_USE_GC false)
SET(ONION_USE_TESTS false)
SET(ONION_EXAMPLES false)
SET(ONION_USE_BINDINGS_CPP false)
SET(ONION_USE_PNG OFF CACHE BOOL "")
SET(ONION_USE_JPEG OFF CACHE BOOL "")
SET(ONION_USE_XML2 OFF CACHE BOOL "")
SET(ONION_USE_SYSTEMD OFF CACHE BOOL "")
SET(ONION_USE_SQLITE3 OFF CACHE BOOL "")
SET(ONION_USE_REDIS OFF CACHE BOOL "")
SET(ONION_USE_GC OFF CACHE BOOL "")
SET(ONION_USE_TESTS OFF CACHE BOOL "")
SET(ONION_EXAMPLES OFF CACHE BOOL "")
SET(ONION_USE_BINDINGS_CPP OFF CACHE BOOL "")
SET(ONION_POLLER default)
add_subdirectory(onion EXCLUDE_FROM_ALL)
set(DEPS_LIBS ${DEPS_LIBS} onion_static)
endif()
set(DEPS_SRC ${PMUSTACHE_PROVIDER_WJE_SRCS} PARENT_SCOPE)
set(DEPS_INCLUDE
......@@ -34,4 +37,4 @@ set(DEPS_INCLUDE
${CMAKE_CURRENT_SOURCE_DIR}/onion/src
${PMUSTACHE_INCLUDE_DIRS}
PARENT_SCOPE)
set(DEPS_LIBS wjelement Lua onion_static pmustache PARENT_SCOPE)
set(DEPS_LIBS ${DEPS_LIBS} wjelement Lua pmustache PARENT_SCOPE)
Subproject commit 43aed4c0188aee04cdd78aad6d1cec6f5f8eb5e8
Subproject commit 88825fe5b2656470544c82a3443a857e9606e3b2
......@@ -13,9 +13,6 @@ set(SRCS
backend/exercise.c
backend/script.c
daemon/daemon.c
daemon/http.c
# Widget sources
widget/widget.c
......@@ -38,7 +35,15 @@ IF(QUIZGRIND_BUILD_PDF)
set(SRCS ${SRCS} gen/pdf.c)
add_definitions(-D_QUIZGRIND_BUILD_PDF)
ENDIF()
if(QUIZGRIND_BUILD_DAEMON)
add_definitions(-D_QUIZGRIND_BUILD_DAEMON)
set(SRCS ${SRCS}
daemon/daemon.c
daemon/http.c
)
endif()
add_executable(quizgrind ${SRCS})
install(TARGETS quizgrind DESTINATION ${CMAKE_INSTALL_FULL_BINDIR})
......
......@@ -4,7 +4,6 @@
#include <stdio.h>
#include <string.h>
#include <alloca.h>
#include <getopt.h>
void args_show_short(struct option_info* opts)
......
......@@ -6,6 +6,8 @@
#define ARGS_ARGUMENT 1
#define ARGS_OPTIONAL 2
#define OPT_HELP ARGS_LONGONLY(0)
struct option_info
{
uint32_t flags;
......
......@@ -15,7 +15,12 @@
#include <string.h>
#include <time.h>
#include <libgen.h>
#include <alloca.h>
#ifdef _WIN32
#include <malloc.h>
//#define alloca _alloca
#else
#include <alloca.h>
#endif
#include <ctype.h>
#include <math.h>
#include <errno.h>
......@@ -312,26 +317,51 @@ char* exercise_load(PG_STATE* state, char* filename)
return pset->name;
}
//TODO: Clean-up deleted exercises
bool exercise_loadAll(PG_STATE* state)
#ifdef _WIN32
bool foreachfile(char* path, bool (*fun)(void* udata, char* path), void* udata)
{
WIN32_FIND_DATA d;
HANDLE dir = FindFirstFile(path, &d);
do
{
if(!fun(udata, d.cFileName)) return false;
} while (FindNextFile(dir, &d));
return true;
}
#else
bool foreachfile(char* path, bool (*fun)(void* udata, char* path), void* udata)
{
DIR *d;
struct dirent *dir;
d = opendir(state->path_pset);
d = opendir(path);
while ((dir = readdir(d)))
{
{
if(dir->d_type == DT_REG)
{
char* fpath = exercise_loadResource(state->path_pset, dir->d_name, NULL);
if(!fpath) return false;
exercise_load(state, fpath);
free(fpath);
if(!fun(udata, dir->d_name)) return false;
}
}
closedir(d);
return true;
}
#endif
bool exercise_loadAll_fun(void* udata, char* path)
{
PG_STATE* state = udata;
char* fpath = exercise_loadResource(state->path_pset, path, NULL);
if(!fpath) return false;
exercise_load(state, fpath);
free(fpath);
return true;
}
//TODO: Clean-up deleted exercises
bool exercise_loadAll(PG_STATE* state)
{
foreachfile(state->path_pset, exercise_loadAll_fun, state);
return true;
}
char* exercise_loadOne(PG_STATE* state, char* set)
{
......
......@@ -20,4 +20,8 @@
#define STR(a) #a
#define XSTR(a) STR(a)
#ifdef _WIN32
#include <windows.h>
#endif
#endif
......@@ -15,7 +15,6 @@
#define OPT_INPUT_PSET 'p'
#define OPT_INPUT_GENMODE 'g'
#define OPT_INPUT_NUM 'n'
#define OPT_HELP ARGS_LONGONLY(0)
#if _QUIZGRIND_BUILD_PDF
#define OPT_PDF_HEADERS ARGS_LONGONLY(1)
#define OPT_PDF_MARGIN ARGS_LONGONLY(2)
......
......@@ -22,9 +22,8 @@
PG_STATE* gstate = NULL;
#define OPT_PATH_EX ARGS_LONGONLY(0)
#define OPT_PATH_PS ARGS_LONGONLY(1)
#define OPT_HELP ARGS_LONGONLY(2)
#define OPT_PATH_EX ARGS_LONGONLY(1)
#define OPT_PATH_PS ARGS_LONGONLY(2)
#define OPT_VERSION ARGS_LONGONLY(3)
static struct option_info opts[] = {
......@@ -37,7 +36,9 @@ static struct option_info opts[] = {
void cleanup(PG_STATE* state)
{
#ifdef _QUIZGRIND_BUILD_DAEMON
daemon_stop(state);
#endif
exercise_cleanup(state);
script_cleanup(state);
}
......@@ -51,8 +52,10 @@ void interrupt(int signal)
struct command commands[] =
{
{.name = "daemon", .hint = "Start the daemon", .fn = daemon_run},
{.name = "gen", .hint = "Generate a quiz file", .fn = handle_file},
#ifdef _QUIZGRIND_BUILD_DAEMON
{.name = "daemon", .hint = "Start the daemon" , .fn = daemon_run},
#endif
{.name = "gen", .hint = "Generate a quiz file", .fn = handle_file},
{0}
};
......@@ -115,7 +118,7 @@ int main(int argc, char* argv[])
PG_STATE state = {0};
signal(SIGINT, interrupt);
gstate = &state;
printf("Hello\n");
if(argc < 2)
{
exit(handle_help(&state));
......
......@@ -12,13 +12,17 @@
#define VERSIONSTRING "QuizGrind version 1.0"
#include "backend/exercise.h"
#include "daemon/daemon.h"
#ifdef _QUIZGRIND_BUILD_DAEMON
#include "daemon/daemon.h"
#endif
#include "gen/gen.h"
typedef struct PG_State
{
PG_EXERCISE exercise;
#ifdef _QUIZGRIND_BUILD_DAEMON
PG_DAEMON daemon;
#endif
PG_GEN gen;
char* path_exercise;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment