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

Can cilantro be used on Windows? #6

Open
adishavit opened this issue Jan 25, 2018 · 10 comments
Open

Can cilantro be used on Windows? #6

adishavit opened this issue Jan 25, 2018 · 10 comments

Comments

@adishavit
Copy link

Can I build cilantro on Windows?

@Algomorph
Copy link
Collaborator

@adishavit , it's a CMake project, so, as long as you can build Eigen & Pangolin (which are also both cross-platform), I don't see why not.

@adishavit
Copy link
Author

adishavit commented Jan 25, 2018 via email

@kzampog
Copy link
Owner

kzampog commented Jan 26, 2018

I don't have a Visual Studio installation handy to test, but my guess is that it should. Feel free to share your results and/or any needed updates!

@adishavit
Copy link
Author

Yeah - it isn't as smooth as I had hoped.
Some missing includes (e.g. <algorithm> for std::min) and the Eigen CMake dependency finders are not working well.
Also, it needs GLEW and all the rest of the Pangolin dependencies.

It would actually great if display dependencies were optional - so one can choose to only use the algorithms without visualization.

@Algomorph
Copy link
Collaborator

@kzampog , I think adding the missing headers should be a one-commit fix.
@adishavit , perhaps you can make a new issue with the feature request for optional visualization compilation?

@kzampog
Copy link
Owner

kzampog commented Jan 31, 2018

It seems that <algorithm> is included by <Eigen/Core> (which is implicitly included pretty much everywhere), so you might be getting errors because of Eigen not having been found. Please let us know whether that is the case, so we can investigate.

Making the visualization stuff optional makes a lot of sense and I do plan to implement it! :)

@adishavit
Copy link
Author

I kinda of gave up after spending too long on this.
I may get back to it.
But the things I did need to do were:

  1. Remove the CMake install commands. They just fail.
-install(DIRECTORY ${CMAKE_SOURCE_DIR}/include/ DESTINATION ${CMAKE_INSTALL_PREFIX}/include)
-install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}Targets LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
+# install(DIRECTORY ${CMAKE_SOURCE_DIR}/include/ DESTINATION ${CMAKE_INSTALL_PREFIX}/include)
+# install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}Targets LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
 
-install(FILES "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${PROJECT_NAME}Config.cmake" DESTINATION ${CMAKECONFIG_INSTALL_DIR})
-install(EXPORT ${PROJECT_NAME}Targets DESTINATION ${CMAKECONFIG_INSTALL_DIR})
+# install(FILES "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${PROJECT_NAME}Config.cmake" DESTINATION ${CMAKECONFIG_INSTALL_DIR})
+# install(EXPORT ${PROJECT_NAME}Targets DESTINATION ${CMAKECONFIG_INSTALL_DIR})
  1. Add M_PI to include/cilantro/connected_component_segmentation.hpp and src/iterative_closest_point.cpp
+#ifndef M_PI
+#define M_PI       3.14159265358979323846   // pi
+#endif
  1. Added NOMINMAX preprocessor to Windows builds.

@kzampog
Copy link
Owner

kzampog commented Jan 31, 2018

I added the missing M_PI defines for now. I'll try to get a VS setup some time soon and see what I could do from there.

Thanks for the feedback!

@kzampog
Copy link
Owner

kzampog commented Feb 7, 2018

I managed to compile the lib and examples in VS 2017. I did the following:

  1. Just configuring Eigen with CMake appears to make it discoverable by other projects via find_package.
  2. Same for Pangolin. It downloaded its dependencies (git required) and built without issues as a static lib (default config).
  3. The following CMakeLists.txt for cilantro seems to more or less work. I basically disabled install commands like @adishavit suggested and forced static CRT or it would not link.
cmake_minimum_required(VERSION 2.8)
project(cilantro)

# Build setup

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")

set(CMAKE_BUILD_TYPE "Release")
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} "/O2")
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "/O2")

list(APPEND FLAG_VARS
    CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO
    CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
)

