Skip to content

Commit

Permalink
Add CMake project and final modifications to build for linux
Browse files Browse the repository at this point in the history
These will surely break the Windows build.
A pass fixing the Visual Studio project will be following soon.
Fixes to get CMake working on Windows will also follow in the next
commits.
  • Loading branch information
fungos committed Apr 29, 2018
1 parent 907993f commit 8c19314
Show file tree
Hide file tree
Showing 23 changed files with 1,918 additions and 29 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
/Release
/Debug
/x64
/build/
/OrionUO/Debug
/OrionUO/Release
/OrionUO/OA
Expand All @@ -55,3 +56,5 @@
!/test_bin64/*.pdb
!/test_bin64/*.sf2
!/WikiData/RU/*.txt
!/CMakeLists.txt
!/OrionUO/CMakeLists.txt
33 changes: 31 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
dist: trusty
sudo: require
language: cpp
os:
- windows
compiler: clang
os:
- linux
addons:
apt:
sources:
- sourceline: "ppa:george-edison55/cmake-3.x"
- ubuntu-toolchain-r-test
packages:
- cmake
- cmake-data
- clang-6
- clang++-6
- libglu1-mesa-dev
- xorg-dev
script:
- export CC=/usr/bin/clang
- export CXX=/usr/bin/clang++
- clang -v && clang++ -v && cmake --version
- git --version
- cd build && cmake .. && make -j 8
- ./OrionUO/OrionUO
notifications:
webhooks:
urls:
secure: https://discordapp.com/api/webhooks/237606690495791104/ewURTxkzbXphiOgXbzImxaHAsFCDuIDsVIDSADAeSs8a_6sd5VgWGWUG42Ij_qRTkocf
on_success: always
on_failure: always
on_start: always
11 changes: 11 additions & 0 deletions CMake/CCache.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
find_program(CCACHE_BIN ccache)
if(CCACHE_BIN)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE_BIN})
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ${CCACHE_BIN})

# ccache uses -I when compiling without preprocessor, which makes clang complain.
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qunused-arguments -fcolor-diagnostics")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Qunused-arguments -fcolor-diagnostics")
endif()
endif()
49 changes: 49 additions & 0 deletions CMake/CheckAndAddFlag.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)

# check_add_add_flag(<variable> <flag> [DEBUG_ONLY | RELEASE_ONLY])
#
# Add a C or C++ compilation flag to the current scope
#
# Can optionally add the flag to Debug or Release configurations only, use this when
# targeting multi-configuration generators like Visual Studio or Xcode.
# Release configurations means NOT Debug, so it will work for RelWithDebInfo or MinSizeRel too.
#
# If the flag is added successfully, the variables FLAG_C_<variable> and FLAG_CXX_<variable>
# may be set to ON.
#
# Examples:
# check_and_add_flag(FOO -foo)
# check_and_add_flag(ONLYDEBUG -onlydebug DEBUG_ONLY)
# check_and_add_flag(OPTMAX -O9001 RELEASE_ONLY)

function(check_and_add_flag var flag)
set(genexp_config_test "1")
if(ARGV2 STREQUAL "DEBUG_ONLY")
set(genexp_config_test "$<CONFIG:Debug>")
elseif(ARGV2 STREQUAL "RELEASE_ONLY")
set(genexp_config_test "$<NOT:$<CONFIG:Debug>>")
elseif(ARGV2)
message(FATAL_ERROR "check_and_add_flag called with incorrect arguments: ${ARGN}")
endif()

set(is_c "$<COMPILE_LANGUAGE:C>")
set(is_cxx "$<COMPILE_LANGUAGE:CXX>")

# The Visual Studio generators don't support COMPILE_LANGUAGE
# So we fail all the C flags and only actually test CXX ones
if(CMAKE_GENERATOR MATCHES "Visual Studio")
set(is_c "0")
set(is_cxx "1")
endif()

check_c_compiler_flag(${flag} FLAG_C_${var})
if(FLAG_C_${var})
add_compile_options("$<$<AND:${is_c},${genexp_config_test}>:${flag}>")
endif()

check_cxx_compiler_flag(${flag} FLAG_CXX_${var})
if(FLAG_CXX_${var})
add_compile_options("$<$<AND:${is_cxx},${genexp_config_test}>:${flag}>")
endif()
endfunction()
34 changes: 34 additions & 0 deletions CMake/CompileDefinitions.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Add C or C++ compile definitions to the current scope
#
# compile_definitions(def [def ...] [DEBUG_ONLY | RELEASE_ONLY])
#
# Can optionally add the definitions to Debug or Release configurations only, use this so we can
# target multi-configuration generators like Visual Studio or Xcode.
# Release configurations means NOT Debug, so it will work for RelWithDebInfo or MinSizeRel too.
# The definitions are added to the COMPILE_DEFINITIONS folder property.
# Supports generator expressions, unlike add_definitions()
#
# Examples:
# compile_definitions(FOO) -> -DFOO
# compile_definitions(_DEBUG DEBUG_ONLY) -> -D_DEBUG
# compile_definitions(NDEBUG RELEASE_ONLY) -> -DNDEBUG
# compile_definitions($<$<COMPILE_LANGUAGE:C>:THISISONLYFORC>)

function(compile_definitions)
set(defs ${ARGN})

list(GET defs -1 last_def)
list(REMOVE_AT defs -1)

set(genexp_config_test "1")
if(last_def STREQUAL "DEBUG_ONLY")
set(genexp_config_test "$<CONFIG:Debug>")
elseif(last_def STREQUAL "RELEASE_ONLY")
set(genexp_config_test "$<NOT:$<CONFIG:Debug>>")
else()
list(APPEND defs ${last_def})
endif()

set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS
"$<${genexp_config_test}:${defs}>")
endfunction()
84 changes: 84 additions & 0 deletions CMake/Compiler.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Compiler Detection and Build Specifics
if(NOT CMAKE_SYSTEM_NAME MATCHES "Windows" AND NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
message(FATAL_ERROR "Compiler must be clang due to use of Microsoft Specific Extensions (-fms-extensions): __declspec(property(get|set))")
endif()

if(CMAKE_GENERATOR MATCHES "Ninja")
check_and_add_flag(DIAGNOSTICS_COLOR -fdiagnostics-color)
elseif(CMAKE_GENERATOR MATCHES "Visual Studio")
add_compile_options("/MP")
endif()

if(CMAKE_C_COMPILER_ID MATCHES "MSVC")
compile_definitions(_DEBUG DEBUG_ONLY)
#check_and_add_flag(EXCEPTIONS /EHsc)

# Enforce C++ standard conforming conversion rules to catch possible bugs
add_compile_options(/permissive-)
# Remove unreferenced inline functions/data to reduce link time and catch bugs
add_compile_options(/Zc:inline)
# Assume `new` (w/o std::nothrow) throws to reduce binary size
add_compile_options(/Zc:throwingNew)
# Enforce strict volatile semantics as per ISO C++
add_compile_options(/volatile:iso)

string(APPEND CMAKE_EXE_LINKER_FLAGS " /NXCOMPAT")
else()
compile_definitions(_DEBUG DEBUG_ONLY)
check_and_add_flag(HAVE_WALL -Wall)

check_and_add_flag(MSEXTENSIONS -fms-extensions) # TODO: GCC does not suppport this, fix code instead
check_and_add_flag(IGNORED_ATTRIBUTES_DISABLE -Wno-ignored-attributes) # FIXME: due the __fastcall in the properties
check_and_add_flag(INCONSISTENT_MISSING_OVERRIDE_DISABLE -Wno-inconsistent-missing-override) # FIXME: OnCharPress, OnKeyDown, OnLeftMouse... etc.
check_and_add_flag(OVERLOADED_VIRTUAL_DISABLE -Wno-overloaded-virtual) # FIXME: CGameItem::GetLightID, CTextContainer::Add, CJournal::Add etc.
check_and_add_flag(REOEDER_DISABLE -Wno-reorder) # FIXME: Initialization order in class fields
check_and_add_flag(NULL_CONVERSION_DISABLE -Wno-null-conversion) # FIXME: NULL to bool m_CanProcessAlpha
check_and_add_flag(SHADOW_DISABLE -Wno-shadow) # FIXME: shadowing local variables
check_and_add_flag(SIGN_COMPARE_DISABLE -Wno-sign-compare) # FIXME
check_and_add_flag(UNUSED_VARIABLE_DISABLE -Wno-unused-variable) # FIXME

#check_and_add_flag(EXTRA -Wextra)
#check_and_add_flag(MISSING_FIELD_INITIALIZERS -Wmissing-field-initializers)
#check_and_add_flag(SWITCH_DEFAULT -Wswitch-default)
#check_and_add_flag(FLOAT_EQUAL -Wfloat-equal)
#check_and_add_flag(CONVERSION -Wconversion)
#check_and_add_flag(ZERO_AS_NULL_POINTER_CONSTANT -Wzero-as-null-pointer-constant)

check_and_add_flag(TYPE_LIMITS -Wtype-limits)
check_and_add_flag(SIGN_COMPARE -Wsign-compare)
check_and_add_flag(IGNORED_QUALIFIERS -Wignored-qualifiers)
check_and_add_flag(UNINITIALIZED -Wuninitialized)
check_and_add_flag(LOGICAL_OP -Wlogical-op)
check_and_add_flag(SHADOW -Wshadow)
check_and_add_flag(INIT_SELF -Winit-self)
check_and_add_flag(MISSING_DECLARATIONS -Wmissing-declarations)
check_and_add_flag(MISSING_VARIABLE_DECLARATIONS -Wmissing-variable-declarations)

# gcc uses some optimizations which might break stuff without this flag
#check_and_add_flag(NO_STRICT_ALIASING -fno-strict-aliasing)
#check_and_add_flag(NO_EXCEPTIONS -fno-exceptions)

check_and_add_flag(VISIBILITY_INLINES_HIDDEN -fvisibility-inlines-hidden)
check_and_add_flag(VISIBILITY_HIDDEN -fvisibility=hidden)

check_and_add_flag(FOMIT_FRAME_POINTER -fomit-frame-pointer RELEASE_ONLY)

check_and_add_flag(GGDB -ggdb DEBUG_ONLY)
endif()

if(ENABLE_LTO)
check_and_add_flag(LTO -flto)
if(CMAKE_CXX_COMPILER_ID STREQUAL GNU)
set(CMAKE_AR gcc-ar)
set(CMAKE_RANLIB gcc-ranlib)
endif()
endif()


if(CMAKE_SYSTEM_NAME MATCHES "Windows")
add_definitions(-DORION_WINDOWS)
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
add_definitions(-DORION_LINUX)
elseif(CMAKE_SYSTEM_NAME MATCHES "Darwin")
add_definitions(-DORION_OSX)
endif()
50 changes: 50 additions & 0 deletions CMake/FindFreeImage.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Find FreeImage includes and library
#
# This module defines
# FREEIMAGE_INCLUDE_DIRS
# FREEIMAGE_LIBRARIES, the libraries to link against to use FreeImage.
# FREEIMAGE_LIBRARY_DIRS, the location of the libraries
# FREEIMAGE_FOUND, If false, do not try to use FreeImage
#
# Copyright © 2007, Matt Williams
#
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.

SET(FREEIMAGE_INCLUDE_SEARCH_DIRS
${FREEIMAGE_LIBRARY_SEARCH_DIRS}
${CMAKE_LIBRARY_PATH}
/usr/include
/usr/local/include
/opt/include
/opt/freeimage/include
)

SET(FREEIMAGE_LIBRARY_SEARCH_DIRS
${FREEIMAGE_LIBRARY_SEARCH_DIRS}
${CMAKE_LIBRARY_PATH}
/usr/lib
/usr/local/lib
/opt/lib
/opt/freeimage/lib
)

FIND_PATH(FREEIMAGE_INCLUDE_DIRS FreeImage.h ${FREEIMAGE_INCLUDE_SEARCH_DIRS})
FIND_LIBRARY(FREEIMAGE_LIBRARIES freeimage PATHS ${FREEIMAGE_LIBRARY_SEARCH_DIRS})

#Do some preparation
SEPARATE_ARGUMENTS(FREEIMAGE_INCLUDE_DIRS)
SEPARATE_ARGUMENTS(FREEIMAGE_LIBRARIES)

MARK_AS_ADVANCED(FREEIMAGE_INCLUDE_DIRS FREEIMAGE_LIBRARIES FREEIMAGE_LIBRARY_DIRS)

IF (FREEIMAGE_INCLUDE_DIRS AND FREEIMAGE_LIBRARIES)
SET(FREEIMAGE_FOUND TRUE)
ENDIF (FREEIMAGE_INCLUDE_DIRS AND FREEIMAGE_LIBRARIES)

IF (NOT FREEIMAGE_FOUND)
IF (FREEIMAGE_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "Could not find FreeImage")
ENDIF (FREEIMAGE_FIND_REQUIRED)
ENDIF (NOT FREEIMAGE_FOUND)

Loading

0 comments on commit 8c19314

Please sign in to comment.