Skip to content

Just some assets improvements - [ALL_PLATFORMS] #18

@vsaint1

Description

@vsaint1

Thanks for the help with cmake configuration for those platforms, i been using your project slightly modified, this is a small improvement that can be added to all supported platforms.

  • windows same copying the files to bin's directory
if(MSVC)
    add_executable(${PROJECT_NAME} ${SOURCES})

    add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy_directory
    ${CMAKE_SOURCE_DIR}/assets ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/assets)

endif()

  • here we can ask emscripten to load/mount the directory
if(EMSCRIPTEN)
    set(CMAKE_EXECUTABLE_SUFFIX ".html")
    add_executable(${PROJECT_NAME} ${SOURCES})

    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-c++11-narrowing")
    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --preload-file ${CMAKE_SOURCE_DIR}/assets@/assets")

    add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy_directory
    ${CMAKE_SOURCE_DIR}/assets ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/assets)


endif()
  • android required me to link android/log ( GLESv2 is only required if willing to use opengles 2.0)
if(ANDROID)
    add_library(${PROJECT_NAME} SHARED ${SOURCES})
    target_link_libraries(${PROJECT_NAME} PUBLIC android log GLESv2)

endif()
  • android task to copy assets before building
tasks.register('copyDependencies') {

    copy {
        from '../../assets'
        into 'src/main/res/drawable'
        include 'icon.png'
    }

    copy {
        from '../../../assets'
        into 'src/main/assets'
    }
}

preBuild.dependsOn copyDependencies
  • on ios/macosx we can add directly through resources the files instead 1 by 1 ( also works for source files )
   set(RESOURCES "${CMAKE_SOURCE_DIR}/assets")

    add_executable(${PROJECT_NAME} MACOSX_BUNDLE ${SOURCES} ${RESOURCES} )

    set_target_properties(${PROJECT_NAME} PROPERTIES 
    MACOSX_BUNDLE TRUE
    RESOURCE "${RESOURCES}")
    target_link_libraries(${PROJECT_NAME} PRIVATE objc stdc++)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions