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 win32 #12

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 48 additions & 22 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@

cmake_minimum_required(VERSION 3.4)

if(WIN32)
set(BUILD_WIN32_DIR ${CMAKE_CURRENT_SOURCE_DIR}/build_win32)
if( NOT DEFINED VCPKG_BUILT )
include(${BUILD_WIN32_DIR}/automate-vcpkg-tks.cmake)
include(${BUILD_WIN32_DIR}/vcpkg_list.cmake)
vcpkg_install_packages(${VCPACKAGES})
set(VCPKG_BUILT TRUE CACHE BOOL "vcpkg_install_packages has run")
endif()
endif(WIN32)

project(Facebook360_DEP CXX)

set(CMAKE_INCLUDE_CURRENT_DIR ON)
Expand All @@ -30,31 +40,36 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -m64 -O3 -funroll-loops -pipe")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -mmmx -mavx -msse -msse3")

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wsign-compare")
if(UNIX)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -m64 -O3 -funroll-loops -pipe")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -mmmx -mavx -msse -msse3")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wsign-compare")
elseif(WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNOMINMAX=1 -DUNICODE")
endif()

if(BUILD_LINE_COVERAGE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-instr-generate -fcoverage-mapping")
endif()

if(NOT APPLE)
if(UNIX AND NOT APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
endif()

# Add extra directories that may not have been added by default
set(OPT_LOCAL_DIR "/opt/local")
if(EXISTS "${OPT_LOCAL_DIR}/lib")
link_directories("${OPT_LOCAL_DIR}/lib")
include_directories(SYSTEM "${OPT_LOCAL_DIR}/include")
endif()

set(USR_LOCAL_DIR "/usr/local")
if(EXISTS "${USR_LOCAL_DIR}/lib")
link_directories("${USR_LOCAL_DIR}/lib")
include_directories(SYSTEM "${USR_LOCAL_DIR}/include")
endif()
if(UNIX)
# Add extra directories that may not have been added by default
set(OPT_LOCAL_DIR "/opt/local")
if(EXISTS "${OPT_LOCAL_DIR}/lib")
link_directories("${OPT_LOCAL_DIR}/lib")
include_directories(SYSTEM "${OPT_LOCAL_DIR}/include")
endif()

set(USR_LOCAL_DIR "/usr/local")
if(EXISTS "${USR_LOCAL_DIR}/lib")
link_directories("${USR_LOCAL_DIR}/lib")
include_directories(SYSTEM "${USR_LOCAL_DIR}/include")
endif()
endif(UNIX)

# Add custom targets to show all source and header files in Xcode
file(GLOB SRC "${CMAKE_CURRENT_SOURCE_DIR}/source/*")
Expand All @@ -71,9 +86,11 @@ set(OPENCV_COMPONENTS

# When adding Boost::chrono to target_link_libraries make sure it is listed after Boost::timer
# because Boost::timer depends on Boost::chrono
find_package(Boost REQUIRED COMPONENTS chrono filesystem system program_options regex timer)
find_package(Boost REQUIRED COMPONENTS chrono filesystem system program_options regex timer locale)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
if(UNIX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
endif()

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
find_package(Ceres 1.14 REQUIRED)
Expand All @@ -83,13 +100,18 @@ find_package(Eigen3 3.3 REQUIRED)
find_package(double-conversion 3.0)
include_directories(${EIGEN3_INCLUDE_DIR})

if(WIN32)
find_package(zlib REQUIRED)
find_package(gtest REQUIRED)
endif()

if(APPLE)
set(FOLLY_LIB folly)
else()
find_package(Folly REQUIRED)
set(FOLLY_LIB Folly::folly)
endif()
set(FOLLY_TARGET ${FOLLY_LIB} double-conversion)
set(FOLLY_TARGET ${FOLLY_LIB})

###### Targets ######

Expand Down Expand Up @@ -166,7 +188,6 @@ target_link_libraries(
)

### TARGET DepUnitTest ###

add_executable(
DepUnitTest
source/test/DepUnitTest.cpp
Expand Down Expand Up @@ -197,8 +218,12 @@ target_link_libraries(
)

### TARGET ConvertToBinary ###
if(UNIX)
include("${CMAKE_CURRENT_SOURCE_DIR}/ISPC.cmake")
elseif(WIN32)
include("${BUILD_WIN32_DIR}/ISPC-win32.cmake")
endif()

include("${CMAKE_CURRENT_SOURCE_DIR}/ISPC.cmake")
add_executable(
ConvertToBinary
source/mesh_stream/ConvertToBinary.cpp
Expand Down Expand Up @@ -428,6 +453,7 @@ target_link_libraries(
Boost::program_options
Boost::timer
Boost::chrono
Boost::locale
Eigen3::Eigen
glog::glog
${OPENCV_COMPONENTS}
Expand Down
23 changes: 23 additions & 0 deletions build_win32/ISPC-win32.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# ISPC-win32.cmake -- for Windows port of facebook360-dep
# created 12 Oct 2019 [email protected]
# ISPC source at https://sourceforge.net/projects/ispcmirror/ was last updated in 2015
# Only one component of facebook360-dep -- convertToBinary -- uses ispc
# Building ispc from source is complex and hard to automate but the result is a simple dll
# So I have chosen to ship prebuilt dlls, import libraries and header with fb360-dep.
# This script makes them visible to generated projects

if(NOT DEFINED BUILD_WIN32_DIR)
set(BUILD_WIN32_DIR ${CMAKE_CURRENT_SOURCE_DIR}/build_win32)
endif()

set(TEXCOMP_DIR ${BUILD_WIN32_DIR}/ispc_texcomp)

add_library(
ispc_texcomp SHARED IMPORTED GLOBAL
${TEXCOMP_DIR}/ispc_texcomp.h
)

set_target_properties(ispc_texcomp PROPERTIES IMPORTED_LOCATION_DEBUG ${TEXCOMP_DIR}/debug/ispc_texcomp.dll)
set_target_properties(ispc_texcomp PROPERTIES IMPORTED_IMPLIB_DEBUG ${TEXCOMP_DIR}/debug/ispc_texcomp.lib)
set_target_properties(ispc_texcomp PROPERTIES IMPORTED_LOCATION_RELEASE ${TEXCOMP_DIR}/release/ispc_texcomp.dll)
set_target_properties(ispc_texcomp PROPERTIES IMPORTED_IMPLIB_RELEASE ${TEXCOMP_DIR}/release/ispc_texcomp.lib)
191 changes: 191 additions & 0 deletions build_win32/automate-vcpkg-tks.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
#------------------------------------------------------------------------------------------------------------
#
# Automate-VCPKG by Andre Taulien modified by T K Sharpless
# ===============================
#
# Project Repository: https://github.com/REGoth-project/Automate-VCPKG
# License ..........: MIT, see end of file.
#
# Based on: https://github.com/sutambe/cpptruths/blob/vcpkg_cmake_blog/cpp0x/vcpkg_test/CMakeLists.txt
#
#
# While [Vcpkg](https://github.com/microsoft/vcpkg) on it's own is awesome, it does add
# a little bit of complexity to getting a project to build. Even more if the one trying
# to compile your application is not too fond of the commandline. Additionally, CMake
# commands tend to get rather long with the toolchain path.
#
# To keep things simple for new users who just want to get the project to build, this
# script offers a solution.
#
# Lets assume your main `CMakelists.txt` looks something like this:
#
# cmake_minimum_required (VERSION 3.12.0)
# project (MyProject)
#
# add_executable(MyExecutable main.c)
#
# To integrate Vcpkg into that `CMakelists.txt`, simple put the following lines before the
# call to `project(MyProject)`:
#
# include(cmake/automate-vcpkg.cmake)
#
# vcpkg_bootstrap()
# vcpkg_install_packages(libsquish physfs)
#
# The call to `vcpkg_bootstrap()` will clone the official Vcpkg repository and bootstrap it.
# If it detected an existing environment variable defining a valid `VCPKG_ROOT`, it will
# update the existing installation of Vcpkg.
#
# Arguments to `vcpkg_install_packages()` are the packages you want to install using Vcpkg.
#
# If you want to keep the possibility for users to chose their own copy of Vcpkg, you can
# simply not run the code snippet mentioned above, something like this will work:
#
# option(SKIP_AUTOMATE_VCPKG "When ON, you will need to built the packages
# required by MyProject on your own or supply your own vcpkg toolchain.")
#
# if (NOT SKIP_AUTOMATE_VCPKG)
# include(cmake/automate-vcpkg.cmake)
#
# vcpkg_bootstrap()
# vcpkg_install_packages(libsquish physfs)
# endif()
#
# Then, the user has to supply the packages on their own, be it through Vcpkg or manually
# specifying their locations.
#------------------------------------------------------------------------------------------------------------

cmake_minimum_required (VERSION 3.12)


macro(_install_or_update_vcpkg)
if(NOT EXISTS ${VCPKG_ROOT})
message(STATUS "Cloning vcpkg in ${VCPKG_ROOT}")
execute_process(COMMAND git clone https://github.com/Microsoft/vcpkg.git ${VCPKG_ROOT})

# If a reproducible build is desired (and potentially old libraries are # ok), uncomment the
# following line and pin the vcpkg repository to a specific githash.
# execute_process(COMMAND git checkout 745a0aea597771a580d0b0f4886ea1e3a94dbca6 WORKING_DIRECTORY ${VCPKG_ROOT})
else()
# The following command has no effect if the vcpkg repository is in a detached head state.
message(STATUS "Auto-updating vcpkg in ${VCPKG_ROOT}")
execute_process(COMMAND git pull WORKING_DIRECTORY ${VCPKG_ROOT})
endif()

if(NOT EXISTS ${VCPKG_ROOT}/README.md)
message(FATAL_ERROR "***** FATAL ERROR: Could not clone vcpkg *****")
endif()

if(WIN32)
set(VCPKG_EXEC ${VCPKG_ROOT}/vcpkg.exe)
set(VCPKG_BOOTSTRAP ${VCPKG_ROOT}/bootstrap-vcpkg.bat)
else()
set(VCPKG_EXEC ${VCPKG_ROOT}/vcpkg)
set(VCPKG_BOOTSTRAP ${VCPKG_ROOT}/bootstrap-vcpkg.sh)
endif()

if(NOT EXISTS ${VCPKG_EXEC})
message("Bootstrapping vcpkg in ${VCPKG_ROOT}")
execute_process(COMMAND ${VCPKG_BOOTSTRAP} WORKING_DIRECTORY ${VCPKG_ROOT})
endif()

if(NOT EXISTS ${VCPKG_EXEC})
message(FATAL_ERROR "***** FATAL ERROR: Could not bootstrap vcpkg *****")
endif()

endmacro()

# Installs the list of packages given as parameters using Vcpkg
macro(vcpkg_install_packages)

message("Installing/Updating vcpkg packages: ")

if (VCPKG_TARGET_TRIPLET)
set(ENV{VCPKG_DEFAULT_TRIPLET} "${VCPKG_TARGET_TRIPLET}")
endif()

foreach(PKG ${ARGN})
message(STATUS "---- ${PKG} ---- ")
execute_process(
COMMAND ${VCPKG_EXEC} install ${PKG}
WORKING_DIRECTORY ${VCPKG_ROOT}
OUTPUT_QUIET
RESULT_VARIABLE RES
)
if( ${RES} ) ## assume zero/null means OK
if(AUTOMATE_VCPKG_UPDATE) # try updating
execute_process(
COMMAND ${VCPKG_EXEC} install ${PKG} --recurse
WORKING_DIRECTORY ${VCPKG_ROOT}
RESULT_VARIABLE RES
)
if( ${RES} )
message(FATAL_ERROR "update ${PKG} failed")
endif()
else()
message(WARNING "install ${PKG} failed -- may want update")
endif()
endif()
endforeach()

endmacro()

# if user did not supply their own VCPKG toolchain file
# set default directory and toolchain names
if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
if(NOT DEFINED ENV{VCPKG_ROOT})
if(WIN32)
set(VCPKG_ROOT ${CMAKE_CURRENT_BINARY_DIR}/vcpkg)
else()
set(VCPKG_ROOT ${CMAKE_CURRENT_BINARY_DIR}/.vcpkg)
endif()
else()
set(VCPKG_ROOT $ENV{VCPKG_ROOT})
endif()
# set the toolchain file name
set(CMAKE_TOOLCHAIN_FILE ${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake CACHE STRING "")
message("New CMAKE_TOOLCHAIN_FILE ${CMAKE_TOOLCHAIN_FILE}")
else()
message("Existing CMAKE_TOOLCHAIN_FILE ${CMAKE_TOOLCHAIN_FILE}")
string(REPLACE "/scripts/buildsystems/vcpkg.cmake" "" TPTH ${CMAKE_TOOLCHAIN_FILE})
if(NOT DEFINED VCPKG_ROOT)
set(VCPKG_ROOT ${TPTH})
elseif( NOT "${VCPKG_ROOT}" EQUAL "${TPTH}")
message(FATAL_ERROR "but existing VCPKG_ROOT is ${VCPKG_ROOT}")
endif()
endif()

# make sure we have a working vcpkg instance
_install_or_update_vcpkg()
message(STATUS "AUTOMATE_VCPKG variables --")
message(STATUS " VCPKG_ROOT: ${VCPKG_ROOT}")
message(STATUS " VCPKG_EXEC: ${VCPKG_EXEC}")
message(STATUS " VCPKG_BOOTSTRAP: ${VCPKG_BOOTSTRAP}")
if (NOT ${VCPKG_TARGET_TRIPLET} EQUAL x64-windows)
message("VCPKG_TARGET_TRIPLET is ${VCPKG_TARGET_TRIPLET}, changing to x64-windows")
set(VCPKG_TARGET_TRIPLET x64-windows)
endif()

##message(FATAL_ERROR "EXIT DEBUG TEST")

# MIT License
#
# Copyright (c) 2019 REGoth-project
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
Loading