Python: now statically linking (i.e. recompiling everything) for better portability.

This commit is contained in:
Philippe Tillet
2015-05-03 02:14:02 -04:00
parent 25242bc19d
commit 29bfff69e9
7 changed files with 38 additions and 34 deletions

View File

@@ -21,6 +21,8 @@ ADD_DEFINITIONS(-Wno-sign-compare -D__CL_ENABLE_EXCEPTIONS ${BACKEND_DEFINES} -W
ADD_EXECUTABLE(bin2cpp ${CMAKE_MODULE_PATH}/bin2cpp.cpp) ADD_EXECUTABLE(bin2cpp ${CMAKE_MODULE_PATH}/bin2cpp.cpp)
include(CTest) include(CTest)
file(GLOB_RECURSE LIBISAAC_SRC lib/*.cpp)
add_subdirectory(lib) add_subdirectory(lib)
add_subdirectory(tests) add_subdirectory(tests)
add_subdirectory(bench) add_subdirectory(bench)

View File

@@ -1,14 +1,11 @@
if(ANDROID) if(ANDROID)
file(GLOB ADRENO_SDK_ROOT /opt/adreno-sdk*) file(GLOB ADRENO_DRIVER_ROOT /opt/adreno-driver*)
set(L_HINTS ${ADRENO_SDK_ROOT}/driver/lib/) set(L_HINTS ${ADRENO_DRIVER_ROOT}/lib/)
else() else()
file(GLOB AMDAPPSDK_ROOT /opt/AMDAPPSDK*) file(GLOB AMDAPPSDK_ROOT /opt/AMDAPPSDK*)
set(L_HINTS ${AMDAPPSDK_ROOT}/lib/x86_64/ ${CUDA_TOOLKIT_ROOT_DIR}/targets/x86_64-linux/lib/) set(L_HINTS ${AMDAPPSDK_ROOT}/lib/x86_64/ ${CUDA_TOOLKIT_ROOT_DIR}/targets/x86_64-linux/lib/)
endif() endif()
find_library(OPENCL_LIBRARIES NAMES OpenCL NO_CMAKE_FIND_ROOT_PATH HINTS ${L_HINTS} ) find_library(OPENCL_LIBRARIES NAMES OpenCL NO_CMAKE_FIND_ROOT_PATH HINTS ${L_HINTS} )
message(STATUS ${OPENCL_LIBRARIES})
include(FindPackageHandleStandardArgs) include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(OpenCL DEFAULT_MSG OPENCL_LIBRARIES) find_package_handle_standard_args(OpenCL DEFAULT_MSG OPENCL_LIBRARIES)
mark_as_advanced(OpenCL) mark_as_advanced(OpenCL)

View File

@@ -1,9 +1,3 @@
set(CMAKE_BUILD_TYPE RELEASE)
set(CMAKE_CXX_FLAGS_RELEASE "-O2")
file( GLOB_RECURSE LIBISAAC_SRC *.cpp)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
if(ANDROID) if(ANDROID)
add_library(isaac STATIC ${LIBISAAC_SRC}) add_library(isaac STATIC ${LIBISAAC_SRC})
else() else()

View File

@@ -2,16 +2,26 @@ file( GLOB_RECURSE PYTHON_SRC *.cpp)
file( GLOB_RECURSE PYTHON_PYSRC *.py) file( GLOB_RECURSE PYTHON_PYSRC *.py)
add_custom_target( MAKE_PYTHON_SRC_VISIBLE SOURCES ${PYTHON_SRC} ${PYTHON_PYSRC}) add_custom_target( MAKE_PYTHON_SRC_VISIBLE SOURCES ${PYTHON_SRC} ${PYTHON_PYSRC})
set(SETUP_PY_IN "${CMAKE_CURRENT_SOURCE_DIR}/setup.py") set(SETUP_PY_IN "${CMAKE_CURRENT_SOURCE_DIR}/external/cmake/setup.py")
set(SETUP_PY "${CMAKE_CURRENT_BINARY_DIR}/setup.py") set(SETUP_PY "${CMAKE_CURRENT_SOURCE_DIR}/setup.py")
set(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/build") set(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/build")
function(JOIN VALUES GLUE OUTPUT)
string (REGEX REPLACE "([^\\]|^);" "\\1${GLUE}" _TMP_STR "${VALUES}")
string (REGEX REPLACE "[\\](.)" "\\1" _TMP_STR "${_TMP_STR}") #fixes escaping
set (${OUTPUT} "${_TMP_STR}" PARENT_SCOPE)
endfunction()
join("${LIBISAAC_SRC}" " " LIBISAAC_SRC_STR)
get_property(INCLUDE_DIRECTORIES_LST DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
join("${INCLUDE_DIRECTORIES_LST}" " " INCLUDE_DIRECTORIES_STR)
configure_file(${SETUP_PY_IN} ${SETUP_PY}) configure_file(${SETUP_PY_IN} ${SETUP_PY})
add_custom_command(OUTPUT ${OUTPUT}/timestamp add_custom_command(OUTPUT ${OUTPUT}/timestamp
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/isaac ${CMAKE_CURRENT_BINARY_DIR}/isaac COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/isaac ${CMAKE_CURRENT_BINARY_DIR}/isaac
COMMAND ${PYTHON} ${CMAKE_CURRENT_BINARY_DIR}/setup.py build COMMAND ${PYTHON} ${CMAKE_CURRENT_SOURCE_DIR}/setup.py build
COMMAND ${CMAKE_COMMAND} -E touch ${OUTPUT}/timestamp COMMAND ${CMAKE_COMMAND} -E touch ${OUTPUT}/timestamp
DEPENDS isaac ${PYTHON_SRC} ${PYTHON_PYSRC} ${SETUP_PY}) DEPENDS ${LIBISAAC_SRC} ${PYTHON_SRC} ${PYTHON_PYSRC} ${SETUP_PY})
add_custom_target(python ALL DEPENDS ${OUTPUT}/timestamp) add_custom_target(python DEPENDS ${OUTPUT}/timestamp)
install(CODE "execute_process(WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND ${PYTHON} ${SETUP_PY} install)" OPTIONAL)
install(CODE "execute_process(WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND ${PYTHON} ${SETUP_PY} install)")

View File

@@ -1,3 +1,6 @@
#Thanks to Andreas Knoeckler for providing stand-alone boost.python
#through PyOpenCL and PyCUDA
import os, sys import os, sys
from distutils.command.build_ext import build_ext from distutils.command.build_ext import build_ext
from distutils.command.build_py import build_py from distutils.command.build_py import build_py
@@ -12,9 +15,6 @@ platform_ldflags = {}
platform_libs = {} platform_libs = {}
class build_ext_subclass(build_ext): class build_ext_subclass(build_ext):
"""Shamelessly stolen from
https://stackoverflow.com/questions/724664
"""
def build_extensions(self): def build_extensions(self):
c = self.compiler.compiler_type c = self.compiler.compiler_type
if c in platform_cflags.keys(): if c in platform_cflags.keys():
@@ -46,20 +46,22 @@ def main():
break break
return optlist return optlist
#Compiler options
cvars = sysconfig.get_config_vars() cvars = sysconfig.get_config_vars()
cvars['OPT'] = "-DNDEBUG -O3 -std=c++11 ${BACKEND_DEFINES}" + str.join(' ', remove_prefixes(cvars['OPT'].split(), ['-g', '-O', '-Wstrict-prototypes', '-DNDEBUG'])) cvars['BASECFLAGS'] = "-D__CL_ENABLE_EXCEPTIONS -fPIC -Wno-sign-compare -Wall -Wextra -pedantic -Wno-ignored-qualifiers -std=c++11 "
cvars['OPT'] = str.join(' ', remove_prefixes(cvars['OPT'].split(), ['-g', '-Wstrict-prototypes']))
cvars["CFLAGS"] = cvars["BASECFLAGS"] + " " + cvars["OPT"] cvars["CFLAGS"] = cvars["BASECFLAGS"] + " " + cvars["OPT"]
cvars["LDFLAGS"] = '-Wl,--no-as-needed ' + cvars["LDFLAGS"] cvars["LDFLAGS"] = '-Wl,--no-as-needed ' + cvars["LDFLAGS"]
DEFINES = [] #Includes
INCLUDE_DIRS = ['${CMAKE_CURRENT_SOURCE_DIR}/external/boost/include', include ='${INCLUDE_DIRECTORIES_STR}'.split() +\
os.path.join(find_module("numpy")[1], "core", "include"), ['${CMAKE_CURRENT_SOURCE_DIR}/external/boost/include',
'${PROJECT_SOURCE_DIR}/include', os.path.join(find_module("numpy")[1], "core", "include")]
'${CUDA_INCLUDE_DIRS}']
LIBRARY_DIRS = ['${CMAKE_BINARY_DIR}/lib']
src = [os.path.join('${CMAKE_CURRENT_SOURCE_DIR}', 'src', sf) for sf in ['_isaac.cpp', 'core.cpp', 'driver.cpp', 'model.cpp', 'exceptions.cpp']]
#Sources
src = '${LIBISAAC_SRC_STR}'.split() +\
[os.path.join('${CMAKE_CURRENT_SOURCE_DIR}', 'src', sf) \
for sf in ['_isaac.cpp', 'core.cpp', 'driver.cpp', 'model.cpp', 'exceptions.cpp']]
boostsrc = '${CMAKE_CURRENT_SOURCE_DIR}/external/boost/libs/' boostsrc = '${CMAKE_CURRENT_SOURCE_DIR}/external/boost/libs/'
for s in ['numpy','python','smart_ptr','system','thread']: for s in ['numpy','python','smart_ptr','system','thread']:
src = src + [x for x in recursive_glob('${CMAKE_CURRENT_SOURCE_DIR}/external/boost/libs/' + s + '/src/','.cpp') if 'win32' not in x and 'pthread' not in x] src = src + [x for x in recursive_glob('${CMAKE_CURRENT_SOURCE_DIR}/external/boost/libs/' + s + '/src/','.cpp') if 'win32' not in x and 'pthread' not in x]
@@ -87,10 +89,8 @@ def main():
'_isaac',src, '_isaac',src,
extra_compile_args= ['-Wno-unused-function', '-Wno-unused-local-typedefs'], extra_compile_args= ['-Wno-unused-function', '-Wno-unused-local-typedefs'],
extra_link_args=['-Wl,-soname=_isaac.so'], extra_link_args=['-Wl,-soname=_isaac.so'],
define_macros=DEFINES,
undef_macros=[], undef_macros=[],
include_dirs=INCLUDE_DIRS, include_dirs=include,
library_dirs=LIBRARY_DIRS,
libraries=['OpenCL', 'isaac'] libraries=['OpenCL', 'isaac']
)], )],
cmdclass={'build_py': build_py, 'build_ext': build_ext_subclass}, cmdclass={'build_py': build_py, 'build_ext': build_ext_subclass},

View File

@@ -12,3 +12,4 @@ void android_main(struct android_app* state)
__android_log_print(ANDROID_LOG_INFO, "IsaacAndroidTest", isaac::tools::to_string(test).c_str()); __android_log_print(ANDROID_LOG_INFO, "IsaacAndroidTest", isaac::tools::to_string(test).c_str());
ANativeActivity_finish(state->activity); ANativeActivity_finish(state->activity);
} }