diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ee89a878..99cf736a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,7 +23,7 @@ jobs: os: [windows-latest, macos-latest, ubuntu-latest] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: submodules: recursive diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 31e85004..00000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "cpp-sc2"] - path = cpp-sc2 - url = https://github.com/cpp-sc2/cpp-sc2.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 1428be3f..c30b6393 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,21 +1,27 @@ -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.15) project(CommandCenter) +include(FetchContent) + # Specify output directories. set(EXECUTABLE_OUTPUT_PATH "${PROJECT_BINARY_DIR}/bin") # Build with c++14 support, required by sc2api. set(CMAKE_CXX_STANDARD 14) -# Disable building of examples in the sc2api submodule. -set(BUILD_API_EXAMPLES OFF CACHE INTERNAL "" FORCE) +if (MSVC) + # Setup MSVC parallelized builds + add_compile_options(/MP) + + # Use statically linked runtime + set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded$<$:Debug>) +endif () -# Disable building of tests in the sc2api submodule. -set(BUILD_API_TESTS OFF CACHE INTERNAL "" FORCE) +list(APPEND CMAKE_MODULE_PATH thirdparty/cmake) -# Dont build sc2renderer in the sc2api submodule. -set(BUILD_SC2_RENDERER OFF CACHE INTERNAL "" FORCE) +# Dependencies +include(cpp_sc2) +include_directories(thirdparty) -add_subdirectory("cpp-sc2") -add_subdirectory("src") +add_subdirectory(src) diff --git a/README.md b/README.md index 04f31035..958d4494 100644 --- a/README.md +++ b/README.md @@ -41,24 +41,19 @@ By default when you run CommandCenter.exe, it will play as Random race vs. a Ran If the bot crashes or does other nasty things, please bear with me while I make it more stable :) -# Developer Install / Compile Instructions (Windows) +# Developer Install / Compile Instructions +## Windows * Download and install [Visual Studio 2017 or newer](https://www.visualstudio.com/downloads/) * Install [CMake](https://cmake.org/download/) and do ```bat :: Get the project. -$ git clone --recursive git@github.com:cpp-sc2/commandcenter.git +$ git clone git@github.com:cpp-sc2/commandcenter.git $ cd commandcenter -:: Create build directory. -$ mkdir build -$ cd build - :: Create Visual Studio project files. -:: For Visual Studio 2019. -$ cmake ../ -G "Visual Studio 16 2019" -:: For Visual Studio 2017. -$ cmake ../ -G "Visual Studio 15 2017 Win64" +:: For Visual Studio 2022. +$ cmake -B build -G "Visual Studio 17 2022" :: Build the project using Visual Studio. :: The binary "CommandCenter_API.exe" should appear in the build/bin/ directory @@ -66,31 +61,45 @@ $ start CommandCenter.sln :: Launch the bot with the specified path to a SC2 map. :: Warning: The CommandCenter/bin/BotConfig.txt file must be in the same directory as the .exe to run properly -$ bin\Debug\CommandCenter.exe Ladder2019Season3/AcropolisLE.SC2Map +$ build\bin\Debug\CommandCenter.exe Ladder2019Season3/AcropolisLE.SC2Map ``` -# Developer Install / Compile Instructions (Linux and OS X) -* OS X: Download and install XCode and Xcode command-line tools. -* Linux: Install 'gcc-c++' with C++14 support and the 'make' utility. -* Install [CMake](https://cmake.org/download/) and do +## OS X +* Download and install XCode and XCode command-line tools. +* Install [CMake](https://cmake.org/download/). ```bash # Get the project. -$ git clone --recursive git@github.com:cpp-sc2/commandcenter.git && cd commandcenter +$ git clone git@github.com:cpp-sc2/commandcenter.git && cd commandcenter + +# Generate CMake build tree +$ cmake -B build -G Xcode + +# Build the project. +$ cmake --build build --parallel --verbose + +# Launch the bot with the specified path to a SC2 map. +# Warning: The CommandCenter/bin/BotConfig.txt file must be in the same directory as the executable to run properly +$ build/bin/CommandCenter Ladder2019Season3/AcropolisLE.SC2Map +``` -# Create build directory. -$ mkdir build && cd build +## Linux +* Install 'gcc-c++' with C++14 support and the 'make' utility. +* Install [CMake](https://cmake.org/download/). + +```bash +# Get the project. +$ git clone git@github.com:cpp-sc2/commandcenter.git && cd commandcenter -# Generate a Makefile. -# Use 'cmake -DCMAKE_BUILD_TYPE=Debug ../' if debuginfo is needed -$ cmake ../ +# Generate CMake build tree +$ cmake -B build # Build the project. -$ VERBOSE=1 cmake --build . --parallel +$ cmake --build build --parallel --verbose # Launch the bot with the specified path to a SC2 map. # Warning: The CommandCenter/bin/BotConfig.txt file must be in the same directory as the executable to run properly -$ bin/Debug/CommandCenter Ladder2019Season3/AcropolisLE.SC2Map +$ build/bin/CommandCenter Ladder2019Season3/AcropolisLE.SC2Map ``` # Bot Development diff --git a/cpp-sc2 b/cpp-sc2 deleted file mode 160000 index c295c562..00000000 --- a/cpp-sc2 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit c295c562ecdd3bbd773b53d7311116c6e34c3cf5 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f2caafbc..1c5f7b13 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,36 +1,94 @@ -# All the source files for the bot. -file(GLOB BOT_SOURCES "*.cpp" "*.h" "*.hpp") - -include_directories(SYSTEM - ${PROJECT_SOURCE_DIR}/cpp-sc2/include - ${PROJECT_SOURCE_DIR}/cpp-sc2/contrib/protobuf/src - ${PROJECT_BINARY_DIR}/cpp-sc2/generated +set(BOT_SOURCES + BaseLocation.cpp + BaseLocation.h + BaseLocationManager.cpp + BaseLocationManager.h + BotAssert.cpp + BotAssert.h + BotConfig.cpp + BotConfig.h + BuildOrder.cpp + BuildOrder.h + BuildOrderQueue.cpp + BuildOrderQueue.h + Building.cpp + Building.h + BuildingData.cpp + BuildingData.h + BuildingManager.cpp + BuildingManager.h + BuildingPlacer.cpp + BuildingPlacer.h + CCBot.cpp + CCBot.h + CombatCommander.cpp + CombatCommander.h + Common.h + Condition.cpp + Condition.h + DistanceMap.cpp + DistanceMap.h + GameCommander.cpp + GameCommander.h + JSONTools.cpp + JSONTools.h + MapTools.cpp + MapTools.h + MeleeManager.cpp + MeleeManager.h + MetaType.cpp + MetaType.h + MicroManager.cpp + MicroManager.h + ProductionManager.cpp + ProductionManager.h + RangedManager.cpp + RangedManager.h + ScoutManager.cpp + ScoutManager.h + Squad.cpp + Squad.h + SquadData.cpp + SquadData.h + SquadOrder.cpp + SquadOrder.h + StrategyManager.cpp + StrategyManager.h + TechTree.cpp + TechTree.h + Timer.hpp + Unit.cpp + Unit.h + UnitData.cpp + UnitData.h + UnitInfoManager.cpp + UnitInfoManager.h + UnitType.cpp + UnitType.h + Util.cpp + Util.h + WorkerData.cpp + WorkerData.h + WorkerManager.cpp + WorkerManager.h + main.cpp ) -link_directories(${PROJECT_BINARY_DIR}/cpp-sc2/bin) +add_executable(CommandCenter ${BOT_SOURCES}) # Show more warnings at compiletime. if (MSVC) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /WX-") + target_compile_options(CommandCenter PRIVATE /W4 /EHsc) else () - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra") + target_compile_options(CommandCenter PRIVATE -Wall -Wextra) endif () -set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG") - -# Create the executable. -add_executable(CommandCenter ${BOT_SOURCES}) -target_link_libraries(CommandCenter sc2api sc2lib sc2utils sc2protocol civetweb libprotobuf) +target_link_libraries(CommandCenter PRIVATE cpp_sc2) if (MINGW) - target_link_libraries(CommandCenter ssp) -endif() - -if (APPLE) - target_link_libraries(CommandCenter "-framework Carbon") -endif () - -# Linux specific. -if (UNIX AND NOT APPLE) - target_link_libraries(CommandCenter pthread dl) + target_link_libraries(CommandCenter PRIVATE ssp) +elseif (APPLE) + target_link_libraries(CommandCenter PRIVATE "-framework Carbon") +elseif (UNIX AND NOT APPLE) # Building on Linux + target_link_libraries(CommandCenter PRIVATE pthread dl) endif () diff --git a/thirdparty/cmake/cpp_sc2.cmake b/thirdparty/cmake/cpp_sc2.cmake new file mode 100644 index 00000000..d454cd88 --- /dev/null +++ b/thirdparty/cmake/cpp_sc2.cmake @@ -0,0 +1,22 @@ +message(STATUS "FetchContent: cpp-sc2") + +# Dont build examples in the sc2api submodule. +set(BUILD_API_EXAMPLES OFF CACHE INTERNAL "" FORCE) + +# Dont build tests in the sc2api submodule. +set(BUILD_API_TESTS OFF CACHE INTERNAL "" FORCE) + +# Dont build sc2renderer in the sc2api submodule. +set(BUILD_SC2_RENDERER OFF CACHE INTERNAL "" FORCE) + +FetchContent_Declare( + cpp_sc2 + GIT_REPOSITORY https://github.com/cpp-sc2/cpp-sc2.git + GIT_TAG e547ca137311447e4fb2af5b5c8a7642fba20b52 +) +FetchContent_MakeAvailable(cpp_sc2) + +set_target_properties(sc2api PROPERTIES FOLDER cpp-sc2) +set_target_properties(sc2lib PROPERTIES FOLDER cpp-sc2) +set_target_properties(sc2protocol PROPERTIES FOLDER cpp-sc2) +set_target_properties(sc2utils PROPERTIES FOLDER cpp-sc2) diff --git a/src/json/json.hpp b/thirdparty/json/json.hpp similarity index 100% rename from src/json/json.hpp rename to thirdparty/json/json.hpp