What you need to do is creating a CMakeLists.txt file which includes all your project configuration.
1. Installation
- Windows: You can download an installation package at http://www.cmake.org/cmake/resourcesEdit HTML/software.html
- Linux: Type the command line below
sudo apt-get install build-essential cmake
2. How to create a CMakeLists.txt to build your program
Let me show with a simple example of CMakeLists.txt.
# Specify the minimum version of CMake
cmake_minimum_required(VERSION 2.6)
# Define the name of your project. If possible, the project name
# should be different from the name of the executable file in case
# that you use eclipse as your IDE tool.
PROJECT( helloWorldPrj )
# List up all the source code files using SET keyword. Here, we
# have a file, main.cpp, for this project.
SET (
SRCS
main.cpp
)
# List up all your include directories
INCLUDE_DIRECTORIES (
${CMAKE_SOURCE_DIR}
)
# List up all your library directories
# As an example, your source code directory is specified.
LINK_DIRECTORIES (
${CMAKE_SOURCE_DIR}
)
# Specify all your source files with your executable name.
# Since SRCS is defined above, ${SRCS} is included here.
ADD_EXECUTABLE(helloWorld
${SRCS}
)
# List up all the libraries that are needed for the link
TARGET_LINK_LIBRARIES(helloWorld
# List your libraries if you have any
)
3. How to build your program with CMakeLists.txt:
- cmake
- cmake-gui
- qtcreator
- Eclipse
4. How to build your CUDA program with CMakeLists.txt:
In your CMakeLists.txt, add command lines below. Note that the minimum version of CMake is 2.8.
The CMakeLists.txt is downloadable at http://vrinside.net/myfiles/simplecuda_cmake.zip
# finding the CUDA path
FIND_PACKAGE(CUDA)
# Add the CUDA header file and library directories and CUDA libraries
INCLUDE(FindCUDA)
# The command line below is to create a file group for Visual
# Studio users
IF(WIN32)
SOURCE_GROUP("CUDA Files" FILES ${CUDA_SRC})
ENDIF(WIN32)
# Replace ADD_EXECUTABLE with CUDA_ADD_EXECUTABLE
CUDA_ADD_EXECUTABLE(${TARGET_NAME}
${SRCS}
${CUDA_SRCS}
)
5. How to build your OpenMP program:
Please add the command lines below in your CMakeLists.txt
SET(CMAKE_CXX_FLAGS “${CMAKE_CXX_FLAGS} -fopenmp”)
SET(CMAKE_C_FLAGS “${CMAKE_C_FLAGS} -fopenmp”)
6. How to create an install option for your Makefile
e.g.)
INSTALL_FILES (/$ENV{VR_ROOT_PATH}/include/vrio FILES ${IO_HEADER})
7. How to test environment variables in IF command
SET (MYVAR1 $ENV{TACC_CUDA_DIR})
IF (MYVAR1)
...
ENDIF (MYVAR1)
8. How to execute command and assign the result to a variableEXECUTE_PROCESS(COMMAND echo $ENV{TACC_CUDA_DIR} OUTPUT_VARIABLE MYVAL2)
9. Links
http://vtk.org/Wiki/CMake
No comments:
Post a Comment