Skip to content

Commit

Permalink
CMake support for PyIlmBase
Browse files Browse the repository at this point in the history
  • Loading branch information
ehanway-ilm committed Aug 8, 2014
1 parent 70b40cf commit a205b29
Show file tree
Hide file tree
Showing 8 changed files with 229 additions and 101 deletions.
77 changes: 77 additions & 0 deletions PyIlmBase/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)

PROJECT (pyilmbase)

SET(ILMBASE_VERSION_MAJOR "2")
SET(ILMBASE_VERSION_MINOR "2")
SET(ILMBASE_VERSION_PATCH "0")

SET(ILMBASE_VERSION ${ILMBASE_VERSION_MAJOR}.${ILMBASE_VERSION_MINOR}.${ILMBASE_VERSION_PATCH})
SET(ILMBASE_VERSION_API ${ILMBASE_VERSION_MAJOR}_${ILMBASE_VERSION_MINOR})


# enable the tests
ENABLE_TESTING()


# distro building
SET(CPACK_PACKAGE_VERSION_MAJOR "${ILMBASE_VERSION_MAJOR}")
SET(CPACK_PACKAGE_VERSION_MINOR "${ILMBASE_VERSION_MINOR}")
SET(CPACK_PACKAGE_VERSION_PATCH "${ILMBASE_VERSION_PATCH}")
SET(CPACK_SOURCE_GENERATOR "TGZ")
set(CPACK_SOURCE_PACKAGE_FILE_NAME
"${CMAKE_PROJECT_NAME}-${ILMBASE_VERSION}"
)
set(CPACK_SOURCE_IGNORE_FILES
"/.git*;/.cvs*;${CPACK_SOURCE_IGNORE_FILES}")
INCLUDE ( CPack )

# Set this option to find the C++ libs with their namespaced versions
# The python modules themselves are built without versioning
OPTION (NAMESPACE_VERSIONING "Use Namespace Versioning" ON)

# Setup osx rpathing
SET (CMAKE_MACOSX_RPATH 1)
SET (BUILD_WITH_INSTALL_RPATH 1)

SET (LIB_TYPE SHARED)

FIND_PACKAGE ( PythonLibs REQUIRED )
FIND_PACKAGE ( PythonInterp REQUIRED )
FIND_PACKAGE ( Boost
COMPONENTS Python
)
FIND_PACKAGE ( NumPy )

INCLUDE_DIRECTORIES (
${ILMBASE_PACKAGE_PREFIX}/include/OpenEXR
PyIex
PyImath
PyImathNumpy
${PYTHON_INCLUDE_PATH}
)

LINK_DIRECTORIES ( ${ILMBASE_PACKAGE_PREFIX}/lib )
MESSAGE ( "ILMBASE_PACKAGE_PREFIX = " ${ILMBASE_PACKAGE_PREFIX})


SET (ILMBASE_LIBSUFFIX "")
IF (NAMESPACE_VERSIONING)
SET ( ILMBASE_LIBSUFFIX "-${ILMBASE_VERSION_API}" )
ENDIF ()

##########################
ADD_SUBDIRECTORY ( PyIex )
ADD_SUBDIRECTORY ( PyImath )

IF (NUMPY_FOUND)
ADD_SUBDIRECTORY ( PyImathNumpy )
ADD_SUBDIRECTORY ( PyImathNumpyTest )
ENDIF ()

##########################
# Tests
##########################
ADD_SUBDIRECTORY ( PyIexTest )
ADD_SUBDIRECTORY ( PyImathTest )

32 changes: 32 additions & 0 deletions PyIlmBase/PyIex/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

ADD_LIBRARY ( PyIex ${LIB_TYPE}
PyIex.cpp
)

TARGET_LINK_LIBRARIES ( PyIex
${PYTHON_LIBRARIES}
)

INSTALL ( TARGETS PyIex
DESTINATION
lib
)

ADD_LIBRARY ( iexmodule ${LIB_TYPE}
iexmodule.cpp
)

SET_TARGET_PROPERTIES ( iexmodule
PROPERTIES PREFIX "" SUFFIX ".so" BUILD_WITH_INSTALL_RPATH ON
)

TARGET_LINK_LIBRARIES ( iexmodule
PyIex
Iex${ILMBASE_LIBSUFFIX}
${Boost_LIBRARIES}
)

INSTALL ( TARGETS iexmodule
DESTINATION lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages
)

