Skip to content

Commit

Permalink
Added build flag ATOMIC_DYNAMIC_RUNTIME which enables building engine…
Browse files Browse the repository at this point in the history
… as shared library and links to a shared msvc runtime on windows.

Some critical compiler flags to be exported by Atomic project (-std=gnu++11 and msvc runtime flags).
  • Loading branch information
rokups committed Jun 10, 2017
1 parent 3850f10 commit 582ab91
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 23 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
2 changes: 1 addition & 1 deletion Build/CMake/Modules/AtomicLinux.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ 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} -fPIC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-invalid-offsetof -std=gnu++0x -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")
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 ()
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 ()

0 comments on commit 582ab91

Please sign in to comment.