Skip to content

Commit

Permalink
Merge pull request AtomicGameEngine#1559 from AtomicGameEngine/ATOMIC…
Browse files Browse the repository at this point in the history
…-JME-SHAREDLIB

[C++] Atomic shared library support
  • Loading branch information
JoshEngebretson authored Jun 10, 2017
2 parents 9d2b050 + 383554e commit 55c9db0
Show file tree
Hide file tree
Showing 82 changed files with 168 additions and 107 deletions.
42 changes: 38 additions & 4 deletions Build/CMake/Modules/AtomicCommon.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,18 @@

include(CMakeParseArguments)

if ($ENV{ATOMIC_BUILD_DIST})
add_definitions(-DATOMIC_BUILD_DIST=1)
endif ()

set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DATOMIC_DEBUG")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DATOMIC_DEBUG")
if (CMAKE_SIZEOF_VOID_P MATCHES 8)
set(ATOMIC_PROJECT_ARCH "x86_64")
set(ATOMIC_PROJECT_ARCH_SHORT "x64")
set(ATOMIC_PROJECT_ARCH_BITS "64")
set(ATOMIC_64BIT 1)
else ()
set(ATOMIC_PROJECT_ARCH "x86")
set(ATOMIC_PROJECT_ARCH_SHORT "x86")
set(ATOMIC_PROJECT_ARCH_BITS "32")
set(ATOMIC_64BIT 0)
endif ()

# Macro for defining source files with optional arguments as follows:
Expand Down Expand Up @@ -189,3 +190,36 @@ macro(setup_executable)

setup_target()
endmacro()

# Macro for replacing substrings in every variable specified in the list.
# Macro arguments:
# substring - a value that is to be replaced.
# replacement - a new value that will replace `substring`.
# variable_list - a list of variables. If list is specified manually enclose it in quotes and separate items with semicolon.
macro(replace_in_list substring replacement variable_list)
foreach (single_variable ${variable_list})
string(REPLACE "${substring}" "${replacement}" ${single_variable} "${${single_variable}}")
endforeach ()
endmacro()

# Macro for setting msvc runtime flags globally.
# Macro arguments:
# runtime_flag - release build runtime flag, /MT or /MD. Debug flag will be deduced automatically by appending 'd'.
macro(msvc_set_runtime runtime_flag)
set(COMPILER_DEBUG_VARS "CMAKE_C_FLAGS_DEBUG;CMAKE_CXX_FLAGS_DEBUG")
set(COMPILER_RELEASE_VARS "CMAKE_C_FLAGS_RELEASE;CMAKE_C_FLAGS_RELWITHDEBINFO;CMAKE_C_FLAGS_MINSIZEREL;CMAKE_CXX_FLAGS_RELEASE;CMAKE_CXX_FLAGS_RELWITHDEBINFO;CMAKE_CXX_FLAGS_MINSIZEREL")
set(COMPILER_COMMON_VARS "CMAKE_C_FLAGS;CMAKE_CXX_FLAGS")
set(COMPILER_RUNTIME_FLAGS "/MDd;/MD;/MTd;/MT")
# Clear old runtime flags.
foreach(flag ${COMPILER_RUNTIME_FLAGS})
replace_in_list(${flag} "" "${COMPILER_DEBUG_VARS};${COMPILER_RELEASE_VARS};${COMPILER_COMMON_VARS}")
endforeach()
# Add release runtime flags.
foreach(var ${COMPILER_RELEASE_VARS})
set(${var} "${${var}} ${runtime_flag}")
endforeach()
# Add debug runtime flags.
foreach(var ${COMPILER_DEBUG_VARS})
set(${var} "${${var}} ${runtime_flag}d")
endforeach()
endmacro()
2 changes: 1 addition & 1 deletion Build/CMake/Modules/AtomicIOS.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ include(BundleUtilities)

set(JAVASCRIPT_BINDINGS_PLATFORM "IOS")

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-invalid-offsetof -std=gnu++0x")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-invalid-offsetof")

set(CMAKE_CROSSCOMPILING TRUE)
set(CMAKE_XCODE_EFFECTIVE_PLATFORMS -iphoneos -iphonesimulator)
Expand Down
9 changes: 7 additions & 2 deletions Build/CMake/Modules/AtomicLinux.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ set(ATOMIC_NODE_JAKE Build/Linux/node/node Build/node_modules/jake/bin/cli.js -f

include(AtomicDesktop)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-warn-absolute-paths -fPIC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-warn-absolute-paths -Wno-invalid-offsetof -std=gnu++0x -fPIC")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-invalid-offsetof -fPIC")

if( CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX )
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-warn-absolute-paths")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-warn-absolute-paths")
endif()

find_package(PkgConfig REQUIRED)
# for native file dialog
Expand Down
2 changes: 1 addition & 1 deletion Build/CMake/Modules/AtomicMac.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ else ()
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Xlinker -no_deduplicate")
endif ()

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-invalid-offsetof -std=gnu++11 -stdlib=libc++")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-invalid-offsetof -stdlib=libc++")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++ -framework AudioToolbox -framework Carbon -framework Cocoa -framework CoreAudio -framework CoreVideo -framework ForceFeedback -framework IOKit -framework OpenGL -framework CoreServices -framework Security")
2 changes: 2 additions & 0 deletions Build/CMake/Modules/AtomicPlatform.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

set(ATOMIC_DYNAMIC_RUNTIME OFF CACHE BOOL "Build engine as shared library and link dynamically to system runtime.")

if (WIN32)
include(AtomicWindows)
elseif (APPLE)
Expand Down
23 changes: 9 additions & 14 deletions Build/CMake/Modules/AtomicWindows.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,16 @@ include(AtomicDesktop)

set(ATOMIC_NODE_JAKE Build/Windows/node/node.exe Build/node_modules/jake/bin/cli.js -f Build\\Scripts\\Bootstrap.js)

if (CMAKE_SIZEOF_VOID_P EQUAL 8)
set(D3DCOMPILER_47_DLL ${ATOMIC_SOURCE_DIR}/Build/Windows/Binaries/x64/D3DCompiler_47.dll)
else ()
set(D3DCOMPILER_47_DLL ${ATOMIC_SOURCE_DIR}/Build/Windows/Binaries/x86/D3DCompiler_47.dll)
endif ()
set(D3DCOMPILER_47_DLL ${ATOMIC_SOURCE_DIR}/Build/Windows/Binaries/${ATOMIC_PROJECT_ARCH_SHORT}/D3DCompiler_47.dll)

add_definitions(-D_CRT_SECURE_NO_WARNINGS)


# compile with static runtime
set(CompilerFlags
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_RELWITHDEBINFO
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_RELWITHDEBINFO
CMAKE_C_FLAGS_MINSIZEREL)

