CMakeLists.txt.switch 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. cmake_minimum_required(VERSION 3.0)
  2. set(CMAKE_VERBOSE_MAKEFILE ON)
  3. option(PLATFORM_LINUX "Linux platform target" OFF)
  4. option(PLATFORM_SWITCH "Nintendo Switch platform target" OFF)
  5. if (PLATFORM_LINUX)
  6. set(CMAKE_SYSTEM_NAME "Linux")
  7. elseif (PLATFORM_SWITCH)
  8. set(CMAKE_SYSTEM_NAME "Generic")
  9. set(DEVKITPRO $ENV{DEVKITPRO})
  10. set(CMAKE_SYSTEM_PROCESSOR "armv8-a")
  11. set(CMAKE_C_COMPILER "${DEVKITPRO}/devkitA64/bin/aarch64-none-elf-gcc")
  12. set(CMAKE_CXX_COMPILER "${DEVKITPRO}/devkitA64/bin/aarch64-none-elf-g++")
  13. set(CMAKE_ASM_COMPILER "${DEVKITPRO}/devkitA64/bin/aarch64-none-elf-as")
  14. set(CMAKE_AR "${DEVKITPRO}/devkitA64/bin/aarch64-none-elf-gcc-ar" CACHE STRING "")
  15. set(CMAKE_RANLIB "${DEVKITPRO}/devkitA64/bin/aarch64-none-elf-gcc-ranlib" CACHE STRING "")
  16. set(CMAKE_C_FLAGS "-g -march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -ftls-model=local-exec -fPIC -I${DEVKITPRO}/libnx/include -I${DEVKITPRO}/portlibs/switch/include" CACHE STRING "C flags")
  17. set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "C++ flags") #-fno-rtti -fno-exceptions
  18. set(CMAKE_FIND_ROOT_PATH ${DEVKITPRO} ${DEVKITPRO}/devkitA64 ${DEVKITPRO}/libnx ${DEVKITPRO}/portlibs/switch)
  19. set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
  20. set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
  21. set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
  22. set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
  23. set(BUILD_SHARED_LIBS OFF CACHE INTERNAL "Shared libs not available")
  24. endif ()
  25. project(ManaPlus)
  26. file(GLOB SOURCES src/*.cpp)
  27. set(SOURCES_DIRS src/being src/enums/being src/fs src/gui src/input
  28. src/listeners src/net src/particle src/progs/manaplus src/render
  29. src/resources src/sdl2gfx src/test src/utils)
  30. foreach (DIR ${SOURCES_DIRS})
  31. file(GLOB_RECURSE FILES ${DIR}/*.cpp)
  32. list(APPEND SOURCES ${FILES})
  33. endforeach (DIR)
  34. set(INCLUDES src src/sdl2gfx)
  35. set(FLAGS -DPACKAGE_NAME=\"ManaPlus\" -DPACKAGE_TARNAME=\"manaplus\" -DPACKAGE_VERSION=\"1.9.3.23\"
  36. -DPACKAGE_STRING=\"ManaPlus\ 1.9.3.23\" -DPACKAGE_BUGREPORT=\"akaras@inbox.ru\" -DPACKAGE_URL=\"\"
  37. -DPACKAGE=\"manaplus\" -DVERSION=\"1.9.3.23\" -DTIME_WITH_SYS_TIME=1 -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1
  38. -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1
  39. -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_SYS_SELECT_H=1 -DHAVE_SYS_SOCKET_H=1
  40. -DSELECT_TYPE_ARG1=int -DSELECT_TYPE_ARG234=\(fd_set\ \\*\) -DSELECT_TYPE_ARG5=\(struct\ timeval\ \\*\)
  41. -DHAVE_VPRINTF=1 -DHAVE_FORK=1 -Dvfork=fork -DHAVE_WORKING_FORK=1 -DHAVE_STDLIB_H=1 -DHAVE_UNISTD_H=1
  42. -DHAVE_SYS_PARAM_H=1 -DHAVE_ATEXIT=1 -DHAVE_FLOOR=1 -DHAVE_GETCWD=1 -DHAVE_GETHOSTBYNAME=1 -DHAVE_MEMSET=1
  43. -DHAVE_MKDIR=1 -DHAVE_SELECT=1 -DHAVE_SOCKET=1 -DHAVE_CLOCK_GETTIME=1 -DHAVE_DUP2=1 -DHAVE_GETTIMEOFDAY=1
  44. -DHAVE_MEMCHR=1 -DHAVE_MEMMOVE=1 -DHAVE_POW=1 -DHAVE_PUTENV=1 -DHAVE_SETENV=1 -DHAVE_SETLOCALE=1
  45. -DHAVE_SQRT=1 -DHAVE_STRCHR=1 -DHAVE_MALLOC_TRIM=1 -DHAVE_LIMITS_H=1 -DHAVE_SYS_PARAM_H=1 -DHAVE_SYS_TIME_H=1
  46. -DHAVE_WCHAR_H=1 -DHAVE_LIBSDL2=1 -DHAVE_LIBSDL2_IMAGE=1 -DHAVE_LIBSDL2_TTF=1 -DHAVE_LIBSDL2_MIXER=1
  47. -DHAVE_LIBSDL2_NET=1 -DUSE_INTERNALSDLGFX=1 -DHAVE_SDL_H=1 -DHAVE_LIBPTHREAD=1 -DHAVE_LIBZ=1 -DHAVE_LIBCURL=1
  48. -DHAVE_CURL_CURL_H=1 -DHAVE_LIBXML2=1 -DHAVE_LIBXML_XMLREADER_H=1 -DHAVE_LIBPNG=1 -DSTDC_HEADERS=1 -DHAVE_ARPA_INET_H=1
  49. -DHAVE_FCNTL_H=1 -DHAVE_MALLOC_H=1 -DHAVE_NETDB_H=1 -DHAVE_NETINET_IN_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1
  50. -DHAVE_SYS_SOCKET_H=1 -DHAVE_UNISTD_H=1 -Wall -DENABLE_ASSERTS -DHAVE_GLEXT -DENABLE_LIBXML -DUSE_SDL2 -DTMWA_SUPPORT -DCURL_STATICLIB
  51. -DUSE_OPENGL=1 -DSAVE_PASSWORD=1
  52. )
  53. if (PLATFORM_SWITCH)
  54. list(APPEND INCLUDES
  55. ${DEVKITPRO}/portlibs/switch/include/SDL2
  56. ${DEVKITPRO}/portlibs/switch/include/libxml2)
  57. list(APPEND FLAGS -D__SWITCH__ )
  58. list(APPEND LDFLAGS
  59. png xml2 curl z pthread SDL2_net SDL2_mixer SDL2_ttf SDL2_image SDL2
  60. SDL2_image png16 z m nx z jpeg webp
  61. SDL2_mixer vorbisidec modplug mpg123
  62. opusfile ogg opus SDL2_net SDL2_ttf freetype bz2
  63. curl mbedtls mbedx509 mbedcrypto
  64. GLESv2 EGL glapi drm_nouveau nx stdc++ m
  65. )
  66. else ()
  67. include(FindPkgConfig)
  68. pkg_search_module(SDL2 REQUIRED sdl2)
  69. pkg_search_module(SDL2_TTF REQUIRED SDL2_ttf)
  70. pkg_search_module(SDL2_IMAGE REQUIRED SDL2_image)
  71. pkg_search_module(SDL2_MIXER REQUIRED SDL2_mixer)
  72. pkg_search_module(SDL2_NET REQUIRED SDL2_net)
  73. pkg_search_module(ZLIB REQUIRED zlib)
  74. pkg_search_module(FREETYPE REQUIRED freetype2)
  75. pkg_search_module(XML2 REQUIRED libxml-2.0)
  76. pkg_search_module(PNG REQUIRED libpng)
  77. pkg_search_module(CURL REQUIRED libcurl)
  78. set(OpenGL_GL_PREFERENCE GLVND)
  79. find_package(OpenGL REQUIRED)
  80. #find_package(X11)
  81. list(APPEND INCLUDES
  82. ${SDL2_INCLUDE_DIRS} ${SDL2_TTF_INCLUDE_DIRS} ${SDL2_IMAGE_INCLUDE_DIRS} ${SDL2_MIXER_INCLUDE_DIRS} ${SDL2_NET_INCLUDE_DIRS}
  83. ${ZLIB_INCLUDE_DIRS} ${FREETYPE_INCLUDE_DIRS} ${XML2_INCLUDE_DIRS} ${PNG_INCLUDE_DIRS} ${CURL_INCLUDE_DIRS}
  84. ${OPENGL_INCLUDE_DIR}
  85. )
  86. list(APPEND LDFLAGS
  87. ${SDL2_LIBRARIES} ${SDL2_TTF_LIBRARIES} ${SDL2_IMAGE_LIBRARIES} ${SDL2_MIXER_LIBRARIES} ${SDL2_NET_LIBRARIES}
  88. ${ZLIB_LIBRARIES} ${FREETYPE_LIBRARIES} ${XML2_LIBRARIES} ${PNG_LIBRARIES} ${CURL_LIBRARIES}
  89. ${OPENGL_LIBRARIES}
  90. )
  91. endif ()
  92. add_executable(${PROJECT_NAME} ${SOURCES})
  93. target_include_directories(${PROJECT_NAME} PRIVATE ${INCLUDES})
  94. target_compile_options(${PROJECT_NAME} PRIVATE ${FLAGS})
  95. target_link_libraries(${PROJECT_NAME} ${LDFLAGS})
  96. if (PLATFORM_SWITCH)
  97. set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS
  98. "-specs=${DEVKITPRO}/libnx/switch.specs -L${DEVKITPRO}/libnx/lib -L${DEVKITPRO}/portlibs/switch/lib")
  99. add_custom_target(${PROJECT_NAME}.nro
  100. DEPENDS ${PROJECT_NAME}
  101. COMMAND ${DEVKITPRO}/tools/bin/nacptool --create "${PROJECT_NAME}" "cpasjuste" "1.9.3.23" ${PROJECT_NAME}.nacp
  102. COMMAND ${DEVKITPRO}/tools/bin/elf2nro ${PROJECT_NAME} ${PROJECT_NAME}.nro --icon=${CMAKE_CURRENT_SOURCE_DIR}/data/icons/manaplus-switch.jpeg --nacp=${PROJECT_NAME}.nacp)
  103. endif ()