all repos — mgba @ 8bbac2f512519b5502748e67e4dae8c36b71547c

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 "-g -Wall -Wextra -std=gnu99")
  5set(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	foreach(REQUIRE ${FEATURE_REQUIRES})
 30		find_package(${REQUIRE} QUIET)
 31		pkg_search_module(${REQUIRE} ${REQUIRE})
 32		if (NOT ${REQUIRE}_FOUND)
 33			message(WARNING "Requested module ${REQUIRE} missing for feature ${FEATURE_NAME}. Feature disabled.")
 34			set(${FEATURE_NAME} OFF PARENT_SCOPE)
 35			return()
 36		endif()
 37	endforeach()
 38endfunction()
 39
 40# Version information
 41set(LIB_VERSION_MAJOR 0)
 42set(LIB_VERSION_MINOR 1)
 43set(LIB_VERSION_PATCH 0)
 44set(LIB_VERSION_ABI 0.1)
 45set(LIB_VERSION_STRING ${LIB_VERSION_MAJOR}.${LIB_VERSION_MINOR}.${LIB_VERSION_PATCH})
 46
 47# Advanced settings
 48set(BUILD_PGO CACHE BOOL "Build with profiling-guided optimization")
 49set(PGO_STAGE_2 CACHE BOOL "Rebuild for profiling-guided optimization after profiles have been generated")
 50set(PGO_DIR "/tmp/gba-pgo/" CACHE PATH "Profiling-guided optimization profiles path")
 51mark_as_advanced(BUILD_PGO PGO_STAGE_2 PGO_DIR)
 52set(PGO_PRE_FLAGS "-pg -fprofile-generate=${PGO_DIR}")
 53set(PGO_POST_FLAGS "-fprofile-use=${PGO_DIR}")
 54
 55if(BUILD_PGO AND NOT PGO_STAGE_2)
 56	set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${PGO_PRE_FLAGS}")
 57	set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${PGO_PRE_FLAGS}")
 58	set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${PGO_PRE_FLAGS}")
 59elseif(BUILD_PGO AND PGO_STAGE_2)
 60	set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${PGO_POST_FLAGS}")
 61	set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${PGO_POST_FLAGS}")
 62	set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${PGO_POST_FLAGS}")
 63endif()
 64
 65add_definitions(-DBINARY_NAME="${BINARY_NAME}" -DPROJECT_NAME="${PROJECT_NAME}")
 66
 67# Feature dependencies
 68find_feature(USE_CLI_DEBUGGER "libedit")
 69find_feature(USE_FFMPEG "libavcodec;libavformat;libavutil")
 70find_feature(USE_PNG "PNG;ZLIB")
 71find_feature(USE_LIBZIP "libzip")
 72
 73# Platform support
 74if(WIN32)
 75	add_definitions(-D_WIN32_WINNT=0x0600)
 76	list(APPEND OS_LIB Ws2_32)
 77	file(GLOB OS_SRC ${CMAKE_SOURCE_DIR}/src/platform/windows/*.c)
 78	source_group("Windows-specific code" FILES ${OS_SRC})
 79else()
 80	add_definitions(-DUSE_PTHREADS)
 81	list(APPEND OS_LIB pthread)
 82	file(GLOB OS_SRC ${CMAKE_SOURCE_DIR}/src/platform/posix/*.c)
 83	source_group("POSIX-specific code" FILES ${OS_SRC})
 84endif()
 85
 86if(BUILD_BBB OR BUILD_RASPI)
 87	enable_language(ASM)
 88	if(NOT BUILD_EGL)
 89		add_definitions(-DCOLOR_16_BIT -DCOLOR_5_6_5)
 90	endif()
 91endif()
 92
 93# Features
 94set(DEBUGGER_SRC ${CMAKE_SOURCE_DIR}/src/debugger/debugger.c ${CMAKE_SOURCE_DIR}/src/debugger/memory-debugger.c)
 95
 96if(USE_CLI_DEBUGGER)
 97	add_definitions(-DUSE_CLI_DEBUGGER)
 98	list(APPEND DEBUGGER_SRC ${CMAKE_SOURCE_DIR}/src/debugger/cli-debugger.c)
 99	list(APPEND DEBUGGER_SRC ${CMAKE_SOURCE_DIR}/src/debugger/parser.c)
100	set(DEBUGGER_LIB ${EDIT_LIBRARIES})
101else()
102	set(DEBUGGER_LIB "")
103endif()
104
105if(USE_GDB_STUB)
106	add_definitions(-DUSE_GDB_STUB)
107	list(APPEND DEBUGGER_SRC ${CMAKE_SOURCE_DIR}/src/debugger/gdb-stub.c)
108endif()
109source_group("ARM debugger" FILES ${DEBUGGER_SRC})
110
111if(USE_FFMPEG)
112	pkg_search_module(LIBAVCODEC libavcodec)
113	pkg_search_module(LIBAVFORMAT libavcodec;libavformat;libavutil)
114	pkg_search_module(LIBAVUTIL libavutil)
115	add_definitions(-DUSE_FFMPEG)
116	list(APPEND UTIL_SRC "${CMAKE_SOURCE_DIR}/src/platform/ffmpeg/ffmpeg-encoder.c")
117	list(APPEND DEPENDENCY_LIB ${LIBAVCODEC_LIBRARIES} ${LIBAVFORMAT_LIBRARIES} ${LIBAVUTIL_LIBRARIES})
118endif()
119
120if(USE_PNG)
121	find_package(PNG)
122	find_package(ZLIB)
123	add_definitions(-DUSE_PNG)
124	include_directories(${PNG_PNG_INCLUDE_DIR})
125	list(APPEND DEPENDENCY_LIB ${PNG_LIBRARIES} ${ZLIB_LIBRARIES})
126endif()
127
128if(USE_LIBZIP)
129	include_directories(${LIBZIP_INCLUDE_DIRS})
130	list(APPEND DEPENDENCY_LIB ${LIBZIP_LIBRARIES})
131	add_definitions(-DENABLE_LIBZIP)
132endif()
133
134# Binaries
135add_library(${BINARY_NAME} SHARED ${ARM_SRC} ${GBA_SRC} ${DEBUGGER_SRC} ${RENDERER_SRC} ${UTIL_SRC} ${VFS_SRC} ${OS_SRC})
136target_link_libraries(${BINARY_NAME} m ${DEBUGGER_LIB} ${OS_LIB} ${DEPENDENCY_LIB})
137install(TARGETS ${BINARY_NAME} DESTINATION lib)
138set_target_properties(${BINARY_NAME} PROPERTIES VERSION ${LIB_VERSION_STRING} SOVERSION ${LIB_VERSION_ABI})
139
140if(BUILD_SDL)
141	add_subdirectory(${CMAKE_SOURCE_DIR}/src/platform/sdl ${CMAKE_BINARY_DIR}/sdl)
142endif()
143
144if(BUILD_PERF)
145	set(PERF_SRC ${CMAKE_SOURCE_DIR}/src/platform/perf-main.c)
146	if(UNIX AND NOT APPLE)
147		list(APPEND PERF_LIB rt)
148	endif()
149
150	add_executable(${BINARY_NAME}-perf ${PERF_SRC})
151	target_link_libraries(${BINARY_NAME}-perf ${BINARY_NAME} ${PERF_LIB})
152	install(TARGETS ${BINARY_NAME}-perf DESTINATION bin)
153endif()
154
155# Summaries
156message(STATUS "Feature summary:")
157message(STATUS "	CLI debugger: ${USE_CLI_DEBUGGER}")
158message(STATUS "	GDB stub: ${USE_GDB_STUB}")
159message(STATUS "	Movie recording: ${USE_FFMPEG}")
160message(STATUS "	Screenshot/advanced savestate support: ${USE_PNG}")
161message(STATUS "	ZIP support: ${USE_LIBZIP}")
162message(STATUS "Frontend summary:")
163message(STATUS "	SDL (${SDL_VERSION}): ${BUILD_SDL}")
164message(STATUS "	Profiling: ${BUILD_PERF}")