From 5411ec4f03df06f83f8f3d1634bcec0900a855b7 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Thu, 22 Apr 2021 09:43:53 +0200 Subject: [PATCH] Hook up examples to CMake --- .gitignore | 2 ++ CMakeLists.txt | 19 +++++++++++------ README.md | 1 + examples/CMakeLists.txt | 45 +++++++++++++++++++++++++++++++++++++++++ examples/Makefile | 8 -------- 5 files changed, 61 insertions(+), 14 deletions(-) create mode 100644 examples/CMakeLists.txt delete mode 100644 examples/Makefile diff --git a/.gitignore b/.gitignore index 07a07d57..43b29fc5 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ cmake_install.cmake Makefile *.so* *.a +*.exe +bin/Linux diff --git a/CMakeLists.txt b/CMakeLists.txt index 5adbb4f7..58e706e7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,17 +8,19 @@ project(Irrlicht message(STATUS "*** Building IrrlichtMt ${PROJECT_VERSION} ***") if(ANDROID) - set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib/Android) + set(sysname Android) elseif(APPLE) - set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib/OSX) + set(sysname OSX) +elseif(MSVC) + set(sysname Win32-VisualStudio) elseif(WIN32) - # good enough - set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib/Win32-gcc) + set(sysname Win32-gcc) else() - set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib/Linux) + set(sysname Linux) endif() +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib/${sysname}) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}) -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/${sysname}) if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type: Debug or Release" FORCE) @@ -27,6 +29,11 @@ endif() list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") add_subdirectory(source/Irrlicht) +option(BUILD_EXAMPLES "Build example applications" FALSE) +if(BUILD_EXAMPLES) + add_subdirectory(examples) +endif() + # Installation of library and headers. include(GNUInstallDirs) install(TARGETS ${INSTALL_TARGETS} diff --git a/README.md b/README.md index aedc0735..243cdea9 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ The following libraries are required to be installed: Aside from standard search options (`ZLIB_INCLUDE_DIR`, `ZLIB_LIBRARY`, ...) the following options are available: * `BUILD_SHARED_LIBS` (default: `ON`) - Build IrrlichtMt as a shared library +* `BUILD_EXAMPLES` (default: `OFF`) - Build example applications e.g. on a Linux system you might want to build for local use like this: diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt new file mode 100644 index 00000000..e35f38cf --- /dev/null +++ b/examples/CMakeLists.txt @@ -0,0 +1,45 @@ + +set(IRREXAMPLES + 01.HelloWorld + 02.Quake3Map + 03.CustomSceneNode + 04.Movement + 05.UserInterface + 06.2DGraphics + 07.Collision + 08.SpecialFX + 09.Meshviewer + 10.Shaders + 11.PerPixelLighting + 12.TerrainRendering + 13.RenderToTexture + 15.LoadIrrFile + 16.Quake3MapShader + 18.SplitScreen + 19.MouseAndJoystick + 20.ManagedLights + 21.Quake3Explorer + 22.MaterialViewer + 23.SMeshHandling + 24.CursorControl + 25.XmlHandling + 26.OcclusionQuery + 27.PostProcessing + 28.CubeMapping + 30.Profiling +) + +if(WIN32) + list(APPEND IRREXAMPLES 14.Win32Window) +endif() + +foreach(exname IN ITEMS ${IRREXAMPLES}) + file(GLOB sources "${CMAKE_CURRENT_SOURCE_DIR}/${exname}/*.cpp") + add_executable(${exname} ${sources}) + + target_include_directories(${exname} PRIVATE + ${CMAKE_SOURCE_DIR}/include + ${CMAKE_CURRENT_SOURCE_DIR}/${exname} + ) + target_link_libraries(${exname} IrrlichtMt) +endforeach() diff --git a/examples/Makefile b/examples/Makefile deleted file mode 100644 index e187a005..00000000 --- a/examples/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -DIRS = $(wildcard [0123]* Demo) - -all: $(DIRS) - -$(DIRS): - -@cd $@ && make clean && make - -.PHONY: $(DIRS)