diff --git a/.gitattributes b/.gitattributes index 343b2023..f452df9a 100644 --- a/.gitattributes +++ b/.gitattributes @@ -16,3 +16,5 @@ *.json eol=lf *.cmake eol=lf *.proto eol=lf + +CMakeLists.txt eol=lf diff --git a/emapp/bundle/CMakeLists.txt b/emapp/bundle/CMakeLists.txt index 51938c83..42a90615 100644 --- a/emapp/bundle/CMakeLists.txt +++ b/emapp/bundle/CMakeLists.txt @@ -1,31 +1,31 @@ -function(nanoem_emapp_build_embundle suffix) - set(_embundle_name "embundle${suffix}") - add_library(${_embundle_name} STATIC ${PROJECT_SOURCE_DIR}/emapp/bundle/bundle_c.c - ${PROJECT_SOURCE_DIR}/emapp/bundle/bundle.cc) - nanoem_cmake_enable_lto(${_embundle_name}) - if(WIN32) - target_link_libraries(${_embundle_name} psapi imm32) - endif() - set_property(TARGET ${_embundle_name} PROPERTY FOLDER nanoem) - target_compile_definitions(${_embundle_name} PRIVATE - $<$:_CRT_SECURE_NO_WARNINGS=1> - $<$:NOMINMAX> - __STDC_LIMIT_MACROS - __STDC_CONSTANT_MACROS - __STDC_FORMAT_MACROS) - target_include_directories(${_embundle_name} PRIVATE - ${BX_COMPAT_INCLUDE_PATH} - ${BX_INCLUDE_DIR} - ${BX_THIRDPARTY_INCLUDE_DIR} - ${BIMG_INCLUDE_DIR} - ${GLM_INCLUDE_DIR} - ${PROJECT_SOURCE_DIR}/emapp/include - ${PROJECT_SOURCE_DIR}/dependencies - ${PROJECT_SOURCE_DIR}/dependencies/imgui) - if(NANOEM_ENABLE_DEBUG_ALLOCATOR) - target_compile_definitions(${_embundle_name} PRIVATE NANODXM_ENABLE_DEBUG_ALLOCATOR UNDO_ENABLE_DEBUG_ALLOCATOR) - endif() - message(STATUS "[emapp/bundle] setup emapp bundle") -endfunction() - -add_subdirectory(sokol) +function(nanoem_emapp_build_embundle suffix) + set(_embundle_name "embundle${suffix}") + add_library(${_embundle_name} STATIC ${PROJECT_SOURCE_DIR}/emapp/bundle/bundle_c.c + ${PROJECT_SOURCE_DIR}/emapp/bundle/bundle.cc) + nanoem_cmake_enable_lto(${_embundle_name}) + if(WIN32) + target_link_libraries(${_embundle_name} psapi imm32) + endif() + set_property(TARGET ${_embundle_name} PROPERTY FOLDER nanoem) + target_compile_definitions(${_embundle_name} PRIVATE + $<$:_CRT_SECURE_NO_WARNINGS=1> + $<$:NOMINMAX> + __STDC_LIMIT_MACROS + __STDC_CONSTANT_MACROS + __STDC_FORMAT_MACROS) + target_include_directories(${_embundle_name} PRIVATE + ${BX_COMPAT_INCLUDE_PATH} + ${BX_INCLUDE_DIR} + ${BX_THIRDPARTY_INCLUDE_DIR} + ${BIMG_INCLUDE_DIR} + ${GLM_INCLUDE_DIR} + ${PROJECT_SOURCE_DIR}/emapp/include + ${PROJECT_SOURCE_DIR}/dependencies + ${PROJECT_SOURCE_DIR}/dependencies/imgui) + if(NANOEM_ENABLE_DEBUG_ALLOCATOR) + target_compile_definitions(${_embundle_name} PRIVATE NANODXM_ENABLE_DEBUG_ALLOCATOR UNDO_ENABLE_DEBUG_ALLOCATOR) + endif() + message(STATUS "[emapp/bundle] setup emapp bundle") +endfunction() + +add_subdirectory(sokol) diff --git a/emapp/bundle/sokol/CMakeLists.txt b/emapp/bundle/sokol/CMakeLists.txt index db1a4ab7..8edfc4e0 100644 --- a/emapp/bundle/sokol/CMakeLists.txt +++ b/emapp/bundle/sokol/CMakeLists.txt @@ -1,116 +1,116 @@ -option(NANOEM_ENABLE_SOKOL_GLES3_COMPAT "Enable building sokol_gles3 with compatibility profile" OFF) -option(NANOEM_ENABLE_SOKOL_WGPU "Enable building sokol_wgpu" OFF) - -function(nanoem_emapp_build_sokol_noop) - if(NOT NANOEM_ENABLE_STATIC_BUNDLE_PLUGIN) - add_library(sokol_noop ${_library_type} - ${CMAKE_CURRENT_SOURCE_DIR}/sokol_noop.c - $<$:${CMAKE_CURRENT_SOURCE_DIR}/sokol_noop.def>) - set_property(TARGET sokol_noop PROPERTY FOLDER nanoem/sokol) - target_include_directories(sokol_noop PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/dependencies) - set_target_properties(sokol_noop PROPERTIES OUTPUT_NAME sokol_noop PREFIX "" DEFINE_SYMBOL "") - nanoem_emapp_plugin_install(sokol_noop) - message(STATUS "[emapp/bundle] setup sokol noop backend renderer plugin") - endif() -endfunction() - -function(nanoem_emapp_build_sokol_glcore33) - if(NOT (NANOEM_ENABLE_STATIC_BUNDLE_PLUGIN OR (MSVC AND "${NANOEM_TARGET_ARCHITECTURE}" STREQUAL "arm64"))) - add_library(sokol_glcore33 ${_library_type} - ${CMAKE_CURRENT_SOURCE_DIR}/sokol_glcore33.c - $<$:${CMAKE_CURRENT_SOURCE_DIR}/sokol_glcore33.def>) - set_property(TARGET sokol_glcore33 PROPERTY FOLDER nanoem/sokol) - target_compile_definitions(sokol_glcore33 PRIVATE SOKOL_DEBUG=$ SOKOL_EXTERNAL_GL_LOADER) - target_include_directories(sokol_glcore33 PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/dependencies) - set_target_properties(sokol_glcore33 PROPERTIES OUTPUT_NAME sokol_glcore33 PREFIX "" DEFINE_SYMBOL "") - nanoem_emapp_plugin_install(sokol_glcore33) - message(STATUS "[emapp/bundle] setup sokol OpenGL 3.3 Core Profile backend renderer plugin") - endif() -endfunction() - -function(nanoem_emapp_build_sokol_gles3) - find_library(GLES3_LIBRARY_PATH NAMES GLESv3 GLESv2) - find_path(GLES3_INCLUDE_DIR NAMES GLES3/gl3.h) - mark_as_advanced(GLES3_LIBRARY_PATH GLES3_INCLUDE_DIR) - if((NANOEM_ENABLE_SOKOL_GLES3_COMPAT OR EMSCRIPTEN) OR (GLES3_LIBRARY_PATH AND GLES3_INCLUDE_DIR)) - add_library(sokol_gles3 ${_library_type} - ${CMAKE_CURRENT_SOURCE_DIR}/sokol_gles3.c - $<$:${CMAKE_CURRENT_SOURCE_DIR}/sokol_gles3.def>) - set_property(TARGET sokol_gles3 PROPERTY FOLDER nanoem/sokol) - target_compile_definitions(sokol_gles3 PRIVATE SOKOL_DEBUG=$ $<$:NANOEM_ENABLE_SOKOL_GLES3_COMPAT> SOKOL_EXTERNAL_GL_LOADER) - target_include_directories(sokol_gles3 PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/dependencies) - set_target_properties(sokol_gles3 PROPERTIES OUTPUT_NAME sokol_gles3 PREFIX "" DEFINE_SYMBOL "") - if(GLES3_INCLUDE_DIR) - target_include_directories(sokol_gles3 PRIVATE ${GLES3_INCLUDE_DIR}) - endif() - if(GLES3_LIBRARY_PATH) - target_link_libraries(sokol_gles3 ${GLES3_LIBRARY_PATH}) - endif() - nanoem_emapp_plugin_install(sokol_gles3) - message(STATUS "[emapp/bundle] setup sokol OpenGL ES 3.0 backend renderer plugin") - endif() -endfunction() - -function(nanoem_emapp_build_sokol_d3d11) - add_library(sokol_d3d11 ${_library_type} - ${CMAKE_CURRENT_SOURCE_DIR}/sokol_d3d11.c - ${CMAKE_CURRENT_SOURCE_DIR}/sokol_d3d11.def) - set_property(TARGET sokol_d3d11 PROPERTY FOLDER nanoem/sokol) - target_compile_definitions(sokol_d3d11 PRIVATE SOKOL_DEBUG=$ SOKOL_STATIC=$ SOKOL_EXTERNAL_GL_LOADER) - target_include_directories(sokol_d3d11 PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/dependencies) - set_target_properties(sokol_d3d11 PROPERTIES OUTPUT_NAME sokol_d3d11 PREFIX "" DEFINE_SYMBOL "") - target_link_libraries(sokol_d3d11 d3d11 dxgi dxguid) - nanoem_emapp_plugin_install(sokol_d3d11) - message(STATUS "[emapp/bundle] setup sokol D3D11 backend renderer plugin") -endfunction() - -function(nanoem_emapp_build_sokol_metal) - add_library(sokol_metal_macos ${_library_type} ${CMAKE_CURRENT_SOURCE_DIR}/sokol_metal_$,ios,macos>.m) - set_property(TARGET sokol_metal_macos PROPERTY FOLDER nanoem/sokol) - target_compile_definitions(sokol_metal_macos PRIVATE SOKOL_DEBUG=$) - target_include_directories(sokol_metal_macos PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/dependencies) - set_target_properties(sokol_metal_macos PROPERTIES OUTPUT_NAME sokol_metal_macos PREFIX "" DEFINE_SYMBOL "") - target_link_libraries(sokol_metal_macos "-framework Metal") - nanoem_emapp_plugin_install(sokol_metal_macos) - message(STATUS "[emapp/bundle] setup sokol Metal backend renderer plugin") -endfunction() - - -function(nanoem_emapp_build_sokol_wgpu) - if(NANOEM_ENABLE_SOKOL_WGPU) - set(DAWN_BASE_PATH ${PROJECT_SOURCE_DIR}/dependencies/dawn) - find_library(WEBGPU_DAWN_NATIVE_LIBRARY_PATH NAMES dawn_native dawn_native.dll PATH_SUFFIXES out/Release/ PATHS ${DAWN_BASE_PATH}) - find_library(WEBGPU_DAWN_PROC_LIBRARY_PATH NAMES dawn_proc dawn_proc.dll PATH_SUFFIXES out/Release PATHS ${DAWN_BASE_PATH}) - find_library(WEBGPU_DAWN_WIRE_LIBRARY_PATH NAMES dawn_wire dawn_wire.dll PATH_SUFFIXES out/Release PATHS ${DAWN_BASE_PATH}) - find_path(WEBGPU_INCLUDE_DIR NAMES dawn/webgpu.h PATH_SUFFIXES out/Release/gen/src/include PATHS ${DAWN_BASE_PATH}) - add_library(sokol_wgpu ${_library_type} ${CMAKE_CURRENT_SOURCE_DIR}/sokol_wgpu.c) - set_property(TARGET sokol_wgpu PROPERTY FOLDER nanoem/sokol) - target_compile_definitions(sokol_wgpu PRIVATE SOKOL_DEBUG=$ SOKOL_EXTERNAL_GL_LOADER) - target_include_directories(sokol_wgpu PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/dependencies ${WEBGPU_INCLUDE_DIR}) - set_target_properties(sokol_wgpu PROPERTIES OUTPUT_NAME sokol_wgpu PREFIX "" DEFINE_SYMBOL "") - target_link_libraries(sokol_wgpu ${WEBGPU_DAWN_NATIVE_LIBRARY_PATH} ${WEBGPU_DAWN_PROC_LIBRARY_PATH} ${WEBGPU_DAWN_WIRE_LIBRARY_PATH}) - nanoem_emapp_plugin_install(sokol_wgpu) - message(STATUS "[emapp/bundle] setup sokol WGPU backend renderer plugin") - endif() -endfunction() - -function(nanoem_emapp_build_sokol) - nanoem_emapp_plugin_set_library_type() - nanoem_emapp_build_sokol_noop() - nanoem_emapp_build_sokol_glcore33() - nanoem_emapp_build_sokol_gles3() - nanoem_emapp_build_sokol_wgpu() - if(WIN32) - nanoem_emapp_build_sokol_d3d11() - if(TARGET sokol_glcore33) - target_link_libraries(sokol_glcore33 opengl32) - endif() - if(TARGET sokol_gles3) - target_link_libraries(sokol_gles3 opengl32) - endif() - elseif(APPLE) - nanoem_emapp_build_sokol_metal() - endif() -endfunction() - -nanoem_emapp_build_sokol() +option(NANOEM_ENABLE_SOKOL_GLES3_COMPAT "Enable building sokol_gles3 with compatibility profile" OFF) +option(NANOEM_ENABLE_SOKOL_WGPU "Enable building sokol_wgpu" OFF) + +function(nanoem_emapp_build_sokol_noop) + if(NOT NANOEM_ENABLE_STATIC_BUNDLE_PLUGIN) + add_library(sokol_noop ${_library_type} + ${CMAKE_CURRENT_SOURCE_DIR}/sokol_noop.c + $<$:${CMAKE_CURRENT_SOURCE_DIR}/sokol_noop.def>) + set_property(TARGET sokol_noop PROPERTY FOLDER nanoem/sokol) + target_include_directories(sokol_noop PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/dependencies) + set_target_properties(sokol_noop PROPERTIES OUTPUT_NAME sokol_noop PREFIX "" DEFINE_SYMBOL "") + nanoem_emapp_plugin_install(sokol_noop) + message(STATUS "[emapp/bundle] setup sokol noop backend renderer plugin") + endif() +endfunction() + +function(nanoem_emapp_build_sokol_glcore33) + if(NOT (NANOEM_ENABLE_STATIC_BUNDLE_PLUGIN OR (MSVC AND "${NANOEM_TARGET_ARCHITECTURE}" STREQUAL "arm64"))) + add_library(sokol_glcore33 ${_library_type} + ${CMAKE_CURRENT_SOURCE_DIR}/sokol_glcore33.c + $<$:${CMAKE_CURRENT_SOURCE_DIR}/sokol_glcore33.def>) + set_property(TARGET sokol_glcore33 PROPERTY FOLDER nanoem/sokol) + target_compile_definitions(sokol_glcore33 PRIVATE SOKOL_DEBUG=$ SOKOL_EXTERNAL_GL_LOADER) + target_include_directories(sokol_glcore33 PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/dependencies) + set_target_properties(sokol_glcore33 PROPERTIES OUTPUT_NAME sokol_glcore33 PREFIX "" DEFINE_SYMBOL "") + nanoem_emapp_plugin_install(sokol_glcore33) + message(STATUS "[emapp/bundle] setup sokol OpenGL 3.3 Core Profile backend renderer plugin") + endif() +endfunction() + +function(nanoem_emapp_build_sokol_gles3) + find_library(GLES3_LIBRARY_PATH NAMES GLESv3) + find_path(GLES3_INCLUDE_DIR NAMES GLES3/gl3.h) + mark_as_advanced(GLES3_LIBRARY_PATH GLES3_INCLUDE_DIR) + if((NANOEM_ENABLE_SOKOL_GLES3_COMPAT OR EMSCRIPTEN) OR (GLES3_LIBRARY_PATH AND GLES3_INCLUDE_DIR) AND NOT APPLE) + add_library(sokol_gles3 ${_library_type} + ${CMAKE_CURRENT_SOURCE_DIR}/sokol_gles3.c + $<$:${CMAKE_CURRENT_SOURCE_DIR}/sokol_gles3.def>) + set_property(TARGET sokol_gles3 PROPERTY FOLDER nanoem/sokol) + target_compile_definitions(sokol_gles3 PRIVATE SOKOL_DEBUG=$ $<$:NANOEM_ENABLE_SOKOL_GLES3_COMPAT> SOKOL_EXTERNAL_GL_LOADER) + target_include_directories(sokol_gles3 PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/dependencies) + set_target_properties(sokol_gles3 PROPERTIES OUTPUT_NAME sokol_gles3 PREFIX "" DEFINE_SYMBOL "") + if(GLES3_INCLUDE_DIR) + target_include_directories(sokol_gles3 PRIVATE ${GLES3_INCLUDE_DIR}) + endif() + if(GLES3_LIBRARY_PATH) + target_link_libraries(sokol_gles3 ${GLES3_LIBRARY_PATH}) + endif() + nanoem_emapp_plugin_install(sokol_gles3) + message(STATUS "[emapp/bundle] setup sokol OpenGL ES 3.0 backend renderer plugin") + endif() +endfunction() + +function(nanoem_emapp_build_sokol_d3d11) + add_library(sokol_d3d11 ${_library_type} + ${CMAKE_CURRENT_SOURCE_DIR}/sokol_d3d11.c + ${CMAKE_CURRENT_SOURCE_DIR}/sokol_d3d11.def) + set_property(TARGET sokol_d3d11 PROPERTY FOLDER nanoem/sokol) + target_compile_definitions(sokol_d3d11 PRIVATE SOKOL_DEBUG=$ SOKOL_STATIC=$ SOKOL_EXTERNAL_GL_LOADER) + target_include_directories(sokol_d3d11 PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/dependencies) + set_target_properties(sokol_d3d11 PROPERTIES OUTPUT_NAME sokol_d3d11 PREFIX "" DEFINE_SYMBOL "") + target_link_libraries(sokol_d3d11 d3d11 dxgi dxguid) + nanoem_emapp_plugin_install(sokol_d3d11) + message(STATUS "[emapp/bundle] setup sokol D3D11 backend renderer plugin") +endfunction() + +function(nanoem_emapp_build_sokol_metal) + add_library(sokol_metal_macos ${_library_type} ${CMAKE_CURRENT_SOURCE_DIR}/sokol_metal_$,ios,macos>.m) + set_property(TARGET sokol_metal_macos PROPERTY FOLDER nanoem/sokol) + target_compile_definitions(sokol_metal_macos PRIVATE SOKOL_DEBUG=$) + target_include_directories(sokol_metal_macos PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/dependencies) + set_target_properties(sokol_metal_macos PROPERTIES OUTPUT_NAME sokol_metal_macos PREFIX "" DEFINE_SYMBOL "") + target_link_libraries(sokol_metal_macos "-framework Metal") + nanoem_emapp_plugin_install(sokol_metal_macos) + message(STATUS "[emapp/bundle] setup sokol Metal backend renderer plugin") +endfunction() + + +function(nanoem_emapp_build_sokol_wgpu) + if(NANOEM_ENABLE_SOKOL_WGPU) + set(DAWN_BASE_PATH ${PROJECT_SOURCE_DIR}/dependencies/dawn) + find_library(WEBGPU_DAWN_NATIVE_LIBRARY_PATH NAMES dawn_native dawn_native.dll PATH_SUFFIXES out/Release/ PATHS ${DAWN_BASE_PATH}) + find_library(WEBGPU_DAWN_PROC_LIBRARY_PATH NAMES dawn_proc dawn_proc.dll PATH_SUFFIXES out/Release PATHS ${DAWN_BASE_PATH}) + find_library(WEBGPU_DAWN_WIRE_LIBRARY_PATH NAMES dawn_wire dawn_wire.dll PATH_SUFFIXES out/Release PATHS ${DAWN_BASE_PATH}) + find_path(WEBGPU_INCLUDE_DIR NAMES dawn/webgpu.h PATH_SUFFIXES out/Release/gen/src/include PATHS ${DAWN_BASE_PATH}) + add_library(sokol_wgpu ${_library_type} ${CMAKE_CURRENT_SOURCE_DIR}/sokol_wgpu.c) + set_property(TARGET sokol_wgpu PROPERTY FOLDER nanoem/sokol) + target_compile_definitions(sokol_wgpu PRIVATE SOKOL_DEBUG=$ SOKOL_EXTERNAL_GL_LOADER) + target_include_directories(sokol_wgpu PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/dependencies ${WEBGPU_INCLUDE_DIR}) + set_target_properties(sokol_wgpu PROPERTIES OUTPUT_NAME sokol_wgpu PREFIX "" DEFINE_SYMBOL "") + target_link_libraries(sokol_wgpu ${WEBGPU_DAWN_NATIVE_LIBRARY_PATH} ${WEBGPU_DAWN_PROC_LIBRARY_PATH} ${WEBGPU_DAWN_WIRE_LIBRARY_PATH}) + nanoem_emapp_plugin_install(sokol_wgpu) + message(STATUS "[emapp/bundle] setup sokol WGPU backend renderer plugin") + endif() +endfunction() + +function(nanoem_emapp_build_sokol) + nanoem_emapp_plugin_set_library_type() + nanoem_emapp_build_sokol_noop() + nanoem_emapp_build_sokol_glcore33() + nanoem_emapp_build_sokol_gles3() + nanoem_emapp_build_sokol_wgpu() + if(WIN32) + nanoem_emapp_build_sokol_d3d11() + if(TARGET sokol_glcore33) + target_link_libraries(sokol_glcore33 opengl32) + endif() + if(TARGET sokol_gles3) + target_link_libraries(sokol_gles3 opengl32) + endif() + elseif(APPLE) + nanoem_emapp_build_sokol_metal() + endif() +endfunction() + +nanoem_emapp_build_sokol() diff --git a/macos/CMakeLists.txt b/macos/CMakeLists.txt index b15bfd9a..2018e9b1 100644 --- a/macos/CMakeLists.txt +++ b/macos/CMakeLists.txt @@ -150,7 +150,7 @@ install(CODE " set(\${path} \"@executable_path/../Frameworks\" PARENT_SCOPE) endfunction() # construct app - set(app_path \"${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}.app\") + set(app_path \"\${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}.app\") file(REMOVE_RECURSE \"\${CMAKE_CURRENT_BINARY_DIR}/Contents/PlugIns\") file(GLOB_RECURSE INSTALLED_PLUGINS \"\${app_path}/Contents/PlugIns/*${CMAKE_SHARED_LIBRARY_SUFFIX}\") fixup_bundle(\"\${app_path}\" \"\${INSTALLED_PLUGINS}\" \"${LIBRARY_PATHS}\") diff --git a/scripts/build.cmake b/scripts/build.cmake index 4ffa666a..462ebf4a 100644 --- a/scripts/build.cmake +++ b/scripts/build.cmake @@ -207,6 +207,9 @@ function(compile_tbb _cmake_build_type _generator _toolset_option _arch_option _ -DCMAKE_CONFIGURATION_TYPES=${_cmake_build_type} -DCMAKE_INSTALL_LIBDIR=lib -DCMAKE_INSTALL_PREFIX=${_build_path}/install-root + -DCMAKE_BUILD_WITH_INSTALL_NAME_DIR=ON + -DCMAKE_MACOS_RPATH=ON + -DCMAKE_INSTALL_NAME_DIR=${_build_path}/install-root/lib -G "${_generator}" ${_arch_option} ${_toolset_option} ${_source_path}) rewrite_cmake_cache(${_build_path}) execute_build(${_build_path})