foreach (CompilerFlag ${CompilerFlags})
string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
endforeach ()
if (MSVC)
if (ATOMIC_DYNAMIC_RUNTIME)
set(ATOMIC_MSVC_RUNTIME /MD)
else ()
set(ATOMIC_MSVC_RUNTIME /MT)
endif ()
msvc_set_runtime(${ATOMIC_MSVC_RUNTIME})
endif ()
2 changes: 1 addition & 1 deletion Source/Atomic/BuildInfo/AtomicBuildInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
namespace Atomic
{

class AtomicBuildInfo : public RefCounted
class ATOMIC_API AtomicBuildInfo : public RefCounted
{
ATOMIC_REFCOUNTED(AtomicBuildInfo)

Expand Down
28 changes: 26 additions & 2 deletions Source/Atomic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,17 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/BuildInfo/AtomicGitSHA.cpp.in" "${CM

set (SOURCE_FILES ${SOURCE_FILES} BuildInfo/AtomicBuildInfo.cpp BuildInfo/AtomicBuildInfo.h BuildInfo/AtomicGitSHA.cpp BuildInfo/AtomicGitSHA.h)

add_library(Atomic ${SOURCE_FILES})
if (ATOMIC_DYNAMIC_RUNTIME)
set(ATOMIC_LIBRARY_TYPE SHARED)
else ()
set(ATOMIC_LIBRARY_TYPE STATIC)
endif ()
add_library(Atomic ${ATOMIC_LIBRARY_TYPE} ${SOURCE_FILES})
if (NOT ATOMIC_DYNAMIC_RUNTIME)
target_compile_definitions (Atomic PUBLIC -DATOMIC_STATIC_DEFINE=1 -DATOMIC_API=)
else ()
target_compile_definitions (Atomic PRIVATE -DATOMIC_EXPORTS=1)
endif ()

include_directories (${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(Atomic PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../)
Expand Down Expand Up @@ -202,7 +212,6 @@ else ()
endif ()

# TODO: enable shared library builds.
target_compile_definitions (Atomic PUBLIC -DATOMIC_STATIC_DEFINE=1 -DATOMIC_API=)
if (NOT APPLE OR IOS OR WEB)
target_compile_definitions (Atomic PUBLIC -DATOMIC_TBUI=1)
endif ()
Expand All @@ -226,3 +235,18 @@ target_include_directories (Atomic PUBLIC
)

include(AtomicDoc)

if ($ENV{ATOMIC_BUILD_DIST})
target_compile_definitions(Atomic PUBLIC -DATOMIC_BUILD_DIST=1)
endif ()

if (MSVC)
target_compile_options(Atomic PUBLIC "$<$<CONFIG:Debug>:${ATOMIC_MSVC_RUNTIME}d>")
target_compile_options(Atomic PUBLIC "$<$<CONFIG:Release>:${ATOMIC_MSVC_RUNTIME}>")
target_compile_options(Atomic PUBLIC "$<$<CONFIG:RelWithDebInfo>:${ATOMIC_MSVC_RUNTIME}>")
target_compile_options(Atomic PUBLIC "$<$<CONFIG:MinSizeRel>:${ATOMIC_MSVC_RUNTIME}>")
endif ()

if (UNIX OR MINGW)
target_compile_options(Atomic PUBLIC -std=gnu++11)
endif ()
3 changes: 1 addition & 2 deletions Source/Atomic/Engine/EngineConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ namespace Atomic
class Context;

/// Atomic engine configuration
class EngineConfig :
Configuration
class ATOMIC_API EngineConfig : Configuration
{

public:
Expand Down
2 changes: 1 addition & 1 deletion Source/Atomic/Environment/Environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
namespace Atomic
{

void RegisterEnvironmentLibrary(Context* context);
void ATOMIC_API RegisterEnvironmentLibrary(Context* context);

}
2 changes: 1 addition & 1 deletion Source/Atomic/Environment/ProcSky.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace Atomic
{


class ProcSky : public Drawable
class ATOMIC_API ProcSky : public Drawable
{
ATOMIC_OBJECT(ProcSky, Drawable);

Expand Down
2 changes: 1 addition & 1 deletion Source/Atomic/IPC/IPC.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ struct QueuedEvent
VariantMap eventData_;
};

class IPC : public Object
class ATOMIC_API IPC : public Object
{
ATOMIC_OBJECT(IPC, Object);

Expand Down
2 changes: 1 addition & 1 deletion Source/Atomic/IPC/IPCBroker.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class IPCProcess;


/// Server application held broker
class IPCBroker : public IPCChannel
class ATOMIC_API IPCBroker : public IPCChannel
{
friend class IPC;

Expand Down
2 changes: 1 addition & 1 deletion Source/Atomic/IPC/IPCChannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
namespace Atomic
{

class IPCChannel : public Object, public Thread
class ATOMIC_API IPCChannel : public Object, public Thread
{
ATOMIC_OBJECT(IPCChannel, Object)

Expand Down
2 changes: 1 addition & 1 deletion Source/Atomic/IPC/IPCMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ struct IPCMessageHeader
unsigned messageSize_;
};

class IPCMessageEvent
class ATOMIC_API IPCMessageEvent
{

public:
Expand Down
4 changes: 2 additions & 2 deletions Source/Atomic/IPC/IPCServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace Atomic
class IPCBroker;

/// IPCResultHandler
class IPCResultHandler : public Object
class ATOMIC_API IPCResultHandler : public Object
{
ATOMIC_OBJECT(IPCResultHandler, Object)

Expand All @@ -59,7 +59,7 @@ namespace Atomic
};

/// IPCServer
class IPCServer : public Object
class ATOMIC_API IPCServer : public Object
{
ATOMIC_OBJECT(IPCServer, Object)

Expand Down
2 changes: 1 addition & 1 deletion Source/Atomic/IPC/IPCUnix.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class PipeTransport : public PipeUnix {
PODVector<char> buf_;
};

class IPCProcess : public Object
class ATOMIC_API IPCProcess : public Object
{
ATOMIC_OBJECT(IPCProcess, Object)

Expand Down
2 changes: 1 addition & 1 deletion Source/Atomic/IPC/IPCWindows.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class PipeTransport : public PipeWin {
PODVector<char> buf_;
};

class IPCProcess : public Object
class ATOMIC_API IPCProcess : public Object
{
ATOMIC_OBJECT(IPCProcess, Object)

Expand Down
2 changes: 1 addition & 1 deletion Source/Atomic/IPC/IPCWorker.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
namespace Atomic
{

class IPCWorker : public IPCChannel
class ATOMIC_API IPCWorker : public IPCChannel
{
ATOMIC_OBJECT(IPCWorker, IPCChannel);

Expand Down
2 changes: 1 addition & 1 deletion Source/Atomic/Metrics/Metrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
namespace Atomic
{

class MetricsSnapshot : public RefCounted
class ATOMIC_API MetricsSnapshot : public RefCounted
{
friend class Metrics;

Expand Down
2 changes: 1 addition & 1 deletion Source/Atomic/Resource/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace Atomic
class Context;

/// Configuration base class for mapping JSON setting files to VariantMap configuration settings
class Configuration
class ATOMIC_API Configuration
{
public:

Expand Down
2 changes: 1 addition & 1 deletion Source/Atomic/Resource/ResourceCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ void ATOMIC_API RegisterResourceLibrary(Context* context);

// ATOMIC BEGIN
/// Extension used for package files
extern const char* PAK_EXTENSION;
extern ATOMIC_API const char* PAK_EXTENSION;
// ATOMIC END


Expand Down
2 changes: 1 addition & 1 deletion Source/Atomic/Scene/PrefabComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace Atomic
{

class PrefabComponent : public Component
class ATOMIC_API PrefabComponent : public Component
{
ATOMIC_OBJECT(PrefabComponent, Component);

Expand Down
4 changes: 2 additions & 2 deletions Source/Atomic/Script/ScriptPhysics.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace Atomic
{
class Node;

class PhysicsContact : public RefCounted
class ATOMIC_API PhysicsContact : public RefCounted
{
friend class PhysicsNodeCollision;

Expand Down Expand Up @@ -64,7 +64,7 @@ namespace Atomic
float impulse_;
};

class PhysicsNodeCollision : public RefCounted
class ATOMIC_API PhysicsNodeCollision : public RefCounted
{
ATOMIC_REFCOUNTED(PhysicsNodeCollision)

Expand Down
2 changes: 1 addition & 1 deletion Source/Atomic/UI/UI.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace SystemUI
class MessageBox;
}

class UI : public Object, private tb::TBWidgetListener
class ATOMIC_API UI : public Object, private tb::TBWidgetListener
{
ATOMIC_OBJECT(UI, Object)

Expand Down
2 changes: 1 addition & 1 deletion Source/Atomic/UI/UIBargraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
namespace Atomic
{

class UIBargraph : public UIWidget
class ATOMIC_API UIBargraph : public UIWidget
{
ATOMIC_OBJECT(UIBargraph, UIWidget)

Expand Down
2 changes: 1 addition & 1 deletion Source/Atomic/UI/UIButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace Atomic
{


class UIButton : public UIWidget
class ATOMIC_API UIButton : public UIWidget
{
ATOMIC_OBJECT(UIButton, UIWidget)

Expand Down
2 changes: 1 addition & 1 deletion Source/Atomic/UI/UICheckBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace Atomic
{


class UICheckBox : public UIWidget
class ATOMIC_API UICheckBox : public UIWidget
{
ATOMIC_OBJECT(UICheckBox, UIWidget)

Expand Down
2 changes: 1 addition & 1 deletion Source/Atomic/UI/UIClickLabel.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace Atomic
{


class UIClickLabel : public UIWidget
class ATOMIC_API UIClickLabel : public UIWidget
{
ATOMIC_OBJECT(UIClickLabel, UIWidget)

Expand Down
Loading

0 comments on commit 55c9db0

Please sign in to comment.