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

cmake python config bugs fixed #1131

Merged
merged 3 commits into from
May 23, 2017
Merged
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
46 changes: 30 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 2.4.3)
set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)

cmake_policy(SET CMP0017 NEW)
#this line has to appear before 'PROJECT' in order to be able to disable incremental linking
SET(MSVC_INCREMENTAL_DEFAULT ON)

Expand All @@ -27,7 +27,7 @@ SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG")
OPTION(USE_DOUBLE_PRECISION "Use double precision" OFF)
OPTION(USE_GRAPHICAL_BENCHMARK "Use Graphical Benchmark" ON)
OPTION(BUILD_SHARED_LIBS "Use shared libraries" OFF)
OPTION(USE_SOFT_BODY_MULTI_BODY_DYNAMICS_WORLD "Use btSoftMultiBodyDynamicsWorld" OFF)
OPTION(USE_SOFT_BODY_MULTI_BODY_DYNAMICS_WORLD "Use btSoftMultiBodyDynamicsWorld" OFF)
OPTION(BULLET2_USE_THREAD_LOCKS "Build Bullet 2 libraries with mutex locking around certain operations" OFF)

OPTION(USE_MSVC_INCREMENTAL_LINKING "Use MSVC Incremental Linking" OFF)
Expand Down Expand Up @@ -123,22 +123,22 @@ IF(MSVC)

OPTION(USE_MSVC_EXEPTIONS "Use MSVC C++ exceptions option" OFF)



OPTION(USE_MSVC_COMDAT_FOLDING "Use MSVC /OPT:ICF COMDAT folding option" ON)

IF(USE_MSVC_COMDAT_FOLDING)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /OPT:ICF")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /OPT:ICF")
ENDIF()

OPTION(USE_MSVC_DISABLE_RTTI "Use MSVC /GR- disabled RTTI flags option" ON)
IF(USE_MSVC_DISABLE_RTTI)
STRING(REGEX REPLACE "/GR" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) # Disable RTTI
SET(CMAKE_C_FLAGS "/GR- ${CMAKE_C_FLAGS}")
SET(CMAKE_CXX_FLAGS "/GR- ${CMAKE_CXX_FLAGS}")
ENDIF(USE_MSVC_DISABLE_RTTI)

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4244 /wd4267")
ENDIF(MSVC)

Expand Down Expand Up @@ -254,24 +254,39 @@ ENDIF()

OPTION(BUILD_BULLET3 "Set when you want to build Bullet 3" ON)

OPTION(BUILD_PYBULLET "Set when you want to build pybullet (Python bindings for Bullet)" OFF)

# Optional Python configuration
# builds pybullet automatically if all the requirements are met
SET(PYTHON_VERSION_PYBULLET "2.7" CACHE STRING "Python version pybullet will use.")
SET(Python_ADDITIONAL_VERSIONS 2.7 2.7.3 3 3.0 3.1 3.2 3.3 3.4 3.5 3.6)
SET_PROPERTY(CACHE PYTHON_VERSION_PYBULLET PROPERTY STRINGS ${Python_ADDITIONAL_VERSIONS})
SET(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/build3/cmake ${CMAKE_MODULE_PATH})
OPTION(EXACT_PYTHON_VERSION "Require Python and match PYTHON_VERSION_PYBULLET exactly, e.g. 2.7.3" OFF)
IF(EXACT_PYTHON_VERSION)
set(EXACT_PYTHON_VERSION_FLAG EXACT REQUIRED)
ENDIF(EXACT_PYTHON_VERSION)
# first find the python interpreter
FIND_PACKAGE(PythonInterp ${PYTHON_VERSION_PYBULLET} ${EXACT_PYTHON_VERSION_FLAG})
# python library should exactly match that of the interpreter
FIND_PACKAGE(PythonLibs ${PYTHON_VERSION_STRING} EXACT)
SET(DEFAULT_BUILD_PYBULLET OFF)
IF(PYTHONLIBS_FOUND)
SET(DEFAULT_BUILD_PYBULLET ON)
ENDIF(PYTHONLIBS_FOUND)
OPTION(BUILD_PYBULLET "Set when you want to build pybullet (Python bindings for Bullet)" ${DEFAULT_BUILD_PYBULLET})

