all repos — mgba @ 53333947552deed0babbdbcaa97e00a103486c61

mGBA Game Boy Advance Emulator

CMakeLists.txt (view raw)

  1cmake_minimum_required(VERSION 2.6)
  2project(mGBA)
  3set(BINARY_NAME mgba CACHE INTERNAL "Name of output binaries")
  4set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g -Wall -Wextra -std=gnu99")
  5set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3 -Wall -Wextra -std=gnu99")
  6set(USE_CLI_DEBUGGER ON CACHE BOOL "Whether or not to enable the CLI-mode ARM debugger")
  7set(USE_GDB_STUB ON CACHE BOOL "Whether or not to enable the GDB stub ARM debugger")
  8set(USE_FFMPEG ON CACHE BOOL "Whether or not to enable FFmpeg support")
  9set(USE_PNG ON CACHE BOOL "Whether or not to enable PNG support")
 10set(USE_LIBZIP ON CACHE BOOL "Whether or not to enable ZIP support")
 11set(BUILD_SDL ON CACHE BOOL "Build SDL frontend")
 12set(BUILD_PERF OFF CACHE BOOL "Build performance profiling tool")
 13file(GLOB ARM_SRC ${CMAKE_SOURCE_DIR}/src/arm/*.c)
 14file(GLOB GBA_SRC ${CMAKE_SOURCE_DIR}/src/gba/*.c)
 15file(GLOB UTIL_SRC ${CMAKE_SOURCE_DIR}/src/util/*.[cS])
 16file(GLOB VFS_SRC ${CMAKE_SOURCE_DIR}/src/util/vfs/*.c)
 17file(GLOB RENDERER_SRC ${CMAKE_SOURCE_DIR}/src/gba/renderers/video-software.c)
 18list(APPEND UTIL_SRC ${CMAKE_SOURCE_DIR}/src/platform/commandline.c)
 19source_group("ARM core" FILES ${ARM_SRC})
 20source_group("GBA board" FILES ${GBA_SRC} ${RENDERER_SRC})
 21source_group("Utilities" FILES ${UTIL_SRC} ${VFS_SRC}})
 22include_directories(${CMAKE_SOURCE_DIR}/src/arm)
 23include_directories(${CMAKE_SOURCE_DIR}/src/gba)
 24include_directories(${CMAKE_SOURCE_DIR}/src)
 25
 26# Function definitions
 27include(FindPkgConfig)
 28function(find_feature FEATURE_NAME FEATURE_REQUIRES)
 29	if (NOT ${FEATURE_NAME})
 30		return()
 31	endif()
 32	foreach(REQUIRE ${FEATURE_REQUIRES})
 33		find_package(${REQUIRE} QUIET)
 34		pkg_search_module(${REQUIRE} ${REQUIRE})
 35		if (NOT ${REQUIRE}_FOUND)
 36			message(WARNING "Requested module ${REQUIRE} missing for feature ${FEATURE_NAME}. Feature disabled.")
 37			set(${FEATURE_NAME} OFF PARENT_SCOPE)
 38			return()
 39		endif()
 40		set(${REQUIRE}_LIBRARIES ${${REQUIRE}_LIBRARIES} PARENT_SCOPE)
 41		set(${REQUIRE}_INCLUDE_DIRS ${${REQUIRE}_INCLUDE_DIRS} PARENT_SCOPE)
 42	endforeach()
 43endfunction()
 44
 45# Version information
 46set(LIB_VERSION_MAJOR 0)
 47set(LIB_VERSION_MINOR 1)
 48set(LIB_VERSION_PATCH 0)
 49set(LIB_VERSION_ABI 0.1)
 50set(LIB_VERSION_STRING ${LIB_VERSION_MAJOR}.${LIB_VERSION_MINOR}.${LIB_VERSION_PATCH})
 51
 52# Advanced settings
 53set(BUILD_PGO CACHE BOOL "Build with profiling-guided optimization")
 54set(PGO_STAGE_2 CACHE BOOL "Rebuild for profiling-guided optimization after profiles have been generated")
 55set(PGO_DIR "/tmp/gba-pgo/" CACHE PATH "Profiling-guided optimization profiles path")
 56mark_as_advanced(BUILD_PGO PGO_STAGE_2 PGO_DIR)
 57set(PGO_PRE_FLAGS "-pg -fprofile-generate=${PGO_DIR}")
 58set(PGO_POST_FLAGS "-fprofile-use=${PGO_DIR}")
 59
 60if(BUILD_PGO AND NOT PGO_STAGE_2)
 61	set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${PGO_PRE_FLAGS}")
 62	set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${PGO_PRE_FLAGS}")
 63	set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${PGO_PRE_FLAGS}")
 64elseif(BUILD_PGO AND PGO_STAGE_2)
 65	set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${PGO_POST_FLAGS}")
 66	set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${PGO_POST_FLAGS}")
 67	set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${PGO_POST_FLAGS}")
 68endif()
 69
 70add_definitions(-DBINARY_NAME="${BINARY_NAME}" -DPROJECT_NAME="${PROJECT_NAME}")
 71
 72# Feature dependencies
 73find_feature(USE_CLI_DEBUGGER "libedit")
 74find_feature(USE_FFMPEG "libavcodec;libavformat;libavutil")
 75find_feature(USE_PNG "PNG;ZLIB")
 76find_feature(USE_LIBZIP "libzip")
 77
 78# Platform support
 79if(WIN32)
 80	add_definitions(-D_WIN32_WINNT=0x0600)
 81	list(APPEND OS_LIB Ws2_32)
 82	file(GLOB OS_SRC ${CMAKE_SOURCE_DIR}/src/platform/windows/*.c)
 83	source_group("Windows-specific code" FILES ${OS_SRC})
 84else()
 85	add_definitions(-DUSE_PTHREADS)
 86	list(APPEND OS_LIB pthread)
 87	file(GLOB OS_SRC ${CMAKE_SOURCE_DIR}/src/platform/posix/*.c)
 88	source_group("POSIX-specific code" FILES ${OS_SRC})
 89endif()
 90
 91if(BUILD_BBB OR BUILD_RASPI)
 92	enable_language(ASM)
 93	if(NOT BUILD_EGL)
 94		add_definitions(-DCOLOR_16_BIT -DCOLOR_5_6_5)
 95	endif()
 96endif()
 97
 98# Features
 99set(DEBUGGER_SRC ${CMAKE_SOURCE_DIR}/src/debugger/debugger.c ${CMAKE_SOURCE_DIR}/src/debugger/memory-debugger.c)
100
101if(USE_CLI_DEBUGGER)
102	add_definitions(-DUSE_CLI_DEBUGGER)
103	list(APPEND DEBUGGER_SRC ${CMAKE_SOURCE_DIR}/src/debugger/cli-debugger.c)
104	list(APPEND DEBUGGER_SRC ${CMAKE_SOURCE_DIR}/src/debugger/parser.c)
105	set(DEBUGGER_LIB ${EDIT_LIBRARIES})
106else()
107	set(DEBUGGER_LIB "")
108endif()
109
110if(USE_GDB_STUB)
111	add_definitions(-DUSE_GDB_STUB)
112	list(APPEND DEBUGGER_SRC ${CMAKE_SOURCE_DIR}/src/debugger/gdb-stub.c)
113endif()
114source_group("ARM debugger" FILES ${DEBUGGER_SRC})
115
116if(USE_FFMPEG)
117	add_definitions(-DUSE_FFMPEG)
118	include_directories(AFTER ${LIBAVCODEC_INCLUDE_DIRS} ${LIBAVFORMAT_INCLUDE_DIRS} ${LIBAVUTIL_INCLUDE_DIRS})
119	list(APPEND UTIL_SRC "${CMAKE_SOURCE_DIR}/src/platform/ffmpeg/ffmpeg-encoder.c")
120	list(APPEND DEPENDENCY_LIB ${LIBAVCODEC_LIBRARIES} ${LIBAVFORMAT_LIBRARIES} ${LIBAVUTIL_LIBRARIES})
121endif()
122
123if(USE_PNG)
124	add_definitions(-DUSE_PNG)
125	include_directories(AFTER ${PNG_INCLUDE_DIRS})
126	list(APPEND DEPENDENCY_LIB ${PNG_LIBRARIES} ${ZLIB_LIBRARIES})
127endif()
128
129if(USE_LIBZIP)
130	include_directories(AFTER ${LIBZIP_INCLUDE_DIRS})
131	list(APPEND DEPENDENCY_LIB ${LIBZIP_LIBRARIES})
132	add_definitions(-DENABLE_LIBZIP)
133endif()
134
135# Binaries
136add_library(${BINARY_NAME} SHARED ${ARM_SRC} ${GBA_SRC} ${DEBUGGER_SRC} ${RENDERER_SRC} ${UTIL_SRC} ${VFS_SRC} ${OS_SRC})
137target_link_libraries(${BINARY_NAME} m ${DEBUGGER_LIB} ${OS_LIB} ${DEPENDENCY_LIB})
138install(TARGETS ${BINARY_NAME} DESTINATION lib)
139set_target_properties(${BINARY_NAME} PROPERTIES VERSION ${LIB_VERSION_STRING} SOVERSION ${LIB_VERSION_ABI})
140
141if(BUILD_SDL)
142	add_subdirectory(${CMAKE_SOURCE_DIR}/src/platform/sdl ${CMAKE_BINARY_DIR}/sdl)
143endif()
144
145if(BUILD_PERF)
146	set(PERF_SRC ${CMAKE_SOURCE_DIR}/src/platform/perf-main.c)
147	if(UNIX AND NOT APPLE)
148		list(APPEND PERF_LIB rt)
149	endif()
150
151	add_executable(${BINARY_NAME}-perf ${PERF_SRC})
152	target_link_libraries(${BINARY_NAME}-perf ${BINARY_NAME} ${PERF_LIB})
153	install(TARGETS ${BINARY_NAME}-perf DESTINATION bin)
154endif()
155
156# Summaries
157message(STATUS "Feature summary:")
158message(STATUS "	CLI debugger: ${USE_CLI_DEBUGGER}")
159message(STATUS "	GDB stub: ${USE_GDB_STUB}")
160message(STATUS "	Video recording: ${USE_FFMPEG}")
161message(STATUS "	Screenshot/advanced savestate support: ${USE_PNG}")
162message(STATUS "	ZIP support: ${USE_LIBZIP}")
163message(STATUS "Frontend summary:")
164message(STATUS "	SDL (${SDL_VERSION}): ${BUILD_SDL}")
165message(STATUS "	Profiling: ${BUILD_PERF}")