all repos — mgba @ 9ac58c69968c2d4a166b74f486fd0b8086cdbc55

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