Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


CMake noob in need of help..

  • You cannot reply to this topic
2 replies to this topic

#1 h0wser   Members   -  Reputation: 220

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?


“Life isn't about finding yourself. Life is about creating yourself.”
― George Bernard Shaw

Sponsor:

#2 CRYP7IK   Members   -  Reputation: 988

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?

 

First you'll have your project cmakelist (above your ProjectDir):

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)

add_subdirectory(ProjectDir)

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
Gold Coast Studio Manager, Lead Programmer and IT Admin at Valhalla Studios Bifrost.

#3 h0wser   Members   -  Reputation: 220

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?

 

First you'll have your project cmakelist (above your ProjectDir):

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)

add_subdirectory(ProjectDir)

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.


“Life isn't about finding yourself. Life is about creating yourself.”
― George Bernard Shaw





PARTNERS