Skip to content

Commit

Permalink
Cmake, Cuda and Opengl
Browse files Browse the repository at this point in the history
  • Loading branch information
MatheusFaria committed Oct 9, 2016
1 parent 6324b9d commit edf3806
Show file tree
Hide file tree
Showing 146 changed files with 106,232 additions and 2 deletions.
12 changes: 12 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Set the default behavior, in case people don't have core.autocrlf set.
* text=auto

# Explicitly declare text files you want to always be normalized and converted
# to native line endings on checkout.
*.c text eol=lf
*.cpp text eol=lf
*.cc text eol=lf
*.h text eol=lf
*.hpp text eol=lf
*.txt text eol=lf
Makefile text eol=lf
107 changes: 107 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@

# Created by https://www.gitignore.io/api/c+,c++,cuda,macos,windows,vim,xcode

#!! ERROR: c+ is undefined. Use list command to see defined gitignore types !!#

### C++ ###
# Prerequisites
*.d

# Compiled Object files
*.slo
*.lo
Expand Down Expand Up @@ -27,3 +36,101 @@
*.exe
*.out
*.app


### CUDA ###
*.i
*.ii
*.gpu
*.ptx
*.cubin
*.fatbin


### macOS ###
*.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk


### Windows ###
# Windows image file caches
Thumbs.db
ehthumbs.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msm
*.msp

# Windows shortcuts
*.lnk


### Vim ###
# swap
[._]*.s[a-w][a-z]
[._]s[a-w][a-z]
# session
Session.vim
# temporary
.netrwhist
*~
# auto-generated tag files
tags


### Xcode ###
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## Build generated
build/
DerivedData/

## Various settings
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata/

## Other
*.moved-aside
*.xccheckout
*.xcscmblueprint
94 changes: 94 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
cmake_minimum_required (VERSION 3.0.2)
project(cudagl LANGUAGES CXX)

#### Check Dependencies ####
# https://cmake.org/cmake/help/v3.0/module/FindOpenGL.html
find_package(OpenGL REQUIRED)
find_package(CUDA REQUIRED)


#### Directory definition ####

set (PROJECT_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/include")
set (PROJECT_SRC_DIR "${PROJECT_SOURCE_DIR}/src")
set (PROJECT_DEPS_DIR "${PROJECT_SOURCE_DIR}/deps")
# PROJECT_SOURCE_DIR points to the project root folder
# PROJECT_BINARY_DIR points to the project build folder


#### Adding dependencies ####

# Adding external libs
add_subdirectory(${PROJECT_DEPS_DIR})


#### Source Files ####

# Gets the list of files inside the src directory
file(GLOB_RECURSE SOURCES "${PROJECT_SRC_DIR}/*.cpp" "${PROJECT_SRC_DIR}/*.c")
file(GLOB_RECURSE SOURCES_CUDA "${PROJECT_SRC_DIR}/*.cu")


#### Header Files ####

# -- CUDA --
include_directories(${CUDA_INCLUDE_DIRS})

# -- Project Includes --
include_directories("${PROJECT_INCLUDE_DIRS}")
cuda_include_directories("${PROJECT_INCLUDE_DIRS}")

## External includes

# -- FreeGLUT 3 --
include_directories(${FreeGLUT3_INCLUDE_DIRS})
cuda_include_directories("${FreeGLUT3_INCLUDE_DIRS}")

# -- GLEW 2 --
include_directories(${GLEW_INCLUDE_DIRS})
cuda_include_directories("${GLEW_INCLUDE_DIRS}")


#### Compilation ####

# Compilation Flags
set(COMPILE_FLAGS "")
set(LINKER_FLAGS "")

if (${CMAKE_CXX_COMPILER_ID} STREQUAL Clang)
set(COMPILE_FLAGS "${COMPILE_FLAGS} -W -Wall -pedantic -std=c++11 -Wshadow -O2 -g")
set(LINKER_FLAGS "${LINKER_FLAGS} -lm")
elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL GNU)
set(COMPILE_FLAGS "${COMPILE_FLAGS} -W -Wall -pedantic -std=c++11 -Wshadow -O2 -g")
set(LINKER_FLAGS "${LINKER_FLAGS} -lm")
elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL Intel)
# using Intel Compiler
elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
set(COMPILE_FLAGS "${COMPILE_FLAGS} /Wall")
set(LINKER_FLAGS "${LINKER_FLAGS}")
endif()

# Cmake compilation flags redefinition
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMPILE_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LINKER_FLAGS}")

set(cuda_additional_flags "--std=c++11")

# findCUDA Options
set(CUDA_VERBOSE_BUILD ON)
set(CUDA_SEPARABLE_COMPILATION ON) # Allow multiple CUDA files compilation

# Generating the commands to compile .cu into .ptx
CUDA_WRAP_SRCS(cudagl PTX CUDA_PTX_FILES ${SOURCES_CUDA}
OPTIONS ${cuda_additional_flags})

cuda_add_executable(cudagl ${SOURCES} ${SOURCES_CUDA} ${CUDA_PTX_FILES}
OPTIONS ${cuda_additional_flags})

target_link_libraries(cudagl
freeglut_static
GLEW
${CUDA_LIBRARIES}
${CUDA_CUDA_LIBRARY}
${CUDA_curand_LIBRARY}
)
52 changes: 50 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,50 @@
# cuda_opengl_cmake
This project shows how to integrate CUDA and OpenGL. Generating the Makefile with Cmake
# Cuda + OpenGL (with CMake)
This project shows how to integrate CUDA and OpenGL. Generating the Makefile with CMake

## Expected Output

After building and running the project (see below). You should see this:

![Expected Output](expected_output.png "Expected Output")

## Dependencies

You need to install:

* CUDA SDK
* OpenGL
* CMake 3.0+

## How to build (Windows)

To build on windows. Open the command line (or use the cmake gui)


* Check your Visual Studio version and change it if needed on the last step
* The CUDA SDK may be installed as 64bit version. If so, you need to use the `Win64` on the last command, otherwise you can omit it. If you omit it on 64bit versions you won't have access to libraries like: CURand or CUBLAS

```
mkdir build
cd build
cmake .. -G "Visual Studio 12 2013 Win64"
```

Open the project in Visual Studio.


## How to build (MacOS and Linux)

This step couldn't be tested, if you test it email me or create an issue saying
if it works or not.

```
mkdir build
cd build
cmake ..
make
```


## Contributors

* Matheus Faria (matheus.sousa.faria@gmail.com)
7 changes: 7 additions & 0 deletions deps/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# -- FreeGLUT 3 --
set(FREEGLUT_BUILD_SHARED_LIBS OFF)
add_subdirectory(freeglut3)
set(FreeGLUT3_INCLUDE_DIRS "deps/freeglut3/include" PARENT_SCOPE)

# -- GLEW 2 --
add_subdirectory("glew2")
32 changes: 32 additions & 0 deletions deps/freeglut3/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Makefile.in
Makefile
INSTALL
.deps
aclocal.m4
autom4te.cache
compile
config.guess
config.sub
configure
configure.cache
config.log
config.status
# config.h.in is now static and used with CMake, keep it:
#config.h.in
config.h
depcomp
install-sh
ltmain.sh
missing
stamp-h1
*.tar
*.tar.gz
*.tar.bz2
*.zip
*.o
*.a
*~
# my build dirs:
cross-android
cross-woe
native
45 changes: 45 additions & 0 deletions deps/freeglut3/AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
Pawel W. Olszta <olszta@sourceforge.net>
the person to be blamed for freeglut

Andreas Umbach <marvin@dataway.ch>
the first person to contribute to the freeglut project,
contributed the cube and sphere geometry code

Steve Baker <sjbaker1@airmail.net>
joystick code (from his great PLIB), numerous hints
tips on the freeglut usability
and for taking the project over when Pawel bowed out

Christopher John Purnell
Don Heyse
Dave McClurg
John F. Fay
Norman Vine
Daniel Wagner
Sven Panne <sven.panne@aedion.de>
contributing to the project, using the product, and generally keeping it going

Brian Paul
Eric Sandall
giving us the oomph! to make an official release

James 'J.C.' Jones
designing the new website

John Tsiombikas <nuclear@member.fsf.org>
Linux spaceball support, XR&R gamemode, misc linux fixes and breakages

Sylvain Beucler
support for Android, X11/EGL, OpenGL(ES) 2.x, misc fixes

Diederick C. Niehorster
Chris Marshall
Clive McCarthy
Eero Pajarre
Florian Echtler
Matti Lehtonen

Vincent Simonetti
support for BlackBerry

...and all the opengl-gamedev-l people that made Pawel start this project :)
Loading

0 comments on commit edf3806

Please # to comment.