diff --git a/source/ports/CMakeLists.txt b/source/ports/CMakeLists.txt index 004a78965..cbabcb43e 100644 --- a/source/ports/CMakeLists.txt +++ b/source/ports/CMakeLists.txt @@ -50,6 +50,7 @@ option(OPTION_BUILD_PORTS_TS "Build TypeScript port." OFF) add_subdirectory(cxx_port) add_subdirectory(node_port) add_subdirectory(py_port) +add_subdirectory(go_port) add_subdirectory(rs_port) # diff --git a/source/ports/go_port/CMakeLists.txt b/source/ports/go_port/CMakeLists.txt index 78fb5288e..d7c03d7d8 100644 --- a/source/ports/go_port/CMakeLists.txt +++ b/source/ports/go_port/CMakeLists.txt @@ -1,9 +1,39 @@ +# Check if port is enabled +if(NOT OPTION_BUILD_PORTS OR NOT OPTION_BUILD_PORTS_GO) + return() +endif() + include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/GoLang.cmake) -# add_go_library(go_port SHARED -# source/go_port.go -# ) +# +# Port name and options +# + +# Target name +set(target go_port) + +# Exit here if required dependencies are not met +message(STATUS "Port ${target}") -add_go_executable(go_port +add_go_library(${target} SHARED + source/await.go + source/pointer.go source/go_port.go ) + +# +# Define test +# + +add_test(NAME ${target} + COMMAND go test + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/source +) + +# +# Define test labels +# + +set_property(TEST ${target} + PROPERTY LABELS ${target} +) diff --git a/source/ports/go_port/cmake/CMakeDetermineGoCompiler.cmake b/source/ports/go_port/cmake/CMakeDetermineGoCompiler.cmake index 2c79e9b13..0af9659fe 100644 --- a/source/ports/go_port/cmake/CMakeDetermineGoCompiler.cmake +++ b/source/ports/go_port/cmake/CMakeDetermineGoCompiler.cmake @@ -19,7 +19,7 @@ if(NOT CMAKE_Go_COMPILER) $ENV{GO_COMPILER} /usr/bin /usr/local/bin - ) + ) if(CMAKE_Go_COMPILER_INIT) set(CMAKE_Go_COMPILER ${CMAKE_Go_COMPILER_INIT} CACHE PATH "Go Compiler") @@ -28,17 +28,19 @@ if(NOT CMAKE_Go_COMPILER) NAMES go PATHS ${Go_BIN_PATH} ) - EXEC_PROGRAM(${CMAKE_Go_COMPILER} ARGS version OUTPUT_VARIABLE GOLANG_VERSION) - STRING(REGEX MATCH "go[0-9]+.[0-9]+.[0-9]+[ /A-Za-z0-9]*" VERSION "${GOLANG_VERSION}") + exec_program(${CMAKE_Go_COMPILER} ARGS version OUTPUT_VARIABLE GOLANG_VERSION) + string(REGEX MATCH "go[0-9]+.[0-9]+.[0-9]+[ /A-Za-z0-9]*" VERSION "${GOLANG_VERSION}") message("-- The Golang compiler identification is ${VERSION}") message("-- Check for working Golang compiler: ${CMAKE_Go_COMPILER}") endif() - endif() mark_as_advanced(CMAKE_Go_COMPILER) -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/CMakeGoCompiler.cmake.in - ${CMAKE_PLATFORM_INFO_DIR}/CMakeGoCompiler.cmake @ONLY) +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/cmake/CMakeGoCompiler.cmake.in + ${CMAKE_PLATFORM_INFO_DIR}/CMakeGoCompiler.cmake + @ONLY +) set(CMAKE_Go_COMPILER_ENV_VAR "GO_COMPILER") diff --git a/source/ports/go_port/cmake/GoLang.cmake b/source/ports/go_port/cmake/GoLang.cmake index 51df45a52..87f9a8726 100644 --- a/source/ports/go_port/cmake/GoLang.cmake +++ b/source/ports/go_port/cmake/GoLang.cmake @@ -1,13 +1,15 @@ set(GOPATH "${CMAKE_CURRENT_BINARY_DIR}/go") file(MAKE_DIRECTORY ${GOPATH}) +include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/CMakeDetermineGoCompiler.cmake) + function(ExternalGoProject_Add TARG) - add_custom_target(${TARG} env GOPATH=${GOPATH} ${CMAKE_Go_COMPILER} get ${ARGN}) + add_custom_target(${TARG} ${CMAKE_COMMAND} -E env GOPATH=${GOPATH} ${CMAKE_Go_COMPILER} get ${ARGN}) endfunction(ExternalGoProject_Add) function(add_go_executable NAME) add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/.timestamp - COMMAND env GOPATH=${GOPATH} ${CMAKE_Go_COMPILER} build + COMMAND ${CMAKE_COMMAND} -E env GOPATH=${GOPATH} ${CMAKE_Go_COMPILER} build -o "${PROJECT_OUTPUT_DIR}/${NAME}" ${CMAKE_GO_FLAGS} ${ARGN} WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}) @@ -18,19 +20,23 @@ endfunction(add_go_executable) function(add_go_library NAME BUILD_TYPE) if(BUILD_TYPE STREQUAL "STATIC") - set(BUILD_MODE -buildmode=c-archive) - set(LIB_NAME "lib${NAME}.a") + if(WIN32) + set(LIB_NAME "lib${NAME}.lib") + else() + set(LIB_NAME "lib${NAME}.a") + endif() else() - set(BUILD_MODE -buildmode=c-shared) if(APPLE) set(LIB_NAME "lib${NAME}.dylib") + elseif(WIN32) + set(LIB_NAME "lib${NAME}.dll") else() set(LIB_NAME "lib${NAME}.so") endif() endif() add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/.timestamp - COMMAND env GOPATH=${GOPATH} ${CMAKE_Go_COMPILER} build ${BUILD_MODE} + COMMAND ${CMAKE_COMMAND} -E env GOPATH=${GOPATH} ${CMAKE_Go_COMPILER} build ${BUILD_MODE} -o "${PROJECT_OUTPUT_DIR}/${LIB_NAME}" ${CMAKE_GO_FLAGS} ${ARGN} WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR})