@ -5,20 +5,28 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake")
set ( PROJECT_VERSION 2.0.0 )
set ( API_VERSION 2 )
set ( RAYLIB raylib ) # N a m e o f t h e g e n e r a t e d l i b r a r y
include ( "CMakeOptions.txt" )
include ( BuildType )
configure_file ( config.h.in ${ CMAKE_BINARY_DIR } /cmake/config.h )
include_directories ( ${ CMAKE_BINARY_DIR } )
include_directories ( SYSTEM . )
include_directories ( ${ CMAKE_BINARY_DIR } . )
# G e t t h e s o u r c e s t o g e t h e r
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 ( )
# E x p l i c i t l y c h e c k a g a i n s t " O N " , b e c a u s e U S E _ E X T E R N A L _ G L F W i s a t r i s t a t e o p t i o n
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 )
@ -30,20 +38,22 @@ if(NOT glfw3_FOUND AND NOT USE_EXTERNAL_GLFW STREQUAL "ON" AND "${PLATFORM}" MAT
endif ( )
add_subdirectory ( external/glfw )
include_directories ( external/glfw/include )
include_directories ( BEFORE SYSTEM external/glfw/include)
list ( APPEND raylib_sources $< TARGET_OBJECTS:glfw_objlib > )
else ( )
MESSAGE ( STATUS "Using external GLFW" )
set ( GLFW_PKG_DEPS glfw )
endif ( )
include ( utils )
add_definitions ( "-DRAYLIB_CMAKE=1" )
if ( USE_AUDIO )
if ( NOT USE_OPENAL_BACKEND )
file ( GLOB mini_al external/mini_al.c )
MESSAGE ( STATUS "Audio Backend: mini_al" )
else ( )
find_package ( OpenAL REQUIRED )
MESSAGE ( STATUS "Audio Backend: OpenAL" )
endif ( )
file ( GLOB stb_vorbis external/stb_vorbis.c )
@ -55,35 +65,36 @@ else()
set ( sources ${ raylib_sources } )
endif ( )
include ( AddIfFlagCompiles )
# # # C o n f i g o p t i o n s # # #
# T r a n s l a t e t h e c o n f i g o p t i o n s t o w h a t r a y l i b w a n t s
if ( ${ PLATFORM } MATCHES "Desktop" )
set ( PLATFORM "PLATFORM_DESKTOP" )
# O p e n G L v e r s i o n
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 ( )
set ( PLATFORM_CPP "PLATFORM_DESKTOP" )
if ( APPLE )
# N e e d t o f o r c e O p e n G L 3 . 3 o n O S X
# S e e : h t t p s : / / g i t h u b . c o m / r a y s a n 5 / r a y l i b / i s s u e s / 3 4 1
set ( GRAPHICS "GRAPHICS_API_OPENGL_33" )
find_library ( OPENGL_LIBRARY OpenGL )
set ( LIBS_PRIVATE ${ OPENGL_LIBRARY } )
link_libraries ( "${LIBS_PRIVATE}" )
elseif ( WIN32 )
add_definitions ( -D_CRT_SECURE_NO_WARNINGS )
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 "PLATFORM_WEB" )
set ( PLATFORM_CPP "PLATFORM_WEB" )
set ( GRAPHICS "GRAPHICS_API_OPENGL_ES2" )
set ( CMAKE_C_FLAGS "-s USE_GLFW=3 -s ASSERTIONS=1 --profiling" )
@ -91,8 +102,9 @@ elseif(${PLATFORM} MATCHES "Web")
# C h a n g e t h e n a m e o f t h e o u t p u t l i b r a r y
elseif ( ${ PLATFORM } MATCHES "Android" )
set ( PLATFORM "PLATFORM_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 )
@ -103,94 +115,139 @@ elseif(${PLATFORM} MATCHES "Android")
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 "PLATFORM_RPI" )
set ( PLATFORM_CPP "PLATFORM_RPI" )
set ( GRAPHICS "GRAPHICS_API_OPENGL_ES2" )
endif ( )
if ( ${ SHARED } )
add_library ( ${ RAYLIB } _shared SHARED ${ sources } )
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 ( )
target_compile_definitions ( ${ RAYLIB } _shared
P U B L I C $ { P L A T F O R M }
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 )
if ( ${ PLATFORM } MATCHES "Web" )
set ( CMAKE_STATIC_LIBRARY_SUFFIX ".bc" )
endif ( )
add_library ( raylib_static STATIC ${ sources } )
target_compile_definitions ( raylib_static
P U B L I C $ { P L A T F O R M _ C P P }
P U B L I C $ { G R A P H I C S }
)
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 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 WIN32 ) # K e e p l i b * . ( a | d l l ) n a m e , b u t a v o i d * . l i b f i l e s o v e r w r i t i n g e a c h o t h e r o n W i n d o w s
set_target_properties ( raylib_static PROPERTIES OUTPUT_NAME raylib )
endif ( )
install (
T A R G E T S r a y l i b _ s t a t i c
A R C H I V E D E S T I N A T I O N " $ { C M A K E _ I N S T A L L _ L I B D I R } "
P U B L I C _ H E A D E R D E S T I N A T I O N " $ { C M A K E _ I N S T A L L _ I N C L U D E D I R } "
)
set_target_properties ( raylib_static PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_BINARY_DIR}/release" )
add_test ( "pkg-config--static" ${ PROJECT_SOURCE_DIR } /../cmake/test-pkgconfig.sh --static )
endif ( STATIC )
if ( SHARED )
add_library ( raylib SHARED ${ sources } )
target_compile_definitions ( raylib
P U B L I C $ { P L A T F O R M _ C P P }
P U B L I C $ { G R A P H I C S }
)
set ( PKG_CONFIG_LIBS_EXTRA "" )
set_property ( TARGET ${ RAYLIB } _shared PROPERTY POSITION_INDEPENDENT_CODE ON )
set_property ( TARGET s">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 } _shared ${ LIBS_PRIVATE } )
if ( ${ PLATFORM } MATCHES "PLATFORM_DESKTOP" )
target_link_libraries ( ${ RAYLIB } _shared glfw )
target_link_libraries ( s">raylib ${ LIBS_PRIVATE } )
if ( ${ PLATFORM } MATCHES "Desktop " )
target_link_libraries ( s">raylib glfw )
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
set_target_properties ( s">raylib PROPERTIES
V E R S I O N $ { P R O J E C T _ V E R S I O N }
S O V E R S I O N $ { A P I _ V E R S I O N }
)
endif ( )
set_target_properties ( ${ RAYLIB } _shared PROPERTIES
set_target_properties ( s">raylib PROPERTIES
P U B L I C _ H E A D E R " r a y l i b . h "
)
if ( WIN32 )
if ( WIN32 )
install (
T A R G E T S $ { R A Y L I B } _ s h a r e d
R U N T I M E D E S T I N A T I O N l i b
P U B L I C _ H E A D E R D E S T I N A T I O N i n c l u d e
T A R G E T S r a y l i b
R U N T I M E D E S T I N A T I O N " li b "
P U B L I C _ H E A D E R D E S T I N A T I O N " in c l u d e "
)
else ( ) # K e e p l i b * . ( a | d l l ) n a m e , b u t a v o i d * . l i b f i l e s o v e r w r i t i n g e a c h o t h e r o n W i n d o w s
set_target_properties ( ${ RAYLIB } _shared PROPERTIES OUTPUT_NAME ${ RAYLIB } )
else ( )
install (
T A R G E T S $ { R A Y L I B } _ s h a r e d
L I B R A R Y D E S T I N A T I O N " $ { C M A K E _ I N S T A L L _ L I B D I R } "
P U B L I C _ H E A D E R D E S T I N A T I O N " $ { C M A K E _ I N S T A L L _ I N C L U D E D I R } "
T A R G E T S r a y l i b
L I B R A R Y D E S T I N A T I O N " $ { C M A K E _ I N S T A L L _ L I B D I R } "
P U B L I C _ H E A D E R D E S T I N A T I O N " $ { C M A K E _ I N S T A L L _ I N C L U D E D I R } "
)
endif ( )
set_target_properties ( raylib PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_BINARY_DIR}/release" )
add_test ( "pkg-config" ${ PROJECT_SOURCE_DIR } /../cmake/test-pkgconfig.sh )
endif ( ${ SHARED } )
if ( ${ STATIC } )
if ( ${ PLATFORM } MATCHES "PLATFORM_WEB" )
set ( CMAKE_STATIC_LIBRARY_SUFFIX ".bc" )
endif ( )
add_library ( ${ RAYLIB } STATIC ${ sources } )
target_compile_definitions ( ${ RAYLIB }
P U B L I C $ { P L A T F O R M }
P U B L I C $ { G R A P H I C S }
)
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 "PLATFORM_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 }
A R C H I V E D E S T I N A T I O N " $ { C M A K E _ I N S T A L L _ L I B D I R } "
P U B L I C _ H E A D E R D E S T I N A T I O N " $ { C M A K E _ I N S T A L L _ I N C L U D E D I R } "
)
add_test ( "pkg-config--static" ${ PROJECT_SOURCE_DIR } /../cmake/test-pkgconfig.sh --static )
endif ( ${ STATIC } )
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 ( )
configure_file ( ../raylib.pc.in raylib.pc @ONLY )
install ( FILES ${ CMAKE_BINARY_DIR } /release/raylib.pc DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig" )
configure_file ( ../cmake/raylib-config-version.cmake raylib-config-version.cmake @ONLY )
install ( FILES ${ CMAKE_BINARY_DIR } /release/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" )
# p o p u l a t e s r a y l i b _ { F O U N D , I N C L U D E _ D I R S , L I B R A R I E S , L D F L A G S , D E F I N I T I O N S }
include ( PopulateConfigVariablesLocally )
populate_config_variables_locally ( raylib )
# C o p y t h e h e a d e r f i l e s t o t h e b u i l d d i r e c t o r y
file ( COPY "raylib.h" DESTINATION "." )
@ -201,7 +258,7 @@ file(COPY "audio.h" DESTINATION ".")
# P r i n t t h e f l a g s f o r t h e u s e r
message ( STATUS "Compiling with the flags:" )
message ( STATUS " PLATFORM=" ${ PLATFORM } )
message ( STATUS " PLATFORM=" ${ PLATFORM_CPP } )
message ( STATUS " GRAPHICS=" ${ GRAPHICS } )
# P a c k a g i n g