Skip to content

Commit

Permalink
Get windows build running.
Browse files Browse the repository at this point in the history
Now compiles and runs.
  • Loading branch information
ben-clayton committed Feb 24, 2017
1 parent 504ed22 commit 07201a7
Show file tree
Hide file tree
Showing 56 changed files with 517 additions and 288 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Expand Up @@ -52,3 +52,6 @@
[submodule "third_party/src/google.golang.org/grpc"]
path = third_party/src/google.golang.org/grpc
url = https://github.com/grpc/grpc-go.git
[submodule "third_party/src/github.com/inconshreveable/mousetrap"]
path = third_party/src/github.com/inconshreveable/mousetrap
url = https://github.com/inconshreveable/mousetrap.git
6 changes: 6 additions & 0 deletions CMakeLists.txt
Expand Up @@ -16,6 +16,7 @@ cmake_minimum_required(VERSION 3.2)
cmake_policy(SET CMP0009 NEW) # GLOB_RECURSE does not recurse symlinks
cmake_policy(SET CMP0053 NEW) # Simplify variable reference
cmake_policy(SET CMP0003 NEW) # Link by full path
cmake_policy(SET CMP0058 NEW) # Custom command DEPENDS on files that are not specified as OUTPUT or BYPRODUCTS

set(GAPID_CMAKE_VERSION "1")
set(GAPID_CMAKE_VERSION_STORE ${GAPID_CMAKE_VERSION} CACHE STRING "Version of the gapid cmake build system")
Expand All @@ -26,6 +27,11 @@ if(NOT ${GAPID_CMAKE_VERSION} STREQUAL ${GAPID_CMAKE_VERSION_STORE})
")
endif()

set(CMAKE_HOST_EXECUTABLE_SUFFIX "")
if(CMAKE_HOST_WIN32)
set(CMAKE_HOST_EXECUTABLE_SUFFIX ".exe")
endif()

file(LOCK ${CMAKE_BINARY_DIR} DIRECTORY GUARD PROCESS RESULT_VARIABLE locked)

# Basic selection controls
Expand Down
2 changes: 1 addition & 1 deletion CMakeProto.cmake
Expand Up @@ -26,7 +26,7 @@ protoc_java("core/image" "image.proto" "com/google/gapid/proto/image/Image")
protoc_go("github.com/google/gapid/core/os/android/apk" "core/os/android/apk" "apk.proto")
protoc_go("github.com/google/gapid/core/os/android" "core/os/android" "keycodes.proto")
protoc_go("github.com/google/gapid/gapidapk/pkginfo" "gapidapk/pkginfo" "pkginfo.proto")
protoc_java("gapidapk/pkginfo" "pkginfo.proto" "com/google/gapid/proto/pkginfo")
protoc_java("gapidapk/pkginfo" "pkginfo.proto" "com/google/gapid/proto/pkginfo/PkgInfo")
protoc_go("github.com/google/gapid/core/os/device/bind" "core/os/device/bind" "bind.proto")
protoc_go("github.com/google/gapid/core/os/device" "core/os/device" "device.proto")
protoc_java("core/os/device" "device.proto" "com/google/gapid/proto/device/Device")
Expand Down
10 changes: 5 additions & 5 deletions cmake/Modules/CMakeDetermineGoCompiler.cmake
Expand Up @@ -61,11 +61,11 @@ set(GO_ARCH amd64)

set(GO_ENV ${CMAKE_BINARY_DIR}/go/goenv.cmake)
file(WRITE ${GO_ENV} "
set(ENV{GOBIN} ${GO_BIN})
set(ENV{GOROOT} ${GO_ROOT})
set(ENV{GOPATH} ${GO_PATH})
set(ENV{GOOS} ${GO_OS})
set(ENV{GOARCH} ${GO_ARCH})
file(TO_NATIVE_PATH \"${GO_BIN}\" ENV{GOBIN})
file(TO_NATIVE_PATH \"${GO_ROOT}\" ENV{GOROOT})
file(TO_NATIVE_PATH \"${GO_PATH}\" ENV{GOPATH})
file(TO_NATIVE_PATH \"${GO_OS}\" ENV{GOOS})
file(TO_NATIVE_PATH \"${GO_ARCH}\" ENV{GOARCH})
set(ENV{CGO_LDFLAGS} \"-L${CMAKE_BINARY_DIR}\")
set(ENV{CGO_CFLAGS} \"-I${CMAKE_SOURCE_DIR}\")
set(CMAKE_Go_COMPILER ${CMAKE_Go_COMPILER})
Expand Down
2 changes: 1 addition & 1 deletion cmake/Modules/GoTest.cmake
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

set(ENV{GOPATH} ${GO_PATH})
set(ENV{GOPATH} "${GO_PATH}")
execute_process(
COMMAND ${TESTER}
OUTPUT_VARIABLE output
Expand Down
7 changes: 6 additions & 1 deletion cmake/Modules/RunGradle.cmake
Expand Up @@ -16,8 +16,13 @@ include(${GRADLE_ENV})

separate_arguments(args UNIX_COMMAND ${GRADLE_ARGS})

set(gradle "./gradlew")
if(CMAKE_HOST_WIN32)
set(gradle "gradlew.bat")
endif(CMAKE_HOST_WIN32)

execute_process(
COMMAND ./gradlew
COMMAND ${gradle}
${args}
-Djava.awt.headless=true # Prevent gradle from stealing window focus.
build
Expand Down
1 change: 1 addition & 0 deletions cmake/Modules/UseCMake.cmake
Expand Up @@ -24,6 +24,7 @@ function (add_cmake proj src)
CMAKE_CACHE_ARGS
"${ARGN}"
CMAKE_CACHE_DEFAULT_ARGS
"-DPYTHON_EXECUTABLE:PATH=${PYTHON_EXECUTABLE}"
"-DPROTO_CC_OUT:PATH=${PROTO_CC_OUT}"
"-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}"
"-DCMAKE_MAKE_PROGRAM:STRING=${CMAKE_MAKE_PROGRAM}"
Expand Down
2 changes: 1 addition & 1 deletion cmake/Modules/UseGo.cmake
Expand Up @@ -135,7 +135,7 @@ function(_go_package VAR package)
POST_BUILD
COMMAND ${CMAKE_COMMAND}
"-DTESTER=$<TARGET_FILE:${test_name}>"
"-DGO_PATH=${GO_PATH}"
"-DGO_PATH=\"${GO_PATH}\""
-P "${GO_TEST_SCRIPT}"
# Let the test run in the original source directory so that
# we can properly locate resources referenced by the test.
Expand Down
4 changes: 2 additions & 2 deletions cmake/Modules/UseGradle.cmake
Expand Up @@ -23,8 +23,8 @@ set(JAVA_HOME $ENV{JAVA_HOME} CACHE PATH "The root path to the JDK")
#TODO: should we try to find an installed SDK here?

file(WRITE ${GRADLE_ENV} "
set(ENV{ANDROID_HOME} ${ANDROID_HOME})
set(ENV{JAVA_HOME} ${JAVA_HOME})
set(ENV{ANDROID_HOME} \"${ANDROID_HOME}\")
set(ENV{JAVA_HOME} \"${JAVA_HOME}\")
")


Expand Down
50 changes: 33 additions & 17 deletions cmake/Modules/UseProtoc.cmake
Expand Up @@ -12,7 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

set(PROTO_PATH "${ROOT_DIR}/src:${CMAKE_SOURCE_DIR}/third_party/src:${PROTOBUF_DIR}/src")
set(PROTO_PATH
"${ROOT_DIR}/src"
"${CMAKE_SOURCE_DIR}/third_party/src"
"${PROTOBUF_DIR}/src"
)

set(PROTO_HEADER "# Copyright (C) 2017 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the \"License\")\;
Expand Down Expand Up @@ -164,47 +169,58 @@ function(protoc_go go_package src_dir protos)
get_filename_component(proto_name ${proto} NAME_WE)
list(APPEND outputs "${GO_SRC}/${go_package}/${proto_name}.pb.go")
endforeach()
file(TO_NATIVE_PATH "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/protoc-gen-go" os_plugin)
file(TO_NATIVE_PATH "${ROOT_DIR}/src" os_go_out)

_do_protoc("go" "${src_dir}" "${protos}" "${outputs}"
"--plugin=${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/protoc-gen-go"
"--go_out=plugins=grpc:${ROOT_DIR}/src")
"--plugin=${os_plugin}"
"--go_out=plugins=grpc:${os_go_out}")
endfunction()

function(protoc_cc cc_package src_dir protos)
set(outputs)
set(cc_out "${CMAKE_BINARY_DIR}/proto_cc")
set(dest_dir "${cc_out}/${cc_package}")
set(outputs)
foreach(proto ${protos})
get_filename_component(proto_name ${proto} NAME_WE)
list(APPEND outputs
"${dest_dir}/${proto_name}.pb.cc"
"${dest_dir}/${proto_name}.pb.h"
)
list(APPEND outputs "${dest_dir}/${proto_name}.pb.cc" "${dest_dir}/${proto_name}.pb.h")
endforeach()
_do_protoc("cc" "${src_dir}" "${protos}" "${outputs}"
"--cpp_out=${cc_out}")
file(TO_NATIVE_PATH ${cc_out} os_cc_out)
_do_protoc("cc" "${src_dir}" "${protos}" "${outputs}" "--cpp_out=${os_cc_out}")
endfunction()

function(protoc_java src_dir protos classes)
set(outputs)
foreach(class ${classes})
list(APPEND outputs "${JAVA_SERVICE}/${class}.java")
endforeach()
set(args
"--plugin=protoc-gen-grpc-java=${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/protoc-gen-grpc-java"
"--java_out=${JAVA_SERVICE}"
"--grpc-java_out=${JAVA_SERVICE}"

file(TO_NATIVE_PATH "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/protoc-gen-grpc-java${CMAKE_HOST_EXECUTABLE_SUFFIX}" os_protoc_gen_grpc_java)
file(TO_NATIVE_PATH "${JAVA_SERVICE}" os_java_service)

_do_protoc("java" "${src_dir}" "${protos}" "${outputs}"
"--plugin=protoc-gen-grpc-java=${os_protoc_gen_grpc_java}"
"--java_out=${os_java_service}"
"--grpc-java_out=${os_java_service}"
)
_do_protoc("java" "${src_dir}" "${protos}" "${outputs}" ${args})
endfunction()

function(_do_protoc type src_dir protos outputs)
abs_list(protos "${CMAKE_SOURCE_DIR}/${src_dir}")
paths_to_native(os_protos protos)

set(os_proto_path "${PROTO_PATH}")
file(TO_NATIVE_PATH "${os_proto_path}" os_proto_path)
if (NOT WIN32)
string(REPLACE ";" ":" os_proto_path "${os_proto_path}")
endif()

add_custom_command(
OUTPUT ${outputs}
COMMAND protoc
--proto_path=${PROTO_PATH}
"--proto_path=${os_proto_path}"
${ARGN}
${protos}
${os_protos}
DEPENDS ${protos} protoc-gen-go protoc-gen-grpc-java
COMMENT "protoc ${proto}"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
Expand Down
18 changes: 7 additions & 11 deletions cmake/Toolchain/AndroidABI.cmake
Expand Up @@ -74,17 +74,13 @@ if(ToolchainHost STREQUAL "Darwin")
set(compiler_host "darwin-x86_64")
endif()
if(ToolchainHost STREQUAL "Windows")
set(compiler_host "darwin-x86_64")
set(compiler_host "windows-x86_64")
endif()

set(ANDROID_TOOLCHAIN_PREFIX_armeabi "${toolchains}/arm-linux-androideabi-4.9/prebuilt/${compiler_host}/bin/arm-linux-androideabi-")
set(ANDROID_TOOLCHAIN_PREFIX_aarch64 "${toolchains}/aarch64-linux-android-4.9/prebuilt/${compiler_host}/bin/aarch64-linux-android-")
set(ANDROID_TOOLCHAIN_PREFIX_x86 "${toolchains}/x86-4.9/prebuilt/${compiler_host}/bin/i686-linux-android-")

set(host_suffix "")
if(ToolchainHost STREQUAL "Windows")
set(host_suffix ".exe")
endif()

# Look up the set of android ABI's by detecting the ANDROID_ABI_NAME_{$abi} variables
set(ANDROID_ABI_LIST)
get_cmake_property(vars VARIABLES)
Expand All @@ -96,11 +92,11 @@ endforeach()

foreach(abi ${ANDROID_ABI_LIST})
# Build any constructed variables
set(ANDROID_GCC_PATH_${abi} "${ANDROID_TOOLCHAIN_PREFIX_${abi}}gcc${host_suffix}")
set(ANDROID_GXX_PATH_${abi} "${ANDROID_TOOLCHAIN_PREFIX_${abi}}g++${host_suffix}")
set(ANDROID_RANLIB_PATH_${abi} "${ANDROID_TOOLCHAIN_PREFIX_${abi}}ranlib${host_suffix}")
set(ANDROID_AR_PATH_${abi} "${ANDROID_TOOLCHAIN_PREFIX_${abi}}ar${host_suffix}")
set(ANDROID_LD_PATH_${abi} "${ANDROID_TOOLCHAIN_PREFIX_${abi}}ld${host_suffix}")
set(ANDROID_GCC_PATH_${abi} "${ANDROID_TOOLCHAIN_PREFIX_${abi}}gcc${CMAKE_HOST_EXECUTABLE_SUFFIX}")
set(ANDROID_GXX_PATH_${abi} "${ANDROID_TOOLCHAIN_PREFIX_${abi}}g++${CMAKE_HOST_EXECUTABLE_SUFFIX}")
set(ANDROID_RANLIB_PATH_${abi} "${ANDROID_TOOLCHAIN_PREFIX_${abi}}ranlib${CMAKE_HOST_EXECUTABLE_SUFFIX}")
set(ANDROID_AR_PATH_${abi} "${ANDROID_TOOLCHAIN_PREFIX_${abi}}ar${CMAKE_HOST_EXECUTABLE_SUFFIX}")
set(ANDROID_LD_PATH_${abi} "${ANDROID_TOOLCHAIN_PREFIX_${abi}}ld${CMAKE_HOST_EXECUTABLE_SUFFIX}")
# Verify that all required variables are set
foreach(var ${ANDROID_ABI_VARS})
if(NOT DEFINED ${var}_${abi})
Expand Down
16 changes: 12 additions & 4 deletions cmake/Toolchain/Windows.cmake
Expand Up @@ -14,7 +14,14 @@

set(TARGET_OS WINDOWS)

if(NOT ToolchainTarget STREQUAL ${ToolchainHost})
if(ToolchainTarget STREQUAL ${ToolchainHost})
set(MSYS2_PATH "" CACHE PATH "Path to the msys2 installation directory")
if(NOT MSYS2_PATH)
message(FATAL_ERROR "MSYS2_PATH not set!")
endif()

set(MINGW_PATH "${MSYS2_PATH}/mingw64")
else()
# Cross compiling
message(FATAL_ERROR "Cross compiling to windows was only supported with PREBUILTS")
if(NOT ToolchainHost STREQUAL "Linux")
Expand All @@ -24,8 +31,9 @@ if(NOT ToolchainTarget STREQUAL ${ToolchainHost})
set(CMAKE_SYSTEM_NAME "Windows")
set(CMAKE_LIBRARY_ARCHITECTURE "x86_64-w64-mingw32")
set(MINGW_PATH "${PREBUILTS}/gcc/linux-x86/host/x86_64-w64-mingw32-4.8")
set(CMAKE_C_COMPILER "${MINGW_PATH}/bin/x86_64-w64-mingw32-gcc")
set(CMAKE_CXX_COMPILER "${MINGW_PATH}/bin/x86_64-w64-mingw32-g++")
list(APPEND CMAKE_LIBRARY_PATH "${MINGW_PATH}/x86_64-w64-mingw32/lib")
list(APPEND CMAKE_PREFIX_PATH "${PREBUILTS}/go/linux-x86")
endif()
endif()

set(CMAKE_C_COMPILER "${MINGW_PATH}/bin/x86_64-w64-mingw32-gcc${CMAKE_HOST_EXECUTABLE_SUFFIX}")
set(CMAKE_CXX_COMPILER "${MINGW_PATH}/bin/x86_64-w64-mingw32-g++${CMAKE_HOST_EXECUTABLE_SUFFIX}")
11 changes: 11 additions & 0 deletions cmake/Utils.cmake
Expand Up @@ -92,6 +92,17 @@ function(abs_list VAR path)
endfunction(abs_list)


# paths_to_native transforms the list of paths to the os-native form
# and assigns the results to OUT.
function(paths_to_native OUT list)
set(result)
foreach(entry ${${list}})
file(TO_NATIVE_PATH ${entry} entry)
list(APPEND result ${entry})
endforeach()
set(${OUT} ${result} PARENT_SCOPE)
endfunction(paths_to_native)

# Override and disable link_libraries, it's been a mistake every time it's been used
function(link_libraries)
message(FATAL_ERROR "Don't use link_libraries, you probably meant target_link_libraries (${ARGV})")
Expand Down
6 changes: 3 additions & 3 deletions cmd/apic/CMakeBuild.cmake
Expand Up @@ -48,14 +48,13 @@ function(apic api)
endif()
abs_list(APIC_OUTPUTS ${CMAKE_CURRENT_SOURCE_DIR})
set(apic_args template
--gopath ${GO_PATH}
--cmake ${deps}
--dir ${APIC_PATH}
)
if(APIC_DEFINES)
set(apic_args ${apic_args} -G ${APIC_DEFINES})
endif()
set(apic_args ${apic_args} ${api} ${APIC_TEMPLATE})
set(apic_args ${apic_args} "${api}" ${APIC_TEMPLATE})
if(NOT EXISTS ${deps})
# Ugly hacks to make intial dependancies not totally broken...
set(APIC_INPUTS ${APIC_INPUTS}
Expand All @@ -65,10 +64,11 @@ function(apic api)
set(api_outputs ${APIC_OUTPUTS})
")
endif()
set(apic_args ${apic_args} "--gopath" "${GO_PATH}")
include(${deps})
add_custom_command(
OUTPUT ${tag} ${api_outputs}
COMMAND apic ${apic_args}
COMMAND apic ${apic_args}
COMMAND ${CMAKE_COMMAND} -E touch ${tag}
DEPENDS apic ${api_inputs}
COMMENT "Apic on ${api} with ${name}"
Expand Down
3 changes: 2 additions & 1 deletion cmd/apic/template.go
Expand Up @@ -20,6 +20,7 @@ import (
"go/build"
"io/ioutil"
"os"
"path/filepath"

"github.com/google/gapid/core/app"
"github.com/google/gapid/core/app/flags"
Expand Down Expand Up @@ -64,7 +65,7 @@ func doTemplate(ctx log.Context, flags flag.FlagSet) error {
return nil
}
if gopath != "" {
build.Default.GOPATH = gopath
build.Default.GOPATH = filepath.FromSlash(gopath)
}
mainTemplate := args[1]
ctx.Info().S("api", apiName).Log("Reading")
Expand Down
2 changes: 1 addition & 1 deletion cmd/codergen/CMakeBuild.cmake
Expand Up @@ -50,7 +50,7 @@ function(codergen)
add_custom_command(
OUTPUT ${signatures} ${outputs}
COMMAND codergen
--gopath ${GO_PATH}
--gopath "${GO_PATH}"
--signatures ${signatures}
--go
-cpp ${CMAKE_SOURCE_DIR}/core/cc/coder
Expand Down
4 changes: 3 additions & 1 deletion cmd/codergen/main.go
Expand Up @@ -22,6 +22,8 @@ import (
"os"
"sync"

"path/filepath"

"github.com/google/gapid/core/app"
"github.com/google/gapid/core/log"
"github.com/google/gapid/core/text/copyright"
Expand Down Expand Up @@ -100,7 +102,7 @@ func run(ctx log.Context) error {
if err != nil {
return err
}
scanner := scan.New(ctx, wd, *gopath)
scanner := scan.New(ctx, wd, filepath.FromSlash(*gopath))
ctx.Print("Scanning")
args := flag.Args()
if len(args) == 0 {
Expand Down

0 comments on commit 07201a7

Please sign in to comment.