Commit b2fc9123 authored by Jørgen Lind's avatar Jørgen Lind
Browse files

Compile with clang on windows

parent 04370ffb
......@@ -27,7 +27,10 @@ macro(build3rdparty)
BuildCppRestSdk()
BuildAzure()
endif()
add_subdirectory(${pybind11_SOURCE_DIR} ${PROJECT_BINARY_DIR}/pybind11_${pybind11_VERSION} EXCLUDE_FROM_ALL)
if (Python3_FOUND)
add_subdirectory(${pybind11_SOURCE_DIR} ${PROJECT_BINARY_DIR}/pybind11_${pybind11_VERSION} EXCLUDE_FROM_ALL)
include(CMake/FindPythonLibsNew.cmake) # This is a hack on Windows to fix case sensitivity for finding the python library when building with the clang toolchain in visual studio
endif()
if (NOT DISABLE_CURL_IOMANAGER)
BuildCurl()
BuildLibUV()
......
......@@ -9,6 +9,9 @@ macro(BuildJsonCpp)
if (WIN32)
target_compile_options(jsoncpp_lib_static PRIVATE "/MD$<$<CONFIG:Debug>:d>")
endif()
if (NOT (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC"))
target_compile_options(jsoncpp_lib_static PRIVATE -Wno-implicit-int-float-conversion -Wno-macro-redefined)
endif()
set_target_properties(jsoncpp_lib_static PROPERTIES FOLDER ExternalProjectTargets/jsoncpp)
endmacro()
# - Find python libraries
# This module finds the libraries corresponding to the Python interpreter
# FindPythonInterp provides.
# This code sets the following variables:
#
# PYTHONLIBS_FOUND - have the Python libs been found
# PYTHON_PREFIX - path to the Python installation
# PYTHON_LIBRARIES - path to the python library
# PYTHON_INCLUDE_DIRS - path to where Python.h is found
# PYTHON_MODULE_EXTENSION - lib extension, e.g. '.so' or '.pyd'
# PYTHON_MODULE_PREFIX - lib name prefix: usually an empty string
# PYTHON_SITE_PACKAGES - path to installation site-packages
# PYTHON_IS_DEBUG - whether the Python interpreter is a debug build
#
# Thanks to talljimbo for the patch adding the 'LDVERSION' config
# variable usage.
#=============================================================================
# Copyright 2001-2009 Kitware, Inc.
# Copyright 2012 Continuum Analytics, Inc.
#
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# * Neither the names of Kitware, Inc., the Insight Software Consortium,
# nor the names of their contributors may be used to endorse or promote
# products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#=============================================================================
# Checking for the extension makes sure that `LibsNew` was found and not just `Libs`.
if(PYTHONLIBS_FOUND AND PYTHON_MODULE_EXTENSION)
return()
endif()
# Use the Python interpreter to find the libs.
if(PythonLibsNew_FIND_REQUIRED)
find_package(PythonInterp ${PythonLibsNew_FIND_VERSION} REQUIRED)
else()
find_package(PythonInterp ${PythonLibsNew_FIND_VERSION})
endif()
if(NOT PYTHONINTERP_FOUND)
set(PYTHONLIBS_FOUND FALSE)
set(PythonLibsNew_FOUND FALSE)
return()
endif()
# According to http://stackoverflow.com/questions/646518/python-how-to-detect-debug-interpreter
# testing whether sys has the gettotalrefcount function is a reliable, cross-platform
# way to detect a CPython debug interpreter.
#
# The library suffix is from the config var LDVERSION sometimes, otherwise
# VERSION. VERSION will typically be like "2.7" on unix, and "27" on windows.
execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c"
"from distutils import sysconfig as s;import sys;import struct;
print('.'.join(str(v) for v in sys.version_info));
print(sys.prefix);
print(s.get_python_inc(plat_specific=True));
print(s.get_python_lib(plat_specific=True));
print(s.get_config_var('SO'));
print(hasattr(sys, 'gettotalrefcount')+0);
print(struct.calcsize('@P'));
print(s.get_config_var('LDVERSION') or s.get_config_var('VERSION'));
print(s.get_config_var('LIBDIR') or '');
print(s.get_config_var('MULTIARCH') or '');
"
RESULT_VARIABLE _PYTHON_SUCCESS
OUTPUT_VARIABLE _PYTHON_VALUES
ERROR_VARIABLE _PYTHON_ERROR_VALUE)
if(NOT _PYTHON_SUCCESS MATCHES 0)
if(PythonLibsNew_FIND_REQUIRED)
message(FATAL_ERROR
"Python config failure:\n${_PYTHON_ERROR_VALUE}")
endif()
set(PYTHONLIBS_FOUND FALSE)
set(PythonLibsNew_FOUND FALSE)
return()
endif()
# Convert the process output into a list
if(WIN32)
string(REGEX REPLACE "\\\\" "/" _PYTHON_VALUES ${_PYTHON_VALUES})
endif()
string(REGEX REPLACE ";" "\\\\;" _PYTHON_VALUES ${_PYTHON_VALUES})
string(REGEX REPLACE "\n" ";" _PYTHON_VALUES ${_PYTHON_VALUES})
list(GET _PYTHON_VALUES 0 _PYTHON_VERSION_LIST)
list(GET _PYTHON_VALUES 1 PYTHON_PREFIX)
list(GET _PYTHON_VALUES 2 PYTHON_INCLUDE_DIR)
list(GET _PYTHON_VALUES 3 PYTHON_SITE_PACKAGES)
list(GET _PYTHON_VALUES 4 PYTHON_MODULE_EXTENSION)
list(GET _PYTHON_VALUES 5 PYTHON_IS_DEBUG)
list(GET _PYTHON_VALUES 6 PYTHON_SIZEOF_VOID_P)
list(GET _PYTHON_VALUES 7 PYTHON_LIBRARY_SUFFIX)
list(GET _PYTHON_VALUES 8 PYTHON_LIBDIR)
list(GET _PYTHON_VALUES 9 PYTHON_MULTIARCH)
# Make sure the Python has the same pointer-size as the chosen compiler
# Skip if CMAKE_SIZEOF_VOID_P is not defined
if(CMAKE_SIZEOF_VOID_P AND (NOT "${PYTHON_SIZEOF_VOID_P}" STREQUAL "${CMAKE_SIZEOF_VOID_P}"))
if(PythonLibsNew_FIND_REQUIRED)
math(EXPR _PYTHON_BITS "${PYTHON_SIZEOF_VOID_P} * 8")
math(EXPR _CMAKE_BITS "${CMAKE_SIZEOF_VOID_P} * 8")
message(FATAL_ERROR
"Python config failure: Python is ${_PYTHON_BITS}-bit, "
"chosen compiler is ${_CMAKE_BITS}-bit")
endif()
set(PYTHONLIBS_FOUND FALSE)
set(PythonLibsNew_FOUND FALSE)
return()
endif()
# The built-in FindPython didn't always give the version numbers
string(REGEX REPLACE "\\." ";" _PYTHON_VERSION_LIST ${_PYTHON_VERSION_LIST})
list(GET _PYTHON_VERSION_LIST 0 PYTHON_VERSION_MAJOR)
list(GET _PYTHON_VERSION_LIST 1 PYTHON_VERSION_MINOR)
list(GET _PYTHON_VERSION_LIST 2 PYTHON_VERSION_PATCH)
# Make sure all directory separators are '/'
string(REGEX REPLACE "\\\\" "/" PYTHON_PREFIX ${PYTHON_PREFIX})
string(REGEX REPLACE "\\\\" "/" PYTHON_INCLUDE_DIR ${PYTHON_INCLUDE_DIR})
string(REGEX REPLACE "\\\\" "/" PYTHON_SITE_PACKAGES ${PYTHON_SITE_PACKAGES})
if(CMAKE_HOST_WIN32 AND NOT (MSYS OR MINGW))
set(PYTHON_LIBRARY
"${PYTHON_PREFIX}/libs/python${PYTHON_LIBRARY_SUFFIX}.lib")
# when run in a venv, PYTHON_PREFIX points to it. But the libraries remain in the
# original python installation. They may be found relative to PYTHON_INCLUDE_DIR.
if(NOT EXISTS "${PYTHON_LIBRARY}")
get_filename_component(_PYTHON_ROOT ${PYTHON_INCLUDE_DIR} DIRECTORY)
set(PYTHON_LIBRARY
"${_PYTHON_ROOT}/libs/python${PYTHON_LIBRARY_SUFFIX}.lib")
endif()
# raise an error if the python libs are still not found.
if(NOT EXISTS "${PYTHON_LIBRARY}")
message(FATAL_ERROR "Python libraries not found")
endif()
else()
if(PYTHON_MULTIARCH)
set(_PYTHON_LIBS_SEARCH "${PYTHON_LIBDIR}/${PYTHON_MULTIARCH}" "${PYTHON_LIBDIR}")
else()
set(_PYTHON_LIBS_SEARCH "${PYTHON_LIBDIR}")
endif()
#message(STATUS "Searching for Python libs in ${_PYTHON_LIBS_SEARCH}")
# Probably this needs to be more involved. It would be nice if the config
# information the python interpreter itself gave us were more complete.
find_library(PYTHON_LIBRARY
NAMES "python${PYTHON_LIBRARY_SUFFIX}"
PATHS ${_PYTHON_LIBS_SEARCH}
NO_DEFAULT_PATH)
# If all else fails, just set the name/version and let the linker figure out the path.
if(NOT PYTHON_LIBRARY)
set(PYTHON_LIBRARY python${PYTHON_LIBRARY_SUFFIX})
endif()
endif()
MARK_AS_ADVANCED(
PYTHON_LIBRARY
PYTHON_INCLUDE_DIR
)
# We use PYTHON_INCLUDE_DIR, PYTHON_LIBRARY and PYTHON_DEBUG_LIBRARY for the
# cache entries because they are meant to specify the location of a single
# library. We now set the variables listed by the documentation for this
# module.
SET(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
SET(PYTHON_LIBRARIES "${PYTHON_LIBRARY}")
SET(PYTHON_DEBUG_LIBRARIES "${PYTHON_DEBUG_LIBRARY}")
find_package_message(PYTHON
"Found PythonLibs: ${PYTHON_LIBRARY}"
"${PYTHON_EXECUTABLE}${PYTHON_VERSION}")
set(PYTHONLIBS_FOUND TRUE)
set(PythonLibsNew_FOUND TRUE)
......@@ -39,9 +39,7 @@ else()
find_package(Python3 ${PYTHON_REQUIRED} COMPONENTS Interpreter Development ${PYTHON_ROOT_DIR_HINT})
endif()
if (Python3_FOUND)
set(PYTHON_EXECUTABLE ${Python3_EXECUTABLE})
else()
if (NOT Python3_FOUND)
message("Failed to find Python3 interpreter. Disabling Python build")
set(BUILD_PYTHON_DEFAULT OFF)
endif()
......@@ -119,13 +117,17 @@ find_package(Threads)
if (ENABLE_OPENMP)
find_package(OpenMP)
endif()
if (UNIX)
add_compile_options(-Werror=return-type)
elseif (MSVC_VERSION GREATER_EQUAL 1910 AND NOT OpenMP_CXX_FOUND)
add_compile_options(/permissive-)
if (MSVC)
if (MSVC_VERSION GREATER_EQUAL 1910 AND NOT OpenMP_CXX_FOUND)
add_compile_options(/permissive-)
endif()
if(MSVC_VERSION GREATER_EQUAL 1915)
add_compile_options( /JMC )
endif()
endif()
if(MSVC_VERSION GREATER_EQUAL 1915)
add_compile_options( /JMC )
if (NOT (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC"))
add_compile_options(-Werror=return-type)
endif()
include(CMake/SetWarnings.cmake)
......
......@@ -28,6 +28,10 @@ pybind11_add_module(core MODULE SYSTEM
PyVolumeSampler.h
)
if (MSVC AND (CMAKE_CXX_COMPILER_ID STREQUAL "Clang"))
target_compile_options(core BEFORE PRIVATE "SHELL:/imsvc\ \"${PYBIND11_INCLUDE_DIR}\" /imsvc\ \"${PYTHON_INCLUDE_DIRS}\"")
endif()
set_target_properties(core
PROPERTIES
VERSION ${CMAKE_PROJECT_VERSION}
......
......@@ -139,7 +139,15 @@ function(compileInTarget to_target source_target)
target_sources(${to_target} PRIVATE ${complete_file})
set_source_files_properties(${complete_file} PROPERTES COMPILE_FLAGS ${DISABLE_WARNING_FLAG})
endforeach()
target_include_directories(${to_target} SYSTEM PRIVATE ${src_include})
if (MSVC AND (CMAKE_CXX_COMPILER_ID STREQUAL "Clang"))
foreach (dir ${src_include})
if (NOT (dir STREQUAL "$<INSTALL_INTERFACE:include>"))
target_compile_options(${to_target} PRIVATE "SHELL:/imsvc\ \"${dir}\"")
endif()
endforeach()
else()
target_include_directories(${to_target} SYSTEM PRIVATE ${src_include})
endif()
endfunction()
compileInTarget(openvds_objects fmt::fmt)
......@@ -162,10 +170,19 @@ endforeach()
target_include_directories(openvds_objects PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}")
target_include_directories(openvds_objects PRIVATE "VDS")
target_include_directories(openvds_objects SYSTEM PRIVATE ${include_3rdparty})
target_compile_definitions(openvds_objects PRIVATE openvds_EXPORTS)
target_compile_definitions(openvds_objects PRIVATE -DHUEBDS_EXPORTS= ) # We're not building HueBulkDataStore as a shared library
if (MSVC AND (CMAKE_CXX_COMPILER_ID STREQUAL "Clang"))
foreach (dir ${include_3rdparty})
if (NOT (dir STREQUAL "$<INSTALL_INTERFACE:include>"))
target_compile_options(openvds_objects PRIVATE "SHELL:/imsvc\ ${dir}")
endif()
endforeach()
else()
target_include_directories(openvds_objects SYSTEM PRIVATE ${include_3rdparty})
endif()
if (WIN32)
target_compile_definitions(openvds_objects PRIVATE _CRT_SECURE_NO_WARNINGS)
endif()
......
......@@ -22,6 +22,21 @@
#include <sstream>
#include <iomanip>
#ifdef WIN32
#ifdef __clang__
namespace google {
namespace cloud {
inline namespace GOOGLE_CLOUD_CPP_NS {
void Terminate(char const *)
{
abort();
}
}
}
}
#endif
#endif
namespace OpenVDS
{
static const std::string GOOGLEAPIS = "https://storage.googleapis.com";
......
......@@ -11,7 +11,7 @@ function(add_python_test scope test_file)
add_test(NAME "python.${scope}.${test_name}"
COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=$<TARGET_FILE_DIR:core>/..${separator}${CMAKE_CURRENT_BINARY_DIR}"
${PYTHON_EXECUTABLE} ${test_file}
${Python3_EXECUTABLE} ${test_file}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
endfunction()
......
function(setCompilerFlagsForTools target)
set_target_properties(${target} PROPERTIES FOLDER tools)
setWarningFlagsForTarget(${target})
copyDllForTarget(${target})
if (MSVC AND (CMAKE_CXX_COMPILER_ID STREQUAL "Clang"))
target_compile_options(${target} BEFORE PRIVATE "SHELL:/imsvc\ ${jsoncpp_SOURCE_DIR}/include")
endif()
if (${MSVC_TOOLSET_VERSION_LOCAL})
set(LIB_TOOLSET_DIR "/msvc_${MSVC_TOOLSET_VERSION_LOCAL}")
endif()
install(TARGETS ${target}
RUNTIME
DESTINATION ${CMAKE_INSTALL_BINDIR}${LIB_TOOLSET_DIR}
)
endfunction()
add_subdirectory(SEGYImport)
add_subdirectory(SEGYExport)
add_subdirectory(VDSInfo)
......@@ -3,16 +3,5 @@ add_executable(SEGYExport
)
target_link_libraries(SEGYExport PUBLIC Threads::Threads openvds segyutils jsoncpp_lib_static fmt::fmt)
set_target_properties(SEGYExport PROPERTIES FOLDER tools)
setWarningFlagsForTarget(SEGYExport)
copyDllForTarget(SEGYExport)
if (${MSVC_TOOLSET_VERSION_LOCAL})
set(LIB_TOOLSET_DIR "/msvc_${MSVC_TOOLSET_VERSION_LOCAL}")
endif()
install(TARGETS SEGYExport
RUNTIME
DESTINATION ${CMAKE_INSTALL_BINDIR}${LIB_TOOLSET_DIR}
)
setCompilerFlagsForTools(SEGYExport)
......@@ -3,16 +3,5 @@ add_executable(SEGYImport
)
target_link_libraries(SEGYImport PRIVATE Threads::Threads openvds segyutils jsoncpp_lib_static fmt::fmt)
set_target_properties(SEGYImport PROPERTIES FOLDER tools)
setWarningFlagsForTarget(SEGYImport)
copyDllForTarget(SEGYImport)
if (${MSVC_TOOLSET_VERSION_LOCAL})
set(LIB_TOOLSET_DIR "/msvc_${MSVC_TOOLSET_VERSION_LOCAL}")
endif()
install(TARGETS SEGYImport
RUNTIME
DESTINATION ${CMAKE_INSTALL_BINDIR}${LIB_TOOLSET_DIR}
)
setCompilerFlagsForTools(SEGYImport)
add_executable(VDSInfo VDSInfo.cpp Base64.cpp)
target_link_libraries(VDSInfo PUBLIC openvds fmt::fmt jsoncpp_lib_static)
set_target_properties(VDSInfo PROPERTIES FOLDER tools)
setWarningFlagsForTarget(VDSInfo)
copyDllForTarget(VDSInfo)
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX ${PROJECT_SOURCE_DIR}/Dist/OpenVDS CACHE STRING "" FORCE)
endif(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
if (${MSVC_TOOLSET_VERSION_LOCAL})
set(LIB_TOOLSET_DIR "/msvc_${MSVC_TOOLSET_VERSION_LOCAL}")
endif()
install(TARGETS VDSInfo
RUNTIME
DESTINATION ${CMAKE_INSTALL_BINDIR}${LIB_TOOLSET_DIR}
)
setCompilerFlagsForTools(VDSInfo)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment