From b2e99bb976c8b470fee567b3eda1ffcd4f89dfa3 Mon Sep 17 00:00:00 2001
From: Dominic Masters <dominic@domsplace.com>
Date: Sun, 17 Oct 2021 00:12:35 -0700
Subject: [PATCH] More CMake stuff

---
 CMakeLists.txt                                | 52 +++++++++++--------
 src/CMakeLists.txt                            |  7 ++-
 src/file/asset.c                              |  4 +-
 src/file/asset.h                              |  4 ++
 src/game/CMakeLists.txt                       | 28 ++++++++++
 tools/vn/character-sheet-maker/CMakeLists.txt | 24 +++++++++
 .../main.c}                                   |  0
 .../main.h}                                   |  4 +-
 8 files changed, 97 insertions(+), 26 deletions(-)
 create mode 100644 src/game/CMakeLists.txt
 create mode 100644 tools/vn/character-sheet-maker/CMakeLists.txt
 rename tools/vn/{character-sheet-maker.c => character-sheet-maker/main.c} (100%)
 rename tools/vn/{character-sheet-maker.h => character-sheet-maker/main.h} (78%)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 21a2f725..ab2bc810 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -11,35 +11,43 @@ set(CMAKE_C_STANDARD_REQUIRED ON)
 # Set some global flags
 add_compile_definitions(
   _CRT_SECURE_NO_WARNINGS=1
-  SETTING_ASSET_PREFIX="../../../assets/"
+  ASSET_PREFIX="../../../assets/"
 )
 
-# Which game are we building?
-if(TARGET_GAME STREQUAL poker)
-  add_compile_definitions(
-    GAME_NAME="Penny's Poker"
-    GAME_FILE="poker/game.h"
-    GAME_TYPE=pokergame_t
-    GAME_INIT=pokerGameInit
-    GAME_UPDATE=pokerGameUpdate
-    GAME_DISPOSE=pokerGameDispose
-    GAME_VERSION=1.0
-  )
+# Do initial set up depending on the build target type.
+if(TARGET_TYPE STREQUAL tool)
+  set(TARGET_NAME tool)
+elseif(TARGET_TYPE STREQUAL test)
+  set(TARGET_NAME test)
+else()
+  set(TARGET_NAME ${TARGET_GAME})
 endif()
 
-# Set up the project.
-project(Dawn VERSION 1.0)
+# Set up the project
+project(${TARGET_NAME} VERSION 1.0)
 add_executable(${PROJECT_NAME})
 
-# Add libraries
-add_subdirectory(lib)
+# Now change sources depending on the target type
+if(TARGET_TYPE STREQUAL tool)
 
-# Add sources
-add_subdirectory(src)
-
-# Are we building a game, a tool or running tests?
-if(TARGET_TYPE STREQUAL test)
+elseif(TARGET_TYPE STREQUAL test)
   add_subdirectory(test)
 else()
+  if(TARGET_GAME STREQUAL poker)
+    add_compile_definitions(
+      GAME_NAME="Penny's Poker"
+      GAME_FILE="poker/game.h"
+      GAME_TYPE=pokergame_t
+      GAME_INIT=pokerGameInit
+      GAME_UPDATE=pokerGameUpdate
+      GAME_DISPOSE=pokerGameDispose
+      GAME_VERSION=1.0
+    )
+  endif()
+
   add_subdirectory(client)
