Skip to content

Commit

Permalink
Merge pull request #75 from madebr/pr69extra
Browse files Browse the repository at this point in the history
cmake: build examples on all platforms + no more need for FindNXGL for Nintendo Switch
  • Loading branch information
aap authored Jun 29, 2021
2 parents 6f5e6fe + a20f9e7 commit b2ceadc
Show file tree
Hide file tree
Showing 34 changed files with 333 additions and 281 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-cmake-conan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ jobs:
fi
- name: "Export Playstation 2 CMake toolchain conan recipe"
run: |
conan export cmake/ps2toolchain ps2dev-cmaketoolchain/master@
conan export cmake/ps2/cmaketoolchain ps2dev-cmaketoolchain/master@
- name: "Download/build dependencies (conan install)"
run: |
conan install ${{ github.workspace }} librw/master@ -if build -o librw:platform=${{ matrix.platform }} -o librw:gl3_gfxlib=${{ matrix.gl3_gfxlib}} --build missing -pr:h ./host_profile -pr:b default
conan install ${{ github.workspace }} librw/master@ -if build -o librw:platform=${{ matrix.platform }} -o librw:gl3_gfxlib=${{ matrix.gl3_gfxlib }} --build missing -pr:h ./host_profile -pr:b default
env:
CONAN_SYSREQUIRES_MODE: enabled
- name: "Build librw (conan build)"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-switch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- uses: actions/checkout@v2
- name: "Build files"
run: |
/opt/devkitpro/portlibs/switch/bin/aarch64-none-elf-cmake -S. -Bbuild .. -DLIBRW_PLATFORM=GL3 -DLIBRW_GL3_GFXLIB=GLFW -DLIBRW_INSTALL=True
/opt/devkitpro/portlibs/switch/bin/aarch64-none-elf-cmake -S. -Bbuild -DLIBRW_PLATFORM=GL3 -DLIBRW_GL3_GFXLIB=GLFW -DLIBRW_INSTALL=True
cmake --build build --parallel
- name: "Create binary package (cpack)"
working-directory: ./build
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
/.vs
librw.vcxproj.user
librw.VC.db
librw.VC.VC.opendb
librw.VC.VC.opendb
imgui.ini
31 changes: 19 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@ if(WIN32)
elseif(NINTENDO_SWITCH)
set(LIBRW_PLATFORMS "NULL" "GL3")
set(LIBRW_PLATFORM_GL3_REQUIRES_OPENGL OFF)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/nxtoolchain")
include(CheckNXFunctions)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/nx")
include(NXFunctions)
elseif(PS2)
set(LIBRW_PLATFORMS "NULL" "PS2")
set(LIBRW_PLATFORM_GL3_REQUIRES_OPENGL OFF)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/ps2")
include(PS2Functions)
else()
set(LIBRW_PLATFORMS "NULL" "GL3" "PS2")
set(LIBRW_PLATFORMS "NULL" "GL3")
set(LIBRW_PLATFORM_GL3_REQUIRES_OPENGL ON)
endif()
set(LIBRW_PLATFORM "NULL" CACHE STRING "Platform")
Expand All @@ -41,8 +46,16 @@ if(LIBRW_PLATFORM_PS2)
enable_language(DSM)
endif()

if(NOT COMMAND librw_platform_target)
function(librw_platform_target)
endfunction()
endif()

include(CMakeDependentOption)

option(LIBRW_TOOLS "Build librw tools" ON)
option(LIBRW_INSTALL "Install librw files" OFF)
cmake_dependent_option(LIBRW_EXAMPLES "Build librw examples" ON "NOT LIBRW_PLATFORM_PS2;NOT LIBRW_PLATFORM_NULL" OFF)

if(LIBRW_INSTALL)
include(GNUInstallDirs)
Expand All @@ -51,12 +64,12 @@ endif()

add_subdirectory(src)

if(LIBRW_TOOLS)
if(NOT LIBRW_PLATFORM_PS2 AND NOT LIBRW_PLATFORM_NULL)
add_subdirectory(skeleton)

add_subdirectory(tools)
endif()

add_subdirectory(tools)

if(LIBRW_INSTALL)
include(CMakePackageConfigHelpers)
configure_package_config_file(cmake/librw-config.cmake.in librw-config.cmake
Expand All @@ -77,12 +90,6 @@ if(LIBRW_INSTALL)
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake"
)
endif()
if(NINTENDO_SWITCH)
install(
FILES "${CMAKE_CURRENT_LIST_DIR}/cmake/nxtoolchain/FindNXGL.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake"
)
endif()

