The CMakeLists.txt
file in the python
subdir can add multiple targets via add_executable
or add_library
or (add_custom_target
and add_custom_command
). Each target added in this manner will need a different target name so it would probably look something like this:
add_libary(my_python2_bindings <list_of_sources>)
add_library(my_python3_bindings <another_list_of_sources>)
The drawback is that both can't use the same name as the target name, which is what the ultimate file name will be based on. If that's a requirement you could use set the target properties for the output name and for where it is created.
project(my_python_bindings)
add_libary(my_python2_bindings <list_of_sources>)
set_target_properties(my_python2_bindings PROPERTIES OUTPUT_NAME "${PROJECT_NAME}")
set_target_properties(my_python2_bindings PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/python2")
add_library(my_python3_bindings <another_list_of_sources>)
set_target_properties(my_python3_bindings PROPERTIES OUTPUT_NAME "${PROJECT_NAME}")
set_target_properties(my_python3_bindings PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/python3")
Edit: for many python versions do something like this in the CMakeLists.txt
in the python
subdir you would have a list containing all python versions PYTHON_VERSION_LIST
and then
foreach(version ${PYTHON_VERSION_LIST})
add_library(my_python${version}_bindings <list_of_sources>)
set_target_properties(my_python${version}_bindings PROPERTIES OUTPUT_NAME "${PROJECT_NAME}")
set_target_properties(my_python${version}_bindings PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/python3")
endforeach()
But now you need to add an if
clause for different source lists for each version. In that case its probably easier to just expand my original example to be 2.7, 3.5, and 3.6 instead of only 2 and 3.
Also, if each version is genuinely different like it sounds like they are, you probably want to think hard about giving them all the same filename.