Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build on Windows with VS 2019 #25

Closed
inkydragon opened this issue Jul 24, 2021 · 3 comments
Closed

Build on Windows with VS 2019 #25

inkydragon opened this issue Jul 24, 2021 · 3 comments
Labels

Comments

@inkydragon
Copy link

inkydragon commented Jul 24, 2021

Update:

  • build with RelWithDebInfo, everything works fine. No imgui window.

When I'am tring to build nanoem on win 10 follow instructions in readme#How to build?. I've got some errors.

After some attempts, I managed to build nanoem on Windows 10.

Describe the bug
readme#How to build? Not work.

To Reproduce
Steps to reproduce the behavior:

  1. set up Prerequisites in readme.
  2. start "Visual Studio 2019 Developer Command Prompt (x64)"
  3. git clone git submodule update --init --recursive
    There is a typo, see fix git cmd typo #23
  4. Patch code 1, remove GnuWin32/patch dep, using git apply
 scripts/build.cmake | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/scripts/build.cmake b/scripts/build.cmake
index f2dc37e..b095f65 100644
--- a/scripts/build.cmake
+++ b/scripts/build.cmake
@@ -623,16 +623,20 @@ if(NOT OSX_TARGET)
 endif()
 set(CMAKE_FIND_LIBRARY_PREFIXES "lib;")
 set(CMAKE_FIND_LIBRARY_SUFFIXES ".so;.a;.lib")
-find_program(PATCH_EXECUTABLE_PATH NAME patch PATHS "${CMAKE_CURRENT_SOURCE_DIR}" "C:/Program Files (x86)/GnuWin32/bin")
+
 find_package(Git REQUIRED)
-if(PATCH_EXECUTABLE_PATH AND GIT_FOUND)
+if(GIT_FOUND)
   execute_process(COMMAND ${GIT_EXECUTABLE} checkout -- .
                   WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/dependencies/bullet3
                   RESULT_VARIABLE result)
-  execute_process(COMMAND ${PATCH_EXECUTABLE_PATH} -p1
-                  INPUT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/cmake/bullet-2.76.diff
+  # apply patch
+  execute_process(COMMAND ${GIT_EXECUTABLE} apply ${CMAKE_CURRENT_SOURCE_DIR}/cmake/bullet-2.76.diff
                   WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/dependencies/bullet3
                   RESULT_VARIABLE result)
+  if(result EQUAL "1")
+      message(FATAL_ERROR "Apply patch for bullet failed!")
+  endif()
+
   execute_process(COMMAND ${GIT_EXECUTABLE} checkout -- .
                   WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/dependencies/glslang)
   file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/dependencies/glslang/glslang/Include/InfoSink.h input_info_sink_h NEWLINE_CONSUME)
  1. Patch code 2, force to compile with cpp mode
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6541f1b..2a08ba4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -180,6 +180,8 @@ if(SOUNDIO_HAVE_WASAPI)
     )
 endif()
 
