From 9821725c6bafeaf4153ab8604e692dfe13cbff09 Mon Sep 17 00:00:00 2001 From: hristo Date: Thu, 14 Jan 2021 00:10:02 +0200 Subject: [PATCH] Big cmake changes (#1514) * Delete emscripten.cmake This file is not needed at this point. EMSDK provides a toolchain file that has a lot more things in it and is better supported. Project currently works fine with the documentation provided in Emscripten SDK on how to build projects. * First pass file separation. The main two files are cleaner now. Only important things can be seen. Major changes include: - raylib_static is now the alias instead of raylib - Repeating segments are removed and pulled into separate files into /cmake - File is reordered to make more sense - Installs are better structured - Library is build into an output directory "raylib" instead of "src" - All public header files are now set as a public header file - Source files need to be listed (it is a bad practice to capture them using wildcards and file globs) - CMakeLists are better commented * Second pass on the example dirs. They are quite complex so I'm more hesitant to do major changes. Also it works pretty well. Noticed that I forgot one of the seperated files and added it into src/CMakeLists.txt. * Returned the header copy as it was convenient to have the public headers copied. * A better description to the variable RAYLIB_IS_MAIN Co-authored-by: Rob Loach * Remove debug message Co-authored-by: Rob Loach * Improvements based on review. * Simplify the install condition to not be platform specific as it was before. Co-authored-by: Alexander Neumann <30894796+Neumann-A@users.noreply.github.com> * Remove some CMAKE variables as they don't affect the build in any way Co-authored-by: Alexander Neumann <30894796+Neumann-A@users.noreply.github.com> Co-authored-by: Rob Loach Co-authored-by: Alexander Neumann <30894796+Neumann-A@users.noreply.github.com> --- CMakeLists.txt | 54 +-- src/CMakeOptions.txt => CMakeOptions.txt | 39 +-- cmake/BuildOptions.cmake | 39 +++ cmake/BuildType.cmake | 43 --- cmake/CompilerFlags.cmake | 33 ++ cmake/GlfwImport.cmake | 29 ++ cmake/InstallConfigurations.cmake | 29 ++ cmake/LibraryConfigurations.cmake | 109 ++++++ cmake/PackConfigurations.cmake | 13 + cmake/emscripten.cmake | 23 -- examples/CMakeLists.txt | 15 - src/CMakeLists.txt | 402 ++++++----------------- src/config.h | 2 +- 13 files changed, 375 insertions(+), 455 deletions(-) rename src/CMakeOptions.txt => CMakeOptions.txt (85%) create mode 100644 cmake/BuildOptions.cmake delete mode 100644 cmake/BuildType.cmake create mode 100644 cmake/CompilerFlags.cmake create mode 100644 cmake/GlfwImport.cmake create mode 100644 cmake/InstallConfigurations.cmake create mode 100644 cmake/LibraryConfigurations.cmake create mode 100644 cmake/PackConfigurations.cmake delete mode 100644 cmake/emscripten.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index e3fbd117..8c5d2113 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,57 +1,27 @@ cmake_minimum_required(VERSION 3.0) +project(raylib) + +# Directory for easier includes set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) +# RAYLIB_IS_MAIN determines whether the project is being used from root, or as a dependency. if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}") set(RAYLIB_IS_MAIN TRUE) else() set(RAYLIB_IS_MAIN FALSE) endif() -# Config options -option(BUILD_EXAMPLES "Build the examples." ${RAYLIB_IS_MAIN}) -option(ENABLE_ASAN "Enable AddressSanitizer (ASAN) for debugging (degrades performance)" OFF) -option(ENABLE_UBSAN "Enable UndefinedBehaviorSanitizer (UBSan) for debugging" OFF) -option(ENABLE_MSAN "Enable MemorySanitizer (MSan) for debugging (not recommended to run with ASAN)" OFF) - -# This helps support the case where emsdk toolchain file is used -# either by setting it with -DCMAKE_TOOLCHAIN_FILE=/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake -# or by using "emcmake cmake -B build -S ." as described in https://emscripten.org/docs/compiling/Building-Projects.html -if(EMSCRIPTEN) - SET(PLATFORM Web CACHE STRING "Forcing PLATFORM_WEB because EMSCRIPTEN was detected") -endif() - -if(CMAKE_VERSION VERSION_LESS "3.1") - if(CMAKE_C_COMPILER_ID STREQUAL "GNU") - set(CMAKE_C_FLAGS "-std=gnu99 ${CMAKE_C_FLAGS}") - endif() -else() - set (CMAKE_C_STANDARD 99) -endif() - -include(AddIfFlagCompiles) -add_if_flag_compiles(-Werror=pointer-arith CMAKE_C_FLAGS) -add_if_flag_compiles(-Werror=implicit-function-declaration CMAKE_C_FLAGS) -# src/external/jar_xm.h does shady stuff -add_if_flag_compiles(-fno-strict-aliasing CMAKE_C_FLAGS) +# Sets compiler flags and language standard +include(CompilerFlags) -if (ENABLE_ASAN) - add_if_flag_compiles(-fno-omit-frame-pointer CMAKE_C_FLAGS CMAKE_LINKER_FLAGS) - add_if_flag_compiles(-fsanitize=address CMAKE_C_FLAGS CMAKE_LINKER_FLAGS) -endif() -if (ENABLE_UBSAN) - add_if_flag_compiles(-fno-omit-frame-pointer CMAKE_C_FLAGS CMAKE_LINKER_FLAGS) - add_if_flag_compiles(-fsanitize=undefined CMAKE_C_FLAGS CMAKE_LINKER_FLAGS) -endif() -if (ENABLE_MSAN) - add_if_flag_compiles(-fno-omit-frame-pointer CMAKE_C_FLAGS CMAKE_LINKER_FLAGS) - add_if_flag_compiles(-fsanitize=memory CMAKE_C_FLAGS CMAKE_LINKER_FLAGS) -endif() +# Registers build options that are exposed to cmake +include(CMakeOptions.txt) -if (ENABLE_MSAN AND ENABLE_ASAN) - MESSAGE(WARNING "Compiling with both AddressSanitizer and MemorySanitizer is not recommended") -endif() +# Checks a few environment and compiler configurations +include(BuildOptions) -add_subdirectory(src) +# Main sources directory (the second parameter sets the output directory name to raylib) +add_subdirectory(src raylib) if (${BUILD_EXAMPLES}) MESSAGE(STATUS "Building examples is enabled") diff --git a/src/CMakeOptions.txt b/CMakeOptions.txt similarity index 85% rename from src/CMakeOptions.txt rename to CMakeOptions.txt index 7eff4c89..f39d17a1 100644 --- a/src/CMakeOptions.txt +++ b/CMakeOptions.txt @@ -6,6 +6,12 @@ enum_option(PLATFORM "Desktop;Web;Android;Raspberry Pi;DRM" "Platform to build f enum_option(OPENGL_VERSION "OFF;3.3;2.1;1.1;ES 2.0" "Force a specific OpenGL Version?") +# Configuration options +option(BUILD_EXAMPLES "Build the examples." ${RAYLIB_IS_MAIN}) +option(ENABLE_ASAN "Enable AddressSanitizer (ASAN) for debugging (degrades performance)" OFF) +option(ENABLE_UBSAN "Enable UndefinedBehaviorSanitizer (UBSan) for debugging" OFF) +option(ENABLE_MSAN "Enable MemorySanitizer (MSan) for debugging (not recommended to run with ASAN)" OFF) + # Shared library is always PIC. Static library should be PIC too if linked into a shared library option(WITH_PIC "Compile static library as position-independent code" OFF) option(SHARED "Build raylib as a dynamic library" OFF) @@ -80,36 +86,3 @@ option(SUPPORT_FILEFORMAT_FLAC "Support loading FLAC for sound" ${OFF}) # utils.c option(SUPPORT_TRACELOG "Show TraceLog() output messages. NOTE: By default LOG_DEBUG traces not shown" ON) - -if(NOT (STATIC OR SHARED)) - message(FATAL_ERROR "Nothing to do if both -DSHARED=OFF and -DSTATIC=OFF...") -endif() - -if (DEFINED BUILD_SHARED_LIBS) - set(SHARED ${BUILD_SHARED_LIBS}) - if (${BUILD_SHARED_LIBS}) - set(STATIC OFF) - else() - set(STATIC ON) - endif() -endif() -if(DEFINED SHARED_RAYLIB) - set(SHARED ${SHARED_RAYLIB}) - message(DEPRECATION "-DSHARED_RAYLIB is deprecated. Please use -DSHARED instead.") -endif() -if(DEFINED STATIC_RAYLIB) - set(STATIC ${STATIC_RAYLIB}) - message(DEPRECATION "-DSTATIC_RAYLIB is deprecated. Please use -DSTATIC instead.") -endif() - -if(${PLATFORM} MATCHES "Desktop" AND APPLE) - if(MACOS_FATLIB) - if (CMAKE_OSX_ARCHITECTURES) - message(FATAL_ERROR "User supplied -DCMAKE_OSX_ARCHITECTURES overrides -DMACOS_FATLIB=ON") - else() - set(CMAKE_OSX_ARCHITECTURES "x86_64;i386") - endif() - endif() -endif() - -# vim: ft=cmake diff --git a/cmake/BuildOptions.cmake b/cmake/BuildOptions.cmake new file mode 100644 index 00000000..00586c23 --- /dev/null +++ b/cmake/BuildOptions.cmake @@ -0,0 +1,39 @@ +if(NOT (STATIC OR SHARED)) + message(FATAL_ERROR "Nothing to do if both -DSHARED=OFF and -DSTATIC=OFF...") +endif() + +if (DEFINED BUILD_SHARED_LIBS) + set(SHARED ${BUILD_SHARED_LIBS}) + if (${BUILD_SHARED_LIBS}) + set(STATIC OFF) + else() + set(STATIC ON) + endif() +endif() +if(DEFINED SHARED_RAYLIB) + set(SHARED ${SHARED_RAYLIB}) + message(DEPRECATION "-DSHARED_RAYLIB is deprecated. Please use -DSHARED instead.") +endif() +if(DEFINED STATIC_RAYLIB) + set(STATIC ${STATIC_RAYLIB}) + message(DEPRECATION "-DSTATIC_RAYLIB is deprecated. Please use -DSTATIC instead.") +endif() + +if(${PLATFORM} MATCHES "Desktop" AND APPLE) + if(MACOS_FATLIB) + if (CMAKE_OSX_ARCHITECTURES) + message(FATAL_ERROR "User supplied -DCMAKE_OSX_ARCHITECTURES overrides -DMACOS_FATLIB=ON") + else() + set(CMAKE_OSX_ARCHITECTURES "x86_64;i386") + endif() + endif() +endif() + +# This helps support the case where emsdk toolchain file is used +# either by setting it with -DCMAKE_TOOLCHAIN_FILE=/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake +# or by using "emcmake cmake -B build -S ." as described in https://emscripten.org/docs/compiling/Building-Projects.html +if(EMSCRIPTEN) + SET(PLATFORM Web CACHE STRING "Forcing PLATFORM_WEB because EMSCRIPTEN was detected") +endif() + +# vim: ft=cmake diff --git a/cmake/BuildType.cmake b/cmake/BuildType.cmake deleted file mode 100644 index 80ccdee2..00000000 --- a/cmake/BuildType.cmake +++ /dev/null @@ -1,43 +0,0 @@ -# Set a default build type if none was specified -set(default_build_type "Release") -if(EXISTS "${CMAKE_SOURCE_DIR}/.git") - set(default_build_type "Debug") -endif() - -if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) - message(STATUS "Setting build type to '${default_build_type}' as none was specified.") - set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE - STRING "Choose the type of build." FORCE) - # Set the possible values of build type for cmake-gui - set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" - "MinSizeRel" "RelWithDebInfo") -endif() - -# Taken from the https://github.com/OpenChemistry/tomviz project -# Copyright (c) 2014-2017, Kitware, Inc. -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# 1. Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# 2. Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# 3. Neither the name of the copyright holder nor the names of its contributors -# may be used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR -# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/cmake/CompilerFlags.cmake b/cmake/CompilerFlags.cmake new file mode 100644 index 00000000..41fee692 --- /dev/null +++ b/cmake/CompilerFlags.cmake @@ -0,0 +1,33 @@ +include(AddIfFlagCompiles) + +add_if_flag_compiles(-Werror=pointer-arith CMAKE_C_FLAGS) +add_if_flag_compiles(-Werror=implicit-function-declaration CMAKE_C_FLAGS) +# src/external/jar_xm.h does shady stuff +add_if_flag_compiles(-fno-strict-aliasing CMAKE_C_FLAGS) + +if (ENABLE_ASAN) + add_if_flag_compiles(-fno-omit-frame-pointer CMAKE_C_FLAGS CMAKE_LINKER_FLAGS) + add_if_flag_compiles(-fsanitize=address CMAKE_C_FLAGS CMAKE_LINKER_FLAGS) +endif() +if (ENABLE_UBSAN) + add_if_flag_compiles(-fno-omit-frame-pointer CMAKE_C_FLAGS CMAKE_LINKER_FLAGS) + add_if_flag_compiles(-fsanitize=undefined CMAKE_C_FLAGS CMAKE_LINKER_FLAGS) +endif() +if (ENABLE_MSAN) + add_if_flag_compiles(-fno-omit-frame-pointer CMAKE_C_FLAGS CMAKE_LINKER_FLAGS) + add_if_flag_compiles(-fsanitize=memory CMAKE_C_FLAGS CMAKE_LINKER_FLAGS) +endif() + +if (ENABLE_MSAN AND ENABLE_ASAN) + MESSAGE(WARNING "Compiling with both AddressSanitizer and MemorySanitizer is not recommended") +endif() + +add_definitions("-DRAYLIB_CMAKE=1") + +if(CMAKE_VERSION VERSION_LESS "3.1") + if(CMAKE_C_COMPILER_ID STREQUAL "GNU") + add_if_flag_compiles(-std=gnu99 CMAKE_C_FLAGS) + endif() +else() + set (CMAKE_C_STANDARD 99) +endif() diff --git a/cmake/GlfwImport.cmake b/cmake/GlfwImport.cmake new file mode 100644 index 00000000..12dbfeb9 --- /dev/null +++ b/cmake/GlfwImport.cmake @@ -0,0 +1,29 @@ + +if(USE_EXTERNAL_GLFW STREQUAL "ON") + find_package(glfw3 3.2.1 REQUIRED) +elseif(USE_EXTERNAL_GLFW STREQUAL "IF_POSSIBLE") + find_package(glfw3 3.2.1 QUIET) +endif() +if (glfw3_FOUND) + set(LIBS_PRIVATE ${LIBS_PRIVATE} glfw) +endif() + +# Explicitly check against "ON", because USE_EXTERNAL_GLFW is a tristate option +# Also adding only on desktop (web also uses glfw but it is more limited and is added using an emcc linker flag) +if(NOT glfw3_FOUND AND NOT USE_EXTERNAL_GLFW STREQUAL "ON" AND "${PLATFORM}" MATCHES "Desktop") + MESSAGE(STATUS "Using raylib's GLFW") + set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE) + set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE) + set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) + set(GLFW_INSTALL OFF CACHE BOOL "" FORCE) + set(BUILD_SHARED_LIBS OFF CACHE BOOL " " FORCE) + set(GLFW_USE_WAYLAND ${USE_WAYLAND} CACHE BOOL "" FORCE) + + add_subdirectory(external/glfw) + + list(APPEND raylib_sources $) + include_directories(BEFORE SYSTEM external/glfw/include) +else() + MESSAGE(STATUS "Using external GLFW") + set(GLFW_PKG_DEPS glfw3) +endif() \ No newline at end of file diff --git a/cmake/InstallConfigurations.cmake b/cmake/InstallConfigurations.cmake new file mode 100644 index 00000000..a26fedf5 --- /dev/null +++ b/cmake/InstallConfigurations.cmake @@ -0,0 +1,29 @@ +install( + TARGETS raylib EXPORT raylib-targets + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" + PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" +) + +# PKG_CONFIG_LIBS_PRIVATE is used in raylib.pc.in +if (STATIC) + include(LibraryPathToLinkerFlags) + library_path_to_linker_flags(__PKG_CONFIG_LIBS_PRIVATE "${LIBS_PRIVATE}") + set(PKG_CONFIG_LIBS_PRIVATE ${__PKG_CONFIG_LIBS_PRIVATE} ${GLFW_PKG_LIBS}) + string(REPLACE ";" " " PKG_CONFIG_LIBS_PRIVATE "${PKG_CONFIG_LIBS_PRIVATE}") +elseif (SHARED) + set(PKG_CONFIG_LIBS_EXTRA "") +endif () + +join_paths(libdir_for_pc_file "\${exec_prefix}" "${CMAKE_INSTALL_LIBDIR}") +join_paths(includedir_for_pc_file "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}") +configure_file(../raylib.pc.in raylib.pc @ONLY) +configure_file(../cmake/raylib-config-version.cmake raylib-config-version.cmake @ONLY) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/raylib.pc DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/raylib-config-version.cmake DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/raylib") +install(FILES ${PROJECT_SOURCE_DIR}/../cmake/raylib-config.cmake DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/raylib") + +# populates raylib_{FOUND, INCLUDE_DIRS, LIBRARIES, LDFLAGS, DEFINITIONS} +include(PopulateConfigVariablesLocally) +populate_config_variables_locally(raylib) diff --git a/cmake/LibraryConfigurations.cmake b/cmake/LibraryConfigurations.cmake new file mode 100644 index 00000000..8cca2464 --- /dev/null +++ b/cmake/LibraryConfigurations.cmake @@ -0,0 +1,109 @@ + +### Config options ### +# Translate the config options to what raylib wants +configure_file(config.h.in ${CMAKE_BINARY_DIR}/cmake/config.h) + +if(${PLATFORM} MATCHES "Desktop") + set(PLATFORM_CPP "PLATFORM_DESKTOP") + + if(APPLE) + # Need to force OpenGL 3.3 on OS X + # See: https://github.com/raysan5/raylib/issues/341 + set(GRAPHICS "GRAPHICS_API_OPENGL_33") + find_library(OPENGL_LIBRARY OpenGL) + set(LIBS_PRIVATE ${OPENGL_LIBRARY}) + link_libraries("${LIBS_PRIVATE}") + if (NOT CMAKE_SYSTEM STRLESS "Darwin-18.0.0") + add_definitions(-DGL_SILENCE_DEPRECATION) + MESSAGE(AUTHOR_WARNING "OpenGL is deprecated starting with macOS 10.14 (Mojave)!") + endif() + elseif(WIN32) + add_definitions(-D_CRT_SECURE_NO_WARNINGS) + set(LIBS_PRIVATE ${LIBS_PRIVATE} winmm) + else() + find_library(pthread NAMES pthread) + find_package(OpenGL QUIET) + if ("${OPENGL_LIBRARIES}" STREQUAL "") + set(OPENGL_LIBRARIES "GL") + endif() + + if ("${CMAKE_SYSTEM_NAME}" MATCHES "(Net|Open)BSD") + find_library(OSS_LIBRARY ossaudio) + endif() + + set(LIBS_PRIVATE m pthread ${OPENGL_LIBRARIES} ${OSS_LIBRARY}) + endif() + +elseif(${PLATFORM} MATCHES "Web") + set(PLATFORM_CPP "PLATFORM_WEB") + set(GRAPHICS "GRAPHICS_API_OPENGL_ES2") + set(CMAKE_C_FLAGS "-s USE_GLFW=3 -s ASSERTIONS=1 --profiling") + set(CMAKE_STATIC_LIBRARY_SUFFIX ".a") + +elseif(${PLATFORM} MATCHES "Android") + set(PLATFORM_CPP "PLATFORM_ANDROID") + set(GRAPHICS "GRAPHICS_API_OPENGL_ES2") + include(AddIfFlagCompiles) + add_if_flag_compiles(-ffunction-sections CMAKE_C_FLAGS) + add_if_flag_compiles(-funwind-tables CMAKE_C_FLAGS) + add_if_flag_compiles(-fstack-protector-strong CMAKE_C_FLAGS) + set(CMAKE_POSITION_INDEPENDENT_CODE ON) + add_if_flag_compiles(-Wa,--noexecstack CMAKE_C_FLAGS) + add_if_flag_compiles(-no-canonical-prefixes CMAKE_C_FLAGS) + add_definitions(-DANDROID -D__ANDROID_API__=21) + include_directories(external/android/native_app_glue) + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--exclude-libs,libatomic.a -Wl,--build-id -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--warn-shared-textrel -Wl,--fatal-warnings -uANativeActivity_onCreate") + + find_library(OPENGL_LIBRARY OpenGL) + set(LIBS_PRIVATE m log android EGL GLESv2 OpenSLES atomic c) + +elseif(${PLATFORM} MATCHES "Raspberry Pi") + set(PLATFORM_CPP "PLATFORM_RPI") + set(GRAPHICS "GRAPHICS_API_OPENGL_ES2") + + add_definitions(-D_DEFAULT_SOURCE) + + find_library(GLESV2 brcmGLESv2 HINTS /opt/vc/lib) + find_library(EGL brcmEGL HINTS /opt/vc/lib) + find_library(BCMHOST bcm_host HINTS /opt/vc/lib) + include_directories(/opt/vc/include /opt/vc/include/interface/vmcs_host/linux /opt/vc/include/interface/vcos/pthreads) + link_directories(/opt/vc/lib) + set(LIBS_PRIVATE ${GLESV2} ${EGL} ${BCMHOST} pthread rt m dl) + +elseif(${PLATFORM} MATCHES "DRM") + set(PLATFORM_CPP "PLATFORM_DRM") + set(GRAPHICS "GRAPHICS_API_OPENGL_ES2") + + add_definitions(-D_DEFAULT_SOURCE) + add_definitions(-DEGL_NO_X11) + add_definitions(-DPLATFORM_DRM) + + find_library(GLESV2 GLESv2) + find_library(EGL EGL) + find_library(DRM drm) + find_library(GBM gbm) + + include_directories(/usr/include/libdrm) + set(LIBS_PRIVATE ${GLESV2} ${EGL} ${DRM} ${GBM} pthread m dl) + +endif() + +if (${OPENGL_VERSION}) + set(${SUGGESTED_GRAPHICS} "${GRAPHICS}") + if (${OPENGL_VERSION} MATCHES "3.3") + set(GRAPHICS "GRAPHICS_API_OPENGL_33") + elseif (${OPENGL_VERSION} MATCHES "2.1") + set(GRAPHICS "GRAPHICS_API_OPENGL_21") + elseif (${OPENGL_VERSION} MATCHES "1.1") + set(GRAPHICS "GRAPHICS_API_OPENGL_11") + elseif (${OPENGL_VERSION} MATCHES "ES 2.0") + set(GRAPHICS "GRAPHICS_API_OPENGL_ES2") + endif() + if ("${SUGGESTED_GRAPHICS}" AND NOT "${SUGGESTED_GRAPHICS}" STREQUAL "${GRAPHICS}") + message(WARNING "You are overriding the suggested GRAPHICS=${SUGGESTED_GRAPHICS} with ${GRAPHICS}! This may fail") + endif() +endif() + +if(NOT GRAPHICS) + set(GRAPHICS "GRAPHICS_API_OPENGL_33") +endif() \ No newline at end of file diff --git a/cmake/PackConfigurations.cmake b/cmake/PackConfigurations.cmake new file mode 100644 index 00000000..74eded02 --- /dev/null +++ b/cmake/PackConfigurations.cmake @@ -0,0 +1,13 @@ +# Packaging +SET(CPACK_PACKAGE_NAME "raylib") +SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Simple and easy-to-use library to enjoy videogames programming") +SET(CPACK_PACKAGE_VERSION "${PROJECT_VERSION}") +SET(CPACK_PACKAGE_VERSION_MAJOR "${PROJECT_VERSION_MAJOR}") +SET(CPACK_PACKAGE_VERSION_MINOR "${PROJECT_VERSION_MINOR}") +SET(CPACK_PACKAGE_VERSION_PATCH "${PROJECT_VERSION_PATCH}") +SET(CPACK_PACKAGE_DESCRIPTION_FILE "${PROJECT_SOURCE_DIR}/../README.md") +SET(CPACK_RESOURCE_FILE_WELCOME "${PROJECT_SOURCE_DIR}/../README.md") +SET(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/../LICENSE") +SET(CPACK_PACKAGE_FILE_NAME "raylib-${PROJECT_VERSION}$ENV{RAYLIB_PACKAGE_SUFFIX}") +SET(CPACK_GENERATOR "ZIP;TGZ") # Remove this, if you want the NSIS installer on Windows +include(CPack) \ No newline at end of file diff --git a/cmake/emscripten.cmake b/cmake/emscripten.cmake deleted file mode 100644 index 1780dee9..00000000 --- a/cmake/emscripten.cmake +++ /dev/null @@ -1,23 +0,0 @@ -SET(CMAKE_SYSTEM_NAME Linux) -SET(CMAKE_SYSTEM_PROCESSOR x86) - -if (CMAKE_HOST_WIN32) - SET(EMSCRIPTEN_EXTENSION ".bat") -else () - SET(EMSCRIPTEN_EXTENSION "") -endif() - -SET(CMAKE_C_COMPILER emcc${EMSCRIPTEN_EXTENSION}) -SET(CMAKE_CXX_COMPILER em++${EMSCRIPTEN_EXTENSION}) - -if(NOT DEFINED CMAKE_AR) - find_program(CMAKE_AR NAMES emar${EMSCRIPTEN_EXTENSION}) -endif() -if(NOT DEFINED CMAKE_RANLIB) - find_program(CMAKE_RANLIB NAMES emranlib${EMSCRIPTEN_EXTENSION}) -endif() - -set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) -set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) -set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH) -set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 57ba74d4..e3ef3a0f 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -28,7 +28,6 @@ if (APPLE AND NOT CMAKE_SYSTEM STRLESS "Darwin-18.0.0") add_definitions(-DGL_SILENCE_DEPRECATION) MESSAGE(AUTHOR_WARNING "OpenGL is deprecated starting with macOS 10.14 (Mojave)!") endif() -list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/others/rlgl_standalone.c) include(CheckIncludeFile) CHECK_INCLUDE_FILE("stdatomic.h" HAVE_STDATOMIC_H) @@ -119,19 +118,5 @@ foreach(example_source ${example_sources}) endif() endforeach() -if (${PLATFORM} MATCHES "Desktop") - # rlgl_standalone can't be linked with raylib because of duplicate rlgl symbols - foreach (example_source "others/rlgl_standalone.c") - # Create the basename for the example - get_filename_component(example_name ${example_source} NAME) - string(REPLACE ".c" "" example_name ${example_name}) - add_executable(${example_name} ${example_source}) - add_dependencies(${example_name} raylib) - target_link_libraries(${example_name} ${raylib_LDFLAGS}) - target_include_directories(${example_name} PRIVATE ${raylib_INCLUDE_DIRS}) - - endforeach() -endif() - # Copy all of the resource files to the destination file(COPY ${example_resources} DESTINATION "resources/") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2e9861f8..b94ac149 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,326 +1,132 @@ # Setup the project and settings project(raylib C) -include(GNUInstallDirs) -include(JoinPaths) -list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake") - set(PROJECT_VERSION 3.5.0) set(API_VERSION 351) -include("CMakeOptions.txt") -include(BuildType) -configure_file(config.h.in ${CMAKE_BINARY_DIR}/cmake/config.h) -include_directories(${CMAKE_BINARY_DIR} .) - -# Get the sources together -file(GLOB raylib_sources *.c) -list(REMOVE_ITEM raylib_sources ${CMAKE_CURRENT_SOURCE_DIR}/rglfw.c) - -if(USE_EXTERNAL_GLFW STREQUAL "ON") - find_package(glfw3 3.2.1 REQUIRED) -elseif(USE_EXTERNAL_GLFW STREQUAL "IF_POSSIBLE") - find_package(glfw3 3.2.1 QUIET) -endif() -if (glfw3_FOUND) - set(LIBS_PRIVATE ${LIBS_PRIVATE} glfw) -endif() - -# Explicitly check against "ON", because USE_EXTERNAL_GLFW is a tristate option -if(NOT glfw3_FOUND AND NOT USE_EXTERNAL_GLFW STREQUAL "ON" AND "${PLATFORM}" MATCHES "Desktop") - MESSAGE(STATUS "Using raylib's GLFW") - set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE) - set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE) - set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) - set(GLFW_INSTALL OFF CACHE BOOL "" FORCE) - set(BUILD_SHARED_LIBS OFF CACHE BOOL " " FORCE) - set(GLFW_USE_WAYLAND ${USE_WAYLAND} CACHE BOOL "" FORCE) - - add_subdirectory(external/glfw) - - list(APPEND raylib_sources $) - include_directories(BEFORE SYSTEM external/glfw/include) -else() - MESSAGE(STATUS "Using external GLFW") - set(GLFW_PKG_DEPS glfw3) -endif() - -add_definitions("-DRAYLIB_CMAKE=1") - -if(USE_AUDIO) - MESSAGE(STATUS "Audio Backend: miniaudio") - set(sources ${raylib_sources}) -else() - MESSAGE(STATUS "Audio Backend: None (-DUSE_AUDIO=OFF)") - set(RAYLIB_MODULE_AUDIO 0) - list(REMOVE_ITEM raylib_sources ${CMAKE_CURRENT_SOURCE_DIR}/raudio.c) - set(sources ${raylib_sources}) -endif() - -### Config options ### -# Translate the config options to what raylib wants -if(${PLATFORM} MATCHES "Desktop") - set(PLATFORM_CPP "PLATFORM_DESKTOP") - - if(APPLE) - # Need to force OpenGL 3.3 on OS X - # See: https://github.com/raysan5/raylib/issues/341 - set(GRAPHICS "GRAPHICS_API_OPENGL_33") - find_library(OPENGL_LIBRARY OpenGL) - set(LIBS_PRIVATE ${OPENGL_LIBRARY}) - link_libraries("${LIBS_PRIVATE}") - if (NOT CMAKE_SYSTEM STRLESS "Darwin-18.0.0") - add_definitions(-DGL_SILENCE_DEPRECATION) - MESSAGE(AUTHOR_WARNING "OpenGL is deprecated starting with macOS 10.14 (Mojave)!") - endif() - elseif(WIN32) - add_definitions(-D_CRT_SECURE_NO_WARNINGS) - set(LIBS_PRIVATE ${LIBS_PRIVATE} winmm) - else() - find_library(pthread NAMES pthread) - find_package(OpenGL QUIET) - if ("${OPENGL_LIBRARIES}" STREQUAL "") - set(OPENGL_LIBRARIES "GL") - endif() +include(GNUInstallDirs) +include(JoinPaths) - if ("${CMAKE_SYSTEM_NAME}" MATCHES "(Net|Open)BSD") - find_library(OSS_LIBRARY ossaudio) +# Sets build type if not set by now +if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + if(RAYLIB_IS_MAIN) + set(default_build_type Debug) endif() - set(LIBS_PRIVATE m pthread ${OPENGL_LIBRARIES} ${OSS_LIBRARY}) - endif() - -elseif(${PLATFORM} MATCHES "Web") - set(PLATFORM_CPP "PLATFORM_WEB") - set(GRAPHICS "GRAPHICS_API_OPENGL_ES2") - - set(CMAKE_C_FLAGS "-s USE_GLFW=3 -s ASSERTIONS=1 --profiling") - - # Change the name of the output library - -elseif(${PLATFORM} MATCHES "Android") - set(PLATFORM_CPP "PLATFORM_ANDROID") - set(GRAPHICS "GRAPHICS_API_OPENGL_ES2") - include(AddIfFlagCompiles) - add_if_flag_compiles(-ffunction-sections CMAKE_C_FLAGS) - add_if_flag_compiles(-funwind-tables CMAKE_C_FLAGS) - add_if_flag_compiles(-fstack-protector-strong CMAKE_C_FLAGS) - set(CMAKE_POSITION_INDEPENDENT_CODE ON) - add_if_flag_compiles(-Wa,--noexecstack CMAKE_C_FLAGS) - add_if_flag_compiles(-no-canonical-prefixes CMAKE_C_FLAGS) - add_definitions(-DANDROID -D__ANDROID_API__=21) - include_directories(external/android/native_app_glue) - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--exclude-libs,libatomic.a -Wl,--build-id -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--warn-shared-textrel -Wl,--fatal-warnings -uANativeActivity_onCreate") - - find_library(OPENGL_LIBRARY OpenGL) - set(LIBS_PRIVATE m log android EGL GLESv2 OpenSLES atomic c) - -elseif(${PLATFORM} MATCHES "Raspberry Pi") - set(PLATFORM_CPP "PLATFORM_RPI") - set(GRAPHICS "GRAPHICS_API_OPENGL_ES2") - - add_definitions(-D_DEFAULT_SOURCE) - - find_library(GLESV2 brcmGLESv2 HINTS /opt/vc/lib) - find_library(EGL brcmEGL HINTS /opt/vc/lib) - find_library(BCMHOST bcm_host HINTS /opt/vc/lib) - include_directories(/opt/vc/include /opt/vc/include/interface/vmcs_host/linux /opt/vc/include/interface/vcos/pthreads) - link_directories(/opt/vc/lib) - set(LIBS_PRIVATE ${GLESV2} ${EGL} ${BCMHOST} pthread rt m dl) - - elseif(${PLATFORM} MATCHES "DRM") - set(PLATFORM_CPP "PLATFORM_DRM") - set(GRAPHICS "GRAPHICS_API_OPENGL_ES2") - - add_definitions(-D_DEFAULT_SOURCE) - add_definitions(-DEGL_NO_X11) - add_definitions(-DPLATFORM_DRM) - - find_library(GLESV2 GLESv2) - find_library(EGL EGL) - find_library(DRM drm) - find_library(GBM gbm) - - include_directories(/usr/include/libdrm) - set(LIBS_PRIVATE ${GLESV2} ${EGL} ${DRM} ${GBM} pthread m dl) - -endif() - -if (${OPENGL_VERSION}) - set(${SUGGESTED_GRAPHICS} "${GRAPHICS}") - if (${OPENGL_VERSION} MATCHES "3.3") - set(GRAPHICS "GRAPHICS_API_OPENGL_33") - elseif (${OPENGL_VERSION} MATCHES "2.1") - set(GRAPHICS "GRAPHICS_API_OPENGL_21") - elseif (${OPENGL_VERSION} MATCHES "1.1") - set(GRAPHICS "GRAPHICS_API_OPENGL_11") - elseif (${OPENGL_VERSION} MATCHES "ES 2.0") - set(GRAPHICS "GRAPHICS_API_OPENGL_ES2") - endif() - if ("${SUGGESTED_GRAPHICS}" AND NOT "${SUGGESTED_GRAPHICS}" STREQUAL "${GRAPHICS}") - message(WARNING "You are overriding the suggested GRAPHICS=${SUGGESTED_GRAPHICS} with ${GRAPHICS}! This may fail") - endif() + message(STATUS "Setting build type to '${default_build_type}' as none was specified.") + + set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE STRING "Choose the type of build." FORCE) + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo") endif() -if(NOT GRAPHICS) - set(GRAPHICS "GRAPHICS_API_OPENGL_33") -endif() - -include_directories(${OPENGL_INCLUDE_DIR} ${OPENAL_INCLUDE_DIR}) -set(LIBS_PRIVATE ${LIBS_PRIVATE} ${OPENAL_LIBRARY}) -include(LibraryPathToLinkerFlags) -library_path_to_linker_flags(__PKG_CONFIG_LIBS_PRIVATE "${LIBS_PRIVATE}") - -if(STATIC) - MESSAGE(STATUS "Building raylib static library") - if(${PLATFORM} MATCHES "Web") - set(CMAKE_STATIC_LIBRARY_SUFFIX ".a") - endif() - - add_library(raylib_static STATIC ${sources}) - - target_compile_definitions(raylib_static - PUBLIC ${PLATFORM_CPP} - PUBLIC PLATFORM=${PLATFORM_CPP} - PUBLIC ${GRAPHICS} - PUBLIC GRAPHICS=${GRAPHICS} - ) - - target_link_libraries(raylib_static - PUBLIC ${LIBS_PRIVATE} - ) - - set(PKG_CONFIG_LIBS_PRIVATE ${__PKG_CONFIG_LIBS_PRIVATE} ${GLFW_PKG_LIBS}) - string (REPLACE ";" " " PKG_CONFIG_LIBS_PRIVATE "${PKG_CONFIG_LIBS_PRIVATE}") - if (${PLATFORM} MATCHES "Desktop") - target_link_libraries(raylib_static PRIVATE glfw ${GLFW_LIBRARIES} ${LIBS_PRIVATE}) - endif() - - if (WITH_PIC) - set_property(TARGET raylib_static PROPERTY POSITION_INDEPENDENT_CODE ON) - endif() - set_target_properties(raylib_static PROPERTIES PUBLIC_HEADER "raylib.h") - if(NOT MSVC) # Keep lib*.(a|dll) name, but avoid *.lib files overwriting each other on Windows - set_target_properties(raylib_static PROPERTIES OUTPUT_NAME raylib) - endif() - install( - TARGETS raylib_static - ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" - PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" - ) - set_target_properties(raylib_static PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_BINARY_DIR}") - - add_test("pkg-config--static" ${PROJECT_SOURCE_DIR}/../cmake/test-pkgconfig.sh --static) -endif(STATIC) - - -if(SHARED) - MESSAGE(STATUS "Building raylib shared library") - add_library(raylib SHARED ${sources}) - - target_compile_definitions(raylib - PUBLIC ${PLATFORM_CPP} - PUBLIC ${GRAPHICS} - ) - - if(MSVC) - target_compile_definitions(raylib - PRIVATE $ - INTERFACE $ +# Get the sources together +set(raylib_public_headers + raylib.h + rlgl.h + physac.h + raymath.h + raudio.h ) - endif() - - set(PKG_CONFIG_LIBS_EXTRA "") - - set_property(TARGET raylib PROPERTY POSITION_INDEPENDENT_CODE ON) - set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_LIBDIR}") - set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) - set(CMAKE_MACOSX_RPATH ON) - - target_link_libraries(raylib ${LIBS_PRIVATE}) - if (${PLATFORM} MATCHES "Desktop") - target_link_libraries(raylib glfw) - endif() - set_target_properties(raylib PROPERTIES - PUBLIC_HEADER "raylib.h" - VERSION ${PROJECT_VERSION} - SOVERSION ${API_VERSION} - ) - if (WIN32) - install( - TARGETS raylib - ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" - LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" - RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" - PUBLIC_HEADER DESTINATION "include" +set(raylib_sources + core.c + models.c + shapes.c + text.c + textures.c + utils.c ) - else() - install( - TARGETS raylib - LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" - PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" - ) - endif() - set_target_properties(raylib PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_BINARY_DIR}") - - add_test("pkg-config" ${PROJECT_SOURCE_DIR}/../cmake/test-pkgconfig.sh) -else(SHARED) - add_library(raylib ALIAS raylib_static) -endif(SHARED) -if (NOT DEFINED PKG_CONFIG_LIBS_EXTRA) - set(PKG_CONFIG_LIBS_EXTRA "${PKG_CONFIG_LIBS_PRIVATE}") -endif() +# cmake/GlfwImport.cmake handles the details around the inclusion of glfw +include(GlfwImport) -join_paths(libdir_for_pc_file "\${exec_prefix}" "${CMAKE_INSTALL_LIBDIR}") -join_paths(includedir_for_pc_file "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}") -configure_file(../raylib.pc.in raylib.pc @ONLY) -install(FILES ${CMAKE_CURRENT_BINARY_DIR}/raylib.pc DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") -configure_file(../cmake/raylib-config-version.cmake raylib-config-version.cmake @ONLY) -install(FILES ${CMAKE_CURRENT_BINARY_DIR}/raylib-config-version.cmake DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/raylib") -install(FILES ${PROJECT_SOURCE_DIR}/../cmake/raylib-config.cmake DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/raylib") +if (USE_AUDIO) + MESSAGE(STATUS "Audio Backend: miniaudio") + list(APPEND raylib_sources raudio.c) +else () + MESSAGE(STATUS "Audio Backend: None (-DUSE_AUDIO=OFF)") +endif () -# populates raylib_{FOUND, INCLUDE_DIRS, LIBRARIES, LDFLAGS, DEFINITIONS} -include(PopulateConfigVariablesLocally) -populate_config_variables_locally(raylib) +include(LibraryConfigurations) -# Copy the header files to the build directory -file(COPY "raylib.h" DESTINATION ".") -file(COPY "rlgl.h" DESTINATION ".") -file(COPY "physac.h" DESTINATION ".") -file(COPY "raymath.h" DESTINATION ".") -file(COPY "raudio.h" DESTINATION ".") +set(LIBS_PRIVATE ${LIBS_PRIVATE} ${OPENAL_LIBRARY}) -# Also install them -install(FILES "raylib.h" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") -install(FILES "rlgl.h" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") -install(FILES "physac.h" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") -install(FILES "raymath.h" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") -install(FILES "raudio.h" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") +if (STATIC) + MESSAGE(STATUS "Building raylib static library") + + add_library(raylib STATIC ${raylib_sources} ${raylib_public_headers}) + add_library(raylib_static ALIAS raylib) + + add_test("pkg-config--static" ${PROJECT_SOURCE_DIR}/../cmake/test-pkgconfig.sh --static) +endif (STATIC) + + +if (SHARED) + MESSAGE(STATUS "Building raylib shared library") + add_library(raylib SHARED ${raylib_sources} ${raylib_public_headers}) + + if (MSVC) + target_compile_definitions(raylib + PRIVATE $ + INTERFACE $ + ) + endif () + + add_test("pkg-config" ${PROJECT_SOURCE_DIR}/../cmake/test-pkgconfig.sh) +endif () + +# Setting target properties +set_target_properties(raylib PROPERTIES + PUBLIC_HEADER "${raylib_public_headers}" + VERSION ${PROJECT_VERSION} + SOVERSION ${API_VERSION} + ) + +if (WITH_PIC OR SHARED) + set_property(TARGET raylib PROPERTY POSITION_INDEPENDENT_CODE ON) +endif () + +# Linking libraries +target_link_libraries(raylib "${LIBS_PRIVATE}") +if (${PLATFORM} MATCHES "Desktop") + target_link_libraries(raylib glfw) +endif () + +# Adding compile definitions +target_compile_definitions(raylib + PUBLIC "${PLATFORM_CPP}" + PUBLIC "${GRAPHICS}" + ) + +# Registering include directories +target_include_directories(raylib + PUBLIC + $ + $ + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/external + ${CMAKE_BINARY_DIR} # For cmake/config.h + ${OPENGL_INCLUDE_DIR} + ${OPENAL_INCLUDE_DIR} + ) + +# Copy the header files to the build directory for convenience +file(COPY ${raylib_public_headers} DESTINATION "include") + +include(InstallConfigurations) # Print the flags for the user if (DEFINED CMAKE_BUILD_TYPE) - message(STATUS "Generated build type: ${CMAKE_BUILD_TYPE}") -else() - message(STATUS "Generated config types: ${CMAKE_CONFIGURATION_TYPES}") -endif() + message(STATUS "Generated build type: ${CMAKE_BUILD_TYPE}") +else () + message(STATUS "Generated config types: ${CMAKE_CONFIGURATION_TYPES}") +endif () + message(STATUS "Compiling with the flags:") message(STATUS " PLATFORM=" ${PLATFORM_CPP}) message(STATUS " GRAPHICS=" ${GRAPHICS}) -# Packaging -SET(CPACK_PACKAGE_NAME "raylib") -SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Simple and easy-to-use library to enjoy videogames programming") -SET(CPACK_PACKAGE_VERSION "${PROJECT_VERSION}") -SET(CPACK_PACKAGE_VERSION_MAJOR "${PROJECT_VERSION_MAJOR}") -SET(CPACK_PACKAGE_VERSION_MINOR "${PROJECT_VERSION_MINOR}") -SET(CPACK_PACKAGE_VERSION_PATCH "${PROJECT_VERSION_PATCH}") -SET(CPACK_PACKAGE_DESCRIPTION_FILE "${PROJECT_SOURCE_DIR}/../README.md") -SET(CPACK_RESOURCE_FILE_WELCOME "${PROJECT_SOURCE_DIR}/../README.md") -SET(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/../LICENSE") -SET(CPACK_PACKAGE_FILE_NAME "raylib-${PROJECT_VERSION}$ENV{RAYLIB_PACKAGE_SUFFIX}") -SET(CPACK_GENERATOR "ZIP;TGZ") # Remove this, if you want the NSIS installer on Windows -include(CPack) +include(PackConfigurations) enable_testing() diff --git a/src/config.h b/src/config.h index f84aa017..dbe77cd9 100644 --- a/src/config.h +++ b/src/config.h @@ -29,7 +29,7 @@ // Edit to control what features Makefile'd raylib is compiled with #if defined(RAYLIB_CMAKE) - // Edit CMakeOptions.txt for CMake instead + // Edit cmake/RaylibOptions.cmake for CMake instead #include "cmake/config.h" #else