Skip to content

Commit

Permalink
Decouple from OSX, Xcode, Brew
Browse files Browse the repository at this point in the history
This patch decouples the build from OSX, Xcode, and Brew.

This represents the theoretical state of dependencies: there's no
dependency on OSX, Xcode or Brew!

These build parameters are expressed as fallback values: they are only
used if the user has not provided their own parameters.

Refactor CMakeLists in a way that is more configurable
- allow the user to provide a boost installation
- allow the user to provide a sourcekit installation

Now, all source code related operations of the build system are governed
by CMake: bootstrapping just calls configure and build.

The fact that it defaults to homebrew for boost isn't really a
requirement, but it is what it uses for now. This is a marginal default
and I added a FIXME, to improve it in the future.

Note: As of writing, my development environments meet these requirements
and it seems like sensible default for many potential users. As much as
I don't enjoy Xcode, this is pragmatic for reasons described in the
README, and CMakeLists, and Swift YCMD RFC.
  • Loading branch information
jerrymarino committed May 13, 2017
1 parent 2ec34a8 commit abde37e
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 46 deletions.
93 changes: 63 additions & 30 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,36 @@
message("__SSVI CMAKE START")
message("SSVIM CMAKE START")

cmake_minimum_required(VERSION 2.8)

# Boost
#

SET(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} /usr/local/include/boost)
SET(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} /usr/local/lib)
# Optionally the user may provide a custom boost.
# For now, we default to homebrew provided boosts.
# FIXME: This isn't really an ideal default, but it is
# what it has.
if(NOT DEFINED ENV{OVERRIDE_BOOST})
message("Attempting to use brew boost")
# if this command fails, the build will explode in a future step
execute_process (
COMMAND bash -c "${CMAKE_CURRENT_SOURCE_DIR}/install_brew_boost_if_needed.sh"
OUTPUT_VARIABLE XCODE_PATH

This comment has been minimized.

Copy link
@jerrymarino

jerrymarino May 13, 2017

Author Owner

FIXME: this isn't actually XCODE_PATH

)
set(BOOST_INCLUDEDIR /usr/local/include/boost)
set(BOOST_ROOT /usr/local/lib)
endif()

## Boost includes

option (Boost_USE_STATIC_LIBS "Use static libraries for boost" ON)
set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} ${BOOST_INCLUDEDIR})
set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} ${BOOST_ROOT})

set (BOOST_INCLUDEDIR /usr/local/Cellar/boost/1.64.0_1)
set (BOOST_ROOT /usr/local/lib)
set (BOOST_USE_MULTITHREADED ON)
include_directories(SYSTEM ${Boost_INCLUDE_DIRS})
include_directories(${BOOST_INCLUDEDIR})

