Skip to content

Commit

Permalink
precompiled headers for core
Browse files Browse the repository at this point in the history
creating nsfplaycore.cpp to contain public interface
  • Loading branch information
bbbradsmith committed Apr 21, 2024
1 parent 35e84c8 commit 5a68726
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 12 deletions.
5 changes: 3 additions & 2 deletions core/core.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// stub
// core.cpp
// high level central operation of core functions

#include <nsfplaycore.h>
#include "core.h"
#include "enums_data.h"
26 changes: 26 additions & 0 deletions core/core.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once
#ifndef __CORE_PCH__
#define __CORE_PCH__
// core.h
// All internal core shared functions and data should be defined here,
// preferring one central header over individual module headers,
// unless they are deliberately self-contained, like an external library.
//
// core.h should be included as the first code line in every core source file.
// Some builds will force-include it as a precompiled header.
// The include guards allow GCC to use the precompiled version in another directory
// without redundantly including this one.

#include <nsfplaycore.h>

typedef int8_t sint8;
typedef int16_t sint16;
typedef int32_t sint32;
typedef int64_t sint64;

typedef uint8_t uint8;
typedef uint16_t uint16;
typedef uint32_t uint32;
typedef uint64_t uint64;

#endif // __CORE_PCH__
28 changes: 20 additions & 8 deletions core/core.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,12 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>core.h</PrecompiledHeaderFile>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<AdditionalIncludeDirectories>..\include\</AdditionalIncludeDirectories>
<TreatWarningAsError>true</TreatWarningAsError>
<ForcedIncludeFiles>core.h</ForcedIncludeFiles>
</ClCompile>
<Link>
<SubSystem>
Expand All @@ -120,11 +121,12 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>core.h</PrecompiledHeaderFile>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<AdditionalIncludeDirectories>..\include\</AdditionalIncludeDirectories>
<TreatWarningAsError>true</TreatWarningAsError>
<ForcedIncludeFiles>core.h</ForcedIncludeFiles>
</ClCompile>
<Link>
<SubSystem>
Expand All @@ -140,11 +142,12 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>core.h</PrecompiledHeaderFile>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<AdditionalIncludeDirectories>..\include\</AdditionalIncludeDirectories>
<TreatWarningAsError>true</TreatWarningAsError>
<ForcedIncludeFiles>core.h</ForcedIncludeFiles>
</ClCompile>
<Link>
<SubSystem>
Expand All @@ -160,11 +163,12 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>core.h</PrecompiledHeaderFile>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<AdditionalIncludeDirectories>..\include\</AdditionalIncludeDirectories>
<TreatWarningAsError>true</TreatWarningAsError>
<ForcedIncludeFiles>core.h</ForcedIncludeFiles>
</ClCompile>
<Link>
<SubSystem>
Expand All @@ -176,10 +180,18 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="core.cpp" />
<ClCompile Include="nsfplaycore.cpp" />
<ClCompile Include="pch.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\include\nsfplaycore.h" />
<ClInclude Include="..\include\nsfplayenums.h" />
<ClInclude Include="core.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
9 changes: 9 additions & 0 deletions core/core.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
<ClCompile Include="core.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="nsfplaycore.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="pch.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\include\nsfplaycore.h">
Expand All @@ -22,5 +28,8 @@
<ClInclude Include="..\include\nsfplayenums.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="core.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
16 changes: 14 additions & 2 deletions core/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,27 @@ OBJS = $(addprefix $(CORE_INTDIR)/,$(SRCS:.cpp=.o))
DEPS = $(addprefix $(CORE_INTDIR)/,$(SRCS:.cpp=.d))
CXXFLAGS_ALL = $(CXXFLAGS) $(CXXFLAGS_EXTRA) $(INC_COMMON)

PCH_H = core.h
PCH_BUILD = pch.cpp
PCH_DECOY = $(CORE_INTDIR)/$(CORE_NAME).h
PCH = $(PCH_DECOY).gch
PCHFLAGS = -Winvalid-pch -include $(PCH_DECOY)

$(TARGET): $(OBJS) | $(dir $(TARGET))
rm -f $(TARGET)
$(AR) rcs $(TARGET) $(OBJS)

$(CORE_INTDIR)/%.d: %.cpp | $(CORE_INTDIR)/
$(PCH_DECOY): | $(CORE_INTDIR)/
echo "#error \"Precompiled header decoy $(notdir $(PCH_DECOY)) used instead of $(notdir $(PCH))\"" > $@

$(PCH): $(PCH_BUILD) $(PCH_DECOY) $(PCH_H) | $(CORE_INTDIR)/
$(CXX) -x c++-header -o $(PCH) $(CXXFLAGS_ALL) -c $(PCH_BUILD)

$(CORE_INTDIR)/%.d: %.cpp $(PCH) | $(CORE_INTDIR)/
$(CXX) -M -MM -MF $@ -MT $(CORE_INTDIR)/$(basename $<).o $(CXXFLAGS_ALL) -c $<

$(CORE_INTDIR)/%.o: %.cpp $(CORE_INTDIR)/%.d | $(CORE_INTDIR)/
$(CXX) -o $@ $(CXXFLAGS_ALL) -c $<
$(CXX) -o $@ $(PCHFLAGS) $(CXXFLAGS_ALL) -c $<

$(CORE_INTDIR)/:
$(MKDIR) $@
Expand Down
4 changes: 4 additions & 0 deletions core/nsfplaycore.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// nsfplaycore.cpp
// Contains the public interface.

#include "core.h"
2 changes: 2 additions & 0 deletions core/pch.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include "core.h"
// Used in some builds to create the precompiled header for core.h

0 comments on commit 5a68726

Please sign in to comment.