<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">On 13/05/2019 12:03, Bill Somerville
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:56dc0bc9-930f-e9e8-b8fd-680780f356c3@classdesign.com">
<p>Hi folks,</p>
<p>I am struggling to understand what the problem is with this:</p>
<pre>find_program (GO go)
set (GOPATH "${CMAKE_CURRENT_BINARY_DIR}/go")
file (MAKE_DIRECTORY ${GOPATH})
set (sources ${CMAKE_CURRENT_SOURCE_DIR}/callback_generator.go)
set (build_command ${GO} build)
set (output callback_generator${CMAKE_EXECUTABLE_SUFFIX})
add_custom_command (OUTPUT ${output}
COMMAND ${CMAKE_COMMAND} -E env GOPATH=${GOPATH} CGO_CFLAGS=${CMAKE_CGO_CFLAGS} ${build_command} -o ${output} ${CMAKE_GO_FLAGS} ${sources}
DEPENDS ${sources}
VERBATIM)
add_custom_target (callback_generator_target DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${output})
add_executable (callback_generator IMPORTED)
set_target_properties (callback_generator
PROPERTIES
IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/${output}
)
add_dependencies (callback_generator callback_generator_target)
add_custom_target (server ALL DEPENDS callback_generator)
</pre>
<p>which gives this error:<br>
</p>
<pre>>cmake --version
cmake --version
cmake version 3.14.3
>cmake -G "MinGW Makefiles" ..\..
cmake -G "MinGW Makefiles" ..\..
-- Configuring done
CMake Error: The inter-target dependency graph contains the following strongly connected component (cycle):
"callback_generator_target" of type UTILITY
depends on "callback_generator_target" (strong)
The component contains at least one cycle consisting of strong dependencies (created by add_dependencies) that cannot be broken.
</pre>
<p>The set_target_properties () call seems to be part of the
problem but I don't understand why.</p>
<p>Regards<br>
Bill Somerville.</p>
</blockquote>
<p>Hi again,</p>
<p>answering my own post since no one has replied. Clearly my
question was too specific. Let me try again with a more general
question. I have tools that can generate executables (programs,
static libraries, and shared libraries, including DLL import
libraries on MS Windows). These tools are not directly supported
by CMake but they are both needed within a project that uses them
and installs them as the project artefacts. How do I integrate,
for example a shared library, into a CMake project as if it were
produced by a supported toolchain like C or C++? The library is
produced by an add_custom_target() command (not
add_custom_command() since the underlying tools do their own
dependency checking so it is right to run the target commands
every build). I need to have a target that I can use in
target_link_libraries() and install(TARGETS ...) just like one
would with a CMake generated library made with add_library() and
programs made with add_executable().<br>
</p>
<p>If it helps the tools that are not supported by CMake are the Go
language build tools. The project builds some Go programs as
utilities but the main project artefact is a shared library with a
C language API built using the cgo tools. There are many of C and
C++ test programs and example programs as well in the project
which need to link against the project shared library etc.<br>
</p>
<p>Regards<br>
Bill Somerville.<br>
</p>
</body>
</html>