Clean up CMakeLists in all C++ examples

+ Rename output executables to match directory structure
+ Remove libraries for small examples
+ Supress -Wreturn-type warnings for singleton that is intentionally not copyable
This commit is contained in:
2022-03-31 16:01:08 -04:00
parent 573fc4e1e8
commit a97dfbe34b
98 changed files with 695 additions and 598 deletions

View File

@@ -1,13 +1,13 @@
###############################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: A root project for practicing C++ ##
## This project can be built to debug and run all nested projects ##
## Or, any subdirectory with a project() statement can be selected ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
##############################################################################
#
################################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: A root project for practicing C++ ##
## This project can be built to debug and run all nested projects ##
## Or, any subdirectory with a project() statement can be selected ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################
cmake_minimum_required(VERSION 3.15)
project(

View File

@@ -1,10 +1,9 @@
###############################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
##############################################################################
#
################################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################
# Define CMake version
cmake_minimum_required(VERSION 3.15)
@@ -15,15 +14,15 @@ project(
LANGUAGES CXX
)
add_library(lib-opengl-test "src/lib-opengl-test.cpp")
target_include_directories(lib-opengl-test PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src)
add_library(graphics-lib-opengl src/lib-opengl-test.cpp)
target_include_directories(graphics-lib-opengl PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src)
# Find OpenGL package
find_package(OpenGL REQUIRED)
if (OPENGL_FOUND)
# Link opengl-test executable to OpenGL
target_include_directories(lib-opengl-test PUBLIC ${OPENGL_INCLUDE_DIR})
target_link_libraries(lib-opengl-test PUBLIC ${OPENGL_LIBRARIES})
target_include_directories(graphics-lib-opengl PUBLIC ${OPENGL_INCLUDE_DIR})
target_link_libraries(graphics-lib-opengl PUBLIC ${OPENGL_LIBRARIES})
else()
message(
"Error: CMake was unable to find the OpenGL package\n"
@@ -35,8 +34,8 @@ endif()
find_package(GLUT REQUIRED)
if (GLUT_FOUND)
# Link lib-opengl-test executable to GLUT
target_include_directories(lib-opengl-test PUBLIC ${GLUT_INCLUDE_DIR})
target_link_libraries(lib-opengl-test PUBLIC ${GLUT_LIBRARIES})
target_include_directories(graphics-lib-opengl PUBLIC ${GLUT_INCLUDE_DIR})
target_link_libraries(graphics-lib-opengl PUBLIC ${GLUT_LIBRARIES})
else()
message(
"Error: CMake was unable to find the GLUT package\n"
@@ -45,6 +44,6 @@ else()
endif()
# Add test executable
add_executable(opengl-test "apps/test-gl.cpp")
target_link_libraries(opengl-test PRIVATE lib-opengl-test)
target_include_directories(opengl-test PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src)
add_executable(graphics-cmake-opengl apps/test-gl.cpp)
target_link_libraries(graphics-cmake-opengl PRIVATE graphics-lib-opengl)
target_include_directories(graphics-cmake-opengl PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src)

View File

@@ -1,10 +1,9 @@
###############################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
##############################################################################
#
################################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################
# Define CMake version
cmake_minimum_required(VERSION 3.15)
@@ -17,16 +16,15 @@ project(
# Add Library
add_library(
lib-sdl-test # Library Name
"src/lib-sdl-test.cpp" # Sources..
"src/lib-sdl-test.h"
graphics-lib-sdl # Library Name
src/lib-sdl-test.cpp src/lib-sdl-test.h # Sources..
)
target_include_directories( # When calling library, include a directory
lib-sdl-test # Library name
graphics-lib-sdl # Library name
PUBLIC # Visibility
"${CMAKE_CURRENT_SOURCE_DIR}/src" # Source directory for library
)
${CMAKE_CURRENT_SOURCE_DIR}/src # Source directory for library
)
# Search for SDL2 package
find_package(SDL2 REQUIRED sdl2)
@@ -35,20 +33,20 @@ find_package(SDL2 REQUIRED sdl2)
if (SDL2_FOUND)
# Any target that links with this library will also link to SDL2
# + Because we choose PUBLIC visibility
target_include_directories(lib-sdl-test PUBLIC ${SDL2_INCLUDE_DIRS})
target_link_libraries(lib-sdl-test PUBLIC "${SDL2_LIBRARIES}")
target_include_directories(graphics-lib-sdl PUBLIC ${SDL2_INCLUDE_DIRS})
target_link_libraries(graphics-lib-sdl PUBLIC "${SDL2_LIBRARIES}")
# Creating executable
add_executable(
sdl-test # Exe name
"apps/sdl-test.cpp" # Exe Source(s)
graphics-cmake-sdl # Exe name
apps/sdl-test.cpp # Exe Source(s)
)
# Linking the exe to library
target_link_libraries(
sdl-test # Executable to link
graphics-cmake-sdl # Executable to link
PRIVATE # Visibility
lib-sdl-test # Library to link
graphics-lib-sdl # Library to link
)
else()