From aa593870dff51a012d64f8799de594bc202d2e65 Mon Sep 17 00:00:00 2001 From: MitchellHansen Date: Sun, 16 Jul 2017 14:04:41 -0700 Subject: [PATCH] restructuring and updating CMakeLists --- CMakeLists.txt | 118 +++++++++++++++++++----- background.png => assets/background.png | Bin screeny.png => assets/screeny.png | Bin App.h => include/App.h | 0 Explorer.h => include/Explorer.h | 0 Map.h => include/Map.h | 0 Pather.h => include/Pather.h | 0 Tile.h => include/Tile.h | 2 +- node.h => include/node.h | 0 App.cpp => src/App.cpp | 2 +- Explorer.cpp => src/Explorer.cpp | 0 Map.cpp => src/Map.cpp | 0 Pather.cpp => src/Pather.cpp | 0 Tile.cpp => src/Tile.cpp | 0 main.cpp => src/main.cpp | 0 node.cpp => src/node.cpp | 0 16 files changed, 96 insertions(+), 26 deletions(-) rename background.png => assets/background.png (100%) rename screeny.png => assets/screeny.png (100%) rename App.h => include/App.h (100%) rename Explorer.h => include/Explorer.h (100%) rename Map.h => include/Map.h (100%) rename Pather.h => include/Pather.h (100%) rename Tile.h => include/Tile.h (92%) rename node.h => include/node.h (100%) rename App.cpp => src/App.cpp (98%) rename Explorer.cpp => src/Explorer.cpp (100%) rename Map.cpp => src/Map.cpp (100%) rename Pather.cpp => src/Pather.cpp (100%) rename Tile.cpp => src/Tile.cpp (100%) rename main.cpp => src/main.cpp (100%) rename node.cpp => src/node.cpp (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index a8c0271..bca96d7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,33 +1,103 @@ -# Check versions message(STATUS "CMake version: ${CMAKE_VERSION}") -cmake_minimum_required(VERSION 3.1) -set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}) +# Check versions +message(STATUS "CMake version: ${CMAKE_VERSION}") +cmake_minimum_required(VERSION 3.1) -# Set the project name -set(PNAME floppy-bird) -project(${PNAME}) +set_property(GLOBAL PROPERTY USE_FOLDERS ON) -# Set up variables, and find SFML -set(SFML_ROOT root CACHE STRING "User specified path") -set(SFML_COMPONENTS graphics window system network audio) +# Set the project name +set(PNAME a-star) +project(${PNAME}) + +# Set up variables, and find SFML +if (WIN32) + set(SFML_ROOT root CACHE STRING "User specified path") + set(SFML_INCLUDE_DIR ${SFML_ROOT}/include) +endif() + +set(SFML_COMPONENTS graphics window system network audio) set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}) +find_package(SFML 2.4 COMPONENTS ${SFML_COMPONENTS} REQUIRED) +message(STATUS "SFML found: ${SFML_FOUND}") + +if (WIN32) + # Find GLEW + find_package(GLEW REQUIRED) + message(STATUS "GLEW found: ${GLEW_FOUND}") +endif() + +# Find OpenGL +find_package(OpenGL REQUIRED) +message(STATUS "OpenGL found: ${OPENGL_FOUND}") + +# Include the directories for the main program, GL, and SFML +include_directories(${SFML_INCLUDE_DIR}) +include_directories(${OpenGL_INCLUDE_DIRS}) +include_directories(include) + +# Glob all thr sources into their values +file(GLOB_RECURSE SOURCES "src/*.cpp") +file(GLOB_RECURSE HEADERS "include/*.h" "include/*.hpp") +file(GLOB_RECURSE SHADERS "shaders/*.vert" "shaders/*.tesc" "shaders/*.tese" "shaders/*.geom" "shaders/*.frag" "shaders/*.comp") + +add_executable(${PNAME} ${SOURCES} ${HEADERS} ${KERNELS} ${SHADERS}) + +# Follow the sub directory structure to add sub-filters in VS +# Gotta do it one by one unfortunately + +foreach (source IN ITEMS ${SOURCES}) + if (IS_ABSOLUTE "${source}") + + get_filename_component(filename ${source} DIRECTORY) + + STRING(REGEX REPLACE "/" "\\\\" filename ${filename}) + + string(REGEX MATCHALL "src(.*)" substrings ${filename}) + list(GET substrings 0 substring) + + SOURCE_GROUP(${substring} FILES ${source}) + + endif() +endforeach() + +foreach (source IN ITEMS ${HEADERS}) + if (IS_ABSOLUTE "${source}") + + get_filename_component(filename ${source} DIRECTORY) + + STRING(REGEX REPLACE "/" "\\\\" filename ${filename}) + + string(REGEX MATCHALL "include(.*)" substrings ${filename}) + list(GET substrings 0 substring) + + SOURCE_GROUP(${substring} FILES ${source}) + + endif() +endforeach() + +foreach (source IN ITEMS ${SHADERS}) + if (IS_ABSOLUTE "${source}") -find_package(SFML 2.1 COMPONENTS ${SFML_COMPONENTS} REQUIRED) -message(STATUS "SFML found: ${SFML_FOUND}") + get_filename_component(filename ${source} DIRECTORY) -# Include the directories for the main program, GL, CL and SFML's headers -include_directories(${SFML_INCLUDE_DIR}) -include_directories(include) + STRING(REGEX REPLACE "/" "\\\\" filename ${filename}) + + string(REGEX MATCHALL "shaders(.*)" substrings ${filename}) + list(GET substrings 0 substring) + + SOURCE_GROUP(${substring} FILES ${source}) + + endif() +endforeach() -# Set the sources, allows VS to filter them properly -file(GLOB SOURCES "*.cpp") -file(GLOB HEADERS "*.h") +# Link CL, GL, and SFML +target_link_libraries (${PNAME} ${SFML_LIBRARIES} ${SFML_DEPENDENCIES}) +target_link_libraries (${PNAME} ${OPENGL_LIBRARIES}) +target_link_libraries (${PNAME} ${GLEW_LIBRARIES}) -add_executable(${PNAME} ${SOURCES}) +if (NOT WIN32) + target_link_libraries (${PNAME} -lpthread) +endif() -# Link CL, GL, and SFML -target_link_libraries (${PNAME} ${SFML_LIBRARIES} ${SFML_DEPENDENCIES}) +# Setup to use C++14 +set_property(TARGET ${PNAME} PROPERTY CXX_STANDARD 14) -# Setup to use C++11 + others -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread") -set_property(TARGET ${PNAME} PROPERTY CXX_STANDARD 11) # Use C++11 \ No newline at end of file diff --git a/background.png b/assets/background.png similarity index 100% rename from background.png rename to assets/background.png diff --git a/screeny.png b/assets/screeny.png similarity index 100% rename from screeny.png rename to assets/screeny.png diff --git a/App.h b/include/App.h similarity index 100% rename from App.h rename to include/App.h diff --git a/Explorer.h b/include/Explorer.h similarity index 100% rename from Explorer.h rename to include/Explorer.h diff --git a/Map.h b/include/Map.h similarity index 100% rename from Map.h rename to include/Map.h diff --git a/Pather.h b/include/Pather.h similarity index 100% rename from Pather.h rename to include/Pather.h diff --git a/Tile.h b/include/Tile.h similarity index 92% rename from Tile.h rename to include/Tile.h index 7b07e76..08b7465 100644 --- a/Tile.h +++ b/include/Tile.h @@ -1,5 +1,5 @@ #pragma once -#include +#include class Tile { public: diff --git a/node.h b/include/node.h similarity index 100% rename from node.h rename to include/node.h diff --git a/App.cpp b/src/App.cpp similarity index 98% rename from App.cpp rename to src/App.cpp index 2ca1443..fc371fd 100644 --- a/App.cpp +++ b/src/App.cpp @@ -19,7 +19,7 @@ void App::Init() { // Set up the background texture background_texture = new sf::Texture(); - background_texture->loadFromFile("background.png"); + background_texture->loadFromFile("../assets/background.png"); backgroundSprite.setTexture(*background_texture); // Pixel array for drawing the tiles, explorer diff --git a/Explorer.cpp b/src/Explorer.cpp similarity index 100% rename from Explorer.cpp rename to src/Explorer.cpp diff --git a/Map.cpp b/src/Map.cpp similarity index 100% rename from Map.cpp rename to src/Map.cpp diff --git a/Pather.cpp b/src/Pather.cpp similarity index 100% rename from Pather.cpp rename to src/Pather.cpp diff --git a/Tile.cpp b/src/Tile.cpp similarity index 100% rename from Tile.cpp rename to src/Tile.cpp diff --git a/main.cpp b/src/main.cpp similarity index 100% rename from main.cpp rename to src/main.cpp diff --git a/node.cpp b/src/node.cpp similarity index 100% rename from node.cpp rename to src/node.cpp