From 506090032a07f2f3a74a44d8c8774cbdd252c947 Mon Sep 17 00:00:00 2001
From: Loek Le Blansch <loek@pipeframe.xyz>
Date: Sat, 28 Sep 2024 14:45:53 +0200
Subject: WIP ExternalProject test

---
 mwe/dynlink/exec/CMakeLists.txt | 10 +++++++++-
 mwe/dynlink/exec/main.c         |  3 ++-
 mwe/dynlink/lib/CMakeLists.txt  | 16 +++++++++++++++-
 mwe/dynlink/lib/lib.c           |  3 ---
 mwe/dynlink/lib/lib.h           |  3 ---
 mwe/dynlink/lib/test.c          |  3 +++
 mwe/dynlink/lib/test.h          |  3 +++
 7 files changed, 32 insertions(+), 9 deletions(-)
 delete mode 100644 mwe/dynlink/lib/lib.c
 delete mode 100644 mwe/dynlink/lib/lib.h
 create mode 100644 mwe/dynlink/lib/test.c
 create mode 100644 mwe/dynlink/lib/test.h

(limited to 'mwe/dynlink')

diff --git a/mwe/dynlink/exec/CMakeLists.txt b/mwe/dynlink/exec/CMakeLists.txt
index 5335f0f..465b45e 100644
--- a/mwe/dynlink/exec/CMakeLists.txt
+++ b/mwe/dynlink/exec/CMakeLists.txt
@@ -5,12 +5,20 @@ set(CMAKE_CXX_STANDARD 20)
 
 project(main C CXX)
 
+add_executable(main main.c)
+
 # Since we have the source code for the test library, we might as well let
 # CMake use it so it automatically picks up the interface headers and compiles
 # the library for us. The same can be achieved manually, but is more code.
 add_subdirectory(../lib test)
 
-add_executable(main main.c)
+# include(ExternalProject)
+# ExternalProject_Add(test_ext
+# 	SOURCE_DIR ../../lib
+# 	CMAKE_ARGS -DCMAKE_INSTALL_PREFIX="${CMAKE_BINARY_DIR}/ext"
+# )
+# add_dependencies(main test_ext)
+# find_package(test REQUIRED)
 
 # Make sure ld.so (linux) looks in the same folder as the final executable for
 # the .so dependency
diff --git a/mwe/dynlink/exec/main.c b/mwe/dynlink/exec/main.c
index 2bbdc20..ea55feb 100644
--- a/mwe/dynlink/exec/main.c
+++ b/mwe/dynlink/exec/main.c
@@ -1,7 +1,8 @@
-#include <lib.h>
+#include <test.h>
 
 int main() {
 	library_function();
 
 	return 0;
 }
+
diff --git a/mwe/dynlink/lib/CMakeLists.txt b/mwe/dynlink/lib/CMakeLists.txt
index 2d15353..7efc91a 100644
--- a/mwe/dynlink/lib/CMakeLists.txt
+++ b/mwe/dynlink/lib/CMakeLists.txt
@@ -5,6 +5,20 @@ set(CMAKE_CXX_STANDARD 20)
 
 project(lib C CXX)
 
-add_library(test SHARED lib.c)
+add_library(test SHARED)
+
 target_include_directories(test SYSTEM INTERFACE .)
 
+target_sources(test PUBLIC
+	test.c
+)
+
+target_sources(test PUBLIC FILE_SET HEADERS FILES
+	test.h
+)
+
+install(
+	TARGETS test
+	FILE_SET HEADERS DESTINATION include
+)
+
diff --git a/mwe/dynlink/lib/lib.c b/mwe/dynlink/lib/lib.c
deleted file mode 100644
index c7a78e4..0000000
--- a/mwe/dynlink/lib/lib.c
+++ /dev/null
@@ -1,3 +0,0 @@
-#include <stdio.h>
-
-void library_function() { printf("%s\n", __PRETTY_FUNCTION__); }
diff --git a/mwe/dynlink/lib/lib.h b/mwe/dynlink/lib/lib.h
deleted file mode 100644
index 093eadb..0000000
--- a/mwe/dynlink/lib/lib.h
+++ /dev/null
@@ -1,3 +0,0 @@
-#pragma once
-
-void library_function();
diff --git a/mwe/dynlink/lib/test.c b/mwe/dynlink/lib/test.c
new file mode 100644
index 0000000..c7a78e4
--- /dev/null
+++ b/mwe/dynlink/lib/test.c
@@ -0,0 +1,3 @@
+#include <stdio.h>
+
+void library_function() { printf("%s\n", __PRETTY_FUNCTION__); }
diff --git a/mwe/dynlink/lib/test.h b/mwe/dynlink/lib/test.h
new file mode 100644
index 0000000..093eadb
--- /dev/null
+++ b/mwe/dynlink/lib/test.h
@@ -0,0 +1,3 @@
+#pragma once
+
+void library_function();
-- 
cgit v1.2.3


From 65eda52aa51017f6f7aad158c4f8b6e91054cf0d Mon Sep 17 00:00:00 2001
From: Loek Le Blansch <loek@pipeframe.xyz>
Date: Tue, 1 Oct 2024 17:27:14 +0200
Subject: `make format`

