From 5a307f9de0bb0523035a5c629a0c8cdd2e47e0df Mon Sep 17 00:00:00 2001 From: WrinklyNinja Date: Sat, 10 May 2014 16:42:31 +0100 Subject: [PATCH] Build system changes. Removed zlib dependency. Boost is now found by CMake. Each library now has separate root directory variables for greater flexibility. A few variables have been renamed for clarity/standardisation. --- CMakeLists.txt | 120 +++++++++++++++++++++++++------------------- README.md | 9 ---- docs/BUILD.MSVC.md | 38 ++++++++------ docs/BUILD.MinGW.md | 17 ------- 4 files changed, 90 insertions(+), 94 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f1c1852b..abcddee7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,7 @@ # Settings passed on the command line: # -# PROJECT_LIBS_DIR = the directory which all external libraries may be referenced from. # PROJECT_ARCH = the build architecture -# PROJECT_LINK = whether to build a static or dynamic library. +# LIBESPM_ROOT = the path to the root of the libespm source. ############################## # General Settings @@ -11,14 +10,41 @@ cmake_minimum_required (VERSION 2.8.9) project (LOOT) -IF (NOT DEFINED PROJECT_LINK) - set (PROJECT_LINK "STATIC") -ENDIF () +option(BUILD_SHARED_LIBS "Build a shared library" OFF) +option(PROJECT_STATIC_RUNTIME "Build with static runtime libs (/MT)" ON) IF (NOT DEFINED PROJECT_ARCH) set (PROJECT_ARCH "32") ENDIF () +IF (NOT DEFINED ALPHANUM_ROOT) + set (ALPHANUM_ROOT "../../alphanum") +ENDIF () + +IF (NOT DEFINED LIBESPM_ROOT) + set (LIBESPM_ROOT "../../libespm") +ENDIF () + +IF (NOT DEFINED LIBGIT2_ROOT) + set (LIBGIT2_ROOT "../../libgit2") +ENDIF () + +IF (NOT DEFINED LIBLOADORDER_ROOT) + set (LIBLOADORDER_ROOT "../../libloadorder") +ENDIF () + +IF (NOT DEFINED YAMLCPP_ROOT) + set (YAMLCPP_ROOT "../../yaml-cpp") +ENDIF () + +IF (NOT DEFINED WXWIDGETS_ROOT) + set (WXWIDGETS_ROOT "../../wxWidgets") +ENDIF () + +set (Boost_USE_STATIC_LIBS ON) +set (Boost_USE_MULTITHREADED ON) +set (Boost_USE_STATIC_RUNTIME PROJECT_STATIC_RUNTIME) + set (LOOT_SRC "${CMAKE_SOURCE_DIR}/src/backend/metadata.cpp" "${CMAKE_SOURCE_DIR}/src/backend/game.cpp" "${CMAKE_SOURCE_DIR}/src/backend/helpers.cpp" @@ -39,23 +65,21 @@ set (LOOT_GUI_SRC ${LOOT_SRC} set (LOOT_API_SRC ${LOOT_SRC} "${CMAKE_SOURCE_DIR}/src/api/api.cpp") +find_package(Boost REQUIRED COMPONENTS log log_setup locale thread chrono date_time filesystem system regex iostreams) + # Include source and library directories. include_directories ("${CMAKE_SOURCE_DIR}/src" - "${PROJECT_LIBS_DIR}/alphanum" - "${PROJECT_LIBS_DIR}/boost" - "${PROJECT_LIBS_DIR}/yaml-cpp/include" - "${PROJECT_LIBS_DIR}/libloadorder/src" - "${PROJECT_LIBS_DIR}/libespm" - "${PROJECT_LIBS_DIR}/zlib" - "${PROJECT_LIBS_DIR}/pugixml/src" - "${PROJECT_LIBS_DIR}/libgit2/include" - "${PROJECT_LIBS_DIR}/wxWidgets/include") + ${ALPHANUM_ROOT} + "${YAMLCPP_ROOT}/include" + "${LIBLOADORDER_ROOT}/src" + "${LIBGIT2_ROOT}/include" + "${WXWIDGETS_ROOT}/include" + ${LIBESPM_ROOT} + ${Boost_INCLUDE_DIRS}) -link_directories ("${PROJECT_LIBS_DIR}/libloadorder/build" - "${PROJECT_LIBS_DIR}/zlib/build" - "${PROJECT_LIBS_DIR}/libgit2/build" - "${PROJECT_LIBS_DIR}/yaml-cpp/build" - "${PROJECT_LIBS_DIR}/boost/stage-${PROJECT_ARCH}/lib") +link_directories ("${LIBLOADORDER_ROOT}/build" + "${LIBGIT2_ROOT}/build" + "${YAMLCPP_ROOT}/build") ############################## @@ -65,18 +89,17 @@ link_directories ("${PROJECT_LIBS_DIR}/libloadorder/build" # Settings when compiling for Windows. Since it's a Windows-only app this is always true, but useful to check for copy/paste into other projects. IF (CMAKE_SYSTEM_NAME MATCHES "Windows") add_definitions (-DUNICODE -D_UNICODE -D__WXMSW__ -DNDEBUG -DLIBLO_STATIC -DWIN32 -D_WINDOWS) - IF (${PROJECT_LINK} MATCHES "STATIC") - add_definitions (-DLOOT_STATIC) - ELSE () + IF (BUILD_SHARED_LIBS) add_definitions (-DLOOT_EXPORT) + ELSE () + add_definitions (-DLOOT_STATIC) ENDIF () ENDIF () # MinGW settings. IF (MINGW) - include_directories("${PROJECT_LIBS_DIR}/wxWidgets/lib/wx/include/${COMPILER_PREFIX}-msw-unicode-static-3.0") - link_directories("${PROJECT_LIBS_DIR}/openssl" - "${PROJECT_LIBS_DIR}/wxWidgets/lib") + include_directories("${WXWIDGETS_ROOT}/lib/wx/include/${COMPILER_PREFIX}-msw-unicode-static-3.0") + link_directories("${WXWIDGETS_ROOT}/lib") set (CMAKE_C_FLAGS "-m${PROJECT_ARCH} -O3") set (CMAKE_CXX_FLAGS "-m${PROJECT_ARCH} -O3") set (CMAKE_EXE_LINKER_FLAGS "-static-libstdc++ -static-libgcc -Wl,--subsystem,windows") @@ -95,7 +118,6 @@ IF (MINGW) boost_regex version git2 - zlibstatic loadorder${PROJECT_ARCH} ssl crypto @@ -111,36 +133,28 @@ IF (MINGW) ELSEIF (MSVC) IF (MSVC_VERSION EQUAL 1800) set (CMAKE_GENERATOR_TOOLSET "v120_xp" CACHE STRING "Platform Toolset" FORCE) - set (BOOST_SUFFIX "-vc120-mt-s-1_55") ELSEIF (MSVC_VERSION EQUAL 1700) - set (BOOST_SUFFIX "-vc110-mt-s-1_55") + set (CMAKE_GENERATOR_TOOLSET "v110_xp" CACHE STRING "Platform Toolset" FORCE) ENDIF () - include_directories("${PROJECT_LIBS_DIR}/wxWidgets/lib/vc_lib/mswu") - link_directories("${PROJECT_LIBS_DIR}/wxWidgets/lib/vc_lib") + include_directories("${WXWIDGETS_ROOT}/lib/vc_lib/mswu") + link_directories("${WXWIDGETS_ROOT}/lib/vc_lib") + # Force static C++ runtime linkage. - FOREACH(flag - CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_RELWITHDEBINFO - CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_DEBUG_INIT - CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_RELWITHDEBINFO - CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_DEBUG_INIT) - STRING(REPLACE "/MD" "/MT" "${flag}" "${${flag}}") - SET("${flag}" "${${flag}} /EHsc") - ENDFOREACH() + IF (PROJECT_STATIC_RUNTIME) + FOREACH(flag + CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_RELWITHDEBINFO + CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_DEBUG_INIT + CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_RELWITHDEBINFO + CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_DEBUG_INIT) + STRING(REPLACE "/MD" "/MT" "${flag}" "${${flag}}") + SET("${flag}" "${${flag}} /EHsc") + ENDFOREACH() + ENDIF () + set (CMAKE_EXE_LINKER_FLAGS "/SUBSYSTEM:WINDOWS") - set (LOOT_LIBS ${LOOT_LIBS} - libyaml-cppmt - libboost_log_setup${BOOST_SUFFIX} - libboost_log${BOOST_SUFFIX} - libboost_locale${BOOST_SUFFIX} - libboost_thread${BOOST_SUFFIX} - libboost_chrono${BOOST_SUFFIX} - libboost_date_time${BOOST_SUFFIX} - libboost_filesystem${BOOST_SUFFIX} - libboost_system${BOOST_SUFFIX} - libboost_regex${BOOST_SUFFIX} + set (LOOT_LIBS libyaml-cppmt version git2 - zlibstatic loadorder${PROJECT_ARCH} ws2_32) set (LOOT_GUI_LIBS ${LOOT_LIBS} @@ -159,9 +173,9 @@ ENDIF () ############################## # Build API. -add_library (loot${PROJECT_ARCH} ${PROJECT_LINK} ${LOOT_API_SRC}) -target_link_libraries (loot${PROJECT_ARCH} ${LOOT_LIBS}) +add_library (loot${PROJECT_ARCH} ${LOOT_API_SRC}) +target_link_libraries (loot${PROJECT_ARCH} ${Boost_LIBRARIES} ${LOOT_LIBS}) # Build application. add_executable (LOOT ${LOOT_GUI_SRC}) -target_link_libraries (LOOT ${LOOT_GUI_LIBS}) +target_link_libraries (LOOT ${Boost_LIBRARIES} ${LOOT_GUI_LIBS}) diff --git a/README.md b/README.md index 25f08773..f5b40f48 100644 --- a/README.md +++ b/README.md @@ -11,11 +11,6 @@ Although LOOT is able to calculate the correct load order positions for the vast LOOT is intended to make using mods easier, and mod users should still possess a working knowledge of mod load ordering. See the "Introduction To Load Orders" section of the LOOT readme for an overview. -## Downloading LOOT - -At the moment, LOOT is in beta testing, and so is not recommended for use unless for testing purposes. The load orders it produces should not be used in-game unless found to be valid by manual checking beforehand. Any releases can be found by clicking on the releases button above the coloured bar on the repository homepage. - - ## Building LOOT LOOT uses [CMake](http://cmake.org) v2.8.9 or later for cross-platform building support, as though it is a Windows application, development has taken place on Windows and Linux. @@ -27,12 +22,8 @@ LOOT requires the following libraries (version numbers used in latest developmen * [Libespm](http://github.com/WrinklyNinja/libespm) * [Libgit2](http://libgit2.github.com/) v0.20.0 * [Libloadorder](http://github.com/WrinklyNinja/libloadorder) -* [OpenSSL](https://www.openssl.org) - only if HTTPS support in libgit2 is required using compilers other than MSVC. * [wxWidgets](http://www.wxwidgets.org) v3.0.0 * [yaml-cpp](http://github.com/WrinklyNinja/yaml-cpp) -* [zlib](http://zlib.net/) v1.2.8 - -LOOT expects all libraries' folders to be present alongside the LOOT repository folder that contains this readme, or otherwise installed such that the compiler and linker used can find them without suppling additional paths. All paths below are relative to the folder(s) containing the libraries and LOOT. Alphanum and Libespm do not require any additional setup. The rest of the libraries must be built separately. Instructions for building them and LOOT itself using MSVC or MinGW are given in [docs/BUILD.MSVC.md](docs/BUILD.MSVC.md) and [docs/BUILD.MinGW.md](docs/BUILD.MinGW.md) respectively. diff --git a/docs/BUILD.MSVC.md b/docs/BUILD.MSVC.md index 1864cd2c..481cb5ce 100644 --- a/docs/BUILD.MSVC.md +++ b/docs/BUILD.MSVC.md @@ -2,24 +2,20 @@ These instructions were used to build LOOT using Microsoft Visual Studio 2012 and Microsoft Visual Studio Express 2013 for Desktop, though they should also apply to other versions of MSVC. -LOOT's CMake configuration builds an executable that can be run on Windows XP, but this support has only been implemented for MSVC 2013 - other versions may require editing of LOOT's `CMakeLists.txt` file. +LOOT's CMake configuration builds an executable that can be run on Windows XP, but this support has only been implemented for MSVC 2012 and 2013 - other versions may require editing of LOOT's `CMakeLists.txt` file. #### Boost ``` bootstrap.bat -b2 toolset=msvc threadapi=win32 link=static variant=release address-model=32 --with-log --with-date_time --with-thread --with-filesystem --with-locale --with-regex --with-system --with-iostreams --stagedir=stage-32 +b2 toolset=msvc threadapi=win32 link=static runtime-link=static variant=release address-model=32 --with-log --with-date_time --with-thread --with-filesystem --with-locale --with-regex --with-system --with-iostreams ``` +`link`, `runtime-link` and `address-model` can all be modified if shared linking or 64 bit builds are desired. LOOT uses statically-linked Boost libraries by default: to change this, edit [CMakeLists.txt](../CMakeLists.txt). + #### wxWidgets -Just build the solution provided by wxWidgets. - -#### zlib - -1. Add `/safeseh` to both lines in `contrib\masmx86\bld_ml32.bat`. -2. Configure CMake and generate a build system for Visual Studio by running CMake with keys `-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY=build`. -3. Open the generated solution file, and build target `zlibstatic` with `Release` configuration. +Just build the solution provided by wxWidgets. You may need to change the C/C++ Runtime Library setting in each project to `Multi-threaded (/MT)`. #### yaml-cpp @@ -30,7 +26,7 @@ Just build the solution provided by wxWidgets. Follow the instructions in libloadorder's README.md to build it as a static library. -CMake keys: `-DCMAKE_RUNTIME_OUTPUT_DIRECTORY=build -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY=build -DPROJECT_ARCH=32 -DPROJECT_LINK=STATIC -DPROJECT_LIBS_DIR=..` +Example CMake keys: `-DCMAKE_RUNTIME_OUTPUT_DIRECTORY=build -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY=build` #### Libgit2 @@ -39,9 +35,21 @@ CMake keys: `-DCMAKE_RUNTIME_OUTPUT_DIRECTORY=build -DCMAKE_ARCHIVE_OUTPUT_DIREC #### LOOT +LOOT uses the following CMake variables to set build parameters: + +Parameter | Values | Description +----------|--------|------------ +`BUILD_SHARED_LIBS` | `ON`, `OFF` | Whether or not to build a shared libloot. Defaults to `OFF`. +`PROJECT_STATIC_RUNTIME` | `ON`, `OFF` | Whether to link the C++ runtime statically or not. This also affects the Boost libraries used. Defaults to `ON`. +`PROJECT_ARCH` | `32`, `64` | Whether to build 32 or 64 bit LOOT binaries. Defaults to `32`. +`ALPHANUM_ROOT` | path | Path to the folder containing `alphanum.hpp`. Defaults to `../../alphanum`, relative to LOOT's CMakeLists.txt. +`LIBESPM_ROOT` | path | Path to the root of the libespm repository folder. Defaults to `../../libespm`, relative to LOOT's CMakeLists.txt. +`LIBGIT2_ROOT` | path | Path to the root of the libgit2 repository folder. Defaults to `../../libgit2`, relative to LOOT's CMakeLists.txt. +`LIBLOADORDER_ROOT` | path | Path to the root of the libloadorder repository folder. Defaults to `../../libloadorder`, relative to LOOT's CMakeLists.txt. +`YAMLCPP_ROOT` | path | Path to the root of the yaml-cpp folder. Defaults to `../../yaml-cpp`, relative to LOOT's CMakeLists.txt. +`WXWIDGETS_ROOT` | path | Path to the root of the wxWidgets folder. Defaults to `../../wxWidgets`, relative to LOOT's CMakeLists.txt. + 1. Set CMake up so that it builds the binaries in the `build` subdirectory of the LOOT folder. -2. Define `PROJECT_ARCH=32` or `PROJECT_ARCH=64` to build 32 or 64 bit executables respectively. -3. Define `PROJECT_LINK=STATIC` to build a static API, or `PROJECT_LINK=SHARED` to build a DLL API. -4. Define `PROEJCT_LIBS_DIR` to point to the folder holding all the required libraries' folders. -5. Configure CMake, then generate a build system for Visual Studio 12. -6. Open the generated solution file, and build it. +2. Define any necessary parameters. +3. Configure CMake, then generate a build system for Visual Studio 12. +4. Open the generated solution file, and build it. diff --git a/docs/BUILD.MinGW.md b/docs/BUILD.MinGW.md index 03a98556..b92a3f7c 100644 --- a/docs/BUILD.MinGW.md +++ b/docs/BUILD.MinGW.md @@ -17,15 +17,6 @@ echo "using gcc : 4.6.3 : i686-w64-mingw32-g++ : i686-w64-mingw32-windres