Skip to content

Commit

Permalink
Package pyluxcoretools in the build tree
Browse files Browse the repository at this point in the history
  • Loading branch information
tschw committed Mar 22, 2018
1 parent 52c2c96 commit 05f57fd
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 26 deletions.
4 changes: 1 addition & 3 deletions CMakeLists.txt
Expand Up @@ -154,9 +154,7 @@ include_directories(${GENERATED_INCLUDE_DIR})
add_subdirectory(src/luxrays)
add_subdirectory(src/slg)
add_subdirectory(src/luxcore)
if (PYSIDE_UIC)
add_subdirectory(src/pyluxcoretools)
endif()
add_subdirectory(src/pyluxcoretools)

################################################################################
#
Expand Down
62 changes: 62 additions & 0 deletions cmake/Utils/BuildStage.cmake
@@ -0,0 +1,62 @@
# Routines to set up build rules that copy files or entire directories to the
# build directory if they do not exist or have changed

if (BuildStage_MODULE_INCLUDED)
return()
else()
set(BuildStage_MODULE_INCLUDED TRUE)
endif()

function(BuildStage_files target dst_dir src_dir first_file) #...

macro(absolute_path out base path)
if (IS_ABSOLUTE "${path}")
set(${out} "${path}")
else()
set(${out} "${base}/${path}")
endif()
endmacro()

absolute_path(abs_dst ${CMAKE_CURRENT_BINARY_DIR} ${dst_dir})
absolute_path(abs_src ${CMAKE_CURRENT_SOURCE_DIR} ${src_dir})

set(files ${first_file} ${ARGN})

set(dirs "")
set(n_dirs "1")
set(dst_files "")
foreach(path IN LISTS files)
absolute_path(src_path ${abs_src} ${path})

file(RELATIVE_PATH rel_path ${abs_src} ${src_path})
absolute_path(dst_path ${abs_dst} ${rel_path})

get_filename_component(dir ${dst_path} DIRECTORY)
list(FIND dirs ${dir} index)
if (${index} EQUAL -1) # first time this directory is seen
set(index ${n_dirs})
math(EXPR n_dirs ${n_dirs}+1)
list(APPEND dirs ${dir})

add_custom_command(OUTPUT ${dir}
COMMAND ${CMAKE_COMMAND} -E make_directory ${dir})
endif()

add_custom_command(OUTPUT ${dst_path}
COMMAND ${CMAKE_COMMAND} -E copy ${src_path} ${dst_path}
DEPENDS ${src_path} ${dir})

list(APPEND dst_files ${dst_path})
endforeach()

add_custom_target(${target} DEPENDS ${dst_files})

endfunction()

function(BuildStage_directory target dst_dir src_dir)

file(GLOB_RECURSE files "${src_dir}/*.*")
BuildStage_files(${target} ${dst_dir} ${src_dir} ${files})

endfunction()

70 changes: 47 additions & 23 deletions src/pyluxcoretools/CMakeLists.txt
Expand Up @@ -26,29 +26,53 @@
#############################################################################
#############################################################################

add_custom_command(
OUTPUT "${LuxRays_SOURCE_DIR}/src/pyluxcoretools/pyluxcoretools/pyluxcoremenu/menuwindow.py"
COMMAND ${PYSIDE_UIC} "${LuxRays_SOURCE_DIR}/src/pyluxcoretools/pyluxcoretools/pyluxcoremenu/menuwindow.ui"
-o "${LuxRays_SOURCE_DIR}/src/pyluxcoretools/pyluxcoretools/pyluxcoremenu/menuwindow.py"
MAIN_DEPENDENCY "${LuxRays_SOURCE_DIR}/src/pyluxcoretools/pyluxcoretools/pyluxcoremenu/menuwindow.ui")

add_custom_command(
OUTPUT "${LuxRays_SOURCE_DIR}/src/pyluxcoretools/pyluxcoretools/pyluxcorenetnode/mainwindow.py"
COMMAND ${PYSIDE_UIC} "${LuxRays_SOURCE_DIR}/src/pyluxcoretools/pyluxcoretools/pyluxcorenetnode/mainwindow.ui"
-o "${LuxRays_SOURCE_DIR}/src/pyluxcoretools/pyluxcoretools/pyluxcorenetnode/mainwindow.py"
MAIN_DEPENDENCY "${LuxRays_SOURCE_DIR}/src/pyluxcoretools/pyluxcoretools/pyluxcorenetnode/mainwindow.ui")

add_custom_command(
OUTPUT "${LuxRays_SOURCE_DIR}/src/pyluxcoretools/pyluxcoretools/pyluxcorenetconsole/mainwindow.py"
COMMAND ${PYSIDE_UIC} "${LuxRays_SOURCE_DIR}/src/pyluxcoretools/pyluxcoretools/pyluxcorenetconsole/mainwindow.ui"
-o "${LuxRays_SOURCE_DIR}/src/pyluxcoretools/pyluxcoretools/pyluxcorenetconsole/mainwindow.py"
MAIN_DEPENDENCY "${LuxRays_SOURCE_DIR}/src/pyluxcoretools/pyluxcoretools/pyluxcorenetconsole/mainwindow.ui")
include(BuildStage)

set(pyluxcoretools_stage "${GENERATED_DIR}/pyluxcoretools")

BuildStage_directory(
pyluxcoretools_copy_dir ${pyluxcoretools_stage} pyluxcoretools)

if (PYSIDE_UIC)

set(pyluxcoretools_dir "${CMAKE_CURRENT_SOURCE_DIR}/pyluxcoretools")

add_custom_command(
OUTPUT "${pyluxcoretools_stage}/pyluxcoremenu/menuwindow.py"
COMMAND ${PYSIDE_UIC} "${pyluxcoretools_dir}/pyluxcoremenu/menuwindow.ui"
-o "${pyluxcoretools_stage}/pyluxcoremenu/menuwindow.py"
MAIN_DEPENDENCY "${pyluxcoretools_dir}/pyluxcoremenu/menuwindow.ui"
DEPENDS pyluxcoretools_copy_dir)


add_custom_command(
OUTPUT "${pyluxcoretools_stage}/pyluxcorenetnode/mainwindow.py"
COMMAND ${PYSIDE_UIC} "${pyluxcoretools_dir}/pyluxcorenetnode/mainwindow.ui"
-o "${pyluxcoretools_stage}/pyluxcorenetnode/mainwindow.py"
MAIN_DEPENDENCY "${pyluxcoretools_dir}/pyluxcorenetnode/mainwindow.ui"
DEPENDS pyluxcoretools_copy_dir)

add_custom_command(
OUTPUT "${pyluxcoretools_stage}/pyluxcorenetconsole/mainwindow.py"
COMMAND ${PYSIDE_UIC} "${pyluxcoretools_dir}/pyluxcorenetconsole/mainwindow.ui"
-o "${pyluxcoretools_stage}/pyluxcorenetconsole/mainwindow.py"
MAIN_DEPENDENCY "${pyluxcoretools_dir}/pyluxcorenetconsole/mainwindow.ui"
DEPENDS pyluxcoretools_copy_dir)

else()

message(WARNING "pyside-uic not available "
"- using pre-generated files from the source tree")

endif()

add_custom_target(pyluxcoretools ALL
COMMAND ${CMAKE_COMMAND} -E make_directory "${LuxRays_SOURCE_DIR}/lib"
COMMAND ${CMAKE_COMMAND} -E tar "cf" "${LuxRays_SOURCE_DIR}/lib/pyluxcoretools.zip" --format=zip
"${CMAKE_CURRENT_SOURCE_DIR}/pyluxcoretools"
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/lib"
COMMAND ${CMAKE_COMMAND} -E
tar "cf" "${CMAKE_BINARY_DIR}/lib/pyluxcoretools.zip"
--format=zip ${pyluxcoretools_stage}
DEPENDS
"${LuxRays_SOURCE_DIR}/src/pyluxcoretools/pyluxcoretools/pyluxcoremenu/menuwindow.py"
"${LuxRays_SOURCE_DIR}/src/pyluxcoretools/pyluxcoretools/pyluxcorenetnode/mainwindow.py"
"${LuxRays_SOURCE_DIR}/src/pyluxcoretools/pyluxcoretools/pyluxcorenetconsole/mainwindow.py")
pyluxcoretools_copy_dir
"${pyluxcoretools_stage}/pyluxcoremenu/menuwindow.py"
"${pyluxcoretools_stage}/pyluxcorenetnode/mainwindow.py"
"${pyluxcoretools_stage}/pyluxcorenetconsole/mainwindow.py")

0 comments on commit 05f57fd

Please sign in to comment.