foreach(FLAG_VAR ${FLAG_VARS})
    string(REGEX REPLACE "/MD" "/MT" NEW_FLAGS "${${FLAG_VAR}}")
    set(${FLAG_VAR} "${NEW_FLAGS}" CACHE STRING "" FORCE)
endforeach()

# Packages

find_package(Eigen3 REQUIRED)
find_package(Pangolin REQUIRED)
# find_package(OpenMP)
# if (OPENMP_FOUND)
#     set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
#     set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
# endif()

set(OTHER_INCLUDES ${EIGEN3_INCLUDE_DIRS} ${Pangolin_INCLUDE_DIRS})

include_directories(include)
include_directories(${OTHER_INCLUDES})

# Build library

file(GLOB_RECURSE 3rd_src ${CMAKE_SOURCE_DIR}/src/3rd_party/*.c ${CMAKE_SOURCE_DIR}/src/3rd_party/*.cpp)
file(GLOB lib_src ${CMAKE_SOURCE_DIR}/src/*.cpp)

add_library(${PROJECT_NAME} STATIC ${3rd_src} ${lib_src})
target_link_libraries(${PROJECT_NAME} ${Pangolin_LIBRARIES})

# Build examples

option(BUILD_EXAMPLES "Build small example apps" ON)
if(BUILD_EXAMPLES)
    file(GLOB example_files RELATIVE ${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/examples/*.cpp)
    foreach(example_file ${example_files})
        get_filename_component(example_name ${example_file} NAME_WE)
        add_executable(${example_name} ${example_file})
        target_link_libraries(${example_name} ${PROJECT_NAME} ${Pangolin_LIBRARIES})
    endforeach(example_file ${example_files})
endif()

# Package config files

file(REMOVE "${CMAKE_BINARY_DIR}/${PROJECT_NAME}Targets.cmake")
export(TARGETS ${PROJECT_NAME} APPEND FILE "${CMAKE_BINARY_DIR}/${PROJECT_NAME}Targets.cmake")

set(CMAKECONFIG_INSTALL_DIR lib/cmake/${PROJECT_NAME})
file(RELATIVE_PATH REL_INCLUDE_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKECONFIG_INSTALL_DIR}" "${CMAKE_INSTALL_PREFIX}/include")

# Build tree config
set(EXPORT_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/include)
configure_file(${CMAKE_SOURCE_DIR}/${PROJECT_NAME}Config.cmake.in ${CMAKE_BINARY_DIR}/${PROJECT_NAME}Config.cmake @ONLY IMMEDIATE)

# Install tree config
set(EXPORT_INCLUDE_DIR "\${PROJECT_CMAKE_DIR}/${REL_INCLUDE_DIR}")
configure_file(${CMAKE_SOURCE_DIR}/${PROJECT_NAME}Config.cmake.in ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${PROJECT_NAME}Config.cmake @ONLY)

# Add package to CMake package registry for use from the build tree
option(EXPORT_${PROJECT_NAME} "Export ${PROJECT_NAME} package for use by other software" ON)
if(EXPORT_${PROJECT_NAME})
    export(PACKAGE ${PROJECT_NAME})
endif()

# Install target

# install(DIRECTORY ${CMAKE_SOURCE_DIR}/include/ DESTINATION ${CMAKE_INSTALL_PREFIX}/include)
# install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}Targets LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)

# install(FILES "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${PROJECT_NAME}Config.cmake" DESTINATION ${CMAKECONFIG_INSTALL_DIR})
# install(EXPORT ${PROJECT_NAME}Targets DESTINATION ${CMAKECONFIG_INSTALL_DIR})

# # Uninstall target

# configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" IMMEDIATE @ONLY)
# add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)

Using the above, everything compiled and ran. I encountered 2 issues:

  1. OpenMP is not enabled and the source must be updated for it to work (change indices to signed type because VS still only supports OpenMP 2.0).
  2. Keyboard and mouse input when spawning multiple Visualizer windows is buggy.

I will reorganize the structure and properly revise CMakeLists at some point! :)

@mastrogiorgis
Copy link

Hi,
Is there any update re the VS version?
Many thanks,
G

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants