-2

I have the following source files:

main.cpp game.cpp TextureManager.cpp GameObject.cpp Map.cpp

and each of them (apart from main.cpp) has a header file with the same name:

game.h TextureManager.h GameObject.h Map.h

I can now compile my source files through the terminal using the following command:

g++ -std=gnu++11 -o executable main.cpp game.cpp TextureManager.cpp GameObject.cpp Map.cpp -lGL -lSDL2 -lSDL

What the make file should look like to compile the aforementioned source files and also incorporating the libraries and the g++ -std=gnu+11?

Acorn
  • 24,970
  • 5
  • 40
  • 69
toumperlekis
  • 39
  • 1
  • 9
  • 1
    I strongly recommend adding your attempt at the makefile for a couple reasons: 1. It gives answerers a good baseline of what you know that they can compose their answers around. 2. It shows that you have tried and aren't just some slacker trying to crowd source their brain. – user4581301 Jun 15 '18 at 18:57
  • 1
    Step 1) learn CMake. Step 2) Write CMakeLists.txt file. There's plenty of [documentation](https://cmake.org/documentation/) available. This is *not* a tutorial site. Do some research. Try things. Learn. Then come back and ask a *specific* question when you get stuck. – Jesper Juhl Jun 15 '18 at 18:59
  • Possible duplicate of [Automatically add all files in a folder to a target using CMake?](https://stackoverflow.com/questions/3201154/automatically-add-all-files-in-a-folder-to-a-target-using-cmake) – Tsyvarev Jun 17 '18 at 08:59

1 Answers1

2
cmake_minimum_required (VERSION 3.8)
project (game)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED on)

add_executable(game main.cpp game.cpp TextureManager.cpp GameObject.cpp Map.cpp)
target_link_libraries(game GL SDL2 SDL)
krisz
  • 2,686
  • 2
  • 11
  • 18