string(REPLACE "." ";" cmake_c_compiler_version_list "${CMAKE_C_COMPILER_VERSION}")
list(GET cmake_c_compiler_version_list 0 cmake_c_compiler_version_major)
Expand Down
9 changes: 9 additions & 0 deletions README.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Build with cmake
================

Linux

mkdir build
cd build
cmake .. -DLIBRW_PLATFORM=GL3 -DLIBRW_GL3_GFXLIB=SDL2
make
12 changes: 5 additions & 7 deletions cmake/librw-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,17 @@ include("${CMAKE_CURRENT_LIST_DIR}/librw-targets.cmake")
set(LIBRW_PLATFORM "@LIBRW_PLATFORM@")
set(LIBRW_PLATFORMS "@LIBRW_PLATFORMS@")
set(LIBRW_PLATFORM_@LIBRW_PLATFORM@ ON)
set(LIBRW_PLATFORM_GL3_REQUIRES_OPENGL @LIBRW_PLATFORM_GL3_REQUIRES_OPENGL@)

if(LIBRW_PLATFORM_GL3)
set(LIBRW_GL3_GFXLIB "@LIBRW_GL3_GFXLIB@")
set(LIBRW_GL3_GFXLIBS "@LIBRW_GL3_GFXLIBS@")

if(LIBRW_PLATFORM_GL3_REQUIRES_OPENGL)
set(OpenGL_GL_PREFERENCE GLVND)
find_package(OpenGL REQUIRED)
endif()
if(NINTENDO_SWITCH)
find_package(NXGL REQUIRED)
set(OpenGL_GL_PREFERENCE GLVND)
find_package(OpenGL)
if(NOT TARGET TARGET OpenGL::OpenGL AND NOT TARGET OpenGL::EGL AND NOT TARGET OpenGL::GL)
message(FATAL_ERROR )
endif()

if(LIBRW_GL3_GFXLIB STREQUAL "GLFW")
find_package(glfw3 REQUIRED)
elseif(LIBRW_GL3_GFXLIB STREQUAL "SDL2")
Expand Down
37 changes: 37 additions & 0 deletions cmake/nx/NXFunctions.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
if(NOT COMMAND nx_generate_nacp)
message(FATAL_ERROR "The `nx_generate_nacp` cmake command is not available. Please use an appropriate Nintendo Switch toolchain.")
endif()

if(NOT COMMAND nx_create_nro)
message(FATAL_ERROR "The `nx_create_nro` cmake command is not available. Please use an appropriate Nintendo Switch toolchain.")
endif()

set(CMAKE_EXECUTABLE_SUFFIX ".elf")

function(librw_platform_target TARGET)
cmake_parse_arguments(LPT "INSTALL" "" "" ${ARGN})

get_target_property(TARGET_TYPE "${TARGET}" TYPE)
if(TARGET_TYPE STREQUAL "EXECUTABLE")
nx_generate_nacp(${TARGET}.nacp
NAME "${TARGET}"
AUTHOR "${librw_AUTHOR}"
VERSION "${librw_VERSION}"
)

nx_create_nro(${TARGET}
NACP ${TARGET}.nacp
)

if(LIBRW_INSTALL AND LPT_INSTALL)
get_target_property(TARGET_OUTPUT_NAME ${TARGET} OUTPUT_NAME)
if(NOT TARGET_OUTPUT_NAME)
set(TARGET_OUTPUT_NAME "${TARGET}")
endif()

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${TARGET_OUTPUT_NAME}.nro"
DESTINATION "${CMAKE_INSTALL_BINDIR}"
)
endif()
endif()
endfunction()
7 changes: 0 additions & 7 deletions cmake/nxtoolchain/CheckNXFunctions.cmake

This file was deleted.

38 changes: 0 additions & 38 deletions cmake/nxtoolchain/FindNXGL.cmake

This file was deleted.

18 changes: 18 additions & 0 deletions cmake/ps2/PS2Functions.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
if(NOT COMMAND add_erl_executable)
message(FATAL_ERROR "The `add_erl_executable` cmake command is not available. Please use an appropriate Playstation 2 toolchain.")
endif()

function(librw_platform_target TARGET)
cmake_parse_arguments(LPT "INSTALL" "" "" ${ARGN})

get_target_property(TARGET_TYPE "${TARGET}" TYPE)
if(TARGET_TYPE STREQUAL "EXECUTABLE")
add_erl_executable(${TARGET} OUTPUT_VAR ERL_FILE)

if(LIBRW_INSTALL AND LPT_INSTALL)
install(FILES "${ERL_FILE}"
DESTINATION "${CMAKE_INSTALL_BINDIR}"
)
endif()
endif()
endfunction()
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@ def package(self):

