Skip to content

Commit

Permalink
test: convert spaces to colons.
Browse files Browse the repository at this point in the history
If this actually works cmake... I will conjour
up your evil twin, cdestroy, and release you two
into the world to battle it out. No really I am
just tired and writing a terrible commit message
that will be squashed anyone if this weirdness
actually works.

Signed-off-by: vsoch <vsoch@users.noreply.github.com>
  • Loading branch information
vsoch committed Sep 16, 2023
1 parent dd9d301 commit 80f9ffb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
16 changes: 4 additions & 12 deletions cmake/GolangSimple.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,15 @@ file(MAKE_DIRECTORY ${GOPATH})
# ADD_GO_INSTALLABLE_PROGRAM builds a custom go program (primarily for testing)
function(BUILD_GO_PROGRAM NAME MAIN_SRC CGO_CFLAGS CGO_LIBRARY_FLAGS)
message(STATUS "GOPATH: ${GOPATH}")
message(STATUS "CGO_LDFLAGS (before): ${CGO_LIBRARY_FLAGS}")
message(STATUS "TEST_FLAGS: ${TEST_FLAGS}")
message(STATUS "CGO_LDFLAGS: ${CGO_LIBRARY_FLAGS}")
get_filename_component(MAIN_SRC_ABS ${MAIN_SRC} ABSOLUTE)
add_custom_target(${NAME})

# THIS IS NOT USED
# IMPORTANT: the trick to getting *spaces* to render in COMMAND is to convert them to ";"
# string(REPLACE <match-string> <replace-string> <out-var> <input>...)
STRING(REPLACE ";" " " CGO_LDFLAGS "${CGO_LIBRARY_FLAGS}")

# set(ENV{<variable>} [<value>]) as environment OR without CMake variable
# Note that I couldn't get this to work (the spaces are always escaped) so I hard coded for now
# We need a solution that takes the CGO_LIBRARY_FLAGS arg, and can pass (with spaces not escaped) to add_custom_command
SET ($ENV{CGO_LDFLAGS} "${CGO_LDFLAGS}")
message(STATUS "CGO_LDFLAGS (after): ${CGO_LDFLAGS}")

STRING(REPLACE " " ";" CGO_LIBRARY_FLAGS ${CGO_LIBRARY_FLAGS})
add_custom_command(TARGET ${NAME}
COMMAND GOPATH=${GOPATH}:${CUSTOM_GO_PATH} GOOS=linux G0111MODULE=off CGO_CFLAGS="${CGO_CFLAGS}" CGO_LDFLAGS='-Wl,-R ${CMAKE_BINARY_DIR}/resource -L${CMAKE_BINARY_DIR}/resource/reapi/bindings -L${CMAKE_BINARY_DIR}/resource/libjobspec -ljobspec_conv -lreapi_cli -L${CMAKE_BINARY_DIR}/resource -lresource -lflux-idset -lstdc++ -lczmq -ljansson -lhwloc -lboost_system -lflux-hostlist -lboost_graph -lyaml-cpp' go build -ldflags '-w'
COMMAND GOPATH=${GOPATH}:${CUSTOM_GO_PATH} GOOS=linux G0111MODULE=off CGO_CFLAGS="${CGO_CFLAGS}" CGO_LDFLAGS='${CGO_LIBRARY_FLAGS}' go build -ldflags '-w'
-o "${CMAKE_CURRENT_SOURCE_DIR}/${NAME}"
${CMAKE_GO_FLAGS} ${MAIN_SRC}
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
Expand Down
2 changes: 1 addition & 1 deletion resource/reapi/bindings/go/src/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set(SRCS main.go)
set(CGO_CFLAGS "-I${CMAKE_BINARY_DIR}/resource/reapi/bindings/c")

# This is currently passed but not used because when passed into add_custom_command the spaces are escaped
set(CGO_LIBRARY_FLAGS "-L${CMAKE_BINARY_DIR}/resource/reapi/bindings;-lreapi_cli;-L${CMAKE_BINARY_DIR}/resource;-lresource;-lflux-idset;-lstdc++;-lczmq;-ljansson;-lhwloc;-lboost_system;-lflux-hostlist;-lboost_graph;-lyaml-cpp")
set(CGO_LIBRARY_FLAGS "-Wl,-R ${CMAKE_BINARY_DIR}/resource -L${CMAKE_BINARY_DIR}/resource/reapi/bindings -L${CMAKE_BINARY_DIR}/resource/libjobspec -ljobspec_conv -lreapi_cli -L${CMAKE_BINARY_DIR}/resource -lresource -lflux-idset -lstdc++ -lczmq -ljansson -lhwloc -lboost_system -lflux-hostlist -lboost_graph -lyaml-cpp")

# This ensures the main binary is cleaned up
set_directory_properties(
Expand Down

0 comments on commit 80f9ffb

Please sign in to comment.