Skip to content

Commit bff9e52

Browse files
committed
Reduce header footprint of optional C++ API files and export C++ symbols properly.
1 parent 1f33c81 commit bff9e52

File tree

8 files changed

+76
-63
lines changed

8 files changed

+76
-63
lines changed

src/libprojectM/CMakeLists.txt

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,19 +140,17 @@ set_target_properties(projectM PROPERTIES
140140
)
141141

142142
if(BUILD_SHARED_LIBS)
143-
target_compile_definitions(projectM
144-
PRIVATE
145-
projectM_api_EXPORTS
143+
set_source_files_properties(ProjectMCWrapper.cpp PROPERTIES
144+
COMPILE_DEFINITIONS projectM_api_EXPORTS
146145
)
147146

148147
target_link_libraries(projectM
149148
PUBLIC
150149
${CMAKE_DL_LIBS}
151150
)
152151
else()
153-
target_compile_definitions(projectM
154-
PUBLIC
155-
PROJECTM_STATIC_DEFINE
152+
set_source_files_properties(ProjectMCWrapper.cpp PROPERTIES
153+
COMPILE_DEFINITIONS PROJECTM_STATIC_DEFINE
156154
)
157155

158156
set_target_properties(projectM PROPERTIES
@@ -172,14 +170,23 @@ install(TARGETS projectM
172170
)
173171

174172
if(ENABLE_CXX_INTERFACE)
173+
set_source_files_properties(ProjectM.cpp PCM.cpp PROPERTIES
174+
COMPILE_DEFINITIONS projectM_api_EXPORTS
175+
)
176+
175177
install(FILES
176178
Common.hpp
177179
PCM.hpp
178-
fatal.h
179180
ProjectM.hpp
180181
DESTINATION "${PROJECTM_INCLUDE_DIR}/libprojectM"
181182
COMPONENT Devel
182183
)
184+
else()
185+
# Set PROJECTM_STATIC_EXPORT for C++ implementations to use project default visibility
186+
# and no dllimport/dllexport.
187+
set_source_files_properties(ProjectM.cpp PCM.cpp PROPERTIES
188+
COMPILE_DEFINITIONS PROJECTM_STATIC_DEFINE
189+
)
183190
endif()
184191

185192

src/libprojectM/Common.hpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,8 @@
1818
* See 'LICENSE.txt' included within this release
1919
*
2020
*/
21-
/**
22-
* $Id$
23-
*
24-
* $Log$
25-
*/
2621

27-
#ifndef COMMON_HPP
28-
#define COMMON_HPP
22+
#pragma once
2923

3024
#include <algorithm>
3125
#include <cassert>
@@ -93,5 +87,3 @@ inline auto ParseFilename(const std::string& filename) -> std::string
9387

9488
return filename.substr(start + 1, filename.length());
9589
}
96-
97-
#endif

src/libprojectM/MilkdropPresetFactory/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ target_include_directories(MilkdropPresetFactory
4747
)
4848

4949
target_link_libraries(MilkdropPresetFactory
50+
PRIVATE
51+
libprojectM::API # For export header
5052
PUBLIC
5153
GLM::GLM
5254
${PROJECTM_OPENGL_LIBRARIES}

src/libprojectM/PCM.hpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@
2626
* $Log$
2727
*/
2828

29-
#ifndef _PCM_H
30-
#define _PCM_H
29+
#pragma once
30+
31+
#include "libprojectM/projectM_export.h"
3132

3233
#include <array>
3334
#include <cstdint>
@@ -46,7 +47,7 @@ enum CHANNEL
4647
CHANNEL_1 = 1
4748
};
4849

49-
class Pcm
50+
PROJECTM_EXPORT class Pcm
5051
{
5152
public:
5253
/* maximum number of sound samples that are actually stored. */
@@ -155,5 +156,3 @@ class Pcm
155156
double m_level{1.f};
156157
AutoLevel m_leveler{};
157158
};
158-
159-
#endif /** !_PCM_H */

src/libprojectM/ProjectM.cpp

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,27 @@
3030
#include "Renderer/PipelineContext.hpp"
3131
#include "TimeKeeper.hpp"
3232

33+
#if USE_THREADS
34+
35+
#include "libprojectM/BackgroundWorker.hpp"
36+
37+
#endif
3338

3439
ProjectM::ProjectM()
35-
: m_pipelineContext(std::make_unique<class PipelineContext>())
40+
: m_presetFactoryManager(std::make_unique<PresetFactoryManager>())
41+
, m_pipelineContext(std::make_unique<class PipelineContext>())
3642
, m_pipelineContext2(std::make_unique<class PipelineContext>())
43+
#if USE_THREADS
44+
, m_workerSync(std::make_unique<BackgroundWorkerSync>())
45+
#endif
3746
{
3847
Initialize();
3948
}
4049

4150
ProjectM::~ProjectM()
4251
{
4352
#if USE_THREADS
44-
m_workerSync.FinishUp();
53+
m_workerSync->FinishUp();
4554
m_workerThread.join();
4655
#endif
4756
}
@@ -64,7 +73,7 @@ void ProjectM::LoadPresetFile(const std::string& presetFilename, bool smoothTran
6473

6574
try
6675
{
67-
StartPresetTransition(m_presetFactoryManager.CreatePresetFromFile(presetFilename), !smoothTransition);
76+
StartPresetTransition(m_presetFactoryManager->CreatePresetFromFile(presetFilename), !smoothTransition);
6877
}
6978
catch (const PresetFactoryException& ex)
7079
{
@@ -82,7 +91,7 @@ void ProjectM::LoadPresetData(std::istream& presetData, bool smoothTransition)
8291

8392
try
8493
{
85-
StartPresetTransition(m_presetFactoryManager.CreatePresetFromStream(".milk", presetData), !smoothTransition);
94+
StartPresetTransition(m_presetFactoryManager->CreatePresetFromStream(".milk", presetData), !smoothTransition);
8695
}
8796
catch (const PresetFactoryException& ex)
8897
{
@@ -117,12 +126,12 @@ void ProjectM::ThreadWorker()
117126
{
118127
while (true)
119128
{
120-
if (!m_workerSync.WaitForWork())
129+
if (!m_workerSync->WaitForWork())
121130
{
122131
return;
123132
}
124133
EvaluateSecondPreset();
125-
m_workerSync.FinishedWork();
134+
m_workerSync->FinishedWork();
126135
}
127136
}
128137

@@ -194,9 +203,9 @@ auto ProjectM::RenderFrameOnlyPass1(Pipeline* pipeline) -> Pipeline*
194203
if (m_timeKeeper->IsSmoothing() && m_transitioningPreset != nullptr)
195204
{
196205
#if USE_THREADS
197-
m_workerSync.WakeUpBackgroundTask();
206+
m_workerSync->WakeUpBackgroundTask();
198207
// FIXME: Instead of waiting after a single render pass, check every frame if it's done.
199-
m_workerSync.WaitForBackgroundTaskToFinish();
208+
m_workerSync->WaitForBackgroundTaskToFinish();
200209
#endif
201210
EvaluateSecondPreset();
202211

@@ -265,7 +274,7 @@ void ProjectM::Reset()
265274
{
266275
this->m_count = 0;
267276

268-
m_presetFactoryManager.initialize(m_meshX, m_meshY);
277+
m_presetFactoryManager->initialize(m_meshX, m_meshY);
269278

270279
ResetEngine();
271280
}
@@ -293,7 +302,7 @@ void ProjectM::Initialize()
293302
m_beatDetect.get(),
294303
m_textureSearchPaths);
295304

296-
m_presetFactoryManager.initialize(m_meshX, m_meshY);
305+
m_presetFactoryManager->initialize(m_meshX, m_meshY);
297306

298307
/* Set the seed to the current time in seconds */
299308
srand(time(nullptr));
@@ -302,7 +311,7 @@ void ProjectM::Initialize()
302311
LoadIdlePreset();
303312

304313
#if USE_THREADS
305-
m_workerSync.Reset();
314+
m_workerSync->Reset();
306315
m_workerThread = std::thread(&ProjectM::ThreadWorker, this);
307316
#endif
308317

@@ -523,7 +532,7 @@ void ProjectM::SetMeshSize(size_t meshResolutionX, size_t meshResolutionY)
523532

524533
// Update mesh size in all sorts of classes.
525534
m_renderer->SetPerPixelMeshSize(m_meshX, m_meshY);
526-
m_presetFactoryManager.initialize(m_meshX, m_meshY);
535+
m_presetFactoryManager->initialize(m_meshX, m_meshY);
527536

528537
// Unload all presets and reload idle preset
529538
m_activePreset.reset();

src/libprojectM/ProjectM.hpp

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
*/
2121
#pragma once
2222

23-
#include "Common.hpp"
24-
#include "PCM.hpp"
25-
#include "PresetFactoryManager.hpp"
26-
#include "fatal.h"
23+
#include "libprojectM/projectM_export.h"
24+
25+
#include "libprojectM/Common.hpp"
26+
#include "libprojectM/PCM.hpp"
2727

2828
#ifdef _WIN32
2929

@@ -41,13 +41,13 @@
4141

4242
#if USE_THREADS
4343

44-
#include "BackgroundWorker.h"
45-
4644
#include <mutex>
4745
#include <thread>
4846

4947
#endif
5048

49+
class BackgroundWorkerSync;
50+
5151
class BeatDetect;
5252

5353
class Pcm;
@@ -64,7 +64,9 @@ class Pipeline;
6464

6565
class PipelineContext;
6666

67-
class ProjectM
67+
class PresetFactoryManager;
68+
69+
PROJECTM_EXPORT class ProjectM
6870
{
6971
public:
7072
ProjectM();
@@ -246,43 +248,43 @@ class ProjectM
246248

247249
class Pcm m_pcm; //!< Audio data buffer and analyzer instance.
248250

249-
size_t m_meshX{32}; //!< Per-point mesh horizontal resolution.
250-
size_t m_meshY{24}; //!< Per-point mesh vertical resolution.
251-
size_t m_targetFps{35}; //!< Target frames per second.
252-
size_t m_textureSize{512}; //!< Render texture size.
253-
size_t m_windowWidth{0}; //!< Render window width. If 0, nothing is rendered.
254-
size_t m_windowHeight{0}; //!< Render window height. If 0, nothing is rendered.
255-
double m_presetDuration{30.0}; //!< Preset duration in seconds.
256-
double m_softCutDuration{3.0}; //!< Soft cut transition time.
257-
double m_hardCutDuration{20.0}; //!< Time after which a hard cut can happen at the earliest.
258-
bool m_hardCutEnabled{false}; //!< If true, hard cuts based on beat detection are enabled.
251+
size_t m_meshX{32}; //!< Per-point mesh horizontal resolution.
252+
size_t m_meshY{24}; //!< Per-point mesh vertical resolution.
253+
size_t m_targetFps{35}; //!< Target frames per second.
254+
size_t m_textureSize{512}; //!< Render texture size.
255+
size_t m_windowWidth{0}; //!< Render window width. If 0, nothing is rendered.
256+
size_t m_windowHeight{0}; //!< Render window height. If 0, nothing is rendered.
257+
double m_presetDuration{30.0}; //!< Preset duration in seconds.
258+
double m_softCutDuration{3.0}; //!< Soft cut transition time.
259+
double m_hardCutDuration{20.0}; //!< Time after which a hard cut can happen at the earliest.
260+
bool m_hardCutEnabled{false}; //!< If true, hard cuts based on beat detection are enabled.
259261
float m_hardCutSensitivity{2.0}; //!< Loudness sensitivity value for hard cuts.
260-
float m_beatSensitivity{1.0}; //!< General beat sensitivity modifier for presets.
261-
bool m_aspectCorrection{true}; //!< If true, corrects aspect ratio for non-rectangular windows.
262-
float m_easterEgg{0.0}; //!< Random preset duration modifier. See TimeKeeper class.
262+
float m_beatSensitivity{1.0}; //!< General beat sensitivity modifier for presets.
263+
bool m_aspectCorrection{true}; //!< If true, corrects aspect ratio for non-rectangular windows.
264+
float m_easterEgg{0.0}; //!< Random preset duration modifier. See TimeKeeper class.
263265

264266
std::vector<std::string> m_textureSearchPaths; ///!< List of paths to search for texture files
265267

266268
/** Timing information */
267269
int m_count{0}; //!< Rendered frame count since start
268270

269-
bool m_presetLocked{false}; //!< If true, the preset change event will not be sent.
271+
bool m_presetLocked{false}; //!< If true, the preset change event will not be sent.
270272
bool m_presetChangeNotified{false}; //!< Stores whether the user has been notified that projectM wants to switch the preset.
271273

272-
PresetFactoryManager m_presetFactoryManager; //!< Provides access to all available preset factories.
274+
std::unique_ptr<PresetFactoryManager> m_presetFactoryManager; //!< Provides access to all available preset factories.
273275

274276
std::unique_ptr<class PipelineContext> m_pipelineContext; //!< Pipeline context for the first/current preset.
275277
std::unique_ptr<class PipelineContext> m_pipelineContext2; //!< Pipeline context for the next/transitioning preset.
276278

277-
std::unique_ptr<Renderer> m_renderer; //!< The Preset renderer.
278-
std::unique_ptr<BeatDetect> m_beatDetect; //!< The beat detection class.
279-
std::unique_ptr<Preset> m_activePreset; //!< Currently loaded preset.
280-
std::unique_ptr<Preset> m_transitioningPreset; //!< Destination preset when smooth preset switching.
281-
std::unique_ptr<TimeKeeper> m_timeKeeper; //!< Keeps the different timers used to render and switch presets.
279+
std::unique_ptr<Renderer> m_renderer; //!< The Preset renderer.
280+
std::unique_ptr<BeatDetect> m_beatDetect; //!< The beat detection class.
281+
std::unique_ptr<Preset> m_activePreset; //!< Currently loaded preset.
282+
std::unique_ptr<Preset> m_transitioningPreset; //!< Destination preset when smooth preset switching.
283+
std::unique_ptr<TimeKeeper> m_timeKeeper; //!< Keeps the different timers used to render and switch presets.
282284

283285
#if USE_THREADS
284-
mutable std::recursive_mutex m_presetSwitchMutex; //!< Mutex for locking preset switching while rendering and vice versa.
285-
std::thread m_workerThread; //!< Background worker for preloading presets.
286-
BackgroundWorkerSync m_workerSync; //!< Background work synchronizer.
286+
mutable std::recursive_mutex m_presetSwitchMutex; //!< Mutex for locking preset switching while rendering and vice versa.
287+
std::thread m_workerThread; //!< Background worker for preloading presets.
288+
std::unique_ptr<BackgroundWorkerSync> m_workerSync; //!< Background work synchronizer.
287289
#endif
288290
};

src/libprojectM/Renderer/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ target_include_directories(Renderer
5555
)
5656

5757
target_link_libraries(Renderer
58+
PRIVATE
59+
libprojectM::API # For export header
5860
PUBLIC
5961
GLM::GLM
6062
hlslparser

0 commit comments

Comments
 (0)