all repos — mgba @ 6291a62860376b1e4a5e0d3ee681b6c93eb10f68

mGBA Game Boy Advance Emulator

CMakeLists.txt (view raw)

  1cmake_minimum_required(VERSION 2.6)
  2project(GBAc)
  3set(BINARY_NAME gbac 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(BUILD_SDL ON CACHE BOOL "Build SDL frontend")
  9set(BUILD_PERF ON CACHE BOOL "Build performance profiling tool")
 10file(GLOB ARM_SRC ${CMAKE_SOURCE_DIR}/src/arm/*.c)
 11file(GLOB GBA_SRC ${CMAKE_SOURCE_DIR}/src/gba/*.c)
 12file(GLOB UTIL_SRC ${CMAKE_SOURCE_DIR}/src/util/*.[cS])
 13file(GLOB VFS_SRC ${CMAKE_SOURCE_DIR}/src/util/vfs/*.c)
 14file(GLOB RENDERER_SRC ${CMAKE_SOURCE_DIR}/src/gba/renderers/video-software.c)
 15set(UTIL_SRC ${UTIL_SRC};${CMAKE_SOURCE_DIR}/src/platform/commandline.c)
 16source_group("ARM core" FILES ${ARM_SRC})
 17source_group("GBA board" FILES ${GBA_SRC} ${RENDERER_SRC})
 18source_group("Utilities" FILES ${UTIL_SRC} ${VFS_SRC}})
 19include_directories(${CMAKE_SOURCE_DIR}/src/arm)
 20include_directories(${CMAKE_SOURCE_DIR}/src/gba)
 21include_directories(${CMAKE_SOURCE_DIR}/src)
 22
 23set(BUILD_PGO CACHE BOOL "Build with profiling-guided optimization")
 24set(PGO_STAGE_2 CACHE BOOL "Rebuild for profiling-guided optimization after profiles have been generated")
 25set(PGO_DIR "/tmp/gba-pgo/" CACHE PATH "Profiling-guided optimization profiles path")
 26mark_as_advanced(BUILD_PGO PGO_STAGE_2 PGO_DIR)
 27set(PGO_PRE_FLAGS "-pg -fprofile-generate=${PGO_DIR}")
 28set(PGO_POST_FLAGS "-fprofile-use=${PGO_DIR}")
 29
 30if(BUILD_PGO AND NOT PGO_STAGE_2)
 31	set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${PGO_PRE_FLAGS}")
 32	set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${PGO_PRE_FLAGS}")
 33	set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${PGO_PRE_FLAGS}")
 34elseif(BUILD_PGO AND PGO_STAGE_2)
 35	set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${PGO_POST_FLAGS}")
 36	set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${PGO_POST_FLAGS}")
 37	set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${PGO_POST_FLAGS}")
 38endif()
 39
 40add_definitions(-DBINARY_NAME="${BINARY_NAME}" -DPROJECT_NAME="${PROJECT_NAME}")
 41
 42include(FindPkgConfig)
 43pkg_search_module(LIBZIP libzip)
 44if(LIBZIP_FOUND)
 45	include_directories(${LIBZIP_INCLUDE_DIRS})
 46	list(APPEND DEPENDENCY_LIB ${LIBZIP_LIBRARIES})
 47	add_definitions(-DENABLE_LIBZIP)
 48else()
 49	message(WARNING "Could not find libzip for archive support")
 50endif()
 51
 52if(WIN32)
 53	add_definitions(-D_WIN32_WINNT=0x0600)
 54	set(OS_LIB "${OS_LIB};Ws2_32")
 55	file(GLOB OS_SRC ${CMAKE_SOURCE_DIR}/src/platform/windows/*.c)
 56	source_group("Windows-specific code" FILES ${OS_SRC})
 57else()
 58	add_definitions(-DUSE_PTHREADS)
 59	set(OS_LIB "${OS_LIB};pthread")
 60	file(GLOB OS_SRC ${CMAKE_SOURCE_DIR}/src/platform/posix/*.c)
 61	source_group("POSIX-specific code" FILES ${OS_SRC})
 62endif()
 63
 64if(BUILD_BBB OR BUILD_RASPI)
 65	enable_language(ASM)
 66	if(NOT BUILD_EGL)
 67		add_definitions(-DCOLOR_16_BIT -DCOLOR_5_6_5)
 68	endif()
 69endif()
 70
 71set(DEBUGGER_SRC "${CMAKE_SOURCE_DIR}/src/debugger/debugger.c;${CMAKE_SOURCE_DIR}/src/debugger/memory-debugger.c")
 72
 73if(USE_CLI_DEBUGGER AND NOT WIN32)
 74	# Win32 doesn't have a usable command line, nor libedit, so this is useless on Windows
 75	add_definitions(-DUSE_CLI_DEBUGGER)
 76	list(APPEND DEBUGGER_SRC "${CMAKE_SOURCE_DIR}/src/debugger/cli-debugger.c")
 77	list(APPEND DEBUGGER_SRC "${CMAKE_SOURCE_DIR}/src/debugger/parser.c")
 78	set(DEBUGGER_LIB "edit")
 79else()
 80	set(DEBUGGER_LIB "")
 81endif()
 82
 83if(USE_GDB_STUB)
 84	add_definitions(-DUSE_GDB_STUB)
 85	set(DEBUGGER_SRC "${DEBUGGER_SRC};${CMAKE_SOURCE_DIR}/src/debugger/gdb-stub.c")
 86endif()
 87source_group("ARM debugger" FILES ${DEBUGGER_SRC})
 88
 89add_library(${BINARY_NAME} SHARED ${ARM_SRC} ${GBA_SRC} ${DEBUGGER_SRC} ${RENDERER_SRC} ${UTIL_SRC} ${VFS_SRC} ${OS_SRC})
 90target_link_libraries(${BINARY_NAME} m ${DEBUGGER_LIB} ${OS_LIB} ${DEPENDENCY_LIB} png)
 91
 92if(BUILD_SDL)
 93	add_subdirectory(${CMAKE_SOURCE_DIR}/src/platform/sdl ${CMAKE_BINARY_DIR}/sdl)
 94endif()
 95
 96if(BUILD_PERF)
 97	set(PERF_SRC ${CMAKE_SOURCE_DIR}/src/platform/perf-main.c)
 98	if(UNIX AND NOT APPLE)
 99		set(PERF_LIB "${PERF_LIB};rt")
100	endif()
101
102	add_executable(${BINARY_NAME}-perf ${PERF_SRC})
103	target_link_libraries(${BINARY_NAME}-perf ${BINARY_NAME} ${PERF_LIB})
104endif()