---
 mwe/audio/soloud/main.cpp     |  3 +--
 mwe/dynlink/exec/main.c       |  1 -
 src/crepe/Sound.cpp           |  1 -
 src/crepe/Sound.h             |  3 +--
 src/crepe/SoundContext.cpp    |  1 -
 src/crepe/SoundContext.h      |  7 +++----
 src/crepe/api/AudioSource.cpp |  5 +----
 src/crepe/api/AudioSource.h   |  3 +--
 src/crepe/api/Component.h     |  3 +--
 src/crepe/api/Resource.cpp    |  9 ++-------
 src/crepe/api/Resource.h      |  5 ++---
 src/crepe/util/color.h        |  3 +--
 src/crepe/util/log.cpp        |  1 -
 src/crepe/util/log.h          | 20 ++++++++++----------
 src/dummy_audio.cpp           |  3 +--
 test/audio.cpp                |  3 +--
 16 files changed, 25 insertions(+), 46 deletions(-)

(limited to 'mwe/dynlink')

diff --git a/mwe/audio/soloud/main.cpp b/mwe/audio/soloud/main.cpp
index 25ba003..50df0b7 100644
--- a/mwe/audio/soloud/main.cpp
+++ b/mwe/audio/soloud/main.cpp
@@ -38,8 +38,7 @@ int main() {
 	this_thread::sleep_for(500ms);
 
 	// play all samples simultaniously
-	for (unsigned i = 0; i < 3; i++)
-		soloud.play(sfx[i]);
+	for (unsigned i = 0; i < 3; i++) soloud.play(sfx[i]);
 	this_thread::sleep_for(1000ms);
 
 	// stop all audio and exit
diff --git a/mwe/dynlink/exec/main.c b/mwe/dynlink/exec/main.c
index ea55feb..ff884f2 100644
--- a/mwe/dynlink/exec/main.c
+++ b/mwe/dynlink/exec/main.c
@@ -5,4 +5,3 @@ int main() {
 
 	return 0;
 }
-
diff --git a/src/crepe/Sound.cpp b/src/crepe/Sound.cpp
index 1758282..e1150ac 100644
--- a/src/crepe/Sound.cpp
+++ b/src/crepe/Sound.cpp
@@ -58,4 +58,3 @@ void Sound::set_looping(bool looping) {
 	if (!ctx.engine.isValidVoiceHandle(this->handle)) return;
 	ctx.engine.setLooping(this->handle, this->looping);
 }
-
diff --git a/src/crepe/Sound.h b/src/crepe/Sound.h
index 4c51188..ac93991 100644
--- a/src/crepe/Sound.h
+++ b/src/crepe/Sound.h
@@ -79,5 +79,4 @@ private:
 	bool looping = false;
 };
 
-}
-
+} // namespace crepe
diff --git a/src/crepe/SoundContext.cpp b/src/crepe/SoundContext.cpp
index cfb7d82..72047d2 100644
--- a/src/crepe/SoundContext.cpp
+++ b/src/crepe/SoundContext.cpp
@@ -18,4 +18,3 @@ SoundContext::~SoundContext() {
 	dbg_trace();
 	engine.deinit();
 }
-
diff --git a/src/crepe/SoundContext.h b/src/crepe/SoundContext.h
index d361d83..090966d 100644
--- a/src/crepe/SoundContext.h
+++ b/src/crepe/SoundContext.h
@@ -15,13 +15,12 @@ private:
 	static SoundContext & get_instance();
 	SoundContext(const SoundContext &) = delete;
 	SoundContext(SoundContext &&) = delete;
-	SoundContext &operator=(const SoundContext &) = delete;
-	SoundContext &operator=(SoundContext &&) = delete;
+	SoundContext & operator=(const SoundContext &) = delete;
+	SoundContext & operator=(SoundContext &&) = delete;
 
 private:
 	SoLoud::Soloud engine;
 	friend class Sound;
 };
 
-}
-
+} // namespace crepe
diff --git a/src/crepe/api/AudioSource.cpp b/src/crepe/api/AudioSource.cpp
index cbde79f..4d1b093 100644
--- a/src/crepe/api/AudioSource.cpp
+++ b/src/crepe/api/AudioSource.cpp
@@ -9,9 +9,7 @@ AudioSource::AudioSource(std::unique_ptr<Resource> audio_clip) {
 	this->_sound = std::make_unique<crepe::Sound>(std::move(audio_clip));
 }
 
-void AudioSource::play() {
-	return this->play(false);
-}
+void AudioSource::play() { return this->play(false); }
 
 void AudioSource::play(bool looping) {
 	this->_sound->set_looping(looping);
@@ -22,4 +20,3 @@ void AudioSource::stop() {
 	this->_sound->pause();
 	this->_sound->rewind();
 }
-
diff --git a/src/crepe/api/AudioSource.h b/src/crepe/api/AudioSource.h
index 6a038be..4300c48 100644
--- a/src/crepe/api/AudioSource.h
+++ b/src/crepe/api/AudioSource.h
@@ -38,5 +38,4 @@ private:
 	std::unique_ptr<crepe::Sound> _sound;
 };
 
