2020-03-06 06:06:54 +00:00
|
|
|
cmake_minimum_required(VERSION 3.5)
|
|
|
|
|
|
|
|
set(PROJECT_NAME MiniFB)
|
|
|
|
project(${PROJECT_NAME})
|
|
|
|
|
|
|
|
message("Processing " ${PROJECT_NAME})
|
|
|
|
|
2020-09-18 08:28:42 +00:00
|
|
|
# Detect iOS
|
|
|
|
#--------------------------------------
|
2020-04-25 21:17:54 +00:00
|
|
|
if(NOT DEFINED IOS)
|
2020-04-26 12:20:48 +00:00
|
|
|
if(DEFINED CMAKE_SYSTEM_NAME)
|
|
|
|
string(TOLOWER CMAKE_SYSTEM_NAME CMAKE_SYSTEM_NAME_LOWER)
|
|
|
|
if(CMAKE_SYSTEM_NAME_LOWER STREQUAL "ios")
|
|
|
|
set(IOS true)
|
|
|
|
endif()
|
2020-04-25 21:17:54 +00:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2020-09-18 08:28:42 +00:00
|
|
|
# Sources
|
|
|
|
#--------------------------------------
|
2020-03-06 06:06:54 +00:00
|
|
|
set(SrcLib
|
|
|
|
include/MiniFB.h
|
|
|
|
include/MiniFB_cpp.h
|
|
|
|
include/MiniFB_enums.h
|
|
|
|
|
|
|
|
src/MiniFB_common.c
|
|
|
|
src/MiniFB_cpp.cpp
|
|
|
|
src/MiniFB_internal.c
|
|
|
|
src/MiniFB_internal.h
|
2020-04-22 11:00:15 +00:00
|
|
|
src/MiniFB_timer.c
|
2020-03-06 06:06:54 +00:00
|
|
|
src/WindowData.h
|
|
|
|
)
|
|
|
|
|
2020-09-18 08:28:42 +00:00
|
|
|
#--
|
2020-03-06 06:06:54 +00:00
|
|
|
set(SrcWindows
|
|
|
|
src/windows/WinMiniFB.c
|
|
|
|
src/windows/WindowData_Win.h
|
|
|
|
)
|
|
|
|
|
2020-09-18 08:28:42 +00:00
|
|
|
#--
|
2020-03-06 06:06:54 +00:00
|
|
|
set(SrcMacOSX
|
|
|
|
src/macosx/MacMiniFB.m
|
|
|
|
src/macosx/OSXWindow.h
|
|
|
|
src/macosx/OSXWindow.m
|
2020-05-17 16:39:51 +00:00
|
|
|
src/macosx/OSXView.h
|
|
|
|
src/macosx/OSXView.m
|
2020-05-17 17:53:06 +00:00
|
|
|
src/macosx/OSXViewDelegate.h
|
|
|
|
src/macosx/OSXViewDelegate.m
|
2020-03-06 06:06:54 +00:00
|
|
|
src/macosx/WindowData_OSX.h
|
|
|
|
)
|
|
|
|
|
2020-09-18 08:28:42 +00:00
|
|
|
#--
|
2020-04-25 21:17:54 +00:00
|
|
|
set(SrcIOS
|
|
|
|
src/ios/WindowData_IOS.h
|
|
|
|
src/ios/iOSMiniFB.m
|
2020-05-17 16:31:00 +00:00
|
|
|
src/ios/iOSView.h
|
|
|
|
src/ios/iOSView.m
|
2020-04-25 21:17:54 +00:00
|
|
|
src/ios/iOSViewController.h
|
|
|
|
src/ios/iOSViewController.m
|
|
|
|
src/ios/iOSViewDelegate.h
|
|
|
|
src/ios/iOSViewDelegate.m
|
|
|
|
include/MiniFB_ios.h
|
|
|
|
)
|
|
|
|
|
2020-09-18 08:28:42 +00:00
|
|
|
#--
|
2020-03-06 06:06:54 +00:00
|
|
|
set(SrcWayland
|
|
|
|
src/wayland/WaylandMiniFB.c
|
|
|
|
src/wayland/WindowData_Way.h
|
2020-04-22 11:00:15 +00:00
|
|
|
src/MiniFB_linux.c
|
2020-03-06 06:06:54 +00:00
|
|
|
)
|
|
|
|
|
2020-09-18 08:28:42 +00:00
|
|
|
#--
|
2020-03-06 06:06:54 +00:00
|
|
|
set(SrcX11
|
|
|
|
src/x11/X11MiniFB.c
|
|
|
|
src/x11/WindowData_X11.h
|
2020-04-22 11:00:15 +00:00
|
|
|
src/MiniFB_linux.c
|
2020-03-06 06:06:54 +00:00
|
|
|
)
|
|
|
|
|
2020-09-18 08:28:42 +00:00
|
|
|
set(SrcGL
|
|
|
|
src/gl/MiniFB_GL.h
|
|
|
|
src/gl/MiniFB_GL.c
|
|
|
|
)
|
|
|
|
|
2020-03-06 06:06:54 +00:00
|
|
|
# Avoid RelWithDebInfo and MinSizeRel
|
|
|
|
#--------------------------------------
|
|
|
|
set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "" FORCE)
|
|
|
|
|
|
|
|
# Define Release by default
|
|
|
|
#--------------------------------------
|
|
|
|
if(NOT CMAKE_BUILD_TYPE)
|
|
|
|
set(CMAKE_BUILD_TYPE "Release")
|
|
|
|
message(STATUS "Build type not specified: Use Release by default")
|
|
|
|
endif(NOT CMAKE_BUILD_TYPE)
|
|
|
|
|
2020-04-22 11:00:15 +00:00
|
|
|
# Set features
|
|
|
|
#--------------------------------------
|
|
|
|
set(CMAKE_CXX_STANDARD 11)
|
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
|
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
|
|
|
|
2020-06-16 19:22:57 +00:00
|
|
|
# Code generation options
|
|
|
|
#--------------------------------------
|
|
|
|
option(MINIFB_BUILD_EXAMPLES "Build minifb example programs" TRUE)
|
|
|
|
|
2020-09-18 08:28:42 +00:00
|
|
|
if(APPLE AND NOT IOS)
|
|
|
|
option(USE_METAL_API "Build the project using metal API code" ON)
|
|
|
|
elseif(UNIX)
|
|
|
|
option(USE_WAYLAND_API "Build the project using wayland API code" OFF)
|
2020-09-18 13:05:39 +00:00
|
|
|
if(NOT USE_WAYLAND_API)
|
|
|
|
option(USE_OPENGL_API "Build the project using OpenGL API code" ON)
|
|
|
|
endif()
|
2020-09-18 08:28:42 +00:00
|
|
|
elseif(WIN32)
|
|
|
|
option(USE_OPENGL_API "Build the project using OpenGL API code" ON)
|
|
|
|
endif()
|
|
|
|
|
2020-03-06 06:06:54 +00:00
|
|
|
# Set GCC/Clang flags
|
|
|
|
#--------------------------------------
|
2020-09-18 08:28:42 +00:00
|
|
|
if(NOT MSVC)
|
2020-03-06 06:06:54 +00:00
|
|
|
# Avoid default flag values
|
|
|
|
#--------------------------------------
|
|
|
|
set(CMAKE_C_FLAGS "" CACHE STRING "" FORCE)
|
|
|
|
set(CMAKE_C_FLAGS_DEBUG "" CACHE STRING "" FORCE)
|
|
|
|
set(CMAKE_C_FLAGS_RELEASE "" CACHE STRING "" FORCE)
|
|
|
|
|
|
|
|
set(CMAKE_CXX_FLAGS "" CACHE STRING "" FORCE)
|
|
|
|
set(CMAKE_CXX_FLAGS_DEBUG "" CACHE STRING "" FORCE)
|
|
|
|
set(CMAKE_CXX_FLAGS_RELEASE "" CACHE STRING "" FORCE)
|
|
|
|
|
|
|
|
set(CMAKE_OBJC_FLAGS "" CACHE STRING "" FORCE)
|
|
|
|
set(CMAKE_OBJC_FLAGS_DEBUG "" CACHE STRING "" FORCE)
|
|
|
|
set(CMAKE_OBJC_FLAGS_RELEASE "" CACHE STRING "" FORCE)
|
|
|
|
|
|
|
|
set(CMAKE_OBJCXX_FLAGS "" CACHE STRING "" FORCE)
|
|
|
|
set(CMAKE_OBJCXX_FLAGS_DEBUG "" CACHE STRING "" FORCE)
|
|
|
|
set(CMAKE_OBJCXX_FLAGS_RELEASE "" CACHE STRING "" FORCE)
|
|
|
|
|
|
|
|
# Set our flags
|
|
|
|
#--------------------------------------
|
|
|
|
add_compile_options("$<$<CONFIG:Debug>:-g>")
|
|
|
|
add_compile_options("$<IF:$<CONFIG:Debug>,-O0,-O2>")
|
2020-09-18 15:45:24 +00:00
|
|
|
|
2020-09-18 08:28:42 +00:00
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -pedantic -Wno-switch -Wno-unused-function -Wno-implicit-fallthrough")
|
2020-09-18 15:45:24 +00:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}")
|
2020-09-18 08:28:42 +00:00
|
|
|
set(CMAKE_OBJC_FLAGS "${CMAKE_C_FLAGS}")
|
|
|
|
set(CMAKE_OBJCXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
2020-03-06 06:06:54 +00:00
|
|
|
endif()
|
|
|
|
|
2020-09-18 15:45:24 +00:00
|
|
|
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
|
|
|
add_definitions(-D_DEBUG)
|
|
|
|
add_definitions(-DDEBUG)
|
|
|
|
endif()
|
|
|
|
|
2020-03-06 06:06:54 +00:00
|
|
|
# Set compiler/platform specific flags and dependencies
|
|
|
|
#--------------------------------------
|
2020-09-18 08:28:42 +00:00
|
|
|
if(WIN32)
|
2020-03-06 06:06:54 +00:00
|
|
|
|
2020-09-18 08:28:42 +00:00
|
|
|
if(MSVC)
|
|
|
|
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
|
|
|
|
endif()
|
|
|
|
add_definitions(-D_WIN32_WINNT=0x0601) # Windows 7 (we are in 2020)
|
|
|
|
|
|
|
|
if(USE_OPENGL_API)
|
|
|
|
list(APPEND SrcLib ${SrcGL})
|
|
|
|
|
|
|
|
add_definitions(-DUSE_OPENGL_API)
|
|
|
|
endif()
|
2020-03-06 06:06:54 +00:00
|
|
|
|
|
|
|
list(APPEND SrcLib ${SrcWindows})
|
2020-09-18 08:28:42 +00:00
|
|
|
|
|
|
|
elseif(IOS)
|
|
|
|
|
2020-04-25 21:17:54 +00:00
|
|
|
list(APPEND SrcLib ${SrcIOS})
|
2020-09-18 08:28:42 +00:00
|
|
|
|
|
|
|
elseif(APPLE)
|
|
|
|
|
2020-03-06 06:06:54 +00:00
|
|
|
if(USE_METAL_API)
|
|
|
|
add_definitions(-DUSE_METAL_API)
|
|
|
|
endif()
|
2020-09-18 08:28:42 +00:00
|
|
|
|
2020-03-06 06:06:54 +00:00
|
|
|
list(APPEND SrcLib ${SrcMacOSX})
|
2020-09-18 08:28:42 +00:00
|
|
|
|
|
|
|
elseif(UNIX)
|
|
|
|
|
2020-03-06 06:06:54 +00:00
|
|
|
if(USE_WAYLAND_API)
|
|
|
|
list(APPEND SrcLib ${SrcWayland})
|
|
|
|
else()
|
2020-09-18 13:05:39 +00:00
|
|
|
if(USE_OPENGL_API)
|
|
|
|
list(APPEND SrcLib ${SrcGL})
|
|
|
|
|
|
|
|
add_definitions(-DUSE_OPENGL_API)
|
|
|
|
endif()
|
2020-03-06 06:06:54 +00:00
|
|
|
list(APPEND SrcLib ${SrcX11})
|
|
|
|
endif()
|
2020-09-18 08:28:42 +00:00
|
|
|
|
2020-03-06 06:06:54 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# Library
|
|
|
|
#--------------------------------------
|
2020-09-18 08:28:42 +00:00
|
|
|
add_library(minifb STATIC
|
2020-03-06 06:06:54 +00:00
|
|
|
${SrcLib}
|
|
|
|
)
|
|
|
|
|
2020-09-18 08:28:42 +00:00
|
|
|
# Link
|
2020-04-22 13:59:42 +00:00
|
|
|
#--------------------------------------
|
2020-09-18 08:28:42 +00:00
|
|
|
if(APPLE)
|
|
|
|
|
2020-04-25 21:17:54 +00:00
|
|
|
if(IOS)
|
2020-09-18 08:28:42 +00:00
|
|
|
target_link_libraries(minifb
|
2020-04-26 12:20:48 +00:00
|
|
|
"-framework UIKit"
|
|
|
|
"-framework QuartzCore"
|
|
|
|
"-framework Metal"
|
|
|
|
"-framework MetalKit"
|
|
|
|
)
|
2020-04-25 21:17:54 +00:00
|
|
|
else()
|
2020-04-26 12:20:48 +00:00
|
|
|
target_link_libraries(minifb
|
|
|
|
"-framework Cocoa"
|
|
|
|
"-framework QuartzCore"
|
|
|
|
"-framework Metal"
|
|
|
|
"-framework MetalKit"
|
|
|
|
)
|
2020-04-25 21:17:54 +00:00
|
|
|
endif()
|
2020-09-18 08:28:42 +00:00
|
|
|
|
|
|
|
elseif(UNIX)
|
|
|
|
|
2020-04-22 13:59:42 +00:00
|
|
|
if(USE_WAYLAND_API)
|
2020-09-18 08:28:42 +00:00
|
|
|
target_link_libraries(minifb
|
2020-04-26 12:20:48 +00:00
|
|
|
"-lwayland-client"
|
|
|
|
"-lwayland-cursor"
|
|
|
|
)
|
2020-04-22 13:59:42 +00:00
|
|
|
else()
|
2020-09-18 08:28:42 +00:00
|
|
|
target_link_libraries(minifb
|
2020-04-26 12:20:48 +00:00
|
|
|
"-lX11"
|
|
|
|
)
|
2020-09-18 13:05:39 +00:00
|
|
|
if(USE_OPENGL_API)
|
|
|
|
target_link_libraries(minifb
|
|
|
|
"-lGL"
|
|
|
|
)
|
|
|
|
endif()
|
2020-04-22 13:59:42 +00:00
|
|
|
endif()
|
2020-09-18 08:28:42 +00:00
|
|
|
|
|
|
|
elseif(WIN32)
|
|
|
|
|
|
|
|
if(USE_OPENGL_API)
|
|
|
|
target_link_libraries(minifb
|
|
|
|
"Opengl32.lib"
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2020-04-22 13:59:42 +00:00
|
|
|
endif()
|
|
|
|
|
2020-03-06 06:06:54 +00:00
|
|
|
# For all projects
|
|
|
|
#--------------------------------------
|
2020-04-22 13:59:42 +00:00
|
|
|
target_include_directories(minifb PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include)
|
2020-03-06 06:06:54 +00:00
|
|
|
target_include_directories(minifb PRIVATE src)
|
2020-04-22 13:59:42 +00:00
|
|
|
|
2020-03-06 06:06:54 +00:00
|
|
|
link_libraries(minifb)
|
|
|
|
|
|
|
|
# Examples
|
|
|
|
#--------------------------------------
|
2020-09-18 08:28:42 +00:00
|
|
|
if(MINIFB_BUILD_EXAMPLES)
|
2020-06-16 19:22:57 +00:00
|
|
|
if(NOT IOS)
|
2020-03-06 06:06:54 +00:00
|
|
|
|
2020-06-16 19:22:57 +00:00
|
|
|
add_executable(noise
|
|
|
|
tests/noise.c
|
|
|
|
)
|
2020-03-06 06:06:54 +00:00
|
|
|
|
2020-06-16 19:22:57 +00:00
|
|
|
add_executable(input_events
|
|
|
|
tests/input_events.c
|
|
|
|
)
|
2020-03-06 06:06:54 +00:00
|
|
|
|
2020-06-16 19:22:57 +00:00
|
|
|
add_executable(input_events_cpp
|
|
|
|
tests/input_events_cpp.cpp
|
|
|
|
)
|
2020-03-06 06:06:54 +00:00
|
|
|
|
2020-06-16 19:22:57 +00:00
|
|
|
add_executable(multiple_windows
|
|
|
|
tests/multiple_windows.c
|
|
|
|
)
|
2020-04-26 12:20:48 +00:00
|
|
|
|
2020-09-20 16:40:03 +00:00
|
|
|
add_executable(hidpi
|
|
|
|
tests/hidpi.c
|
|
|
|
)
|
|
|
|
|
2020-06-16 19:22:57 +00:00
|
|
|
else()
|
|
|
|
|
|
|
|
add_executable(noise
|
|
|
|
tests/ios/main.m
|
|
|
|
tests/ios/AppDelegate.h
|
|
|
|
tests/ios/AppDelegate.m
|
|
|
|
)
|
2020-04-25 21:17:54 +00:00
|
|
|
|
2020-06-16 19:22:57 +00:00
|
|
|
set(CMAKE_OSX_DEPLOYMENT_TARGET "11.0" CACHE STRING "Set CMake deployment target" ${FORCE_CACHE})
|
2020-04-25 21:17:54 +00:00
|
|
|
|
2020-06-16 19:22:57 +00:00
|
|
|
target_include_directories(noise PRIVATE src)
|
|
|
|
target_include_directories(noise PRIVATE src/ios)
|
2020-04-25 21:17:54 +00:00
|
|
|
|
2020-06-16 19:22:57 +00:00
|
|
|
add_definitions(-DTVOS_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET})
|
|
|
|
|
|
|
|
endif()
|
2020-04-25 21:17:54 +00:00
|
|
|
|
|
|
|
endif()
|
2020-03-06 06:06:54 +00:00
|
|
|
|
|
|
|
message("Done " ${PROJECT_NAME})
|