Skip to content

Commit

Permalink
Enable Windows build of habitat-sim
Browse files Browse the repository at this point in the history
  • Loading branch information
cegbertOculus committed Aug 28, 2019
1 parent f31f3f8 commit b1f09bd
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 18 deletions.
23 changes: 15 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def is_pip():
class CMakeExtension(Extension):
def __init__(self, name, sourcedir=""):
Extension.__init__(self, name, sources=[])
self.sourcedir = os.path.abspath(sourcedir)
self.sourcedir = os.path.abspath(sourcedir).replace("\\", "/")


# populated in CMakeBuild.build_extension()
Expand Down Expand Up @@ -207,8 +207,8 @@ def build_extension(self, ext):

cmake_args = [
"-DBUILD_PYTHON_BINDINGS=ON",
"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=" + extdir,
"-DPYTHON_EXECUTABLE=" + sys.executable,
"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=" + extdir.replace("\\", "/"),
"-DPYTHON_EXECUTABLE=" + sys.executable.replace("\\", "/"),
"-DCMAKE_EXPORT_COMPILE_COMMANDS={}".format("OFF" if is_pip() else "ON"),
]
cmake_args += shlex.split(args.cmake_args)
Expand All @@ -226,8 +226,9 @@ def build_extension(self, ext):
# doesn't require a number (but builds sequentially by default), so we
# add the argument only when it's not ninja or the number of jobs is
# specified.
if not has_ninja() or self.parallel:
build_args += ["-j{}".format(self.parallel) if self.parallel else "-j"]
if sys.platform != "win32":
if not has_ninja() or self.parallel:
build_args += ["-j{}".format(self.parallel) if self.parallel else "-j"]

cmake_args += [
"-DBUILD_GUI_VIEWERS={}".format("ON" if not args.headless else "OFF")
Expand All @@ -247,13 +248,18 @@ def build_extension(self, ext):

if self.run_cmake(cmake_args):
subprocess.check_call(
shlex.split("cmake -H{} -B{}".format(ext.sourcedir, self.build_temp))
shlex.split(
"cmake -H{} -B{}".format(
ext.sourcedir, self.build_temp.replace("\\", "/")
)
)
+ cmake_args,
env=env,
)

subprocess.check_call(
shlex.split("cmake --build {}".format(self.build_temp)) + build_args
shlex.split("cmake --build {}".format(self.build_temp.replace("\\", "/")))
+ build_args
)
print() # Add an empty line for cleaner output

Expand All @@ -262,7 +268,8 @@ def build_extension(self, ext):
return

if not args.headless:
link_dst = osp.join(self.build_temp, "viewer")
shlex.split("cmake --build {}".format(self.build_temp.replace("\\", "/")))
+build_args
if not osp.islink(link_dst):
os.symlink(
osp.abspath(osp.join(self.build_temp, "utils/viewer/viewer")),
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ cmake_minimum_required(VERSION 3.10)
project(esp)

if(MSVC)
add_definitions(/DNOMINMAX)
add_definitions(/DNOMINMAX /DEIGEN_DONT_ALIGN_STATICALLY)
endif()

find_program(CCACHE_FOUND ccache)
Expand Down
5 changes: 5 additions & 0 deletions src/esp/assets/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ endif()

add_library(assets STATIC ${assets_SOURCES})

if(MSVC)
# Define common math constants if we compile with MSVC. This is needed because of Sophus.
target_compile_definitions(assets PUBLIC _USE_MATH_DEFINES)
endif (MSVC)

target_link_libraries(assets
PUBLIC
core
Expand Down
2 changes: 0 additions & 2 deletions src/esp/assets/FRLInstanceMeshData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
#include <Magnum/Trade/Trade.h>

#include <fcntl.h>
#include <sys/mman.h>
#include <tinyply.h>
#include <unistd.h>
#include <fstream>
#include <sophus/so3.hpp>
#include <sstream>
Expand Down
2 changes: 0 additions & 2 deletions src/esp/assets/GenericInstanceMeshData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
#include <Magnum/Trade/Trade.h>

#include <fcntl.h>
#include <sys/mman.h>
#include <tinyply.h>
#include <unistd.h>
#include <fstream>
#include <sophus/so3.hpp>
#include <sstream>
Expand Down
6 changes: 3 additions & 3 deletions src/esp/assets/PTexMeshData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ std::vector<PTexMeshData::MeshData> splitMesh(

// calculate vertex grid position and code
#pragma omp parallel for
for (size_t i = 0; i < mesh.vbo.size(); i++) {
for (int32_t i = 0; i < mesh.vbo.size(); i++) {
const vec3f p = mesh.vbo[i].head<3>();
vec3f pi = (p - boundingBox.min()) / splitSize;
verts[i] = EncodeMorton3(pi.cast<int>());
Expand All @@ -109,7 +109,7 @@ std::vector<PTexMeshData::MeshData> splitMesh(
faces.resize(numFaces);

#pragma omp parallel for
for (size_t i = 0; i < numFaces; i++) {
for (int32_t i = 0; i < numFaces; i++) {
faces[i].originalFace = i;
faces[i].code = std::numeric_limits<uint32_t>::max();
for (int j = 0; j < 4; j++) {
Expand Down Expand Up @@ -155,7 +155,7 @@ std::vector<PTexMeshData::MeshData> splitMesh(
}

#pragma omp parallel for
for (size_t i = 0; i < numChunks; i++) {
for (int32_t i = 0; i < numChunks; i++) {
uint32_t chunkSize = chunkStart[i + 1] - chunkStart[i];

std::vector<uint32_t> refdVerts;
Expand Down
5 changes: 5 additions & 0 deletions src/esp/gfx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ target_include_directories(gfx
"${DEPS_DIR}/glad/include"
)

if(MSVC)
# Define common math constants if we compile with MSVC. This is needed because of Sophus.
target_compile_definitions(gfx PUBLIC _USE_MATH_DEFINES)
endif (MSVC)

target_link_libraries(gfx
PUBLIC
assets
Expand Down
1 change: 0 additions & 1 deletion src/esp/gfx/PTexMeshShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "PTexMeshShader.h"

#include <fcntl.h>
#include <sys/mman.h>
#include <iostream>

#include <Corrade/Containers/Reference.h>
Expand Down
5 changes: 5 additions & 0 deletions src/esp/nav/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ target_include_directories(nav
"${DEPS_DIR}/recastnavigation/Recast/Include"
)

if(MSVC)
# Define common math constants if we compile with MSVC. This is needed because of Sophus.
target_compile_definitions(nav PUBLIC _USE_MATH_DEFINES)
endif (MSVC)

target_link_libraries(nav
PUBLIC
core
Expand Down
2 changes: 1 addition & 1 deletion src/esp/nav/PathFinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class dtQueryPathState;
namespace esp {
// forward declaration
namespace assets {
class MeshData;
struct MeshData;
}
namespace nav {

Expand Down

0 comments on commit b1f09bd

Please sign in to comment.