FIND_PACKAGE(PythonInterp 3 REQUIRED)
FIND_PACKAGE(pybind11 REQUIRED)
FIND_PACKAGE(PythonLibsNew 3 REQUIRED)

GET_FILENAME_COMPONENT(MODULE_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME)

ADD_CUSTOM_COMMAND(
    OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/src/${MODULE_NAME}.h"
           "${CMAKE_CURRENT_BINARY_DIR}/src/${MODULE_NAME}.cpp"
    COMMAND ${CMAKE_COMMAND}
    ARGS -E env
        PYTHONPATH="${NUCLEAR_ROLES_DIR}/module/python/"
        NUCLEAR_MODULE_DIR="${PROJECT_SOURCE_DIR}/${NUCLEAR_MODULE_DIR}"
    ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/src/${MODULE_NAME}.py"
    WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/src"
    DEPENDS "src/${MODULE_NAME}.py"
            "${NUCLEAR_ROLES_DIR}/module/python/nuclear.py"
    COMMENT "Generating bindings for python module ${MODULE_NAME}")

# Build our NUClear module
NUCLEAR_MODULE(SOURCES "${CMAKE_CURRENT_BINARY_DIR}/src/${MODULE_NAME}.h"
                       "${CMAKE_CURRENT_BINARY_DIR}/src/${MODULE_NAME}.cpp")

FIND_PACKAGE(PythonInterp 3 REQUIRED)
FIND_PACKAGE(pybind11 REQUIRED)
FIND_PACKAGE(PythonLibsNew 3 REQUIRED)

GET_FILENAME_COMPONENT(MODULE_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME)

FILE(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/src/")

ADD_CUSTOM_COMMAND(
    OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/src/${MODULE_NAME}.h"
           "${CMAKE_CURRENT_BINARY_DIR}/src/${MODULE_NAME}.cpp"
    COMMAND ${CMAKE_COMMAND}
    ARGS -E env
        PYTHONPATH="${NUCLEAR_ROLES_DIR}/module/python/"
        NUCLEAR_MODULE_DIR="${PROJECT_SOURCE_DIR}/${NUCLEAR_MODULE_DIR}"
    ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/src/${MODULE_NAME}.py"
    WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/src"
    DEPENDS "src/${MODULE_NAME}.py"
            "${NUCLEAR_ROLES_DIR}/module/python/nuclear.py"
    COMMENT "Generating bindings for python module ${MODULE_NAME}")

# Build our NUClear module
NUCLEAR_MODULE(SOURCES "${CMAKE_CURRENT_BINARY_DIR}/src/${MODULE_NAME}.h"
                       "${CMAKE_CURRENT_BINARY_DIR}/src/${MODULE_NAME}.cpp")

Make src directory for generating into
Make src directory for generating into
