summaryrefslogtreecommitdiffhomepage
path: root/cmake/LibraryConfigurations.cmake
diff options
context:
space:
mode:
authorhristo <[email protected]>2021-01-14 00:10:02 +0200
committerGitHub <[email protected]>2021-01-13 23:10:02 +0100
commit9821725c6bafeaf4153ab8604e692dfe13cbff09 (patch)
tree5dc264f722473f8f5f6c48dcfb4d1ada5761f501 /cmake/LibraryConfigurations.cmake
parent3d22709808fd9ba2843e6cad5e106bcd90eecaca (diff)
downloadraylib-9821725c6bafeaf4153ab8604e692dfe13cbff09.tar.gz
raylib-9821725c6bafeaf4153ab8604e692dfe13cbff09.zip
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 <root>/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 <[email protected]> * Remove debug message Co-authored-by: Rob Loach <[email protected]> * Improvements based on review. * Simplify the install condition to not be platform specific as it was before. Co-authored-by: Alexander Neumann <[email protected]> * Remove some CMAKE variables as they don't affect the build in any way Co-authored-by: Alexander Neumann <[email protected]> Co-authored-by: Rob Loach <[email protected]> Co-authored-by: Alexander Neumann <[email protected]>
Diffstat (limited to 'cmake/LibraryConfigurations.cmake')
-rw-r--r--cmake/LibraryConfigurations.cmake109
1 files changed, 109 insertions, 0 deletions
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