• Create Account

## CMake noob in need of help..

2 replies to this topic

### #1h0wser  Members

221
Like
0Likes
Like

Posted 01 March 2014 - 04:04 AM

So I recently started a project that I'm developing in Linux. So I want to use CMake to build this project but I'm not sure on how CMake really works. I have looked at a few examples and tried using them but I have trouble wrapping my head around all of this.

My directory structure looks like this

ProjectDir
src
-file.cpp
-file.h
dir1
-otherfile.cpp
test
-main.cpp
build
//build stuff goes here


Where I want the file in the src directory to be built as a library.

The test directory to be built as an executable linking to the library from src

Anyone have any guidelines on what my CMakeLists.txt should look like?

― George Bernard Shaw

### #2CRYP7IK  Members

1283
Like
0Likes
Like

Posted 02 March 2014 - 05:16 PM

So I recently started a project that I'm developing in Linux. So I want to use CMake to build this project but I'm not sure on how CMake really works. I have looked at a few examples and tried using them but I have trouble wrapping my head around all of this.

My directory structure looks like this

ProjectDir
src
-file.cpp
-file.h
dir1
-otherfile.cpp
test
-main.cpp
build
//build stuff goes here


Where I want the file in the src directory to be built as a library.

The test directory to be built as an executable linking to the library from src

Anyone have any guidelines on what my CMakeLists.txt should look like?

cmake_minimum_required(VERSION 2.8.3) #Or whatever version

project(ProjectName) #This is the 'solution' in visual studio or workspace in most other things

set(Project_VERSION_MAJOR 0)
set(Project_VERSION_MINOR 1)
set(Project_VERSION_PATCH 0)



Then in your ProjectDir you would have another one:

file(includefiles
"include/file1.h"
"include/file2.h"
)

file(sourcefiles
"src/file1.cpp"
"src/file2.cpp"
)

add_library(ProjectDir SHARED #Remove shared if you want a static library
${includefiles}${sourcefiles}
)

include_directories("include/")


If you only ever plan on having one project you can just have 1 CMakeList with the above combined. I recommend keeping your include and source files seperate as this way it's easier to write an 'install' cmakelist.

Edited by CRYP7IK, 02 March 2014 - 05:18 PM.

To accomplish great things we must first dream, then visualize, then plan...believe... act! - Alfred A. Montapert
C# Programmer and Unity Developer at Well Placed Cactus.

### #3h0wser  Members

221
Like
0Likes
Like

Posted 03 March 2014 - 12:10 PM

So I recently started a project that I'm developing in Linux. So I want to use CMake to build this project but I'm not sure on how CMake really works. I have looked at a few examples and tried using them but I have trouble wrapping my head around all of this.

My directory structure looks like this

ProjectDir
src
-file.cpp
-file.h
dir1
-otherfile.cpp
test
-main.cpp
build
//build stuff goes here


Where I want the file in the src directory to be built as a library.

The test directory to be built as an executable linking to the library from src

Anyone have any guidelines on what my CMakeLists.txt should look like?

cmake_minimum_required(VERSION 2.8.3) #Or whatever version

project(ProjectName) #This is the 'solution' in visual studio or workspace in most other things

set(Project_VERSION_MAJOR 0)
set(Project_VERSION_MINOR 1)
set(Project_VERSION_PATCH 0)



Then in your ProjectDir you would have another one:

file(includefiles
"include/file1.h"
"include/file2.h"
)

file(sourcefiles
"src/file1.cpp"
"src/file2.cpp"
)

add_library(ProjectDir SHARED #Remove shared if you want a static library
${includefiles}${sourcefiles}
)

include_directories("include/")


If you only ever plan on having one project you can just have 1 CMakeList with the above combined. I recommend keeping your include and source files seperate as this way it's easier to write an 'install' cmakelist.

huh wasn't as hard as I though it would be, really clicked this time. Thanks for your help.