From 0cb491e13522e8d5847354c57bd6568e534ee733 Mon Sep 17 00:00:00 2001 From: bubnikv Date: Mon, 28 Aug 2017 19:11:16 +0200 Subject: [PATCH] CMake build process: Added the "test" target to execute the perl prove unit / integration tests. Added a post-build step to copy the XS.dll & Slic3r/XS.pm to local-lib. --- CMakeLists.txt | 18 ++++++++++++++++++ cmake/modules/FindPerlEmbed.cmake | 2 ++ xs/CMakeLists.txt | 24 ++++++++++-------------- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a4d478fe..65b326d4a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,8 +25,26 @@ if (MSVC AND SLIC3R_MSVC_COMPILE_PARALLEL) add_compile_options(/MP) endif () +# Find the Perl interpreter, add local-lib to PATH and PERL5LIB environment variables, +# so the locally installed modules (mainly the Alien::wxPerl) will be reached. +if (WIN32) + set(ENV_PATH_SEPARATOR ";") +else() + set(ENV_PATH_SEPARATOR ":") +endif() +set(ENV{PATH} "${PROJECT_SOURCE_DIR}/local-lib/bin${ENV_PATH_SEPARATOR}$ENV{PATH}") +set(ENV{PERL5LIB} "${PROJECT_SOURCE_DIR}/local-lib/lib/perl${ENV_PATH_SEPARATOR}$ENV{PERL5LIB}") +message("PATH: $ENV{PATH}") +message("PERL5LIB: $ENV{PERL5LIB}") +find_package(Perl REQUIRED) + add_subdirectory(xs) +enable_testing () +get_filename_component(PERL_BIN_PATH "${PERL_EXECUTABLE}" DIRECTORY) +add_test (NAME xs COMMAND "${PERL_EXECUTABLE}" ${PERL_BIN_PATH}/prove -I ${PROJECT_SOURCE_DIR}/local-lib/lib/perl5 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/xs) +add_test (NAME integration COMMAND "${PERL_EXECUTABLE}" ${PERL_BIN_PATH}/prove WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}) + install(PROGRAMS slic3r.pl DESTINATION bin RENAME slic3r-prusa3d) file(GLOB MyVar var/*.png) diff --git a/cmake/modules/FindPerlEmbed.cmake b/cmake/modules/FindPerlEmbed.cmake index c005980be..b12fc4063 100644 --- a/cmake/modules/FindPerlEmbed.cmake +++ b/cmake/modules/FindPerlEmbed.cmake @@ -46,6 +46,7 @@ sub cmake_set_var { my @words = shellwords(\$content); print \$fh \"set(PerlEmbed_\$varname \\\"\" . join(';', @words) . \"\\\")\\n\"; } +cmake_set_var('ARCHNAME', \$Config{archname}); cmake_set_var('CCFLAGS', \$ccflags); \$ldflags =~ s/ -L/ -LIBPATH:/g if \$msvc; cmake_set_var('LD', \$Config{ld}); @@ -72,6 +73,7 @@ if (PerlEmbed_DEBUG) message(STATUS " PERL_PRIVLIB = ${PERL_PRIVLIB}") message(STATUS " PERL_EXTRA_C_FLAGS = ${PERL_EXTRA_C_FLAGS}") # Second show the configuration extracted by this module (FindPerlEmbed): + message(STATUS " PerlEmbed_ARCHNAME = ${PerlEmbed_ARCHNAME}") message(STATUS " PerlEmbed_CCFLAGS = ${PerlEmbed_CCFLAGS}") message(STATUS " PerlEmbed_CCCDLFLAGS = ${PerlEmbed_CCCDLFLAGS}") message(STATUS " LD = ${PerlEmbed_LD}") diff --git a/xs/CMakeLists.txt b/xs/CMakeLists.txt index a7f19ea5e..7be742216 100644 --- a/xs/CMakeLists.txt +++ b/xs/CMakeLists.txt @@ -232,19 +232,6 @@ add_library(Shiny STATIC ${LIBDIR}/Shiny/ShinyZone.h ) -# Find the Perl interpreter, add local-lib to PATH and PERL5LIB environment variables, -# so the locally installed modules (mainly the Alien::wxPerl) will be reached. -if (WIN32) - set(ENV_PATH_SEPARATOR ";") -else() - set(ENV_PATH_SEPARATOR ":") -endif() -set(ENV{PATH} "${PROJECT_SOURCE_DIR}/local-lib/bin${ENV_PATH_SEPARATOR}$ENV{PATH}") -set(ENV{PERL5LIB} "${PROJECT_SOURCE_DIR}/local-lib/lib/perl${ENV_PATH_SEPARATOR}$ENV{PERL5LIB}") -message("PATH: $ENV{PATH}") -message("PERL5LIB: $ENV{PERL5LIB}") -find_package(Perl REQUIRED) - # Generate the Slic3r Perl module (XS) typemap file. set(MyTypemap ${CMAKE_CURRENT_BINARY_DIR}/typemap) add_custom_command( @@ -507,7 +494,16 @@ if (NOT GLEW_FOUND) endif () include_directories(${GLEW_INCLUDE_DIRS}) target_link_libraries(XS ${GLEW_LIBRARIES}) - +# Install the XS.pm and XS.{so,dll,bundle} into the local-lib directory. +set(PERL_LOCAL_LIB_DIR "${PROJECT_SOURCE_DIR}/local-lib/lib/perl5/${PerlEmbed_ARCHNAME}") +add_custom_command( + TARGET XS + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E make_directory "${PERL_LOCAL_LIB_DIR}/auto/Slic3r/XS/" + COMMAND ${CMAKE_COMMAND} -E copy "$" "${PERL_LOCAL_LIB_DIR}/auto/Slic3r/XS/" + COMMAND ${CMAKE_COMMAND} -E make_directory "${PERL_LOCAL_LIB_DIR}/Slic3r/" + COMMAND ${CMAKE_COMMAND} -E copy "${PROJECT_SOURCE_DIR}/xs/lib/Slic3r/XS.pm" "${PERL_LOCAL_LIB_DIR}/Slic3r/" +) # Create a slic3r executable add_executable(slic3r ${PROJECT_SOURCE_DIR}/src/slic3r.cpp)