How do I get CMake to work with the go programming language?

You might wish to implement CMake' support for Go. Roughly speaking it involves following steps:

  1. Create CMakeDetermineGoCompiler.cmake module, which would find Go compiler for the current system.
  2. Create CMakeGoCompiler.cmake.in - a template, which would be configured by CMakeDetermineGoCompiler.

  3. Create CMakeTestGoCompiler.cmake, module which would compile a simple go source to check if the compiler works.

  4. Create CMakeGoInformation.cmake, which would set some language-related variables (CMAKE_GO_LINK_EXECUTABLE and so on)

These things should be placed in CMAKE_MODULES_DIR. For reference you can take a look at how Java/CXX support is implemented.

Alternatively, if don't want to mess with such internal stuff, you can solve your task by creating a macro(), which would create a bunch of custom targets/commands (see add_custom_{target,command}() documentation).


It's in your best interest to not use CMake (or any other build system).

Go has a simple, built-in way to build packages: go build (which also makes go get and go install work). go build, by design, doesn't require additional tools like make or cmake.

If you use CMake (or any other build system) you'll just make life harder for yourself (if you plan to use libraries developed by others) or for other people (if you plan to develop libraries that are meant to be used by others).

Tags:

Cmake

Go