-}
-
+} // namespace crepe::api
diff --git a/src/crepe/api/Component.h b/src/crepe/api/Component.h
index 2abb461..d5e0499 100644
--- a/src/crepe/api/Component.h
+++ b/src/crepe/api/Component.h
@@ -7,5 +7,4 @@ public:
 	bool active;
 };
 
-}
-
+} // namespace crepe::api
diff --git a/src/crepe/api/Resource.cpp b/src/crepe/api/Resource.cpp
index 6bb081d..1a647ce 100644
--- a/src/crepe/api/Resource.cpp
+++ b/src/crepe/api/Resource.cpp
@@ -9,11 +9,6 @@ Resource::Resource(const std::string & src) {
 	this->file = std::ifstream(this->src, std::ios::in | std::ios::binary);
 }
 
-const std::istream & Resource::read() {
-	return this->file;
-}
-
-const char * Resource::canonical() {
-	return this->src.c_str();
-}
+const std::istream & Resource::read() { return this->file; }
 
+const char * Resource::canonical() { return this->src.c_str(); }
diff --git a/src/crepe/api/Resource.h b/src/crepe/api/Resource.h
index 2b62ff9..f2b2a0e 100644
--- a/src/crepe/api/Resource.h
+++ b/src/crepe/api/Resource.h
@@ -1,8 +1,8 @@
 #pragma once
 
-#include <string>
 #include <fstream>
 #include <iostream>
+#include <string>
 
 namespace crepe::api {
 
@@ -21,5 +21,4 @@ private:
 	std::ifstream file;
 };
 
-}
-
+} // namespace crepe::api
diff --git a/src/crepe/util/color.h b/src/crepe/util/color.h
index 1af6c8f..066c9d3 100644
--- a/src/crepe/util/color.h
+++ b/src/crepe/util/color.h
@@ -38,5 +38,4 @@ constexpr const char * BG_MAGENTA_BRIGHT = "\e[105m";
 constexpr const char * BG_CYAN_BRIGHT = "\e[106m";
 constexpr const char * BG_WHITE_BRIGHT = "\e[107m";
 
-}
-
+} // namespace crepe::util::color
diff --git a/src/crepe/util/log.cpp b/src/crepe/util/log.cpp
index 796df49..6829ec3 100644
--- a/src/crepe/util/log.cpp
+++ b/src/crepe/util/log.cpp
@@ -48,4 +48,3 @@ void crepe::util::logf(log_level level, const char * fmt, ...) {
 	va_logf(level, args, fmt);
 	va_end(args);
 }
-
diff --git a/src/crepe/util/log.h b/src/crepe/util/log.h
index 5295cb9..4cab338 100644
--- a/src/crepe/util/log.h
+++ b/src/crepe/util/log.h
@@ -8,12 +8,9 @@
 // utility macros
 #define _crepe_logf_here(fmt, ...) \
 	crepe::util::logf(util::log_level::debug, "%s%s (%s:%d)" fmt "\n", \
-			crepe::util::color::FG_WHITE, \
-			__PRETTY_FUNCTION__, \
-			__FILE_NAME__, \
-			__LINE__, \
-			crepe::util::color::RESET, \
-			__VA_ARGS__)
+					  crepe::util::color::FG_WHITE, __PRETTY_FUNCTION__, \
+					  __FILE_NAME__, __LINE__, crepe::util::color::RESET, \
+					  __VA_ARGS__)
 
 #define dbg_logf(fmt, ...) _crepe_logf_here(": " fmt, __VA_ARGS__)
 #define dbg_log(str) _crepe_logf_here(": %s", str)
@@ -23,11 +20,14 @@
 
 namespace crepe::util {
 
-enum log_level { debug, info, warning, error, };
+enum log_level {
+	debug,
+	info,
+	warning,
+	error,
+};
 
 void logf(const char * fmt, ...);
 void logf(enum log_level level, const char * fmt, ...);
 
-}
-
-
+} // namespace crepe::util
diff --git a/src/dummy_audio.cpp b/src/dummy_audio.cpp
index 1249076..049bb49 100644
--- a/src/dummy_audio.cpp
+++ b/src/dummy_audio.cpp
@@ -1,5 +1,5 @@
-#include "crepe/util/log.h"
 #include "crepe/Sound.h"
+#include "crepe/util/log.h"
 
 #include <chrono>
 #include <thread>
@@ -38,4 +38,3 @@ int main() {
 
 	return 0;
 }
-
diff --git a/test/audio.cpp b/test/audio.cpp
index a415919..47c5e84 100644
--- a/test/audio.cpp
+++ b/test/audio.cpp
@@ -1,8 +1,8 @@
 #include <gtest/gtest.h>
 #include <memory>
 
-#include <crepe/api/Resource.h>
 #include <crepe/api/AudioSource.h>
+#include <crepe/api/Resource.h>
 
 #include <chrono>
 #include <thread>
@@ -26,4 +26,3 @@ TEST(audio, play) {
 
 	ASSERT_TRUE(true);
 }
-
-- 
cgit v1.2.3