@@ -53,18 +53,58 @@ endif()
53
53
set (GO_OUT libipfs-${GOOS}-${GOARCH}.a )
54
54
set (GO_HEADER libipfs.h )
55
55
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
+
56
94
add_custom_command (
57
95
OUTPUT ${CMAKE_CURRENT_BINARY_DIR} /${GO_OUT} ${CMAKE_CURRENT_BINARY_DIR} /${GO_HEADER}
58
96
COMMAND ${CMAKE_COMMAND} -E env
97
+ ${CROSS_CC}
59
98
CGO_ENABLED=1
60
99
GOOS=${GOOS}
61
100
GOARCH=${GOARCH}
62
101
go build
63
102
-buildmode=c-archive
64
103
-trimpath
65
- -ldflags=-s\ -w
104
+ " -ldflags=-s -w"
66
105
-o ${CMAKE_CURRENT_BINARY_DIR} /${GO_OUT}
67
106
${CMAKE_CURRENT_SOURCE_DIR} /libipfs.go
107
+ ${GO_EXTRA_COMMANDS}
68
108
COMMAND ${CMAKE_COMMAND} -E copy_if_different
69
109
${CMAKE_CURRENT_BINARY_DIR} /libipfs-${GOOS}-${GOARCH}.h
70
110
${CMAKE_CURRENT_BINARY_DIR} /libipfs.h
@@ -73,7 +113,6 @@ add_custom_command(
73
113
COMMENT "Building Go IPFS library (${GOOS} /${GOARCH} )"
74
114
)
75
115
76
-
77
116
add_custom_target (libipfs_build ALL
78
117
DEPENDS ${CMAKE_CURRENT_BINARY_DIR} /${GO_OUT}
79
118
)
@@ -88,6 +127,10 @@ if(APPLE)
88
127
set_target_properties (libipfs PROPERTIES
89
128
INTERFACE_LINK_LIBRARIES "${SECURITY_FRAMEWORK} ;${RESOLV_LIBRARY} "
90
129
)
130
+ elseif (UNIX AND NOT FREEBSD )
131
+ set_target_properties (libipfs PROPERTIES
132
+ INTERFACE_LINK_LIBRARIES "resolv"
133
+ )
91
134
endif ()
92
135
93
136
add_dependencies (libipfs libipfs_build )
0 commit comments