Skip to content

Commit 4b93636

Browse files
committed
cmake: scala specific stuff
1 parent 35acac1 commit 4b93636

File tree

1 file changed

+45
-2
lines changed

1 file changed

+45
-2
lines changed

CMakeLists.txt

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,58 @@ endif()
5353
set(GO_OUT libipfs-${GOOS}-${GOARCH}.a)
5454
set(GO_HEADER libipfs.h)
5555

56+
set(CROSS_CC "")
57+
if(GOARCH STREQUAL "arm64")
58+
set(CROSS_CC "CC=aarch64-linux-gnu-gcc")
59+
endif()
60+
61+
if(GOARCH STREQUAL "riscv64")
62+
set(CROSS_CC "CC=riscv64-linux-gnu-gcc")
63+
endif()
64+
65+
if(GOOS STREQUAL "windows" AND CMAKE_C_PLATFORM_ID STREQUAL "MinGW")
66+
set(CROSS_CC "CC=x86_64-w64-mingw32-gcc-posix")
67+
endif()
68+
69+
if(APPLE)
70+
if(DEFINED scala_BINARY_DIR AND NOT "${scala_BINARY_DIR}" STREQUAL "")
71+
if(DEFINED CMAKE_OSX_SYSROOT)
72+
set(CROSS_CC "CC=clang --target=${CLANG_TARGET} --sysroot=${CMAKE_OSX_SYSROOT}")
73+
endif()
74+
endif()
75+
endif()
76+
77+
if(FREEBSD)
78+
if(DEFINED scala_BINARY_DIR AND NOT "${scala_BINARY_DIR}" STREQUAL "")
79+
foreach(path IN LISTS CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES)
80+
if("${path}" MATCHES "(.*/native)/usr/lib")
81+
set(FREEBSD_SYSROOT "${CMAKE_MATCH_1}")
82+
break()
83+
endif()
84+
endforeach()
85+
86+
if(DEFINED FREEBSD_SYSROOT)
87+
set(CROSS_CC "CC=clang --target=x86_64-unknown-freebsd --sysroot=${FREEBSD_SYSROOT}")
88+
else()
89+
message(FATAL_ERROR "Could not detect FreeBSD sysroot from CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES")
90+
endif()
91+
endif()
92+
endif()
93+
5694
add_custom_command(
5795
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${GO_OUT} ${CMAKE_CURRENT_BINARY_DIR}/${GO_HEADER}
5896
COMMAND ${CMAKE_COMMAND} -E env
97+
${CROSS_CC}
5998
CGO_ENABLED=1
6099
GOOS=${GOOS}
61100
GOARCH=${GOARCH}
62101
go build
63102
-buildmode=c-archive
64103
-trimpath
65-
-ldflags=-s\ -w
104+
"-ldflags=-s -w"
66105
-o ${CMAKE_CURRENT_BINARY_DIR}/${GO_OUT}
67106
${CMAKE_CURRENT_SOURCE_DIR}/libipfs.go
107+
${GO_EXTRA_COMMANDS}
68108
COMMAND ${CMAKE_COMMAND} -E copy_if_different
69109
${CMAKE_CURRENT_BINARY_DIR}/libipfs-${GOOS}-${GOARCH}.h
70110
${CMAKE_CURRENT_BINARY_DIR}/libipfs.h
@@ -73,7 +113,6 @@ add_custom_command(
73113
COMMENT "Building Go IPFS library (${GOOS}/${GOARCH})"
74114
)
75115

76-
77116
add_custom_target(libipfs_build ALL
78117
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${GO_OUT}
79118
)
@@ -88,6 +127,10 @@ if(APPLE)
88127
set_target_properties(libipfs PROPERTIES
89128
INTERFACE_LINK_LIBRARIES "${SECURITY_FRAMEWORK};${RESOLV_LIBRARY}"
90129
)
130+
elseif(UNIX AND NOT FREEBSD)
131+
set_target_properties(libipfs PROPERTIES
132+
INTERFACE_LINK_LIBRARIES "resolv"
133+
)
91134
endif()
92135

93136
add_dependencies(libipfs libipfs_build)

0 commit comments

Comments
 (0)