Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add install target for Linux and Mac #206

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
5475d38
Add install targets for the libraries and headers.
kuzi117 Aug 18, 2017
1b16bcc
Generate protocol headers instead of glob.
kuzi117 Aug 18, 2017
e2c5c3e
Disable installing CivetWeb's executable.
kuzi117 Aug 18, 2017
1d886d0
Remove debug print.
kuzi117 Aug 19, 2017
ac9855f
Add export and components.
kuzi117 Aug 20, 2017
ad776a3
Add install scripts.
kuzi117 Aug 20, 2017
dbb6817
Use install script
kuzi117 Aug 20, 2017
d488e71
Fix cmake files destination.
kuzi117 Aug 21, 2017
beafffb
Disable SC2APITargets.cmake.
kuzi117 Aug 21, 2017
3e246b4
Disable installing export set.
kuzi117 Aug 21, 2017
b90715e
Nit pick cleanup spacing and indentation.
drivehappy Aug 16, 2017
f4930ea
Refactoring manual memory management to use unique_ptr's where approp…
drivehappy Aug 16, 2017
6f6eb44
Refactor to range-based for loop for consistency.
drivehappy Aug 16, 2017
331074f
Switched implementation of for-loop to use the any_of algorithm. Refa…
drivehappy Aug 16, 2017
c546e9c
Add linking to pthread.
kuzi117 Aug 21, 2017
2c67723
Updated civetweb to latest.
AnthonyBrunasso Aug 21, 2017
7f0e11b
Make include path absolute.
kuzi117 Aug 23, 2017
5501549
Merge branch 'master' of github.com:Blizzard/s2client-api
kuzi117 Sep 8, 2017
6901d7d
Move to correct civetweb.
kuzi117 Sep 8, 2017
90b194a
Make windows install to Documents directory.
kuzi117 Sep 12, 2017
da749e9
Revert "Make windows install to Documents directory."
kuzi117 Sep 12, 2017
c07abae
Merge remote-tracking branch 'blizz/master'
kuzi117 Sep 28, 2017
028086a
Merge remote-tracking branch 'blizz/master'
kuzi117 Nov 25, 2017
e4da6db
Move cmake include to keep readability.
kuzi117 Nov 25, 2017
732aba0
Move protocol headers to folder.
kuzi117 Nov 25, 2017
8b258a3
Merge branch 'master' into master
kuzi117 Apr 14, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -79,6 +83,9 @@ set(CIVETWEB_ENABLE_WEBSOCKETS ON CACHE BOOL "" FORCE)
set(CIVETWEB_ENABLE_SERVER_EXECUTABLE OFF CACHE BOOL "" FORCE)
set(CIVETWEB_ENABLE_IPV6 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)

Expand All @@ -92,9 +99,13 @@ 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")

#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)

# Enable IPv6 in civetweb
target_compile_options(civetweb-c-library PUBLIC -DUSE_IPV6=1)

Expand Down Expand Up @@ -136,6 +147,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 ()
Expand Down
42 changes: 42 additions & 0 deletions cmake/SC2APIConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# 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@")
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.
# 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()

find_package(Protobuf REQUIRED)

# 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
pthread # Required to link with civetweb
)
if(NOT APPLE)
set(SC2API_LIBRARIES ${SC2API_LIBRARIES} sc2renderer)
endif()

# If we had executables.. (update file header please)
# set(SC2API_EXECUTABLE [target names])
42 changes: 42 additions & 0 deletions cmake/install.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# 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
)

# 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
# )
59 changes: 59 additions & 0 deletions cmake/install_dirs.cmake
Original file line number Diff line number Diff line change
@@ -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 <sc2api/sc2_api.h>

# 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()
55 changes: 53 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/generated/s2clientprotocol)
foreach(proto ${proto_files})
get_filename_component(proto_name ${proto} NAME_WE)
list(APPEND proto_src ${PROJECT_BINARY_DIR}/generated/s2clientprotocol/${proto_name}.pb.h ${PROJECT_BINARY_DIR}/generated/s2clientprotocol/${proto_name}.pb.cc)
# Get just headers for lib install
list(APPEND sc2protocol_headers "${PROJECT_BINARY_DIR}/generated/s2clientprotocol/${proto_name}.pb.h")
endforeach()

# Now include that directory
Expand All @@ -33,6 +35,47 @@ 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 sc2utils_headers "../include/sc2utils/*.h")

# 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
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/s2clientprotocol"
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")
set_target_properties(sc2lib PROPERTIES DEBUG_POSTFIX "d")
set_target_properties(sc2protocol PROPERTIES DEBUG_POSTFIX "d")
Expand All @@ -47,6 +90,15 @@ 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
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)
include_directories("../contrib/SDL-mirror/include")
Expand All @@ -68,7 +120,7 @@ if (MSVC)

set_target_properties(civetweb-c-library PROPERTIES COMPILE_FLAGS "/MT")
else()
set(CMAKE_CXX_FLAGS "-fpermissive")
set(CMAKE_CXX_FLAGS "-fpermissive")
endif()

add_dependencies(sc2protocol protoc)
Expand All @@ -87,7 +139,6 @@ foreach (proto ${proto_files})

endforeach()


if (MSVC)
set_target_properties(sc2api PROPERTIES COMPILE_FLAGS "/W4 /WX")
set_target_properties(sc2lib PROPERTIES COMPILE_FLAGS "/W4 /WX")
Expand Down