diff --git a/.github/workflows/build-cmake-conan.yml b/.github/workflows/build-cmake-conan.yml index 78bed1d..d30f2c2 100644 --- a/.github/workflows/build-cmake-conan.yml +++ b/.github/workflows/build-cmake-conan.yml @@ -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)" diff --git a/.github/workflows/build-switch.yml b/.github/workflows/build-switch.yml index faa5865..a532b15 100644 --- a/.github/workflows/build-switch.yml +++ b/.github/workflows/build-switch.yml @@ -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 diff --git a/.gitignore b/.gitignore index d536cfb..de870ed 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ /.vs librw.vcxproj.user librw.VC.db -librw.VC.VC.opendb \ No newline at end of file +librw.VC.VC.opendb +imgui.ini diff --git a/CMakeLists.txt b/CMakeLists.txt index 417c77a..de3211d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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") @@ -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) @@ -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 @@ -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) diff --git a/README.cmake b/README.cmake new file mode 100644 index 0000000..59493b1 --- /dev/null +++ b/README.cmake @@ -0,0 +1,9 @@ +Build with cmake +================ + +Linux + + mkdir build + cd build + cmake .. -DLIBRW_PLATFORM=GL3 -DLIBRW_GL3_GFXLIB=SDL2 + make diff --git a/cmake/librw-config.cmake.in b/cmake/librw-config.cmake.in index 6ea7619..519e63e 100644 --- a/cmake/librw-config.cmake.in +++ b/cmake/librw-config.cmake.in @@ -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") diff --git a/cmake/nx/NXFunctions.cmake b/cmake/nx/NXFunctions.cmake new file mode 100644 index 0000000..bab3360 --- /dev/null +++ b/cmake/nx/NXFunctions.cmake @@ -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() diff --git a/cmake/nxtoolchain/CheckNXFunctions.cmake b/cmake/nxtoolchain/CheckNXFunctions.cmake deleted file mode 100644 index 8fa23fa..0000000 --- a/cmake/nxtoolchain/CheckNXFunctions.cmake +++ /dev/null @@ -1,7 +0,0 @@ -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() diff --git a/cmake/nxtoolchain/FindNXGL.cmake b/cmake/nxtoolchain/FindNXGL.cmake deleted file mode 100644 index 25e86d2..0000000 --- a/cmake/nxtoolchain/FindNXGL.cmake +++ /dev/null @@ -1,38 +0,0 @@ -find_library(NXGL_EGL_LIBRARY EGL) -find_library(NXGL_GLAPI_LIBRARY glapi) -find_library(NXGL_DRM_NOUVEAU_LIBRARY drm_nouveau) - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(NXGL - REQUIRED_VARS NXGL_EGL_LIBRARY NXGL_GLAPI_LIBRARY NXGL_DRM_NOUVEAU_LIBRARY -) - -if(NXGL_FOUND) - if(NOT TARGET NXGL::EGL) - add_library(NXGL::EGL UNKNOWN IMPORTED) - set_target_properties(NXGL::EGL PROPERTIES - IMPORTED_LOCATION "${NXGL_EGL_LIBRARY}" - ) - endif() - - if(NOT TARGET NXGL::glapi) - add_library(NXGL::glapi UNKNOWN IMPORTED) - set_target_properties(NXGL::glapi PROPERTIES - IMPORTED_LOCATION "${NXGL_GLAPI_LIBRARY}" - ) - endif() - - if(NOT TARGET NXGL::drm_nouveau) - add_library(NXGL::drm_nouveau UNKNOWN IMPORTED) - set_target_properties(NXGL::drm_nouveau PROPERTIES - IMPORTED_LOCATION "${NXGL_DRM_NOUVEAU_LIBRARY}" - ) - endif() - - if(NOT TARGET NXGL::OpenGL) - add_library(NXGL::OpenGL INTERFACE IMPORTED) - set_target_properties(NXGL::OpenGL PROPERTIES - INTERFACE_LINK_LIBRARIES "NXGL::EGL;NXGL::glapi;NXGL::drm_nouveau" - ) - endif() -endif() diff --git a/cmake/ps2/PS2Functions.cmake b/cmake/ps2/PS2Functions.cmake new file mode 100644 index 0000000..5cd81dd --- /dev/null +++ b/cmake/ps2/PS2Functions.cmake @@ -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() diff --git a/cmake/ps2toolchain/CMakeDSMCompiler.cmake.in b/cmake/ps2/cmaketoolchain/CMakeDSMCompiler.cmake.in similarity index 100% rename from cmake/ps2toolchain/CMakeDSMCompiler.cmake.in rename to cmake/ps2/cmaketoolchain/CMakeDSMCompiler.cmake.in diff --git a/cmake/ps2toolchain/CMakeDSMInformation.cmake b/cmake/ps2/cmaketoolchain/CMakeDSMInformation.cmake similarity index 100% rename from cmake/ps2toolchain/CMakeDSMInformation.cmake rename to cmake/ps2/cmaketoolchain/CMakeDSMInformation.cmake diff --git a/cmake/ps2toolchain/CMakeDetermineDSMCompiler.cmake b/cmake/ps2/cmaketoolchain/CMakeDetermineDSMCompiler.cmake similarity index 100% rename from cmake/ps2toolchain/CMakeDetermineDSMCompiler.cmake rename to cmake/ps2/cmaketoolchain/CMakeDetermineDSMCompiler.cmake diff --git a/cmake/ps2toolchain/CMakeTestDSMCompiler.cmake b/cmake/ps2/cmaketoolchain/CMakeTestDSMCompiler.cmake similarity index 100% rename from cmake/ps2toolchain/CMakeTestDSMCompiler.cmake rename to cmake/ps2/cmaketoolchain/CMakeTestDSMCompiler.cmake diff --git a/cmake/ps2toolchain/Platform/PlayStation2.cmake b/cmake/ps2/cmaketoolchain/Platform/PlayStation2.cmake similarity index 100% rename from cmake/ps2toolchain/Platform/PlayStation2.cmake rename to cmake/ps2/cmaketoolchain/Platform/PlayStation2.cmake diff --git a/cmake/ps2toolchain/conanfile.py b/cmake/ps2/cmaketoolchain/conanfile.py similarity index 71% rename from cmake/ps2toolchain/conanfile.py rename to cmake/ps2/cmaketoolchain/conanfile.py index 11c8628..4cc9d3c 100644 --- a/cmake/ps2toolchain/conanfile.py +++ b/cmake/ps2/cmaketoolchain/conanfile.py @@ -18,4 +18,7 @@ class Ps2devCMakeToolchainConan(ConanFile): 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 diff --git a/cmake/ps2toolchain/cmaketoolchain.cmake b/cmake/ps2/cmaketoolchain/toolchain_ps2_ee.cmake similarity index 80% rename from cmake/ps2toolchain/cmaketoolchain.cmake rename to cmake/ps2/cmaketoolchain/toolchain_ps2_ee.cmake index 6f83c96..9f3c24a 100644 --- a/cmake/ps2toolchain/cmaketoolchain.cmake +++ b/cmake/ps2/cmaketoolchain/toolchain_ps2_ee.cmake @@ -45,7 +45,7 @@ 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) @@ -53,9 +53,19 @@ 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 "$" "${outfile}" COMMAND "${CMAKE_STRIP}" --strip-unneeded -R .mdebug.eabi64 -R .reginfo -R .comment "${outfile}" @@ -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() diff --git a/cmake/ps2toolchain/toolchain_ps2_ee.cmake b/cmake/ps2toolchain/toolchain_ps2_ee.cmake deleted file mode 100644 index 95517d0..0000000 --- a/cmake/ps2toolchain/toolchain_ps2_ee.cmake +++ /dev/null @@ -1,60 +0,0 @@ -cmake_minimum_required(VERSION 3.7) - -list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") - -set(CMAKE_SYSTEM_NAME "PlayStation2") -set(CMAKE_SYSTEM_PROCESSOR "mipsel") -set(CMAKE_SYSTEM_VERSION 1) - -set(CMAKE_POSITION_INDEPENDENT_CODE ON) - -set(CMAKE_NO_SYSTEM_FROM_IMPORTED ON) - -set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) - -if(NOT DEFINED ENV{PS2DEV}) - message(FATAL_ERROR "Need environment variable PS2DEV set") -endif() -if(NOT DEFINED ENV{PS2SDK}) - message(FATAL_ERROR "Need environment variable PS2SDK set") -endif() -set(PS2DEV "$ENV{PS2DEV}") -set(PS2SDK "$ENV{PS2SDK}") - -set(CMAKE_DSM_SOURCE_FILE_EXTENSIONS "dsm") - -set(CMAKE_C_COMPILER "${PS2DEV}/ee/bin/ee-gcc") -set(CMAKE_CXX_COMPILER "${PS2DEV}/ee/bin/ee-g++") -set(CMAKE_ASM_COMPILER "${PS2DEV}/ee/bin/ee-g++") -set(CMAKE_DSM_COMPILER "${PS2DEV}/dvp/bin/dvp-as") -set(CMAKE_AR "${PS2DEV}/ee/bin/ee-ar" CACHE FILEPATH "archiver") -set(CMAKE_LINKER "${PS2DEV}/ee/bin/ee-ld") -set(CMAKE_RANLIB "${PS2DEV}/ee/bin/ee-ranlib" CACHE FILEPATH "ranlib") -set(CMAKE_STRIP "${PS2DEV}/ee/bin/ee-strip" CACHE FILEPATH "strip") - -set(CMAKE_ASM_FLAGS_INIT "-G0 -I\"${PS2SDK}/ee/include\" -I\"${PS2SDK}/common/include\"") -set(CMAKE_C_FLAGS_INIT "-G0 -fno-common -I\"${PS2SDK}/ee/include\" -I\"${PS2SDK}/common/include\"") -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_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") - add_custom_command(OUTPUT "${outfile}" - COMMAND "${CMAKE_COMMAND}" -E copy "$" "${outfile}" - COMMAND "${CMAKE_STRIP}" --strip-unneeded -R .mdebug.eabi64 -R .reginfo -R .comment "${outfile}" - DEPENDS ${TARGET} - ) - add_custom_target("${TARGET}_erl" ALL - DEPENDS "${outfile}" - ) - set("${OUTFILE}" "${outfile}" PARENT_SCOPE) -endfunction() diff --git a/conanfile.py b/conanfile.py index 3032eae..4cefb49 100644 --- a/conanfile.py +++ b/conanfile.py @@ -36,6 +36,7 @@ class LibrwConan(ConanFile): 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): @@ -44,13 +45,10 @@ class LibrwConan(ConanFile): 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": @@ -114,7 +112,6 @@ class LibrwConan(ConanFile): 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) diff --git a/skeleton/CMakeLists.txt b/skeleton/CMakeLists.txt index 98970bc..1c7c031 100644 --- a/skeleton/CMakeLists.txt +++ b/skeleton/CMakeLists.txt @@ -1,42 +1,68 @@ add_library(librw_skeleton - glfw.cpp - sdl2.cpp - skeleton.cpp - skeleton.h - win.cpp + glfw.cpp + sdl2.cpp + skeleton.cpp + skeleton.h + win.cpp + + imgui/imconfig.h + imgui/imgui.cpp + imgui/imgui_demo.cpp + imgui/imgui_draw.cpp + imgui/imgui.h + imgui/imgui_impl_rw.cpp + imgui/imgui_impl_rw.h + imgui/imgui_internal.h + imgui/ImGuizmo.cpp + imgui/ImGuizmo.h + imgui/stb_rect_pack.h + imgui/stb_textedit.h + imgui/stb_truetype.h ) +add_library(librw::skeleton ALIAS librw_skeleton) set_target_properties(librw_skeleton PROPERTIES PREFIX "" + EXPORT_NAME skeleton ) target_link_libraries(librw_skeleton - PUBLIC + PRIVATE librw ) target_include_directories(librw_skeleton - INTERFACE + PUBLIC $ + $ ) -if(NOT LIBRW_PLATFORM_PS2 AND NOT LIBRW_PLATFORM_NULL) - add_subdirectory(imgui) -endif() - if(LIBRW_INSTALL) - target_include_directories(librw_skeleton - INTERFACE - $ - ) - install( FILES skeleton.h DESTINATION "${LIBRW_INSTALL_INCLUDEDIR}/skeleton" ) + install( + FILES + imgui/imconfig.h + imgui/imgui.h + imgui/imgui_impl_rw.h + imgui/imgui_internal.h + imgui/ImGuizmo.h + imgui/stb_textedit.h + DESTINATION "${LIBRW_INSTALL_INCLUDEDIR}/skeleton/imgui" + ) + + install( + FILES + imgui/LICENSE_imgui.txt + imgui/LICENSE_imguizmo.txt + DESTINATION "${CMAKE_INSTALL_DOCDIR}" + ) + install( TARGETS librw_skeleton EXPORT librw-targets diff --git a/skeleton/imgui/CMakeLists.txt b/skeleton/imgui/CMakeLists.txt deleted file mode 100644 index cb65dee..0000000 --- a/skeleton/imgui/CMakeLists.txt +++ /dev/null @@ -1,46 +0,0 @@ -add_library(librw_skeleton_imgui - imconfig.h - imgui.cpp - imgui_demo.cpp - imgui_draw.cpp - imgui.h - imgui_impl_rw.cpp - imgui_impl_rw.h - imgui_internal.h - ImGuizmo.cpp - ImGuizmo.h - stb_rect_pack.h - stb_textedit.h - stb_truetype.h -) - -set_target_properties(librw_skeleton_imgui - PROPERTIES - PREFIX "" -) - -target_link_libraries(librw_skeleton_imgui - PUBLIC - librw_skeleton -) - -if(LIBRW_INSTALL) - install( - FILES - imconfig.h - imgui.h - imgui_impl_rw.h - imgui_internal.h - ImGuizmo.h - stb_textedit.h - DESTINATION "${LIBRW_INSTALL_INCLUDEDIR}/skeleton/imgui" - ) - - install( - TARGETS librw_skeleton_imgui - EXPORT librw-targets - RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" - LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" - ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" - ) -endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 423883a..5b16901 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -100,6 +100,7 @@ add_library(librw::librw ALIAS librw) target_include_directories(librw INTERFACE $ + $ ) target_compile_definitions(librw @@ -148,16 +149,6 @@ set_target_properties(librw ) if(LIBRW_PLATFORM_GL3) - if(LIBRW_PLATFORM_GL3_REQUIRES_OPENGL) - set(OpenGL_GL_PREFERENCE GLVND) - find_package(OpenGL REQUIRED) - - target_link_libraries(librw - PUBLIC - OpenGL::GL - ) - endif() - if (LIBRW_GL3_GFXLIB STREQUAL "GLFW") find_package(glfw3 REQUIRED) target_link_libraries(librw @@ -171,35 +162,37 @@ if(LIBRW_PLATFORM_GL3) PUBLIC SDL2::SDL2 ) - if(TARGET SDL2::SDL2main) - target_link_libraries(librw - PUBLIC - SDL2::SDL2main - ) - endif() endif() - if(NINTENDO_SWITCH) - find_package(NXGL REQUIRED) + set(OpenGL_GL_PREFERENCE GLVND) + find_package(OpenGL) + if(TARGET OpenGL::OpenGL) target_link_libraries(librw - PUBLIC - NXGL::OpenGL + PRIVATE + OpenGL::OpenGL ) + elseif(TARGET OpenGL::EGL) + target_link_libraries(librw + PRIVATE + OpenGL::EGL + ) + elseif(TARGET OpenGL::GL) + target_link_libraries(librw + PRIVATE + OpenGL::GL + ) + else() + message(FATAL_ERROR "find_package(OpenGL) failed.") endif() elseif(LIBRW_PLATFORM_D3D9) target_link_libraries(librw - PUBLIC + PRIVATE d3d9 xinput ) endif() if(LIBRW_INSTALL) - target_include_directories(librw - INTERFACE - $ - ) - install( FILES "${PROJECT_SOURCE_DIR}/args.h" diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 1d06544..be7ea66 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -1,11 +1,20 @@ -if(NOT LIBRW_PLATFORM_PS2) +if(LIBRW_TOOLS AND NOT LIBRW_PLATFORM_PS2) add_subdirectory(dumprwtree) + add_subdirectory(ska2anm) endif() -if(TARGET librw_skeleton_imgui) - add_subdirectory(imguitest) -endif() +if(LIBRW_EXAMPLES) + if(TARGET librw::skeleton) + add_subdirectory(imguitest) + add_subdirectory(playground) + add_subdirectory(lights) + add_subdirectory(subrast) + add_subdirectory(camera) + add_subdirectory(im2d) + add_subdirectory(im3d) + endif() -if(LIBRW_PLATFORM_PS2) - add_subdirectory(ps2test) + if(LIBRW_PLATFORM_PS2) + add_subdirectory(ps2test) + endif() endif() diff --git a/tools/camera/CMakeLists.txt b/tools/camera/CMakeLists.txt new file mode 100644 index 0000000..2607441 --- /dev/null +++ b/tools/camera/CMakeLists.txt @@ -0,0 +1,18 @@ +add_executable(camera WIN32 + main.cpp + camexamp.cpp + viewer.cpp +) + +target_link_libraries(camera + PRIVATE + librw::skeleton + librw::librw +) + +add_custom_command( + TARGET camera POST_BUILD + COMMAND "${CMAKE_COMMAND}" -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/files" "$/files" +) + +librw_platform_target(camera) diff --git a/tools/dumprwtree/CMakeLists.txt b/tools/dumprwtree/CMakeLists.txt index 96b05e7..fdd0a23 100644 --- a/tools/dumprwtree/CMakeLists.txt +++ b/tools/dumprwtree/CMakeLists.txt @@ -3,8 +3,8 @@ add_executable(dumprwtree ) target_link_libraries(dumprwtree - PUBLIC - librw + PRIVATE + librw::librw ) if(LIBRW_INSTALL) @@ -13,20 +13,4 @@ if(LIBRW_INSTALL) ) endif() -if(NINTENDO_SWITCH) - nx_generate_nacp(dumprwtree.nacp - NAME "dumprwtree" - AUTHOR "${librw_AUTHOR}" - VERSION "${librw_VERSION}" - ) - - nx_create_nro(dumprwtree - NACP dumprwtree.nacp - ) - - if(LIBRW_INSTALL) - install(FILES "${CMAKE_CURRENT_BINARY_DIR}/dumprwtree.nro" - DESTINATION "${CMAKE_INSTALL_BINDIR}" - ) - endif() -endif() +librw_platform_target(dumprwtree INSTALL) diff --git a/tools/im2d/CMakeLists.txt b/tools/im2d/CMakeLists.txt new file mode 100644 index 0000000..9c14b03 --- /dev/null +++ b/tools/im2d/CMakeLists.txt @@ -0,0 +1,22 @@ +add_executable(im2d WIN32 + im2d.cpp + linelist.cpp + main.cpp + polyline.cpp + trifan.cpp + trilist.cpp + tristrip.cpp +) + +target_link_libraries(im2d + PRIVATE + librw::skeleton + librw::librw +) + +add_custom_command( + TARGET im2d POST_BUILD + COMMAND "${CMAKE_COMMAND}" -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/files" "$/files" +) + +librw_platform_target(im2d) diff --git a/tools/im3d/CMakeLists.txt b/tools/im3d/CMakeLists.txt new file mode 100644 index 0000000..52102f6 --- /dev/null +++ b/tools/im3d/CMakeLists.txt @@ -0,0 +1,22 @@ +add_executable(im3d WIN32 + im3d.cpp + linelist.cpp + main.cpp + polyline.cpp + trifan.cpp + trilist.cpp + tristrip.cpp +) + +target_link_libraries(im3d + PRIVATE + librw::skeleton + librw::librw +) + +add_custom_command( + TARGET im3d POST_BUILD + COMMAND "${CMAKE_COMMAND}" -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/files" "$/files" +) + +librw_platform_target(im3d) diff --git a/tools/imguitest/CMakeLists.txt b/tools/imguitest/CMakeLists.txt index 293a4f1..4f2e31d 100644 --- a/tools/imguitest/CMakeLists.txt +++ b/tools/imguitest/CMakeLists.txt @@ -4,8 +4,8 @@ add_executable(imguitest WIN32 target_link_libraries(imguitest PUBLIC - librw - librw_skeleton_imgui + librw::skeleton + librw::librw ) if(LIBRW_INSTALL) @@ -14,20 +14,4 @@ if(LIBRW_INSTALL) ) endif() -if(NINTENDO_SWITCH) - nx_generate_nacp(imguitest.nacp - NAME "librw imguitest" - AUTHOR "${librw_AUTHOR}" - VERSION "${librw_VERSION}" - ) - - nx_create_nro(imguitest - NACP imguitest.nacp - ) - - if(LIBRW_INSTALL) - install(FILES "${CMAKE_CURRENT_BINARY_DIR}/imguitest.nro" - DESTINATION "${CMAKE_INSTALL_BINDIR}" - ) - endif() -endif() +librw_platform_target(imguitest INSTALL) diff --git a/tools/lights/CMakeLists.txt b/tools/lights/CMakeLists.txt new file mode 100644 index 0000000..282f30d --- /dev/null +++ b/tools/lights/CMakeLists.txt @@ -0,0 +1,17 @@ +add_executable(lights WIN32 + main.cpp + lights.cpp +) + +target_link_libraries(lights + PRIVATE + librw::skeleton + librw::librw +) + +add_custom_command( + TARGET lights POST_BUILD + COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/checker.dff" "$" +) + +librw_platform_target(lights) diff --git a/tools/playground/CMakeLists.txt b/tools/playground/CMakeLists.txt new file mode 100644 index 0000000..3db9307 --- /dev/null +++ b/tools/playground/CMakeLists.txt @@ -0,0 +1,21 @@ +add_executable(playground WIN32 + camera.cpp + font.cpp + main.cpp + ras_test.cpp + splines.cpp + tl_tests.cpp +) + +target_link_libraries(playground + PRIVATE + librw::skeleton + librw::librw +) + +add_custom_command( + TARGET playground POST_BUILD + COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/teapot.dff" "${CMAKE_CURRENT_SOURCE_DIR}/maze.tga" "${CMAKE_CURRENT_SOURCE_DIR}/Bm437_IBM_VGA8.FON" "${CMAKE_CURRENT_SOURCE_DIR}/Bm437_IBM_BIOS.FON" "$" +) + +librw_platform_target(playground) diff --git a/tools/playground/main.cpp b/tools/playground/main.cpp index 87acd6e..add7380 100644 --- a/tools/playground/main.cpp +++ b/tools/playground/main.cpp @@ -258,7 +258,7 @@ InitRW(void) tex = rw::Texture::read("maze", nil); tex2 = rw::Texture::read("checkers", nil); - const char *filename = "teapot2.dff"; + const char *filename = "teapot.dff"; if(sk::args.argc > 1) filename = sk::args.argv[1]; rw::StreamFile in; diff --git a/tools/ps2test/CMakeLists.txt b/tools/ps2test/CMakeLists.txt index 9ed4260..69bcc98 100644 --- a/tools/ps2test/CMakeLists.txt +++ b/tools/ps2test/CMakeLists.txt @@ -8,18 +8,15 @@ add_executable(ps2test ) target_link_libraries(ps2test - PUBLIC - librw + PRIVATE + librw::librw kernel ) -add_erl_executable(PS2TEST_ERL ps2test) +librw_platform_target(ps2test) if(LIBRW_INSTALL) install(TARGETS ps2test RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" ) - install(FILES "${PS2TEST_ERL}" - DESTINATION "${CMAKE_INSTALL_BINDIR}" - ) endif() diff --git a/tools/ska2anm/CMakeLists.txt b/tools/ska2anm/CMakeLists.txt new file mode 100644 index 0000000..ffd63d5 --- /dev/null +++ b/tools/ska2anm/CMakeLists.txt @@ -0,0 +1,16 @@ +add_executable(ska2anm + ska2anm.cpp +) + +target_link_libraries(ska2anm + PUBLIC + librw::librw +) + +librw_platform_target(ska2anm INSTALL) + +if(LIBRW_INSTALL) + install(TARGETS ska2anm + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" + ) +endif() diff --git a/tools/subrast/CMakeLists.txt b/tools/subrast/CMakeLists.txt new file mode 100644 index 0000000..1bf1de7 --- /dev/null +++ b/tools/subrast/CMakeLists.txt @@ -0,0 +1,11 @@ +add_executable(subrast WIN32 + main.cpp subrast.cpp +) + +target_link_libraries(subrast + PUBLIC + librw::skeleton + librw::librw +) + +librw_platform_target(subrast)