From 5475d3822a3f2b94474811a6d4d9c9f4592e2278 Mon Sep 17 00:00:00 2001 From: Braedy Kuzma Date: Fri, 18 Aug 2017 00:23:49 -0600 Subject: [PATCH 01/22] Add install targets for the libraries and headers. Still needed: the SC2APIConfig.cmake. I'm not particularly satisfied with the way the protocol headers are installed. It might be better if they were at a subdirectory, but that means that their internal includes need to be changed during protoc generation. --- src/CMakeLists.txt | 48 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 09fdcde3..11e12c5a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -20,13 +20,49 @@ endforeach() # Now include that directory include_directories(SYSTEM "${PROJECT_BINARY_DIR}/generated") - # Create the library add_library(sc2api ${sources_sc2}) add_library(sc2lib ${sources_sc2_lib}) add_library(sc2protocol ${proto_src} ${proto_files}) add_library(sc2utils ${sources_utils}) +# Glob header files together for install +file(GLOB sc2api_headers "../include/sc2api/*.h") +file(GLOB sc2lib_headers "../include/sc2lib/*.h") +file(GLOB sc2protocol_headers "${PROJECT_BINARY_DIR}/generated/*.pb.h") +file(GLOB sc2utils_headers "../include/sc2utils/*.h") + +message(STATUS "PROTOCOL ${sc2protocol_headers}") + +# Set the public headers for install +set_target_properties(sc2api PROPERTIES PUBLIC_HEADER "${sc2api_headers}") +set_target_properties(sc2lib PROPERTIES PUBLIC_HEADER "${sc2lib_headers}") +set_target_properties(sc2protocol PROPERTIES PUBLIC_HEADER "${sc2protocol_headers}") +set_target_properties(sc2utils PROPERTIES PUBLIC_HEADER "${sc2utils_headers}") + +# Install the libraries and their includes +install( + TARGETS sc2api + ARCHIVE DESTINATION "lib" + PUBLIC_HEADER DESTINATION "include/sc2api" +) +install( + TARGETS sc2lib + ARCHIVE DESTINATION "lib" + PUBLIC_HEADER DESTINATION "include/sc2lib" +) +install( + TARGETS sc2protocol + ARCHIVE DESTINATION "lib" + PUBLIC_HEADER DESTINATION "include" # These are expected to be included as + # "*.pb.h" not "dir/*.pb.h" +) +install( + TARGETS sc2utils + ARCHIVE DESTINATION "lib" + PUBLIC_HEADER DESTINATION "include/sc2utils" +) + set_target_properties(sc2api PROPERTIES DEBUG_POSTFIX "d") set_target_properties(sc2lib PROPERTIES DEBUG_POSTFIX "d") set_target_properties(sc2protocol PROPERTIES DEBUG_POSTFIX "d") @@ -41,6 +77,13 @@ endif () # Exclude SDL and related projects to work around linker issue. if (NOT APPLE) add_library(sc2renderer ${sources_renderer}) + file(GLOB sc2renderer_headers "../include/sc2renderer/*.h") + set_target_properties(sc2renderer PROPERTIES PUBLIC_HEADER "${sc2renderer_headers}") + install( + TARGETS sc2renderer + ARCHIVE DESTINATION "lib" + PUBLIC_HEADER DESTINATION "include/sc2renderer" + ) set_target_properties(sc2renderer PROPERTIES DEBUG_POSTFIX "d") target_link_libraries(sc2renderer SDL2-static) include_directories("../contrib/SDL-mirror/include") @@ -60,7 +103,7 @@ if (MSVC) set_target_properties(c-library PROPERTIES COMPILE_FLAGS "/MT") else() - set(CMAKE_CXX_FLAGS "-fpermissive") + set(CMAKE_CXX_FLAGS "-fpermissive") endif() add_dependencies(sc2protocol protoc) @@ -78,7 +121,6 @@ foreach (proto ${proto_files}) endforeach() - if (WIN32) set_target_properties(sc2api PROPERTIES COMPILE_FLAGS "/W4 /WX") set_target_properties(sc2lib PROPERTIES COMPILE_FLAGS "/W4 /WX") From 1b16bcc5d2bba1f5209ea07c0ba30126daf55451 Mon Sep 17 00:00:00 2001 From: Braedy Kuzma Date: Fri, 18 Aug 2017 16:41:02 -0600 Subject: [PATCH 02/22] Generate protocol headers instead of glob. --- src/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 11e12c5a..dd7c43a6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -15,6 +15,8 @@ file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/generated) foreach(proto ${proto_files}) get_filename_component(proto_name ${proto} NAME_WE) list(APPEND proto_src ${PROJECT_BINARY_DIR}/generated/${proto_name}.pb.h ${PROJECT_BINARY_DIR}/generated/${proto_name}.pb.cc) + # Get just headers for lib install + list(APPEND sc2protocol_headers "${PROJECT_BINARY_DIR}/generated/${proto_name}.pb.h") endforeach() # Now include that directory @@ -29,7 +31,6 @@ add_library(sc2utils ${sources_utils}) # Glob header files together for install file(GLOB sc2api_headers "../include/sc2api/*.h") file(GLOB sc2lib_headers "../include/sc2lib/*.h") -file(GLOB sc2protocol_headers "${PROJECT_BINARY_DIR}/generated/*.pb.h") file(GLOB sc2utils_headers "../include/sc2utils/*.h") message(STATUS "PROTOCOL ${sc2protocol_headers}") From e2c5c3eb8440db5ff7ccffabb00ef5b6bfe734e8 Mon Sep 17 00:00:00 2001 From: Braedy Kuzma Date: Fri, 18 Aug 2017 16:43:00 -0600 Subject: [PATCH 03/22] Disable installing CivetWeb's executable. --- CMakeLists.txt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 150baeed..a77fdff7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,6 +29,9 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON) set(BUILD_TESTING OFF CACHE BOOL "" FORCE) set(CIVETWEB_ENABLE_WEBSOCKETS ON CACHE BOOL "" FORCE) +# Disable installing the executable. +set(CIVETWEB_INSTALL_EXECUTABLE OFF CACHE BOOL "" FORCE) + # Don't build civetweb with sanitizers set(CIVETWEB_ENABLE_ASAN OFF CACHE BOOL "" FORCE) @@ -39,11 +42,9 @@ set(protobuf_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) # Don't build SDL dynamic lib. set(SDL_SHARED OFF CACHE BOOL "" FORCE) -# Run civetwebs cmake. +# Run civetweb's cmake. add_subdirectory("contrib/civetweb") -# TODO: This generates a cmake warning but we don't -# want to include it in the project. #set_target_properties(c-executable PROPERTIES FOLDER contrib) set_target_properties(c-executable PROPERTIES EXCLUDE_FROM_ALL 1 EXCLUDE_FROM_DEFAULT_BUILD 1) set_target_properties(c-library c-executable PROPERTIES FOLDER contrib) From 1d886d0aa86085636f8a38dcadae510902642e22 Mon Sep 17 00:00:00 2001 From: Braedy Kuzma Date: Sat, 19 Aug 2017 15:45:18 -0600 Subject: [PATCH 04/22] Remove debug print. --- src/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index dd7c43a6..9e37c5c2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -33,8 +33,6 @@ file(GLOB sc2api_headers "../include/sc2api/*.h") file(GLOB sc2lib_headers "../include/sc2lib/*.h") file(GLOB sc2utils_headers "../include/sc2utils/*.h") -message(STATUS "PROTOCOL ${sc2protocol_headers}") - # Set the public headers for install set_target_properties(sc2api PROPERTIES PUBLIC_HEADER "${sc2api_headers}") set_target_properties(sc2lib PROPERTIES PUBLIC_HEADER "${sc2lib_headers}") From ac9855f14bac16292913068af89ccb51a2cbcd11 Mon Sep 17 00:00:00 2001 From: Braedy Kuzma Date: Sun, 20 Aug 2017 17:19:01 -0600 Subject: [PATCH 05/22] Add export and components. --- src/CMakeLists.txt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9e37c5c2..2b9b2c5e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -42,24 +42,32 @@ set_target_properties(sc2utils PROPERTIES PUBLIC_HEADER "${sc2utils_headers}") # Install the libraries and their includes install( TARGETS sc2api + EXPORT SC2API_EXPORTS ARCHIVE DESTINATION "lib" PUBLIC_HEADER DESTINATION "include/sc2api" + COMPONENT api ) install( TARGETS sc2lib + EXPORT SC2API_EXPORTS ARCHIVE DESTINATION "lib" PUBLIC_HEADER DESTINATION "include/sc2lib" + COMPONENT lib ) install( TARGETS sc2protocol + EXPORT SC2API_EXPORTS ARCHIVE DESTINATION "lib" PUBLIC_HEADER DESTINATION "include" # These are expected to be included as # "*.pb.h" not "dir/*.pb.h" + COMPONENT protocol ) install( TARGETS sc2utils + EXPORT SC2API_EXPORTS ARCHIVE DESTINATION "lib" PUBLIC_HEADER DESTINATION "include/sc2utils" + COMPONENT utils ) set_target_properties(sc2api PROPERTIES DEBUG_POSTFIX "d") @@ -80,8 +88,10 @@ if (NOT APPLE) set_target_properties(sc2renderer PROPERTIES PUBLIC_HEADER "${sc2renderer_headers}") install( TARGETS sc2renderer + EXPORT SC2API_EXPORTS ARCHIVE DESTINATION "lib" PUBLIC_HEADER DESTINATION "include/sc2renderer" + COMPONENT renderer ) set_target_properties(sc2renderer PROPERTIES DEBUG_POSTFIX "d") target_link_libraries(sc2renderer SDL2-static) @@ -128,5 +138,6 @@ if (WIN32) set_target_properties(sc2protocol PROPERTIES COMPILE_FLAGS "/W0") endif (WIN32) + target_link_libraries(sc2api sc2protocol c-library) target_link_libraries(sc2lib sc2api) From ad776a3d9a4fb015f11cb4135dd87ff28e578ac1 Mon Sep 17 00:00:00 2001 From: Braedy Kuzma Date: Sun, 20 Aug 2017 17:23:07 -0600 Subject: [PATCH 06/22] Add install scripts. All that's missing is fixing the export set problem. --- cmake/SC2APIConfig.cmake.in | 26 ++++++++++++++++ cmake/install.cmake | 37 +++++++++++++++++++++++ cmake/install_dirs.cmake | 59 +++++++++++++++++++++++++++++++++++++ 3 files changed, 122 insertions(+) create mode 100644 cmake/SC2APIConfig.cmake.in create mode 100644 cmake/install.cmake create mode 100644 cmake/install_dirs.cmake diff --git a/cmake/SC2APIConfig.cmake.in b/cmake/SC2APIConfig.cmake.in new file mode 100644 index 00000000..120fb1fe --- /dev/null +++ b/cmake/SC2APIConfig.cmake.in @@ -0,0 +1,26 @@ +# Config file for the SC2API package. +# +# It defines the following variables +# SC2API_INCLUDE_DIRS - include directories for sc2api +# SC2API_LIBRARIES - libraries to link against +# +# It does not define the following variables +# SC2API_EXECUTABLE - there are no exectuables at this time + +# Compute paths +get_filename_component(SC2API_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) +set(SC2API_INCLUDE_DIRS "@CONF_INCLUDE_DIRS@") + +# Our library dependencies (contains definitions for IMPORTED targets) +if(NOT TARGET sc2_api AND NOT SC2API_BINARY_DIR) + include("${SC2API_CMAKE_DIR}/SC2APITargets.cmake") +endif() + +# These are IMPORTED targets created by SC2APITargets.cmake +set(SC2API_LIBRARIES sc2api sc2lib sc2protocol sc2utils) +if(NOT APPLE) + set(SC2API_LIBRARIES ${SC2API_LIBRARIES} sc2renderer) +endif() + +# If we had executables.. (update file header please) +# set(SC2API_EXECUTABLE [target names]) diff --git a/cmake/install.cmake b/cmake/install.cmake new file mode 100644 index 00000000..9da42000 --- /dev/null +++ b/cmake/install.cmake @@ -0,0 +1,37 @@ +# This file contains all of the install logic for the sc2api package. That is, +# this doesn't install the actual libraries and headers, but it provides the +# structures that allow a user to import and use those libraries and headers. + +# Get the relative path from the cmake install dir to the include dir +file( + RELATIVE_PATH + REL_INCLUDE_DIR + "${SC2API_INSTALL_CMAKE_DIR}" + "${SC2API_INSTALL_INCLUDE_DIR}" +) + +# Set up the variables to configure the SC2APIConfig.cmake file with +set(CONF_INCLUDE_DIRS "\${SC2API_CMAKE_DIR}/${REL_INCLUDE_DIR}") + +# Configure the config file that will end up being installed +configure_file( + "cmake/SC2APIConfig.cmake.in" + "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/SC2APIConfig.cmake" + @ONLY +) + +# Install the SC2APIConfig.cmake file +install( + FILES + "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/SC2APIConfig.cmake" + # "${PROJECT_BINARY_DIR}/SC2APIConfigVersion.cmake" + DESTINATION "${SC2API_INSTALL_CMAKE_DIR}" + COMPONENT cmake_package +) + +# Install the export set for use with the install-tree +install( + EXPORT SC2API_EXPORTS + DESTINATION "${SC2API_INSTALL_CMAKE_DIR}" + COMPONENT cmake_package +) diff --git a/cmake/install_dirs.cmake b/cmake/install_dirs.cmake new file mode 100644 index 00000000..14d865a3 --- /dev/null +++ b/cmake/install_dirs.cmake @@ -0,0 +1,59 @@ +# This file sets up the paths necessary for installing the sc2api executables, +# libraries, includes, and cmake package. + +# Offer the user the choice of overriding the installation directories. +# Notes: +# - These are APPENDED TO CMAKE_INSTALL_PREFIX if they aren't absolute paths. +# If the user specifies an absolute path from the command line then they're +# used verbatim. +# - The include directory provided is */include/sc2api. Inside this directory +# will be the other include directories and files. E.g. +# */include/sc2api/sc2api/. sc2_api.h is still included via +# # include + +# Set up lib, bin, include install destination dirs +set( + SC2API_INSTALL_LIB_DIR + "lib/sc2api" + CACHE + PATH + "Installation directory for libraries" +) +set( + SC2API_INSTALL_BIN_DIR + "bin/sc2api" + CACHE + PATH + "Installation directory for executables" +) +set( + SC2API_INSTALL_INCLUDE_DIR + "include/sc2api" + CACHE + PATH + "Installation directory for header files" +) + +# Choose our cmake file install dir based on OS +if(WIN32 AND NOT CYGWIN) + set(DEF_INSTALL_CMAKE_DIR CMake) +else() + set(DEF_INSTALL_CMAKE_DIR lib/CMake/SC2API) +endif() + +# Set up actual cmake file install dir +set( + SC2API_INSTALL_CMAKE_DIR + ${DEF_INSTALL_CMAKE_DIR} + CACHE + PATH + "Installation directory for CMake files" +) + +# Make relative paths absolute +foreach(p LIB BIN INCLUDE CMAKE) + set(var SC2API_INSTALL_${p}_DIR) + if(NOT IS_ABSOLUTE "${${var}}") + set(${var} "${CMAKE_INSTALL_PREFIX}/${${var}}") + endif() +endforeach() From dbb681739bc0f756c777bc8b94d5d261a7775977 Mon Sep 17 00:00:00 2001 From: Braedy Kuzma Date: Sun, 20 Aug 2017 17:24:46 -0600 Subject: [PATCH 07/22] Use install script --- CMakeLists.txt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index a77fdff7..32ee239a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,6 +19,10 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${PROJECT_BINARY_DIR}/bin) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${PROJECT_BINARY_DIR}/bin) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${PROJECT_BINARY_DIR}/bin) +# Create our install directories. Necessary so that the install directives in +# the src directory have the correct paths +include("cmake/install_dirs.cmake") + # Build with c++14 support. set(CMAKE_CXX_STANDARD 14) @@ -82,6 +86,9 @@ if (NOT APPLE) set_target_properties(uninstall PROPERTIES FOLDER CMakePredefinedTargets) endif () +# Install the SC2API cmake package +include("cmake/install.cmake") + if (BUILD_API_EXAMPLES) add_subdirectory("examples") endif () From d488e716e65ef99ec08e1c7c0c967dcbf2057526 Mon Sep 17 00:00:00 2001 From: Braedy Kuzma Date: Mon, 21 Aug 2017 13:22:29 -0600 Subject: [PATCH 08/22] Fix cmake files destination. --- cmake/install_dirs.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/install_dirs.cmake b/cmake/install_dirs.cmake index 14d865a3..040ac81c 100644 --- a/cmake/install_dirs.cmake +++ b/cmake/install_dirs.cmake @@ -36,9 +36,9 @@ set( # Choose our cmake file install dir based on OS if(WIN32 AND NOT CYGWIN) - set(DEF_INSTALL_CMAKE_DIR CMake) + set(DEF_INSTALL_CMAKE_DIR cmake) else() - set(DEF_INSTALL_CMAKE_DIR lib/CMake/SC2API) + set(DEF_INSTALL_CMAKE_DIR lib/cmake/SC2API) endif() # Set up actual cmake file install dir From beafffb2a3a6f74a1103aaffda443a98c03a81fe Mon Sep 17 00:00:00 2001 From: Braedy Kuzma Date: Mon, 21 Aug 2017 13:25:51 -0600 Subject: [PATCH 09/22] Disable SC2APITargets.cmake. --- cmake/SC2APIConfig.cmake.in | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/cmake/SC2APIConfig.cmake.in b/cmake/SC2APIConfig.cmake.in index 120fb1fe..8569dd37 100644 --- a/cmake/SC2APIConfig.cmake.in +++ b/cmake/SC2APIConfig.cmake.in @@ -11,13 +11,27 @@ get_filename_component(SC2API_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) set(SC2API_INCLUDE_DIRS "@CONF_INCLUDE_DIRS@") +# This is disabled right now, please see s2client-api/cmake/install.cmake for an +# explanation of why. # Our library dependencies (contains definitions for IMPORTED targets) -if(NOT TARGET sc2_api AND NOT SC2API_BINARY_DIR) - include("${SC2API_CMAKE_DIR}/SC2APITargets.cmake") -endif() +# if(NOT TARGET sc2_api AND NOT SC2API_BINARY_DIR) +# include("${SC2API_CMAKE_DIR}/SC2APITargets.cmake") +# endif() + +find_package(Protobuf REQUIRED) -# These are IMPORTED targets created by SC2APITargets.cmake -set(SC2API_LIBRARIES sc2api sc2lib sc2protocol sc2utils) +# This isn't true because of the disabled including of the SC2APITargets.cmake +# ~These are IMPORTED targets created by SC2APITargets.cmake +set( + SC2API_LIBRARIES + sc2api + sc2lib + sc2protocol + sc2utils + ${Protobuf_LIBRARIES} # Required to link with sc2protocol + civetweb # Required to link with sc2protocol + dl # Required to link with civetweb +) if(NOT APPLE) set(SC2API_LIBRARIES ${SC2API_LIBRARIES} sc2renderer) endif() From 3e246b495f3972a850d4ac9bfabecad3a084fa93 Mon Sep 17 00:00:00 2001 From: Braedy Kuzma Date: Mon, 21 Aug 2017 13:35:06 -0600 Subject: [PATCH 10/22] Disable installing export set. --- cmake/install.cmake | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/cmake/install.cmake b/cmake/install.cmake index 9da42000..3c8162f5 100644 --- a/cmake/install.cmake +++ b/cmake/install.cmake @@ -29,9 +29,14 @@ install( COMPONENT cmake_package ) +# This is currently disabled due to some issues with the build process. Due to +# the sc2api target's dependence on CivetWeb's c-library target and the +# sc2renderer target's dependence on SDL2's SDL2-static target we encounter +# errors from cmake when trying to install our own export set. Please see +# issue #90 in the blizzard/s2client-api repo for further discussion. # Install the export set for use with the install-tree -install( - EXPORT SC2API_EXPORTS - DESTINATION "${SC2API_INSTALL_CMAKE_DIR}" - COMPONENT cmake_package -) +# install( +# EXPORT SC2API_EXPORTS +# DESTINATION "${SC2API_INSTALL_CMAKE_DIR}" +# COMPONENT cmake_package +# ) From b90715e70ffdab353b7071898657363f2708591a Mon Sep 17 00:00:00 2001 From: drivehappy Date: Tue, 15 Aug 2017 22:32:39 -0700 Subject: [PATCH 11/22] Nit pick cleanup spacing and indentation. --- src/sc2api/sc2_data.cc | 4 ++-- src/sc2api/sc2_proto_to_pods.cc | 8 ++++---- src/sc2api/sc2_replay_observer.cc | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/sc2api/sc2_data.cc b/src/sc2api/sc2_data.cc index 8fbd54dc..0cd09637 100644 --- a/src/sc2api/sc2_data.cc +++ b/src/sc2api/sc2_data.cc @@ -185,7 +185,7 @@ static Attribute ConvertAttributeEnum(SC2APIProtocol::Attribute attribute) { case SC2APIProtocol::Attribute::Hover: return Attribute::Hover; case SC2APIProtocol::Attribute::Heroic: return Attribute::Heroic; case SC2APIProtocol::Attribute::Summoned: return Attribute::Summoned; - default: return Attribute::Invalid; + default: return Attribute::Invalid; } } @@ -205,7 +205,7 @@ static Weapon::TargetType ConvertTargetTypeEnum(SC2APIProtocol::Weapon::TargetTy case SC2APIProtocol::Weapon::Ground: return Weapon::TargetType::Ground; case SC2APIProtocol::Weapon::Air: return Weapon::TargetType::Air; case SC2APIProtocol::Weapon::Any: return Weapon::TargetType::Any; - default: return Weapon::TargetType::Invalid; + default: return Weapon::TargetType::Invalid; } } diff --git a/src/sc2api/sc2_proto_to_pods.cc b/src/sc2api/sc2_proto_to_pods.cc index 8bbe5fd2..cfe2f5bd 100644 --- a/src/sc2api/sc2_proto_to_pods.cc +++ b/src/sc2api/sc2_proto_to_pods.cc @@ -419,10 +419,10 @@ void Convert(const SC2APIProtocol::SpatialCameraSetup& setup_proto, SpatialSetup setup.camera_width = setup_proto.width(); const SC2APIProtocol::Size2DI& resolution = setup_proto.resolution(); const SC2APIProtocol::Size2DI& minimap_resolution = setup_proto.minimap_resolution(); - setup.map_resolution_x= resolution.x(); - setup.map_resolution_y= resolution.y(); - setup.minimap_resolution_x= minimap_resolution.x(); - setup.minimap_resolution_y= minimap_resolution.y(); + setup.map_resolution_x = resolution.x(); + setup.map_resolution_y = resolution.y(); + setup.minimap_resolution_x = minimap_resolution.x(); + setup.minimap_resolution_y = minimap_resolution.y(); } bool Convert(const SC2APIProtocol::InterfaceOptions& options_proto, InterfaceOptions& options) { diff --git a/src/sc2api/sc2_replay_observer.cc b/src/sc2api/sc2_replay_observer.cc index 736be0f5..3aa716c3 100644 --- a/src/sc2api/sc2_replay_observer.cc +++ b/src/sc2api/sc2_replay_observer.cc @@ -75,10 +75,10 @@ bool ReplayControlImp::GatherReplayInfo(const std::string& path) { return false; } - replay_info_.map_name = map_name.c_str(); - replay_info_.map_path = map_path.c_str(); - replay_info_.replay_path = path.c_str(); - replay_info_.version = version.c_str(); + replay_info_.map_name = map_name.c_str(); + replay_info_.map_path = map_path.c_str(); + replay_info_.replay_path = path.c_str(); + replay_info_.version = version.c_str(); replay_info_.duration = proto_replay_info.game_duration_seconds(); replay_info_.duration_gameloops = proto_replay_info.game_duration_loops(); From f4930eaf8fb78f74a388f43e66cebb2a5c070c08 Mon Sep 17 00:00:00 2001 From: drivehappy Date: Tue, 15 Aug 2017 23:30:39 -0700 Subject: [PATCH 12/22] Refactoring manual memory management to use unique_ptr's where appropriate. This cleans up a lot of the destructors as well. --- src/sc2api/sc2_agent.cc | 19 +++++++------------ src/sc2api/sc2_client.cc | 21 +++++++++------------ 2 files changed, 16 insertions(+), 24 deletions(-) diff --git a/src/sc2api/sc2_agent.cc b/src/sc2api/sc2_agent.cc index 95b7705f..7fd44c56 100644 --- a/src/sc2api/sc2_agent.cc +++ b/src/sc2api/sc2_agent.cc @@ -272,12 +272,12 @@ void ActionFeatureLayerImp::Select(const Point2DI& p0, const Point2DI& p1, bool class AgentControlImp : public AgentControlInterface { public: ControlInterface* control_interface_; - ActionImp* actions_; - ActionFeatureLayerImp* actions_feature_layer_; + std::unique_ptr actions_; + std::unique_ptr actions_feature_layer_; Agent* agent_; AgentControlImp(Agent* agent, ControlInterface* control_interface); - ~AgentControlImp(); + ~AgentControlImp() = default; bool Restart() override; }; @@ -286,13 +286,8 @@ AgentControlImp::AgentControlImp(Agent* agent, ControlInterface* control_interfa control_interface_(control_interface), actions_(nullptr), agent_(agent) { - actions_ = new ActionImp(control_interface_->Proto(), *control_interface); - actions_feature_layer_ = new ActionFeatureLayerImp(control_interface_->Proto(), *control_interface); -} - -AgentControlImp::~AgentControlImp() { - delete actions_; - delete actions_feature_layer_; + actions_ = std::make_unique(control_interface_->Proto(), *control_interface); + actions_feature_layer_ = std::make_unique(control_interface_->Proto(), *control_interface); } bool AgentControlImp::Restart() { @@ -338,11 +333,11 @@ Agent::~Agent() { } ActionInterface* Agent::Actions() { - return agent_control_imp_->actions_; + return agent_control_imp_->actions_.get(); } ActionFeatureLayerInterface* Agent::ActionsFeatureLayer() { - return agent_control_imp_->actions_feature_layer_; + return agent_control_imp_->actions_feature_layer_.get(); } AgentControlInterface* Agent::AgentControl() { diff --git a/src/sc2api/sc2_client.cc b/src/sc2api/sc2_client.cc index f781b2a2..c019c6fc 100644 --- a/src/sc2api/sc2_client.cc +++ b/src/sc2api/sc2_client.cc @@ -1345,9 +1345,9 @@ class ControlImp : public ControlInterface { ObservationPtr observation_; ResponseObservationPtr response_; - ObservationImp* observation_imp_; - QueryImp* query_imp_; - DebugImp* debug_imp_; + std::unique_ptr observation_imp_; + std::unique_ptr query_imp_; + std::unique_ptr debug_imp_; ProcessInfo pi_; // Errors that may have occured during calls to the various interfaces. @@ -1423,15 +1423,12 @@ ControlImp::ControlImp(Client& client) : query_imp_(nullptr), debug_imp_(nullptr) { proto_.SetControl(this); - observation_imp_ = new ObservationImp(proto_, observation_, response_, *this); - query_imp_ = new QueryImp(proto_, *this, *observation_imp_); - debug_imp_= new DebugImp(proto_, *observation_imp_, *this); + observation_imp_ = std::make_unique(proto_, observation_, response_, *this); + query_imp_ = std::make_unique(proto_, *this, *observation_imp_); + debug_imp_= std::make_unique(proto_, *observation_imp_, *this); } ControlImp::~ControlImp() { - delete observation_imp_; - delete query_imp_; - delete debug_imp_; proto_.Quit(); } @@ -2202,16 +2199,16 @@ Client::~Client() { const ObservationInterface* Client::Observation() const { // TODO: Should this return a nullptr if the interface is not valid (e.g., before a game is started)? - return control_imp_->observation_imp_; + return control_imp_->observation_imp_.get(); } QueryInterface* Client::Query() { // TODO: Should this return a nullptr if the interface is not valid (e.g., before a game is started)? - return control_imp_->query_imp_; + return control_imp_->query_imp_.get(); } DebugInterface* Client::Debug() { - return control_imp_->debug_imp_; + return control_imp_->debug_imp_.get(); } ControlInterface* Client::Control() { From 6f6eb44dc732dea767349aed34757815bc1d6f3b Mon Sep 17 00:00:00 2001 From: drivehappy Date: Tue, 15 Aug 2017 23:18:33 -0700 Subject: [PATCH 13/22] Refactor to range-based for loop for consistency. --- src/sc2api/sc2_client.cc | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/sc2api/sc2_client.cc b/src/sc2api/sc2_client.cc index c019c6fc..55ad6499 100644 --- a/src/sc2api/sc2_client.cc +++ b/src/sc2api/sc2_client.cc @@ -1234,13 +1234,12 @@ void DebugImp::SendDebug() { unit_value->set_unit_tag(set_unit_value.tag); } - for (std::size_t i = 0; i < debug_state_.size(); ++i) { + for (const SC2APIProtocol::DebugGameState& state : debug_state_) { SC2APIProtocol::DebugCommand* command = request_debug->add_debug(); - command->set_game_state(debug_state_[i]); + command->set_game_state(state); } - for (const DebugUnit& unit : debug_unit_) - { + for (const DebugUnit& unit : debug_unit_) { if (unit.count < 1) { continue; } From 331074fde80616fc1a684e3d5821cf664cbf642b Mon Sep 17 00:00:00 2001 From: drivehappy Date: Tue, 15 Aug 2017 23:12:59 -0700 Subject: [PATCH 14/22] Switched implementation of for-loop to use the any_of algorithm. Refactored thread vector setup to construct the thread in-place within the vector. --- src/sc2api/sc2_coordinator.cc | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/sc2api/sc2_coordinator.cc b/src/sc2api/sc2_coordinator.cc index 668bfcd0..f471ce2e 100644 --- a/src/sc2api/sc2_coordinator.cc +++ b/src/sc2api/sc2_coordinator.cc @@ -10,6 +10,7 @@ #include "sc2api.pb.h" +#include #include #include #include @@ -213,13 +214,10 @@ CoordinatorImp::~CoordinatorImp() { } bool CoordinatorImp::AnyObserverAvailable() const { - for (auto r : replay_observers_) { - if (!r->Control()->IsInGame()) { - return true; - } - } - - return false; + return std::any_of(replay_observers_.cbegin(), replay_observers_.cend(), + [](ReplayObserver* r) { + return !r->Control()->IsInGame(); + }); } void CoordinatorImp::StartReplay() { @@ -398,15 +396,15 @@ void CoordinatorImp::StepReplayObservers() { } else { // Run all steps in parallel. - std::vector threads(replay_observers_.size()); - for (size_t i = 0; i < replay_observers_.size(); ++i) { - ReplayObserver* r = replay_observers_[i]; - threads[i] = std::thread(std::bind(run_replay, r)); + std::vector threads; + threads.reserve(replay_observers_.size()); + for (auto r : replay_observers_) { + threads.emplace_back(run_replay, r); } // Join all threads. - for (size_t i = 0; i < threads.size(); ++i) { - threads[i].join(); + for (auto& t : threads) { + t.join(); } } From c546e9c96429b8a6db5bf7e3f890843a0f794f02 Mon Sep 17 00:00:00 2001 From: Braedy Kuzma Date: Mon, 21 Aug 2017 16:43:18 -0600 Subject: [PATCH 15/22] Add linking to pthread. --- cmake/SC2APIConfig.cmake.in | 1 + 1 file changed, 1 insertion(+) diff --git a/cmake/SC2APIConfig.cmake.in b/cmake/SC2APIConfig.cmake.in index 8569dd37..f69412b7 100644 --- a/cmake/SC2APIConfig.cmake.in +++ b/cmake/SC2APIConfig.cmake.in @@ -31,6 +31,7 @@ set( ${Protobuf_LIBRARIES} # Required to link with sc2protocol civetweb # Required to link with sc2protocol dl # Required to link with civetweb + pthread # Required to link with civetweb ) if(NOT APPLE) set(SC2API_LIBRARIES ${SC2API_LIBRARIES} sc2renderer) From 2c67723e57954bb428ce3098f7c02f332df772bf Mon Sep 17 00:00:00 2001 From: abrunasso Date: Mon, 21 Aug 2017 16:04:50 -0700 Subject: [PATCH 16/22] Updated civetweb to latest. --- contrib/civetweb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/civetweb b/contrib/civetweb index 1b25c739..73303c45 160000 --- a/contrib/civetweb +++ b/contrib/civetweb @@ -1 +1 @@ -Subproject commit 1b25c739802bac622edc83f9ca9f0f9e695879a4 +Subproject commit 73303c4562d3ea5922e65a543d55233fc0d1f747 From 7f0e11ba6149b67ae205ea871f699f98d7c6f607 Mon Sep 17 00:00:00 2001 From: Braedy Kuzma Date: Wed, 23 Aug 2017 14:20:16 -0600 Subject: [PATCH 17/22] Make include path absolute. --- cmake/SC2APIConfig.cmake.in | 1 + 1 file changed, 1 insertion(+) diff --git a/cmake/SC2APIConfig.cmake.in b/cmake/SC2APIConfig.cmake.in index f69412b7..7f0f15ca 100644 --- a/cmake/SC2APIConfig.cmake.in +++ b/cmake/SC2APIConfig.cmake.in @@ -10,6 +10,7 @@ # Compute paths get_filename_component(SC2API_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) set(SC2API_INCLUDE_DIRS "@CONF_INCLUDE_DIRS@") +get_filename_component(SC2API_INCLUDE_DIRS ${SC2API_INCLUDE_DIRS} ABSOLUTE) # This is disabled right now, please see s2client-api/cmake/install.cmake for an # explanation of why. From 6901d7d247055663c11f17edb3493dc7b1b35e5a Mon Sep 17 00:00:00 2001 From: Braedy Kuzma Date: Fri, 8 Sep 2017 02:57:59 -0600 Subject: [PATCH 18/22] Move to correct civetweb. --- contrib/civetweb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/civetweb b/contrib/civetweb index 2229d6b5..9a6b9c49 160000 --- a/contrib/civetweb +++ b/contrib/civetweb @@ -1 +1 @@ -Subproject commit 2229d6b5c9e5b16a97b8b1c6660dbf7002be0221 +Subproject commit 9a6b9c49ffd0edbf4c03c096534f2893752d1bd7 From 90b194a0adafde959fee4761bb2bdecc3853ea8e Mon Sep 17 00:00:00 2001 From: Braedy Kuzma Date: Tue, 12 Sep 2017 16:05:21 -0600 Subject: [PATCH 19/22] Make windows install to Documents directory. --- cmake/install_dirs.cmake | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/cmake/install_dirs.cmake b/cmake/install_dirs.cmake index 040ac81c..bfb908be 100644 --- a/cmake/install_dirs.cmake +++ b/cmake/install_dirs.cmake @@ -11,6 +11,13 @@ # */include/sc2api/sc2api/. sc2_api.h is still included via # # include +# If on windows we want to install to the StarCraft II User's Document folder +# https://github.com/Blizzard/s2client-api/issues/90#issuecomment-325395402 +if(WIN32 AND NOT CYGWIN) + set(SC2API_OLD_CMAKE_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}) + get_filename_component(CMAKE_INSTALL_PREFIX "$ENV{USERPROFILE}/Documents/StarCraft II" ABSOLUTE) +endif() + # Set up lib, bin, include install destination dirs set( SC2API_INSTALL_LIB_DIR @@ -36,7 +43,7 @@ set( # Choose our cmake file install dir based on OS if(WIN32 AND NOT CYGWIN) - set(DEF_INSTALL_CMAKE_DIR cmake) + set(DEF_INSTALL_CMAKE_DIR CMake) else() set(DEF_INSTALL_CMAKE_DIR lib/cmake/SC2API) endif() @@ -57,3 +64,8 @@ foreach(p LIB BIN INCLUDE CMAKE) set(${var} "${CMAKE_INSTALL_PREFIX}/${${var}}") endif() endforeach() + +# Reset CMAKE_INSTALL_PREFIX to not affect super projects who potentially use it... +if (WIN32 AND NOT CYGWIN) + set(CMAKE_INSTALL_PREFIX ${OLD_PREFIX}) +endif() From da749e921300d81fea7899dbeb4aa43c82c71558 Mon Sep 17 00:00:00 2001 From: Braedy Kuzma Date: Tue, 12 Sep 2017 16:26:41 -0600 Subject: [PATCH 20/22] Revert "Make windows install to Documents directory." This reverts commit 90b194a0adafde959fee4761bb2bdecc3853ea8e. --- cmake/install_dirs.cmake | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/cmake/install_dirs.cmake b/cmake/install_dirs.cmake index bfb908be..040ac81c 100644 --- a/cmake/install_dirs.cmake +++ b/cmake/install_dirs.cmake @@ -11,13 +11,6 @@ # */include/sc2api/sc2api/. sc2_api.h is still included via # # include -# If on windows we want to install to the StarCraft II User's Document folder -# https://github.com/Blizzard/s2client-api/issues/90#issuecomment-325395402 -if(WIN32 AND NOT CYGWIN) - set(SC2API_OLD_CMAKE_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}) - get_filename_component(CMAKE_INSTALL_PREFIX "$ENV{USERPROFILE}/Documents/StarCraft II" ABSOLUTE) -endif() - # Set up lib, bin, include install destination dirs set( SC2API_INSTALL_LIB_DIR @@ -43,7 +36,7 @@ set( # Choose our cmake file install dir based on OS if(WIN32 AND NOT CYGWIN) - set(DEF_INSTALL_CMAKE_DIR CMake) + set(DEF_INSTALL_CMAKE_DIR cmake) else() set(DEF_INSTALL_CMAKE_DIR lib/cmake/SC2API) endif() @@ -64,8 +57,3 @@ foreach(p LIB BIN INCLUDE CMAKE) set(${var} "${CMAKE_INSTALL_PREFIX}/${${var}}") endif() endforeach() - -# Reset CMAKE_INSTALL_PREFIX to not affect super projects who potentially use it... -if (WIN32 AND NOT CYGWIN) - set(CMAKE_INSTALL_PREFIX ${OLD_PREFIX}) -endif() From e4da6db516dd9e8f5b2991dd6cbd5d8832fd45ac Mon Sep 17 00:00:00 2001 From: Braedy Kuzma Date: Fri, 24 Nov 2017 22:51:37 -0700 Subject: [PATCH 21/22] Move cmake include to keep readability. --- CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 22bc8554..a27f2f73 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,10 @@ project(s2client-api) set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) +# Create our install directories. Necessary so that the install directives in +# the src directory have the correct paths +include("cmake/install_dirs.cmake") + # Windows builds subdirectories Debug/Release. # These variables will overwrite that and put binaries in bin. set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${PROJECT_BINARY_DIR}/bin) @@ -19,10 +23,6 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${PROJECT_BINARY_DIR}/bin) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${PROJECT_BINARY_DIR}/bin) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${PROJECT_BINARY_DIR}/bin) -# Create our install directories. Necessary so that the install directives in -# the src directory have the correct paths -include("cmake/install_dirs.cmake") - set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_MINSIZEREL ${PROJECT_BINARY_DIR}/bin) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_MINSIZEREL ${PROJECT_BINARY_DIR}/bin) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${PROJECT_BINARY_DIR}/bin) From 732aba043063b6c0eacd3b8810dadbfecf035a5b Mon Sep 17 00:00:00 2001 From: Braedy Kuzma Date: Fri, 24 Nov 2017 23:01:04 -0700 Subject: [PATCH 22/22] Move protocol headers to folder. --- src/CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 52d69c8a..a7e83090 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -61,8 +61,7 @@ install( TARGETS sc2protocol EXPORT SC2API_EXPORTS ARCHIVE DESTINATION "lib" - PUBLIC_HEADER DESTINATION "include" # These are expected to be included as - # "*.pb.h" not "dir/*.pb.h" + PUBLIC_HEADER DESTINATION "include/s2clientprotocol" COMPONENT protocol ) install(