Commit d42c4b08 authored by Matt Pharr's avatar Matt Pharr

Rewrite much of CMakeLists.txt

Be better about detecting the compiler's/system's capabilities rather than
have a bunch of hard-coded "if this is FreeBSD, then <memory.h> is
available" sort of stuff. (Similarly for detecting C++11 features.)
Similarly, in code, the #defines to be checked are based on language
features, not compilers or compiler versions.

This should improve portability overall.

Along the way, got rid of port.h, which is basically unneeded now.
parent 62e79cb8
This diff is collapsed.
......@@ -387,12 +387,7 @@ uint32_t CMaxMinDist[17][32] = {
// Low Discrepancy Static Functions
template <int base>
#if defined(PBRT_IS_MSVC)
__declspec(noinline)
#else
__attribute__ ((noinline))
#endif
static Float RadicalInverseSpecialized(uint64_t a) {
PBRT_NOINLINE static Float RadicalInverseSpecialized(uint64_t a) {
const Float invBase = (Float)1 / (Float)base;
uint64_t reversedDigits = 0;
Float invBaseN = 1;
......@@ -408,12 +403,7 @@ static Float RadicalInverseSpecialized(uint64_t a) {
}
template <int base>
#if defined(PBRT_IS_MSVC)
__declspec(noinline)
#else
__attribute__((noinline))
#endif
static Float
PBRT_NOINLINE static Float
ScrambledRadicalInverseSpecialized(const uint16_t *perm, uint64_t a) {
const Float invBase = (Float)1 / (Float)base;
uint64_t reversedDigits = 0;
......
......@@ -38,9 +38,9 @@ namespace pbrt {
// Memory Allocation Functions
void *AllocAligned(size_t size) {
#if defined(PBRT_IS_WINDOWS)
#if defined(PBRT_HAVE__ALIGNED_MALLOC)
return _aligned_malloc(size, PBRT_L1_CACHE_LINE_SIZE);
#elif defined(PBRT_IS_OPENBSD) || defined(PBRT_IS_OSX) || defined(PBRT_IS_FREEBSD)
#elif defined(PBRT_HAVE_POSIX_MEMALIGN)
void *ptr;
if (posix_memalign(&ptr, PBRT_L1_CACHE_LINE_SIZE, size) != 0) ptr = nullptr;
return ptr;
......@@ -51,7 +51,7 @@ void *AllocAligned(size_t size) {
void FreeAligned(void *ptr) {
if (!ptr) return;
#if defined(PBRT_IS_WINDOWS)
#if defined(PBRT_HAVE__ALIGNED_MALLOC)
_aligned_free(ptr);
#else
free(ptr);
......
......@@ -40,7 +40,6 @@
// core/memory.h*
#include "pbrt.h"
#include "port.h"
#include <list>
#include <cstddef>
......@@ -78,7 +77,7 @@ alignas(PBRT_L1_CACHE_LINE_SIZE)
#else
const int align = alignof(std::max_align_t);
#endif
#ifndef PBRT_IS_MSVC2013
#ifdef PBRT_HAVE_CONSTEXPR
static_assert(IsPowerOf2(align), "Minimum alignment not a power of two");
#endif
nBytes = (nBytes + align - 1) & ~(align - 1);
......
......@@ -39,8 +39,6 @@
#define PBRT_CORE_PBRT_H
// core/pbrt.h*
#include "port.h"
// Global Include Files
#include <type_traits>
#include <algorithm>
......@@ -63,6 +61,21 @@
#include <glog/logging.h>
// Platform-specific definitions
#if defined(_WIN32) || defined(_WIN64)
#define PBRT_IS_WINDOWS
#endif
#if defined(_MSC_VER)
#define PBRT_IS_MSVC
#if _MSC_VER == 1800
#define snprintf _snprintf
#endif
#endif
#ifndef PBRT_L1_CACHE_LINE_SIZE
#define PBRT_L1_CACHE_LINE_SIZE 64
#endif
#include <stdint.h>
#if defined(PBRT_IS_MSVC)
#include <float.h>
......
/*
pbrt source code is Copyright(c) 1998-2016
Matt Pharr, Greg Humphreys, and Wenzel Jakob.
This file is part of pbrt.
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.
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.
*/
#if defined(_MSC_VER)
#define NOMINMAX
#pragma once
#endif
#ifndef PBRT_CORE_PORT_H
#define PBRT_CORE_PORT_H
#if defined(_WIN32) || defined(_WIN64)
#define PBRT_IS_WINDOWS
#if defined(__MINGW32__) // Defined for both 32 bit/64 bit MinGW
#define PBRT_IS_MINGW
#elif defined(_MSC_VER)
#define PBRT_IS_MSVC
#endif
#elif defined(__linux__)
#define PBRT_IS_LINUX
#elif defined(__APPLE__)
#define PBRT_IS_OSX
#elif defined(__OpenBSD__)
#define PBRT_IS_OPENBSD
#elif defined(__FreeBSD__)
#define PBRT_IS_FREEBSD
#endif
#if defined(_MSC_VER) && _MSC_VER == 1900
#define PBRT_IS_MSVC2015
#endif
#if defined(_MSC_VER) && _MSC_VER == 1800
#define PBRT_IS_MSVC2013
#endif
///////////////////////////////////////////////////////////////////////////
// Now, use what we've figured out to do #defines for features and to do
// various target-specific workarounds.
#if !defined(PBRT_IS_MSVC)
#define PBRT_HAVE_HEX_FP_CONSTANTS
#define PBRT_HAVE_BINARY_CONSTANTS
#endif
#if defined(PBRT_IS_LINUX) || defined(PBRT_IS_WINDOWS)
#define PBRT_HAVE_MALLOC_H
#endif
#ifdef PBRT_IS_LINUX
#define PBRT_HAVE_ALLOCA_H
#endif
#if defined(PBRT_IS_MSVC)
#define PBRT_THREAD_LOCAL __declspec(thread)
#else
#define PBRT_THREAD_LOCAL __thread
#endif
#ifdef PBRT_IS_MSVC2013
#define PBRT_CONSTEXPR const
#else
#define PBRT_CONSTEXPR constexpr
#endif
#if !defined(PBRT_IS_MSVC2013)
#define PBRT_HAVE_ALIGNAS
#define PBRT_HAVE_ALIGNOF
#endif
#ifdef PBRT_IS_MSVC2013
#define snprintf _snprintf
#endif
#ifndef PBRT_L1_CACHE_LINE_SIZE
#define PBRT_L1_CACHE_LINE_SIZE 64
#endif
#if defined(PBRT_IS_MSVC)
#define PBRT_FORCEINLINE __forceinline
#else
#define PBRT_FORCEINLINE __attribute__((always_inline)) inline
#endif
// Is setitimer() available (and working)?
#if !defined(PBRT_IS_WINDOWS) && !defined(__CYGWIN__)
#define PBRT_HAVE_ITIMER
#endif
#endif // PBRT_CORE_PORT_H
......@@ -291,8 +291,7 @@ void CleanupProfiler();
} \
static StatRegisterer STATS_REG##var(STATS_FUNC##var)
// Work around lack of support for constexpr in VS2013.
#ifdef PBRT_IS_MSVC2013
#ifndef PBRT_HAVE_CONSTEXPR
#define STATS_INT64_T_MIN LLONG_MAX
#define STATS_INT64_T_MAX _I64_MIN
#define STATS_DBL_T_MIN DBL_MAX
......
......@@ -156,11 +156,11 @@ struct Vertex {
// Vertex Public Data
VertexType type;
Spectrum beta;
#ifdef PBRT_IS_MSVC2013
struct {
#else
#ifdef PBRT_HAVE_NONPOD_IN_UNIONS
union {
#endif // PBRT_IS_MSVC2013
#else
struct {
#endif // PBRT_HAVE_NONPOD_IN_UNIONS
EndpointInteraction ei;
MediumInteraction mi;
SurfaceInteraction si;
......
......@@ -73,7 +73,7 @@ TEST(Spectrum, LinearUpsampleSubset) {
for (int i = 0; i < 3; ++i) EXPECT_EQ(val[i + 1], newVal[i]);
}
#ifndef PBRT_IS_MSVC2013
#if !defined(PBRT_IS_MSVC) || _MSC_VER > 1800
// FIXME: the i=0 case fails with MSVC 2013; it returns 1.125 instead of 1.
// Should chase this down to figure out if it's an edge-case in our
// implementation that happens to work out for other compilers but is
......
Markdown is supported
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