OPTION(BUILD_ENET "Set when you want to build apps with enet UDP networking support" ON)
OPTION(BUILD_CLSOCKET "Set when you want to build apps with enet TCP networking support" ON)


IF(BUILD_PYBULLET)

FIND_PACKAGE(PythonLibs)
IF(BUILD_PYBULLET)

OPTION(BUILD_PYBULLET_NUMPY "Set when you want to build pybullet with NumPy support" OFF)
OPTION(BUILD_PYBULLET_NUMPY "Set when you want to build pybullet with NumPy support" ON)
OPTION(BUILD_PYBULLET_ENET "Set when you want to build pybullet with enet UDP networking support" ON)
OPTION(BUILD_PYBULLET_CLSOCKET "Set when you want to build pybullet with enet TCP networking support" ON)

OPTION(BUILD_PYBULLET_MAC_USE_PYTHON_FRAMEWORK "Set when you want to use the Python Framework on Mac" ON)
OPTION(BUILD_PYBULLET_MAC_USE_PYTHON_FRAMEWORK "Set when you want to use the Python Framework on Mac" OFF)

IF(BUILD_PYBULLET_NUMPY)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_LIST_DIR}/build3/cmake)
IF(BUILD_PYBULLET_NUMPY)
#include(FindNumPy)
FIND_PACKAGE(NumPy)
if (PYTHON_NUMPY_FOUND)
Expand All @@ -281,7 +296,6 @@ IF(BUILD_PYBULLET)
message("NumPy not found")
endif()
ENDIF()
OPTION(BUILD_PYBULLET "Set when you want to build pybullet (experimental Python bindings for Bullet)" OFF)

IF(WIN32)
SET(BUILD_SHARED_LIBS OFF CACHE BOOL "Shared Libs" FORCE)
Expand Down
25 changes: 25 additions & 0 deletions build3/cmake/FindLibPython.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Note by Nikolaus Demmel 28.03.2014: My contributions are licensend under the
# same as CMake (BSD). My adaptations are in part based
# https://github.com/qgis/QGIS/tree/master/cmake which has the following
# copyright note:

# FindLibPython.py
# Copyright (c) 2007, Simon Edwards <simon@simonzone.com>
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.

import sys
import distutils.sysconfig

print("exec_prefix:%s" % sys.exec_prefix)
print("major_version:%s" % str(sys.version_info[0]))
print("minor_version:%s" % str(sys.version_info[1]))
print("patch_version:%s" % str(sys.version_info[2]))
print("short_version:%s" % '.'.join(map(lambda x:str(x), sys.version_info[0:2])))
print("long_version:%s" % '.'.join(map(lambda x:str(x), sys.version_info[0:3])))
print("py_inc_dir:%s" % distutils.sysconfig.get_python_inc())
print("site_packages_dir:%s" % distutils.sysconfig.get_python_lib(plat_specific=1))
for e in distutils.sysconfig.get_config_vars ('LIBDIR'):
if e != None:
print("py_lib_dir:%s" % e)
break
92 changes: 55 additions & 37 deletions build3/cmake/FindNumPy.cmake
Original file line number Diff line number Diff line change
@@ -1,41 +1,59 @@
# Find the Python NumPy package
# PYTHON_NUMPY_INCLUDE_DIR
# PYTHON_NUMPY_FOUND
# will be set by this script

cmake_minimum_required(VERSION 2.6)

if(NOT PYTHON_EXECUTABLE)
if(NumPy_FIND_QUIETLY)
find_package(PythonInterp QUIET)
else()
find_package(PythonInterp)
set(__numpy_out 1)
# - Find the NumPy libraries
# This module finds if NumPy is installed, and sets the following variables
# indicating where it is.
#
# TODO: Update to provide the libraries and paths for linking npymath lib.
#
# PYTHON_NUMPY_FOUND - was NumPy found
# PYTHON_NUMPY_VERSION - the version of NumPy found as a string
# PYTHON_NUMPY_VERSION_MAJOR - the major version number of NumPy
# PYTHON_NUMPY_VERSION_MINOR - the minor version number of NumPy
# PYTHON_NUMPY_VERSION_PATCH - the patch version number of NumPy
# PYTHON_NUMPY_VERSION_DECIMAL - e.g. version 1.6.1 is 10601
# PYTHON_NUMPY_INCLUDE_DIR - path to the NumPy include files

