Working on C tooling
This commit is contained in:
@ -4,4 +4,5 @@
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
add_subdirectory(file)
|
||||
add_subdirectory(vn)
|
||||
add_subdirectory(vn)
|
||||
add_subdirectory(display)
|
32
tools/display/CMakeLists.txt
Normal file
32
tools/display/CMakeLists.txt
Normal file
@ -0,0 +1,32 @@
|
||||
# Copyright (c) 2021 Dominic Msters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
cmake_minimum_required(VERSION 3.13)
|
||||
set(CMAKE_C_STANDARD 99)
|
||||
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||
|
||||
SET(TOOL_NAME texture_generation)
|
||||
set(TOOL_TEXTURE_GENERATION_SOURCE_DIR)
|
||||
|
||||
# Build Tool
|
||||
project(${TOOL_NAME} VERSION 1.0)
|
||||
add_executable(${TOOL_NAME})
|
||||
target_sources(${TOOL_NAME}
|
||||
PRIVATE
|
||||
texture_generation.c
|
||||
)
|
||||
target_link_libraries(${TOOL_NAME}
|
||||
PUBLIC
|
||||
stb
|
||||
)
|
||||
|
||||
# Function for creating the target
|
||||
function(tool_texture target in out)
|
||||
add_custom_target(${target}
|
||||
COMMAND texture_generation "${ROOT_DIR}/${ASSETS_DIR}/${in}" "${ASSETS_DIR}/${out}"
|
||||
COMMENT "Generating texture ${target} from ${in}"
|
||||
SOURCES ${TOOL_NAME}
|
||||
)
|
||||
endfunction()
|
68
tools/utils/file.h
Normal file
68
tools/utils/file.h
Normal file
@ -0,0 +1,68 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#include <direct.h>
|
||||
#define getcwd _getcwd
|
||||
#define FILE_PATH_SEP '\\'
|
||||
#elif defined(__GNUC__)
|
||||
#include <unistd.h>
|
||||
#define FILE_PATH_SEP '/'
|
||||
#endif
|
||||
|
||||
#ifndef STB_IMAGE_IMPLEMENTATION
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include <stb_image.h>
|
||||
#endif
|
||||
|
||||
void fileNormalizeSlashes(char *string) {
|
||||
char c;
|
||||
int i = 0;
|
||||
|
||||
while(c = string[i++]) {
|
||||
if(c != '\\' && c != '/') continue;
|
||||
string[i-1] = FILE_PATH_SEP;
|
||||
}
|
||||
}
|
||||
|
||||
void fileMkdirp(char *path) {
|
||||
char buffer[FILENAME_MAX];
|
||||
char c;
|
||||
int i = 0;
|
||||
bool inFile;
|
||||
bool hasMore;
|
||||
|
||||
inFile = false;
|
||||
hasMore = false;
|
||||
while(c = path[i]) {
|
||||
if((c == '\\' || c == '/') && i > 0) {
|
||||
buffer[i] = '\0';
|
||||
_mkdir(buffer);
|
||||
inFile = false;
|
||||
hasMore = false;
|
||||
buffer[i] = FILE_PATH_SEP;
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(c == '.') inFile = true;
|
||||
hasMore = true;
|
||||
buffer[i] = c;
|
||||
i++;
|
||||
}
|
||||
|
||||
if(!inFile && hasMore) {
|
||||
buffer[i] = '\0';
|
||||
_mkdir(buffer);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user