I think an example would be the best way to demonstrate my problem:
Lets say I have a source directory named src. This directory has two files, a CMakeLists.txt file and a python file named blah. In the same place where src is stored, there is a folder named build. Now, I would like to be able to run cmake and make it compile my python file blah and place it into my build directory. Currently, my CMakeLists.txt is just copying the uncompiled code straight into my build directory using the call:
CONFIGURE_FILE(${PATH_TO_SOURCE}/blah.py ${PATH_TO_BUILD}/blah.py COPYONLY)
Then I run make in the terminal to compile the actual file. This leaves the uncompiled python file in my build directory, which is no good. I've tried using ADD_EXECUTABLES, creating a custom target and using COMMAND, but my syntax must be off somewhere. Any help would be greatly appreciated!
解决方案
CMake doesn't support Python out of the box, AFAIK. because of this, you will need to write rule to build .py files, something like that:
macro(add_python_target tgt)
foreach(file ${ARGN})
set(OUT ${CMAKE_CURRENT_BINARY_DIR}/${file}.pyo)
list(APPEND OUT_FILES ${OUT})
add_custom_command(OUTPUT ${OUT}
COMMAND )
endforeach()
add_custom_target(${tgt} ALL
DEPENDS ${OUT_FILES}
endmacro()
After defining it, you can use it this way:
add_python_target(blabla blah.py)
If you want to make adjustmenets or need more information, see CMake documentation.