mirror of
https://github.com/raysan5/raylib.git
synced 2025-12-25 10:22:33 -05:00
cmake: Fix PLATFORM_WEB build
Did this ever work? Surely, doesn't look like it...
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
# Setup the project and settings
|
||||
project(raylib)
|
||||
project(raylib C)
|
||||
include(GNUInstallDirs)
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake")
|
||||
|
||||
@ -13,14 +13,6 @@ configure_file(config.h.in ${CMAKE_BINARY_DIR}/cmake/config.h)
|
||||
include_directories(${CMAKE_BINARY_DIR})
|
||||
include_directories(SYSTEM .)
|
||||
|
||||
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()
|
||||
|
||||
# Get the sources together
|
||||
file(GLOB raylib_sources *.c)
|
||||
list(REMOVE_ITEM raylib_sources ${CMAKE_CURRENT_SOURCE_DIR}/rglfw.c)
|
||||
@ -72,9 +64,9 @@ if(${PLATFORM} MATCHES "Desktop")
|
||||
set(GRAPHICS "GRAPHICS_API_OPENGL_ES2")
|
||||
endif()
|
||||
|
||||
# Need to force OpenGL 3.3 on OS X
|
||||
# See: https://github.com/raysan5/raylib/issues/341
|
||||
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")
|
||||
link_libraries("${LIBS_PRIVATE}")
|
||||
elseif(WIN32)
|
||||
@ -85,12 +77,9 @@ elseif(${PLATFORM} MATCHES "Web")
|
||||
set(PLATFORM "PLATFORM_WEB")
|
||||
set(GRAPHICS "GRAPHICS_API_OPENGL_ES2")
|
||||
|
||||
# Need to use `emcc`
|
||||
set(CMAKE_C_COMPILER "emcc")
|
||||
set(CMAKE_CXX_COMPILER "em++")
|
||||
set(CMAKE_C_FLAGS "-s USE_GLFW=3 -s ASSERTIONS=1 --profiling")
|
||||
|
||||
# Change the name of the output library
|
||||
set(RAYLIB "libraylib.bc")
|
||||
|
||||
elseif(${PLATFORM} MATCHES "Android")
|
||||
set(PLATFORM "PLATFORM_ANDROID")
|
||||
@ -110,89 +99,87 @@ elseif(${PLATFORM} MATCHES "Raspberry Pi")
|
||||
set(GRAPHICS "GRAPHICS_API_OPENGL_ES2")
|
||||
endif()
|
||||
|
||||
# Which platform?
|
||||
if(${PLATFORM} MATCHES "PLATFORM_WEB")
|
||||
# For the web.
|
||||
add_executable(${RAYLIB} ${sources})
|
||||
if(${SHARED})
|
||||
add_library(${RAYLIB}_shared SHARED ${sources})
|
||||
|
||||
else()
|
||||
if(${SHARED})
|
||||
add_library(${RAYLIB}_shared SHARED ${sources})
|
||||
target_compile_definitions(${RAYLIB}_shared
|
||||
PUBLIC ${PLATFORM}
|
||||
PUBLIC ${GRAPHICS}
|
||||
)
|
||||
|
||||
target_compile_definitions(${RAYLIB}_shared
|
||||
PUBLIC ${PLATFORM}
|
||||
PUBLIC ${GRAPHICS}
|
||||
)
|
||||
set_property(TARGET ${RAYLIB}_shared 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)
|
||||
|
||||
set_property(TARGET ${RAYLIB}_shared 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}_shared ${LIBS_PRIVATE})
|
||||
if (${PLATFORM} MATCHES "Desktop")
|
||||
target_link_libraries(${RAYLIB}_shared glfw ${GLFW_LIBRARIES})
|
||||
endif()
|
||||
if (UNIX AND ${FILESYSTEM_LACKS_SYMLINKS})
|
||||
MESSAGE(WARNING "Can't version UNIX shared library on file system without symlink support")
|
||||
else()
|
||||
set_target_properties(${RAYLIB}_shared PROPERTIES
|
||||
VERSION ${PROJECT_VERSION}
|
||||
SOVERSION ${API_VERSION}
|
||||
)
|
||||
endif()
|
||||
set_target_properties(${RAYLIB}_shared PROPERTIES
|
||||
PUBLIC_HEADER "raylib.h"
|
||||
)
|
||||
if(WIN32)
|
||||
install(
|
||||
TARGETS ${RAYLIB}_shared
|
||||
RUNTIME DESTINATION lib
|
||||
PUBLIC_HEADER DESTINATION include
|
||||
target_link_libraries(${RAYLIB}_shared ${LIBS_PRIVATE})
|
||||
if (${PLATFORM} MATCHES "Desktop")
|
||||
target_link_libraries(${RAYLIB}_shared glfw ${GLFW_LIBRARIES})
|
||||
endif()
|
||||
if (UNIX AND ${FILESYSTEM_LACKS_SYMLINKS})
|
||||
MESSAGE(WARNING "Can't version UNIX shared library on file system without symlink support")
|
||||
else()
|
||||
set_target_properties(${RAYLIB}_shared PROPERTIES
|
||||
VERSION ${PROJECT_VERSION}
|
||||
SOVERSION ${API_VERSION}
|
||||
)
|
||||
else() # Keep lib*.(a|dll) name, but avoid *.lib files overwriting each other on Windows
|
||||
set_target_properties(${RAYLIB}_shared PROPERTIES OUTPUT_NAME ${RAYLIB})
|
||||
install(
|
||||
TARGETS ${RAYLIB}_shared
|
||||
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
|
||||
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
|
||||
)
|
||||
endif()
|
||||
endif(${SHARED})
|
||||
|
||||
if(${STATIC})
|
||||
add_library(${RAYLIB} STATIC ${sources})
|
||||
|
||||
target_compile_definitions(${RAYLIB}
|
||||
PUBLIC ${PLATFORM}
|
||||
PUBLIC ${GRAPHICS}
|
||||
endif()
|
||||
set_target_properties(${RAYLIB}_shared PROPERTIES
|
||||
PUBLIC_HEADER "raylib.h"
|
||||
)
|
||||
if(WIN32)
|
||||
install(
|
||||
TARGETS ${RAYLIB}_shared
|
||||
RUNTIME DESTINATION lib
|
||||
PUBLIC_HEADER DESTINATION include
|
||||
)
|
||||
|
||||
set(PKG_CONFIG_LIBS_PRIVATE ${__PKG_CONFIG_LIBS_PRIVATE})
|
||||
if (${PLATFORM} MATCHES "Desktop")
|
||||
target_link_libraries(${RAYLIB} glfw ${GLFW_LIBRARIES})
|
||||
endif()
|
||||
|
||||
if (WITH_PIC)
|
||||
set_property(TARGET ${RAYLIB} PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||
endif()
|
||||
set_target_properties(${RAYLIB} PROPERTIES PUBLIC_HEADER "raylib.h")
|
||||
install(TARGETS ${RAYLIB}
|
||||
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
|
||||
else() # Keep lib*.(a|dll) name, but avoid *.lib files overwriting each other on Windows
|
||||
set_target_properties(${RAYLIB}_shared PROPERTIES OUTPUT_NAME ${RAYLIB})
|
||||
install(
|
||||
TARGETS ${RAYLIB}_shared
|
||||
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
|
||||
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
|
||||
)
|
||||
endif(${STATIC})
|
||||
endif()
|
||||
endif(${SHARED})
|
||||
|
||||
configure_file(../raylib.pc.in raylib.pc @ONLY)
|
||||
install(FILES ${CMAKE_BINARY_DIR}/release/raylib.pc DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
|
||||
if(${STATIC})
|
||||
if(${PLATFORM} MATCHES "PLATFORM_WEB")
|
||||
set(CMAKE_STATIC_LIBRARY_SUFFIX ".bc")
|
||||
endif()
|
||||
|
||||
add_library(${RAYLIB} STATIC ${sources})
|
||||
|
||||
set(PKG_CONFIG_LIBS_PRIVATE ${__PKG_CONFIG_LIBS_PRIVATE})
|
||||
if (${PLATFORM} MATCHES "Desktop")
|
||||
target_link_libraries(${RAYLIB} glfw ${GLFW_LIBRARIES})
|
||||
endif()
|
||||
|
||||
if (WITH_PIC)
|
||||
set_property(TARGET ${RAYLIB} PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||
endif()
|
||||
set_target_properties(${RAYLIB} PROPERTIES PUBLIC_HEADER "raylib.h")
|
||||
install(TARGETS ${RAYLIB}
|
||||
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
|
||||
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
|
||||
)
|
||||
endif(${STATIC})
|
||||
|
||||
configure_file(../raylib.pc.in raylib.pc @ONLY)
|
||||
install(FILES ${CMAKE_BINARY_DIR}/release/raylib.pc DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
|
||||
|
||||
# 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 "audio.h" DESTINATION ".")
|
||||
|
||||
target_compile_definitions(${RAYLIB}
|
||||
PUBLIC ${PLATFORM}
|
||||
PUBLIC ${GRAPHICS}
|
||||
)
|
||||
|
||||
# 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 "audio.h" DESTINATION ".")
|
||||
endif()
|
||||
|
||||
# Print the flags for the user
|
||||
message(STATUS "Compiling with the flags:")
|
||||
|
||||
Reference in New Issue
Block a user