unset(PYTHON_NUMPY_VERSION)
unset(PYTHON_NUMPY_INCLUDE_DIR)

if(PYTHONINTERP_FOUND)
execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c"
"import numpy as n; print(n.__version__); print(n.get_include());"
RESULT_VARIABLE __result
OUTPUT_VARIABLE __output
OUTPUT_STRIP_TRAILING_WHITESPACE)

if(__result MATCHES 0)
string(REGEX REPLACE ";" "\\\\;" __values ${__output})
string(REGEX REPLACE "\r?\n" ";" __values ${__values})
list(GET __values 0 PYTHON_NUMPY_VERSION)
list(GET __values 1 PYTHON_NUMPY_INCLUDE_DIR)

string(REGEX MATCH "^([0-9])+\\.([0-9])+\\.([0-9])+" __ver_check "${PYTHON_NUMPY_VERSION}")
if(NOT "${__ver_check}" STREQUAL "")
set(PYTHON_NUMPY_VERSION_MAJOR ${CMAKE_MATCH_1})
set(PYTHON_NUMPY_VERSION_MINOR ${CMAKE_MATCH_2})
set(PYTHON_NUMPY_VERSION_PATCH ${CMAKE_MATCH_3})
math(EXPR PYTHON_NUMPY_VERSION_DECIMAL
"(${PYTHON_NUMPY_VERSION_MAJOR} * 10000) + (${PYTHON_NUMPY_VERSION_MINOR} * 100) + ${PYTHON_NUMPY_VERSION_PATCH}")
string(REGEX REPLACE "\\\\" "/" PYTHON_NUMPY_INCLUDE_DIR ${PYTHON_NUMPY_INCLUDE_DIR})
else()
unset(PYTHON_NUMPY_VERSION)
unset(PYTHON_NUMPY_INCLUDE_DIR)
message(STATUS "Requested NumPy version and include path, but got instead:\n${__output}\n")
endif()
endif()
else()
message(STATUS "To find NumPy Python interpretor is required to be found.")
endif()

if (PYTHON_EXECUTABLE)
# Find out the include path
execute_process(
COMMAND "${PYTHON_EXECUTABLE}" -c
"from __future__ import print_function\ntry: import numpy; print(numpy.get_include(), end='')\nexcept:pass\n"
OUTPUT_VARIABLE __numpy_path)
# And the version
execute_process(
COMMAND "${PYTHON_EXECUTABLE}" -c
"from __future__ import print_function\ntry: import numpy; print(numpy.__version__, end='')\nexcept:pass\n"
OUTPUT_VARIABLE __numpy_version)
elseif(__numpy_out)
message(STATUS "Python executable not found.")
endif(PYTHON_EXECUTABLE)

find_path(PYTHON_NUMPY_INCLUDE_DIR numpy/arrayobject.h
HINTS "${__numpy_path}" "${PYTHON_INCLUDE_PATH}" NO_DEFAULT_PATH)

if(PYTHON_NUMPY_INCLUDE_DIR)
set(PYTHON_NUMPY_FOUND 1 CACHE INTERNAL "Python numpy found")
endif(PYTHON_NUMPY_INCLUDE_DIR)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(NumPy REQUIRED_VARS PYTHON_NUMPY_INCLUDE_DIR
VERSION_VAR __numpy_version)
find_package_handle_standard_args(NumPy REQUIRED_VARS PYTHON_NUMPY_INCLUDE_DIR PYTHON_NUMPY_VERSION
VERSION_VAR PYTHON_NUMPY_VERSION)

if(NUMPY_FOUND)
set(PYTHON_NUMPY_FOUND TRUE)
message(STATUS "NumPy ver. ${PYTHON_NUMPY_VERSION} found (include: ${PYTHON_NUMPY_INCLUDE_DIR})")
endif()

# caffe_clear_vars(__result __output __error_value __values __ver_check __error_value)

Loading