-endif()
\ No newline at end of file
+endif()
+
+# Add global sources.
+add_subdirectory(lib)
+add_subdirectory(src)
\ No newline at end of file
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index b6ad078f..5b90ce65 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -31,4 +31,9 @@ target_sources(${PROJECT_NAME}
 target_include_directories(${PROJECT_NAME}
   PUBLIC
     ${CMAKE_CURRENT_LIST_DIR}
-)
\ No newline at end of file
+)
+
+# Sub
+if(TARGET_TYPE STREQUAL game)
+  add_subdirectory(game)
+endif()
\ No newline at end of file
diff --git a/src/file/asset.c b/src/file/asset.c
index fa08e70f..700488c7 100644
--- a/src/file/asset.c
+++ b/src/file/asset.c
@@ -36,14 +36,14 @@ assetbuffer_t * assetBufferOpen(char *assetName) {
   // Get the directory based on the raw input by creating a new string.
   FILE *fptr;
   size_t lenAsset = strlen(assetName);// Get the length of asset
-  size_t lenPrefix = strlen(SETTING_ASSET_PREFIX);// Get the length of the prefix
+  size_t lenPrefix = strlen(ASSET_PREFIX);// Get the length of the prefix
   
   // Create str to house both the prefix and asset, and null terminator
   char *joined = malloc(lenAsset + lenPrefix + 1);
   if(joined == NULL) return NULL;// Mem okay?
 
   joined[0] = '\0';//Start at null
-  strcat(joined, SETTING_ASSET_PREFIX);//Add prefix
+  strcat(joined, ASSET_PREFIX);//Add prefix
   strcat(joined, assetName);//Add body
 
   printf("Opening up %s\n", joined);
diff --git a/src/file/asset.h b/src/file/asset.h
index 0806f269..295bd87a 100644
--- a/src/file/asset.h
+++ b/src/file/asset.h
@@ -13,6 +13,10 @@
 #include "../script/scripter.h"
 #include "xml.h"
 
+#if !defined(ASSET_PREFIX)
+  #error Asset Prefix has not been defined.
+#endif
+
 /** Definition of an asset ready to be buffered */
 typedef FILE assetbuffer_t;
 
diff --git a/src/game/CMakeLists.txt b/src/game/CMakeLists.txt
new file mode 100644
index 00000000..652e62a4
--- /dev/null
+++ b/src/game/CMakeLists.txt
@@ -0,0 +1,28 @@
+# Copyright (c) 2021 Dominic Msters
+# 
+# This software is released under the MIT License.
+# https://opensource.org/licenses/MIT
+
+# Definitions
+
+# Libraries
+
+# Sources
+file(GLOB GAME_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.c)
+file(GLOB GAME_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/*.h)
+file(GLOB_RECURSE SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/${TARGET_GAME}/*.c)
+file(GLOB_RECURSE HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/${TARGET_GAME}*.h)
+
+target_sources(${PROJECT_NAME}
+  PRIVATE
+    ${GAME_SOURCES}
+    ${SOURCES}
+    ${GAME_HEADERS}
+    ${HEADERS}
+)
+
+# Includes
+target_include_directories(${PROJECT_NAME}
+  PUBLIC
+    ${CMAKE_CURRENT_LIST_DIR}
+)
\ No newline at end of file
diff --git a/tools/vn/character-sheet-maker/CMakeLists.txt b/tools/vn/character-sheet-maker/CMakeLists.txt
new file mode 100644
index 00000000..f49e3604
--- /dev/null
+++ b/tools/vn/character-sheet-maker/CMakeLists.txt
@@ -0,0 +1,24 @@
+# Copyright (c) 2021 Dominic Msters
+# 
+# This software is released under the MIT License.
+# https://opensource.org/licenses/MIT
+
+# Definitions
+
+# Libraries
+
+# Sources
+file(GLOB_RECURSE SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.c)
+file(GLOB_RECURSE HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/*.h)
+
+target_sources(${PROJECT_NAME}
+  PRIVATE
+    ${SOURCES}
+    ${HEADERS}
+)
+
+# Includes
+target_include_directories(${PROJECT_NAME}
+  PUBLIC
+    ${CMAKE_CURRENT_LIST_DIR}
+)
\ No newline at end of file
diff --git a/tools/vn/character-sheet-maker.c b/tools/vn/character-sheet-maker/main.c
similarity index 100%
rename from tools/vn/character-sheet-maker.c
rename to tools/vn/character-sheet-maker/main.c
diff --git a/tools/vn/character-sheet-maker.h b/tools/vn/character-sheet-maker/main.h
similarity index 78%
rename from tools/vn/character-sheet-maker.h
rename to tools/vn/character-sheet-maker/main.h
index 61d565be..71ddb411 100644
--- a/tools/vn/character-sheet-maker.h
+++ b/tools/vn/character-sheet-maker/main.h
@@ -6,4 +6,6 @@
  */
 
 #pragma once
-#include <libs.h>
\ No newline at end of file
+
+
+int32_t main(int32_t argc, char *argv[]);
\ No newline at end of file