[CMake] Various problems deploying a python module

Michael Wild themiwi at gmail.com
Sat Jun 26 05:55:04 EDT 2010


On 25. Jun, 2010, at 22:30 , Janosch Peters wrote:

> On 2010-06-25 18:36:06 +0200, Michael Wild said:
>>> AFAIK all directories you give gcc with the "-I" option will be searched _before_ the standard include paths or C_INCLUDE_PATH. So I think you do have control over what is included. But I know almost nohting about all the compiling/linking stuff, so I might be wrong.
>> The problem is the line
>> #include <Python/Python.h>
>> which resolves to /path/to/Python.framework/Headers/Python.h. No way to specify the version, only the framework location using the -F flag.
> 
> Okay. But as Mark Moll pointed out, we could just ignore the -F flag and use plain Unix include/library paths. 

Ignoring -F doesn't matter at all. As soon as gcc sees <Python/Python.h> it will pick up /path/to/Python.framework/Headers/Python.h. That's how it works on Mac. Really, the problem is the "Python/" prefix which makes gcc look for a Python.framework, no matter what. So if you want a specific version to be used, you have to get creative.

Say your code indeed uses #include <Python/Python.h>, but you want to let the user select the actual version of the Python framework that's being used, you could do the following (completely untried, PYTHON_IS_FRAMEWORK, PYTHON_FRAMEWORK and PYTHON_VERSION are variables with the obvious content):

if(PYTHON_IS_FRAMEWORK)
  set(FW_DIR ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/Frameworks)
  file(MAKE_DIRECTORY ${FW_DIR})
  execute_process(
    COMMAND ${CMAKE_COMMAND} -E remove -f Python.framework
    COMMAND ${CMAKE_COMMAND} -E create_symlink
      ${PYTHON_FRAMEWORK}/Versions/${PYTHON_VERSION}
      ${FW_DIR}/Python.framework)
  add_definitions(-F${FW_DIR})
  include_directories(${FW_DIR}/Python.framework/include)
endif()

This code creates a custom Python framework which actually is a symlink to the desired version.

Michael



More information about the CMake mailing list