├── .gitignore ├── CMakeDetermineGoCompiler.cmake ├── CMakeGoCompiler.cmake.in ├── CMakeGoInformation.cmake ├── CMakeLists.txt ├── CMakeTestGoCompiler.cmake ├── README.md └── src └── main.go /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### CMake template 3 | CMakeCache.txt 4 | CMakeFiles 5 | Makefile 6 | cmake_install.cmake 7 | install_manifest.txt 8 | 9 | 10 | ### C++ template 11 | # Compiled Object files 12 | *.slo 13 | *.lo 14 | *.o 15 | *.obj 16 | 17 | # Precompiled Headers 18 | *.gch 19 | *.pch 20 | 21 | # Compiled Dynamic libraries 22 | *.so 23 | *.dylib 24 | *.dll 25 | 26 | # Fortran module files 27 | *.mod 28 | 29 | # Compiled Static libraries 30 | *.lai 31 | *.la 32 | *.a 33 | *.lib 34 | 35 | # Executables 36 | *.exe 37 | *.out 38 | *.app 39 | 40 | 41 | ### C template 42 | # Object files 43 | *.ko 44 | *.elf 45 | 46 | # Shared objects (inc. Windows DLLs) 47 | *.so.* 48 | 49 | # Executables 50 | *.i*86 51 | *.x86_64 52 | *.hex 53 | 54 | # Debug files 55 | *.dSYM/ 56 | 57 | 58 | ### JetBrains template 59 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm 60 | 61 | *.iml 62 | 63 | ## Directory-based project format: 64 | .idea/ 65 | # if you remove the above rule, at least ignore the following: 66 | 67 | # User-specific stuff: 68 | # .idea/workspace.xml 69 | # .idea/tasks.xml 70 | # .idea/dictionaries 71 | 72 | # Sensitive or high-churn files: 73 | # .idea/dataSources.ids 74 | # .idea/dataSources.xml 75 | # .idea/sqlDataSources.xml 76 | # .idea/dynamic.xml 77 | # .idea/uiDesigner.xml 78 | 79 | # Gradle: 80 | # .idea/gradle.xml 81 | # .idea/libraries 82 | 83 | # Mongo Explorer plugin: 84 | # .idea/mongoSettings.xml 85 | 86 | ## File-based project format: 87 | *.ipr 88 | *.iws 89 | 90 | ## Plugin-specific files: 91 | 92 | # IntelliJ 93 | /out/ 94 | 95 | # mpeltonen/sbt-idea plugin 96 | .idea_modules/ 97 | 98 | # JIRA plugin 99 | atlassian-ide-plugin.xml 100 | 101 | # Crashlytics plugin (for Android Studio and IntelliJ) 102 | com_crashlytics_export_strings.xml 103 | crashlytics.properties 104 | crashlytics-build.properties 105 | 106 | 107 | ### Go template 108 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 109 | # Folders 110 | _obj 111 | _test 112 | 113 | # Architecture specific extensions/prefixes 114 | *.[568vq] 115 | [568vq].out 116 | 117 | *.cgo1.go 118 | *.cgo2.c 119 | _cgo_defun.c 120 | _cgo_gotypes.go 121 | _cgo_export.* 122 | 123 | _testmain.go 124 | 125 | *.test 126 | *.prof 127 | 128 | 129 | 130 | ### OSX template 131 | .DS_Store 132 | .AppleDouble 133 | .LSOverride 134 | 135 | # Icon must end with two \r 136 | Icon 137 | 138 | # Thumbnails 139 | ._* 140 | 141 | # Files that might appear in the root of a volume 142 | .DocumentRevisions-V100 143 | .fseventsd 144 | .Spotlight-V100 145 | .TemporaryItems 146 | .Trashes 147 | .VolumeIcon.icns 148 | 149 | # Directories potentially created on remote AFP share 150 | .AppleDB 151 | .AppleDesktop 152 | Network Trash Folder 153 | Temporary Items 154 | .apdisk 155 | 156 | 157 | ### Windows template 158 | # Windows image file caches 159 | Thumbs.db 160 | ehthumbs.db 161 | 162 | # Folder config file 163 | Desktop.ini 164 | 165 | # Recycle Bin used on file shares 166 | $RECYCLE.BIN/ 167 | 168 | # Windows Installer files 169 | *.cab 170 | *.msi 171 | *.msm 172 | *.msp 173 | 174 | # Windows shortcuts 175 | *.lnk 176 | 177 | 178 | ### Linux template 179 | *~ 180 | 181 | # KDE directory preferences 182 | .directory 183 | 184 | # Linux trash folder which might appear on any partition or disk 185 | .Trash-* 186 | 187 | ### Vim template 188 | [._]*.s[a-w][a-z] 189 | [._]s[a-w][a-z] 190 | *.un~ 191 | Session.vim 192 | .netrwhist 193 | -------------------------------------------------------------------------------- /CMakeDetermineGoCompiler.cmake: -------------------------------------------------------------------------------- 1 | if(NOT CMAKE_Go_COMPILER) 2 | if(NOT $ENV{GO_COMPILER} STREQUAL "") 3 | get_filename_component(CMAKE_Go_COMPILER_INIT $ENV{GO_COMPILER} PROGRAM PROGRAM_ARGS CMAKE_Go_FLAGS_ENV_INIT) 4 | 5 | if(CMAKE_Go_FLAGS_ENV_INIT) 6 | set(CMAKE_Go_COMPILER_ARG1 "${CMAKE_Go_FLAGS_ENV_INIT}" CACHE STRING "First argument to Go compiler") 7 | endif() 8 | 9 | if(NOT EXISTS ${CMAKE_Go_COMPILER_INIT}) 10 | message(SEND_ERROR "Could not find compiler set in environment variable GO_COMPILER:\n$ENV{GO_COMPILER}.") 11 | endif() 12 | 13 | endif() 14 | 15 | set(Go_BIN_PATH 16 | $ENV{GOPATH} 17 | $ENV{GOROOT} 18 | $ENV{GOROOT}/../bin 19 | $ENV{GO_COMPILER} 20 | /usr/bin 21 | /usr/local/bin 22 | ) 23 | 24 | if(CMAKE_Go_COMPILER_INIT) 25 | set(CMAKE_Go_COMPILER ${CMAKE_Go_COMPILER_INIT} CACHE PATH "Go Compiler") 26 | else() 27 | find_program(CMAKE_Go_COMPILER 28 | NAMES go 29 | PATHS ${Go_BIN_PATH} 30 | ) 31 | endif() 32 | 33 | endif() 34 | 35 | mark_as_advanced(CMAKE_Go_COMPILER) 36 | 37 | configure_file(CMakeGoCompiler.cmake.in 38 | ${CMAKE_PLATFORM_INFO_DIR}/CMakeGoCompiler.cmake @ONLY) 39 | 40 | set(CMAKE_Go_COMPILER_ENV_VAR "GO_COMPILER") 41 | -------------------------------------------------------------------------------- /CMakeGoCompiler.cmake.in: -------------------------------------------------------------------------------- 1 | set(CMAKE_Go_COMPILER "@CMAKE_Go_COMPILER@") 2 | set(CMAKE_Go_COMPILER_LOADED 1) 3 | 4 | set(CMAKE_Go_SOURCE_FILE_EXTENSIONS go) 5 | set(CMAKE_Go_LINKER_PREFERENCE 40) 6 | set(CMAKE_Go_OUTPUT_EXTENSION .o) 7 | set(CMAKE_Go_OUTPUT_EXTENSION_REPLACE 1) 8 | set(CMAKE_Go_COMPILER_ENV_VAR "GO_COMPILER") 9 | -------------------------------------------------------------------------------- /CMakeGoInformation.cmake: -------------------------------------------------------------------------------- 1 | if(NOT CMAKE_Go_COMPILE_OBJECT) 2 | set(CMAKE_Go_COMPILE_OBJECT "go tool compile -l -N -o ") 3 | endif() 4 | 5 | if(NOT CMAKE_Go_LINK_EXECUTABLE) 6 | set(CMAKE_Go_LINK_EXECUTABLE "go tool link -o ") 7 | endif() 8 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.2) 2 | 3 | set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/) 4 | 5 | project(hello_world Go) 6 | 7 | set(SOURCE_FILES 8 | src/main.go) 9 | 10 | add_executable(hello_world ${SOURCE_FILES}) 11 | -------------------------------------------------------------------------------- /CMakeTestGoCompiler.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_Go_COMPILER_WORKS 1 CACHE INTERNAL "") 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Example CMake for Golang 2 | 3 | Minimum Go version 1.5 4 | -------------------------------------------------------------------------------- /src/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | fmt.Println("Hello, world") 7 | } 8 | --------------------------------------------------------------------------------