all repos — mgba @ 8ef31b1c3d6c170ed808ce99717ef2587a6e725e

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(BUILD_SDL ON CACHE BOOL "Build SDL frontend")
 11set(BUILD_PERF ON CACHE BOOL "Build performance profiling tool")
 12file(GLOB ARM_SRC ${CMAKE_SOURCE_DIR}/src/arm/*.c)
 13file(GLOB GBA_SRC ${CMAKE_SOURCE_DIR}/src/gba/*.c)
 14file(GLOB UTIL_SRC ${CMAKE_SOURCE_DIR}/src/util/*.[cS])
 15file(GLOB VFS_SRC ${CMAKE_SOURCE_DIR}/src/util/vfs/*.c)
 16file(GLOB RENDERER_SRC ${CMAKE_SOURCE_DIR}/src/gba/renderers/video-software.c)
 17list(APPEND UTIL_SRC ${CMAKE_SOURCE_DIR}/src/platform/commandline.c)
 18source_group("ARM core" FILES ${ARM_SRC})
 19source_group("GBA board" FILES ${GBA_SRC} ${RENDERER_SRC})
 20source_group("Utilities" FILES ${UTIL_SRC} ${VFS_SRC}})
 21include_directories(${CMAKE_SOURCE_DIR}/src/arm)
 22include_directories(${CMAKE_SOURCE_DIR}/src/gba)
 23include_directories(${CMAKE_SOURCE_DIR}/src)
 24
 25set(LIB_VERSION_MAJOR 0)
 26set(LIB_VERSION_MINOR 1)
 27set(LIB_VERSION_PATCH 0)
 28set(LIB_VERSION_ABI 0.1)
 29set(LIB_VERSION_STRING ${LIB_VERSION_MAJOR}.${LIB_VERSION_MINOR}.${LIB_VERSION_PATCH})
 30
 31set(BUILD_PGO CACHE BOOL "Build with profiling-guided optimization")
 32set(PGO_STAGE_2 CACHE BOOL "Rebuild for profiling-guided optimization after profiles have been generated")
 33set(PGO_DIR "/tmp/gba-pgo/" CACHE PATH "Profiling-guided optimization profiles path")
 34mark_as_advanced(BUILD_PGO PGO_STAGE_2 PGO_DIR)
 35set(PGO_PRE_FLAGS "-pg -fprofile-generate=${PGO_DIR}")
 36set(PGO_POST_FLAGS "-fprofile-use=${PGO_DIR}")
 37
 38if(BUILD_PGO AND NOT PGO_STAGE_2)
 39	set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${PGO_PRE_FLAGS}")
 40	set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${PGO_PRE_FLAGS}")
 41	set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${PGO_PRE_FLAGS}")
 42elseif(BUILD_PGO AND PGO_STAGE_2)
 43	set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${PGO_POST_FLAGS}")
 44	set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${PGO_POST_FLAGS}")
 45	set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${PGO_POST_FLAGS}")
 46endif()
 47
 48add_definitions(-DBINARY_NAME="${BINARY_NAME}" -DPROJECT_NAME="${PROJECT_NAME}")
 49
 50include(FindPkgConfig)
 51pkg_search_module(LIBZIP libzip)
 52if(LIBZIP_FOUND)
 53	include_directories(${LIBZIP_INCLUDE_DIRS})
 54	list(APPEND DEPENDENCY_LIB ${LIBZIP_LIBRARIES})
 55	add_definitions(-DENABLE_LIBZIP)
 56else()
 57	message(WARNING "Could not find libzip for archive support")
 58endif()
 59
 60if(WIN32)
 61	add_definitions(-D_WIN32_WINNT=0x0600)
 62	list(APPEND OS_LIB Ws2_32)
 63	file(GLOB OS_SRC ${CMAKE_SOURCE_DIR}/src/platform/windows/*.c)
 64	source_group("Windows-specific code" FILES ${OS_SRC})
 65else()
 66	add_definitions(-DUSE_PTHREADS)
 67	list(APPEND OS_LIB pthread)
 68	file(GLOB OS_SRC ${CMAKE_SOURCE_DIR}/src/platform/posix/*.c)
 69	source_group("POSIX-specific code" FILES ${OS_SRC})
 70endif()
 71
 72if(BUILD_BBB OR BUILD_RASPI)
 73	enable_language(ASM)
 74	if(NOT BUILD_EGL)
 75		add_definitions(-DCOLOR_16_BIT -DCOLOR_5_6_5)
 76	endif()
 77endif()
 78
 79set(DEBUGGER_SRC ${CMAKE_SOURCE_DIR}/src/debugger/debugger.c ${CMAKE_SOURCE_DIR}/src/debugger/memory-debugger.c)
 80
 81if(USE_CLI_DEBUGGER)
 82	pkg_search_module(EDIT libedit)
 83	if(EDIT_FOUND)
 84		add_definitions(-DUSE_CLI_DEBUGGER)
 85		list(APPEND DEBUGGER_SRC ${CMAKE_SOURCE_DIR}/src/debugger/cli-debugger.c)
 86		list(APPEND DEBUGGER_SRC ${CMAKE_SOURCE_DIR}/src/debugger/parser.c)
 87		set(DEBUGGER_LIB ${EDIT_LIBRARIES})
 88	else()
 89		message(WARNING "Could not find libedit for CLI debugger support")
 90		set(USE_CLI_DEBUGGER OFF)
 91	endif()
 92else()
 93	set(DEBUGGER_LIB "")
 94endif()
 95
 96if(USE_GDB_STUB)
 97	add_definitions(-DUSE_GDB_STUB)
 98	list(APPEND DEBUGGER_SRC ${CMAKE_SOURCE_DIR}/src/debugger/gdb-stub.c)
 99endif()
100source_group("ARM debugger" FILES ${DEBUGGER_SRC})
101
102if(USE_FFMPEG)
103	pkg_search_module(LIBAVCODEC libavcodec REQUIRED)
104	pkg_search_module(LIBAVFORMAT libavformat REQUIRED)
105	pkg_search_module(LIBAVUTIL libavutil REQUIRED)
106	add_definitions(-DUSE_FFMPEG)
107	list(APPEND UTIL_SRC "${CMAKE_SOURCE_DIR}/src/platform/ffmpeg/ffmpeg-encoder.c")
108	list(APPEND DEPENDENCY_LIB ${LIBAVCODEC_LIBRARIES} ${LIBAVFORMAT_LIBRARIES} ${LIBAVUTIL_LIBRARIES})
109endif()
110
111if(USE_PNG)
112	find_package(PNG REQUIRED)
113	find_package(ZLIB REQUIRED)
114	add_definitions(-DUSE_PNG)
115	include_directories(${PNG_PNG_INCLUDE_DIR})
116	list(APPEND DEPENDENCY_LIB ${PNG_LIBRARIES} ${ZLIB_LIBRARIES})
117endif()
118
119add_library(${BINARY_NAME} SHARED ${ARM_SRC} ${GBA_SRC} ${DEBUGGER_SRC} ${RENDERER_SRC} ${UTIL_SRC} ${VFS_SRC} ${OS_SRC})
120target_link_libraries(${BINARY_NAME} m ${DEBUGGER_LIB} ${OS_LIB} ${DEPENDENCY_LIB})
121install(TARGETS ${BINARY_NAME} DESTINATION lib)
122set_target_properties(${BINARY_NAME} PROPERTIES VERSION ${LIB_VERSION_STRING} SOVERSION ${LIB_VERSION_ABI})
123
124if(BUILD_SDL)
125	add_subdirectory(${CMAKE_SOURCE_DIR}/src/platform/sdl ${CMAKE_BINARY_DIR}/sdl)
126endif()
127
128if(BUILD_PERF)
129	set(PERF_SRC ${CMAKE_SOURCE_DIR}/src/platform/perf-main.c)
130	if(UNIX AND NOT APPLE)
131		list(APPEND PERF_LIB rt)
132	endif()
133
134	add_executable(${BINARY_NAME}-perf ${PERF_SRC})
135	target_link_libraries(${BINARY_NAME}-perf ${BINARY_NAME} ${PERF_LIB})
136	install(TARGETS ${BINARY_NAME}-perf DESTINATION bin)
137endif()