[CMake] Python project using Cmake

Matthew Keeler mkeeler at tenable.com
Thu Oct 22 13:45:42 EDT 2015


Sorry Srinivas, the projects was for a former employer of mine and I no longer have access to it. We were distributing “scripts” as executable zip files (a lesser known feature of Python). So we had a few things going on.

include(FindPythonInterp)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/setup.py @ONLY)
add_custom_command(${CMAKE_CURRENT_BINARY_DIR}/<executable name> COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/setup.py bdist -format zip COMMAND …)

For the add_custom_command we ran more commands after invoking python to run the setup.py file. The extra commands were to rename from the normal distutils name to the final name and to prepend a UNIX #!/usr/bin/env python text line to the zip file. In this way you can make a self contained “executable” that on UNIX at least runs like any other binary.

All of the add_custom_command logic to build these zip executables was put into a cmake function:
https://cmake.org/cmake/help/v3.3/command/function.html

If you do go the function route I would recommend taking a look at the CMakeParseArguments module it was very useful for me.
https://cmake.org/cmake/help/v3.3/module/CMakeParseArguments.html

Sorry I don’t have more specifics.

--
Matt Keeler


On October 21, 2015 at 16:21:36, srinivas boppu (srinivas.boppu at gmail.com<mailto:srinivas.boppu at gmail.com>) wrote:

Hi Matthew Keeler,

Thanks for your quick reply. My project is a pure python project. I wanted to use cmake and ctest for testing my individual python modules. Later on, I might have some "tcl" scripts and may be some c++ sources in the same project.

It would be great, if you could share your pure python project details and the macros or related documents.

Thanks and Regards,
Srinivas Boppu




On Wed, Oct 21, 2015 at 9:52 PM, Matthew Keeler <mkeeler at tenable.com<mailto:mkeeler at tenable.com>> wrote:
What are you trying to do? Are you trying to build Python C extensions? If so then the FindPythonLibs module will help you in that regard. It will determine if the Python development files are installed and populate variables with the necessary paths to provide to link_directories and include_directories. https://cmake.org/cmake/help/v3.3/module/FindPythonLibs.html

Additionally there is the FindPythonInterp module which will find the Python interpreter for invoking via custom commands or execute_process.
https://cmake.org/cmake/help/v3.3/module/FindPythonInterp.html

Also if you aren’t actually compiling any C/C++ code it will speed up build system generation if you specify the languages as NONE during the project command invocation. That behavior is documented at: https://cmake.org/cmake/help/v3.3/command/project.html

In the past I have used cmake even for pure Python projects to just get the benefits of generic packaging with cpack and to be able to use ctest. If this is the case for you then you may end up defining a bunch of functions/macros to do all the work as I did.

--
Matt Keeler


On October 21, 2015 at 11:28:28, srinivas boppu (srinivas.boppu at gmail.com<mailto:srinivas.boppu at gmail.com>) wrote:

Hello All,

I am new to cmake and its build and ctest system. I read some where that cmake default look for c++ compiler and we need to modify/configure the cmake to recongize the python files.
I googled for the same but I couldn't find any concrete and complete example.
Any pointers in this regard would be useful.

Thanks in advance.

--
Apologizing doesn't mean U r wrong & the other is right,It means that U value the relationship more than Ur ego...

--

Powered by www.kitware.com<http://www.kitware.com>

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake



--
Apologizing doesn't mean U r wrong & the other is right,It means that U value the relationship more than Ur ego...

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20151022/ce1d4650/attachment-0001.html>


More information about the CMake mailing list