def package_info(self):
self.user_info.cmake_dir = os.path.join(self.package_folder, "cmake").replace("\\", "/")
self.user_info.cmake_toolchain_file = os.path.join(self.package_folder, "cmake", "cmaketoolchain.cmake").replace("\\", "/")

cmake_toolchain_file = os.path.join(self.package_folder, "cmake", "toolchain_ps2_ee.cmake").replace("\\", "/")
self.user_info.cmake_toolchain_file = cmake_toolchain_file
self.cpp_info.CONAN_CMAKE_TOOLCHAIN_FILE = cmake_toolchain_file
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,27 @@ set(CMAKE_C_FLAGS_INIT "-G0 -fno-common -I\"${PS2SDK}/ee/include\" -I\"${PS2SDK}
set(CMAKE_CXX_FLAGS_INIT "-G0 -fno-common -I\"${PS2SDK}/ee/include\" -I\"${PS2SDK}/common/include\"")
set(CMAKE_EXE_LINKER_FLAGS_INIT "-G0 -L\"${PS2SDK}/ee/lib\" -Wl,-r -Wl,-d")

set(CMAKE_FIND_ROOT_PATH "${PS2DEV}/ee;${PS2SDK}/ee")
set(CMAKE_FIND_ROOT_PATH "${PS2DEV}/ee" "${PS2SDK}/ee")
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

set(PS2 1)
set(EE 1)

function(add_erl_executable OUTFILE TARGET)
get_property(output_dir TARGET ${TARGET} PROPERTY RUNTIME_OUTPUT_DIRECTORY)
set(outfile "${output_dir}/${TARGET}.erl")
set(CMAKE_EXECUTABLE_SUFFIX ".elf")

function(add_erl_executable TARGET)
cmake_parse_arguments("AEE" "" "OUTPUT_VAR" "" ${ARGN})

get_target_property(output_dir ${TARGET} RUNTIME_OUTPUT_DIRECTORY)

get_target_property(output_name ${TARGET} OUTPUT_NAME)
if(NOT output_name)
set(output_name ${TARGET})
endif()
set(outfile "${output_dir}/${output_name}.erl")

add_custom_command(OUTPUT "${outfile}"
COMMAND "${CMAKE_COMMAND}" -E copy "$<TARGET_FILE:${TARGET}>" "${outfile}"
COMMAND "${CMAKE_STRIP}" --strip-unneeded -R .mdebug.eabi64 -R .reginfo -R .comment "${outfile}"
Expand All @@ -64,5 +74,8 @@ function(add_erl_executable OUTFILE TARGET)
add_custom_target("${TARGET}_erl" ALL
DEPENDS "${outfile}"
)
set("${OUTFILE}" "${outfile}" PARENT_SCOPE)

if(AEE_OUTPUT_VAR)
set("${AEE_OUTPUT_VAR}" "${outfile}" PARENT_SCOPE)
endif()
endfunction()
60 changes: 0 additions & 60 deletions cmake/ps2toolchain/toolchain_ps2_ee.cmake

This file was deleted.

13 changes: 5 additions & 8 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def config_options(self):
if self._os_is_playstation2:
self.options.platform = "ps2"
if self.settings.os == "Windows":
self.options.platform = "d3d9"
self.options["sdl2"].directx = False

def configure(self):
Expand All @@ -44,13 +45,10 @@ def configure(self):

def validate(self):
if self.options.platform == "d3d9" and self.settings.os != "Windows":
raise ConanInvalidConfiguration("d3d9 can only be built for Windows")
if self.options.platform == "ps2":
if not self._os_is_playstation2:
raise ConanInvalidConfiguration("platform=ps2 is only valid for os=Playstation2")
else:
if self._os_is_playstation2:
raise ConanInvalidConfiguration("os=Playstation2 only supports platform=ps2")
raise ConanInvalidConfiguration("platform=d3d9 can only be built for os=Windows")
if self._os_is_playstation2:
if self.options.platform not in ("null", "ps2"):
raise ConanInvalidConfiguration("os=Playstation2 only supports platform=(null,ps2)")

def requirements(self):
if self.options.platform == "gl3":
Expand Down Expand Up @@ -114,7 +112,6 @@ def build(self):
if self.options.platform == "gl3":
cmake.definitions["LIBRW_GL3_GFXLIB"] = str(self.options.gl3_gfxlib).upper()
if self._os_is_playstation2:
cmake.definitions["CMAKE_TOOLCHAIN_FILE"] = self.deps_user_info["ps2dev-cmaketoolchain"].cmake_toolchain_file
env["PS2SDK"] = self.deps_cpp_info["ps2dev-ps2sdk"].rootpath
with tools.environment_append(env):
cmake.configure(source_folder=self.build_folder)
Expand Down
Loading

0 comments on commit b2ceadc

Please sign in to comment.