find_package (Boost REQUIRED COMPONENTS
option(Boost_USE_STATIC_LIBS "Use static libraries for boost" ON)
set(BOOST_USE_MULTITHREADED ON)

find_package(Boost REQUIRED COMPONENTS
coroutine
context
filesystem
Expand All @@ -23,16 +39,15 @@ find_package (Boost REQUIRED COMPONENTS
thread
)

include_directories (SYSTEM ${Boost_INCLUDE_DIRS})
include_directories(/usr/local/include/boost)
link_libraries (${Boost_LIBRARIES})
add_definitions (-DBOOST_COROUTINES_NO_DEPRECATION_WARNING=1) # for asio
link_libraries(${Boost_LIBRARIES})
add_definitions(-DBOOST_COROUTINES_NO_DEPRECATION_WARNING=1) # for asio

## Beast HTTP

include_directories(vendor/Beast/include/)

set(THREADS_PREFER_PTHREAD_FLAG ON)

find_package(Threads)

# Include vendored deps
Expand All @@ -41,27 +56,45 @@ include_directories(vendor)

# Sourcekit

# OSX First
# Use Xcode'd sourcekitd build.
execute_process (
COMMAND bash -c "xcode-select --print-path | tr -d '\n'"
OUTPUT_VARIABLE XCODE_PATH
)

message(${XCODE_PATH})

set(SKT_FLAGS "-framework sourcekitd")
set(SKT_FLAGS " ${SKT_FLAGS} -F ${XCODE_PATH}/Toolchains/XcodeDefault.xctoolchain/usr/lib")
set(SKT_FLAGS " ${SKT_FLAGS} -rpath ${XCODE_PATH}/Toolchains/XcodeDefault.xctoolchain/usr/lib")

set(GLOBAL_CXX_FLAGS "-std=c++1y -stdlib=libc++")
# Try using Xcode's sourcekitd build.
# We provide this as a fallback ( and sensible default ) so that the user
# doesn't have to build SourceKit from source.
macro(TryXcodeSourceKit)
message("Attempting to find system SourceKit")
if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
message (FATAL_ERROR "SourceKit default option requires OSX.")
endif()
execute_process(
COMMAND bash -c "xcode-select --print-path | tr -d '\n'"
OUTPUT_VARIABLE XCODE_PATH
)
if("${XCODE_PATH}" STREQUAL "")
message(FATAL_ERROR "Cannot find Xcode install.")
endif()

message("Using Sourcekit from Xcode install at: ${XCODE_PATH}.")

set(SKT_FLAGS "-framework sourcekitd")
set(SKT_FLAGS " ${SKT_FLAGS} -F ${XCODE_PATH}/Toolchains/XcodeDefault.xctoolchain/usr/lib")
set(SKT_FLAGS " ${SKT_FLAGS} -rpath ${XCODE_PATH}/Toolchains/XcodeDefault.xctoolchain/usr/lib")
endmacro()

# The user can provide a SourceKit via SOURCEKIT_FLAGS
if(DEFINED ENV{SOURCEKIT_FLAGS})
message("Using user provided SourceKit")
set(SKT_FLAGS ENV{SOURCEKIT_FLAGS})
else()
TryXcodeSourceKit()
endif()

set(GLOBAL_CXX_FLAGS "-std=c++1z -stdlib=libc++")
set(GLOBAL_CXX_FLAGS "${GLOBAL_CXX_FLAGS} -Wall -Wextra -Wpedantic -Wno-unused-parameter")
set(GLOBAL_CXX_FLAGS "${GLOBAL_CXX_FLAGS} -Wno-import-preprocessor-directive-pedantic -Wno-unused-command-line-argument")

add_definitions(${GLOBAL_CXX_FLAGS})
set(CMAKE_CXX_FLAGS ${SKT_FLAGS})

add_executable (http_server
add_executable(http_server
file_body.hpp
Logging.hpp
SemanticHTTPServer.hpp
Expand All @@ -71,7 +104,7 @@ add_executable (http_server
HTTPServerMain.cpp
)

add_executable (test_driver
add_executable(test_driver
Logging.hpp
SwiftCompleter.hpp
SwiftCompleter.cpp
Expand All @@ -85,4 +118,4 @@ INSTALL( TARGETS http_server
INSTALL( FILES scripts/activate
DESTINATION . )

message("__SSVI CMAKE FINISH")
message("SSVIM CMAKE FINISH")
16 changes: 0 additions & 16 deletions bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,6 @@
set -e
cd `dirname $0`

# System Dependencies
if [[ ! -d /Applications/Xcode.app/ ]]; then
>&2 echo "Needs OSX and Xcode for SourceKitD"
exit 1
fi

# Use boost is installed via brew for now
EXPECTED_BOOST=/usr/local/Cellar/boost/1.64.0_1
if [[ ! -d $EXPECTED_BOOST ]]; then
echo "Missing Boost $EXPECTED_BOOST. \
trying $ brew install boost 1.64"
brew install [email protected]
fi

echo "Deps satisfied.."

echo "Configure.."
./configure

Expand Down
10 changes: 10 additions & 0 deletions install_brew_boost_if_needed.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
set -e

EXPECTED_BOOST=/usr/local/include/boost/
if [[ ! -d $EXPECTED_BOOST ]]; then
echo "Missing Boost $EXPECTED_BOOST. \
trying $ brew install boost 1.64"
brew install [email protected]
fi

0 comments on commit abde37e

Please sign in to comment.