Jump to content
  • Advertisement
Sign in to follow this  
h0wser

CMake noob in need of help..

This topic is 2054 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement

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

Share this post


Link to post
Share on other sites

 

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!