3 changes: 3 additions & 0 deletions PyIlmBase/PyIexTest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ADD_TEST ( PyIexTest
${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/pyIexTest.in
)
70 changes: 70 additions & 0 deletions PyIlmBase/PyImath/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@

ADD_LIBRARY ( PyImath ${LIB_TYPE}
PyImath.cpp
PyImathAutovectorize.cpp
PyImathBox2Array.cpp
PyImathBox3Array.cpp
PyImathBox.cpp
PyImathColor3.cpp
PyImathColor4.cpp
PyImathEuler.cpp
PyImathFixedArray.cpp
PyImathFrustum.cpp
PyImathLine.cpp
PyImathMatrix33.cpp
PyImathMatrix44.cpp
PyImathPlane.cpp
PyImathQuat.cpp
PyImathRandom.cpp
PyImathShear.cpp
PyImathStringArray.cpp
PyImathStringTable.cpp
PyImathTask.cpp
PyImathUtil.cpp
PyImathFixedVArray.cpp
PyImathVec2fd.cpp
PyImathVec2si.cpp
PyImathVec3fd.cpp
PyImathVec3siArray.cpp
PyImathVec3si.cpp
PyImathVec4fd.cpp
PyImathVec4siArray.cpp
PyImathVec4si.cpp

)

TARGET_LINK_LIBRARIES ( PyImath
Iex${ILMBASE_LIBSUFFIX}
IexMath${ILMBASE_LIBSUFFIX}
Imath${ILMBASE_LIBSUFFIX}
${Boost_LIBRARIES}
${PYTHON_LIBRARIES}
)

INSTALL ( TARGETS PyImath
DESTINATION
lib
)

ADD_LIBRARY ( imathmodule ${LIB_TYPE}
imathmodule.cpp
PyImathFun.cpp
PyImathBasicTypes.cpp
)

SET_TARGET_PROPERTIES ( imathmodule
PROPERTIES PREFIX "" SUFFIX ".so" BUILD_WITH_INSTALL_RPATH ON
)

TARGET_LINK_LIBRARIES ( imathmodule
PyImath
PyIex
Imath${ILMBASE_LIBSUFFIX}
Iex${ILMBASE_LIBSUFFIX}
${Boost_LIBRARIES}
)

INSTALL ( TARGETS imathmodule
DESTINATION lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages
)

25 changes: 25 additions & 0 deletions PyIlmBase/PyImathNumpy/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

ADD_LIBRARY ( imathnumpymodule ${LIB_TYPE}
imathnumpymodule.cpp
)

SET_TARGET_PROPERTIES ( imathnumpymodule
PROPERTIES PREFIX "" SUFFIX ".so" BUILD_WITH_INSTALL_RPATH ON
)

INCLUDE_DIRECTORIES (
${NUMPY_INCLUDE_DIRS}
)

TARGET_LINK_LIBRARIES ( imathnumpymodule
PyImath
PyIex
Imath${ILMBASE_LIBSUFFIX}
Iex${ILMBASE_LIBSUFFIX}
${Boost_LIBRARIES}
)

INSTALL ( TARGETS imathnumpymodule
DESTINATION lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages
)

3 changes: 3 additions & 0 deletions PyIlmBase/PyImathNumpyTest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ADD_TEST ( PyImathMumpyTest
${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/pyImathMumpyTest.in
)
3 changes: 3 additions & 0 deletions PyIlmBase/PyImathTest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ADD_TEST ( PyImathTest
${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/pyImathTest.in
)
117 changes: 16 additions & 101 deletions PyIlmBase/PyImathTest/pyImathTest.in
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,21 @@ def numNonZeroMaskEntries(mask):
def equalWithAbsErrorScalar(x1, x2, e):
return abs(x1 - x2) < e

def make_range(start, end):
num = end-start
increment = 1
if num < 0:
num = -num;
increment = -1

retval = IntArray(num)
val = start
for i in range(0, num):
retval[i] = val
val += increment

return retval

# We want to be able to use the test helper
# functions generically with different array types
# so we use hasattr to check if the arguments support
Expand Down Expand Up @@ -7809,106 +7824,6 @@ def testFrustum ():
testList.append (('testFrustum',testFrustum))


# -------------------------------------------------------------------------
# Tests for Perlin noise

def testNoise ():

eps = 40 * FLT_EPS

assert equal(noiseCen(0.0), 0, eps)
assert equal(noiseCen(0.1), 0.110369916, eps)
assert equal(noiseCen(0.2), 0.210070048, eps)

assert equal(noiseCen((0.0, 0.0)), 0, eps)
assert equal(noiseCen((0.1, 0.1)), -0.150489230832, eps)
assert equal(noiseCen((0.2, 0.2)), -0.219769121024, eps)

assert equal(noiseCen((0.0, 0.0, 0.0)), 0, eps)
assert equal(noiseCen((0.1, 0.1, 0.1)), -0.150404556446, eps)
assert equal(noiseCen((0.2, 0.2, 0.2)), -0.259250157847, eps)

assert equal(noise(0.0), 0.5, eps)
assert equal(noise(0.1), 0.555184958, eps)
assert equal(noise(0.2), 0.605035024, eps)

assert equal(noise((0.0, 0.0)), 0.5, eps)
assert equal(noise((0.1, 0.1)), 0.424755384584, eps)
assert equal(noise((0.2, 0.2)), 0.390115439488, eps)

assert equal(noise((0.0, 0.0, 0.0)), 0.5, eps)
assert equal(noise((0.1, 0.1, 0.1)), 0.424797721777, eps)
assert equal(noise((0.2, 0.2, 0.2)), 0.370374921076, eps)

(n, g) = noiseCenGrad(0.0)
assert equal(n, 0.0, eps) and equal(g, 1.088993, eps)
(n, g) = noiseCenGrad(0.1)
assert equal(n, 0.110369916, eps) and equal(g, 1.08184108, eps)
(n, g) = noiseCenGrad(0.2)
assert equal(n, 0.210070048, eps) and equal(g, 0.88574412, eps)

(n, g) = noiseCenGrad((0.0, 0.0))
assert equal(n, 0.0, eps) and \
g.equalWithAbsError((-0.828791, -0.9116), eps)

(n, g) = noiseCenGrad((0.1, 0.1))
assert equal(n, -0.150489230832, eps) and \
g.equalWithAbsError((-0.923214, -0.24764), eps)

(n, g) = noiseCenGrad((0.2, 0.2))
assert equal(n, -0.219769121024, eps) and \
g.equalWithAbsError((-0.574699, 0.399376), eps)

(n, g) = noiseCenGrad((0.0, 0.0, 0.0))
assert equal(n, 0.0, eps) and \
g.equalWithAbsError((-0.478393, -1.17491, 0.063697), eps)

(n, g) = noiseCenGrad((0.1, 0.1, 0.1))
assert equal(n, -0.150404556446, eps) and \
g.equalWithAbsError((-0.493882, -1.53089, 0.700577), eps)

(n, g) = noiseCenGrad((0.2, 0.2, 0.2))
assert equal(n, -0.259250157847, eps) and \
g.equalWithAbsError((-0.359504, -1.49074, 0.975563), eps)

(n, g) = noiseGrad(0.0)
assert equal(n, 0.5, eps) and equal(g, 0.5444965, eps)
(n, g) = noiseGrad(0.1)
assert equal(n, 0.555184958, eps) and equal(g, 0.54092054, eps)
(n, g) = noiseGrad(0.2)
assert equal(n, 0.605035024, eps) and equal(g, 0.44287206, eps)

(n, g) = noiseGrad((0.0, 0.0))
assert equal(n, 0.5, eps) and \
g.equalWithAbsError((-0.414396, -0.4558), eps)

(n, g) = noiseGrad((0.1, 0.1))
assert equal(n, 0.424755384584, eps) and \
g.equalWithAbsError((-0.461607, -0.12382), eps)

(n, g) = noiseGrad((0.2, 0.2))
assert equal(n, 0.390115439488, eps) and \
g.equalWithAbsError((-0.287349, 0.199688), eps)

(n, g) = noiseGrad((0.0, 0.0, 0.0))
assert equal(n, 0.5, eps) and \
g.equalWithAbsError((-0.239197, -0.587455, 0.0318485), eps)

(n, g) = noiseGrad((0.1, 0.1, 0.1))
assert equal(n, 0.424797721777, eps) and \
g.equalWithAbsError((-0.246941, -0.765447, 0.350289), eps)

(n, g) = noiseGrad((0.2, 0.2, 0.2))
assert equal(n, 0.370374921076, eps) and \
g.equalWithAbsError((-0.179752, -0.745372, 0.487781), eps)

print "ok"

return

testList.append (('testNoise',testNoise))


# -------------------------------------------------------------------------
# Tests for random number generators

Expand Down Expand Up @@ -8109,7 +8024,7 @@ def testFpExceptions():
# Platform/PlatformFpu.cpp and note the non-implementation of
# setFpExceptions().
#
if sys.platform != 'win32':
if sys.platform != 'win32' and sys.platform != 'darwin':
try:
v = V3d (1e200, 1e200, 1e200)
v = v * v * v
Expand Down

0 comments on commit a205b29

Please sign in to comment.