+set_source_files_properties(${LIBSOUNDIO_SOURCES} PROPERTIES LANGUAGE CXX )
+
 include_directories(
     ${libsoundio_SOURCE_DIR}
     ${libsoundio_BINARY_DIR}
@@ -241,7 +243,7 @@ if(BUILD_STATIC_LIBS)
     set_target_properties(libsoundio_static PROPERTIES
         OUTPUT_NAME ${SOUNDIO_STATIC_LIBNAME}
         COMPILE_FLAGS ${LIB_CFLAGS}
-        LINKER_LANGUAGE C
+        LINKER_LANGUAGE CXX
     )
     install(TARGETS libsoundio_static DESTINATION ${CMAKE_INSTALL_LIBDIR})
 endif()

MSVC dosn't have stdatomic.h in std C mode.
xref: Visual Studio Feedback

// https://github.com/andrewrk/libsoundio/blob/dc4f84339039ac518b6cd1c0e7683e88e25be470/src/atomics.h#L14-L16
#ifdef __cplusplus
#include <atomic>

...

// https://github.com/andrewrk/libsoundio/blob/dc4f84339039ac518b6cd1c0e7683e88e25be470/src/atomics.h#L46-L48
#else
#include <stdatomic.h>

...

#endif
  1. Patch code 3, Do not clean up temp files.
diff --git a/scripts/build.cmake b/scripts/build.cmake
index b095f65..5963f54 100644
--- a/scripts/build.cmake
+++ b/scripts/build.cmake
@@ -708,4 +708,4 @@ foreach(arch_item ${ARCH_LIST})
     compile_all_repositories(${target_generator} ${target_toolset} ${target_compiler} ${arch_item} ${config_item})
   endforeach()
 endforeach()
-cleanup_all_repositories()
+# cleanup_all_repositories()

nanoem/scripts/build.cmake

Lines 598 to 605 in 9f75edf

function(cleanup_all_repositories)
set(all_repositories "bullet3;glslang;minizip;zlib")
foreach(item ${all_repositories})
string(STRIP "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/${item}" _path)
execute_process(COMMAND ${GIT_EXECUTABLE} checkout -- . WORKING_DIRECTORY ${_path})
execute_process(COMMAND ${GIT_EXECUTABLE} clean -df -e build WORKING_DIRECTORY ${_path})
endforeach()
endfunction()

On my PC, the output dir is out, so ${GIT_EXECUTABLE} clean -df -e build will rm all output files.
So I commented out this function call.

  1. Build with
cd nanoem

cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -P scripts/build.cmake

mkdir out
cd out

cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -G Ninja ..
cmake --build . --config Release

Must build with flag -DCONFIG=release, or cmake cannot find includes

for example:

nanoem/emapp/CMakeLists.txt

Lines 272 to 279 in 9f75edf

function(nanoem_emapp_find_minizip)
nanoem_cmake_get_install_path("minizip" MINIZIP_BASE_PATH MINIZIP_INSTALL_PATH_DEBUG MINIZIP_INSTALL_PATH_RELEASE)
find_path(MINIZIP_INCLUDE_DIR NAMES mz.h PATH_SUFFIXES include PATHS ${MINIZIP_INSTALL_PATH_RELEASE} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
find_library(MINIZIP_LIBRARY_DEBUG NAMES minizip libminizip minizipd libminizipd PATH_SUFFIXES lib PATHS ${MINIZIP_INSTALL_PATH_DEBUG} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
find_library(MINIZIP_LIBRARY_RELEASE NAMES minizip libminizip PATH_SUFFIXES lib PATHS ${MINIZIP_INSTALL_PATH_RELEASE} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
mark_as_advanced(MINIZIP_INCLUDE_DIR MINIZIP_LIBRARY_DEBUG MINIZIP_LIBRARY_RELEASE)
message(STATUS "[emapp] minizip is located at ${MINIZIP_BASE_PATH}")
endfunction()

find_path only search MINIZIP_INSTALL_PATH_RELEASE.

  1. Run out\win32\nanoem.exe

image

Desktop:

  • OS: Windows 10 - 21H1
  • VS 2019 - 16.10.4
    • cmake version 3.20.21032501-MSVC_2
    • ninja 1.10.2
    • cl (msvc) 19.29.30040

Still need more explore, then I'll make a new pr and add new github CI for win build.

@inkydragon
Copy link
Author

There are decisions to be made:
I don't know what your opinion is, so let's discuss it first.

  • STEP 3: remove GnuWin32/patch dependency, switch to git apply
  • STEP 4: MSVC in C mode doesn't have stdatomic.h.
  • STEP 5: Do not clean up output libs.
    • Exclude the correct dir: clean -df -e build => clean -df -e out (minimum modify)
    • replace all /out/ with /build/
      Many projects use build as the default compile output folder and add it to the .gitignore file.
      Otherwise, git will complain that many submodules are dirty.
    • Do not clean temp files.

@hkrn
Copy link
Owner

hkrn commented Jul 25, 2021

STEP 3: remove GnuWin32/patch dependency, switch to git apply

I'll fix it.

STEP 4: MSVC in C mode doesn't have stdatomic.h

libsoundio is an optional dependency (built for GLFW application in glfw directory and can disable by NANOEM_DISABLE_BUILD_GLFW environmnet variable) and disable it by NANOEM_DISABLE_BUILD_LIBSOUNDIO environment variable. The WASAPI based audio player implementation is used in Windows native application (in win32 directory) and there is not reason to build libsoundio unless GLFW based application is built.

STEP 5: Do not clean up output libs.

The default behavior is built to out directory for each dependencies, this can be controlled by NANOEM_BUILD_DEPENDENCIES_DIRECTORY and FX9_BUILD_DEPENDENCIES_DIRECTORY environment variables and set them to outside of nanoem source directory.

NANOEM_BUILD_DEPENDENCIES_DIRECTORY and FX9_BUILD_DEPENDENCIES_DIRECTORY are used in GitHub CI workflow.

For historical reasons, build directory was used as artifact directory and ignore it, It's now out directory therefore built artifact will be purged by cleanup_all_repositories. This is unintentional behavior and will be fixed by changing built to out directory.

hkrn added a commit that referenced this issue Jul 26, 2021
hkrn added a commit that referenced this issue Jul 26, 2021
hkrn added a commit that referenced this issue Jul 27, 2021
* [misc] revise build flow, fixes #23 and #25
* [cmake] add --ignore-space-change to fix CI failure
@stale
Copy link

stale bot commented Oct 15, 2021

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the wontfix label Oct 15, 2021
@stale stale bot closed this as completed Oct 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants