3 ####################################################################################
5 # Created : Thu Jan 27 09:50:55 2005
6 # Author : Vadim SANDLER, Open CASCADE SAS (vadim.sandler@opencascade.com)
8 # Module : Installation Wizard
9 # Copyright : 2002-2014 CEA
11 # This script is the part of the SALOME installation procedure.
13 # This script can be used to build and install SALOME modules from sources.
14 # Try build.sh -h for more details about usage.
16 # Last update: 13/12/2013: porting SALOME build procedure to CMake
18 ####################################################################################
20 # set to 1 to print debug information for script
21 if [ "${DEBUG_SCRIPT}" = "" ] ; then
25 # default installation directory
26 def_install_dir="$(pwd)/INSTALL"
27 # default modules list
29 def_modules="${def_modules} KERNEL GUI GEOM MED SMESH PARAVIS YACS HOMARD HEXABLOCK JOBMANAGER"
30 def_modules="${def_modules} NETGENPLUGIN GHS3DPLUGIN BLSURFPLUGIN HexoticPLUGIN GHS3DPRLPLUGIN HEXABLOCKPLUGIN"
31 def_modules="${def_modules} COMPONENT CALCULATOR PYCALCULATOR HELLO PYHELLO LIGHT PYLIGHT"
32 def_modules="${def_modules} RANDOMIZER SIERPINSKY ATOMIC ATOMGEN ATOMSOLV DOCUMENTATION"
34 ###############################################################
35 # Function: Print usage information and exit
36 ###############################################################
39 echo "Build specified SALOME module(s)"
42 echo " $(basename $0) [ <option> ] ... [ <module> [ <module> ... ] ]"
44 echo "<module> Modules to build, separated by space(s)."
45 echo " By default, all modules are built."
46 echo " Note, that modules given in the command lines are automatically"
47 echo " sorted according to the inter-dependencies."
51 echo "-h Print help on the information."
53 echo "-d Delete build (and install) directories before calling CMake,"
54 echo " to force full rebuild of each specified module."
57 echo "-t Perform make dev_docs step to build developer documentation,"
58 echo " for those modules which support this feature."
61 echo "-j <JOBS> Specify number of jobs (commands) to run simultaneously,"
62 echo " this option, when specified, passed directly to make."
64 echo "-p <PREFIX> Specify installation directory."
65 echo " Default: ${def_install_dir}."
67 echo "-D<OPT>=<VAL> Specify additional options to be passed to CMake command."
71 echo " $(basename $0) -p /home/user/salome KERNEL MED GEOM"
73 echo " This will make KERNEL, GEOM and MED modules and install them to the "
74 echo " /home/user/salome directory."
75 echo " The modules will be built in the Release mode."
77 echo " $(basename $0) -DCMAKE_BUILD_TYPE=Debug -DSALOME_BUILD_GUI=OFF"
79 echo " This will build all modules without GUI support. Those modules, that do not"
80 echo " support compilation without GUI, won't be affected."
81 echo " The modules will be built in the Debug mode and installed to the default"
87 ###############################################################
88 # Function: Show error, print usage information and exit
89 ###############################################################
93 echo "$(basename $0): $*"
98 ###############################################################
99 # Function: Get CMake options for the specified module
100 ###############################################################
103 local def_options="-DCMAKE_BUILD_TYPE=Release"
105 KERNEL ) def_options="${def_options} -DSALOME_USE_LIBBATCH=ON -DSALOME_USE_SIMAN=ON" ;;
106 SMESH ) def_options="${def_options} -DSALOME_SMESH_USE_CGNS=ON -DSALOME_SMESH_USE_TBB=ON" ;;
111 ###############################################################
112 # Function: Check if module supports compilation without gui
113 ###############################################################
118 KERNEL | GEOM | MED | SMESH | NETGENPLUGIN | GHS3DPLUGIN | GHS3DPRLPLUGIN | BLSURFPLUGIN | HexoticPLUGIN ) res=0 ;;
119 YACS | HEXABLOCK | HEXABLOCKPLUGIN ) res=0 ;;
125 ###############################################################
126 # Function: Check if module supports make dev_docs step
127 ###############################################################
132 KERNEL | GUI | GEOM | MED | SMESH | YACS | BLSURFPLUGIN | PYCALCULATOR ) res=0 ;;
139 # set initial values for options
155 if [ "${wait_arg}" = "1" ] ; then
156 error_exit "option requires an argument -- ${wait_opt}"
159 while [ "${o}" != "" ] ; do
164 D ) cmake_option=${ov}
165 if [ "${cmake_option}" = "" ] ; then
166 error_exit "specify cmake option in -D<OPT>=<VAL> format"
168 cmake_options="${cmake_options} -${o}"
172 if [ "${prefix}" = "" ] ; then
179 if [ "${nbjobs}" = "" ] ; then
186 t ) build_devdocs=1 ;;
187 * ) error_exit "unknown option -- ${oo}" ;;
193 echo ${def_modules} | grep -e "\<${o}\>" > /dev/null
194 if [ "$?" = "0" ] ; then
195 if [ "${wait_arg}" = "1" ] ; then
196 error_exit "option requires an argument -- ${wait_opt}"
198 modules="${modules} ${o}"
199 elif [ "${wait_opt}" != "" ] ; then
203 * ) error_exit "unknown option -- ${wait_opt}" ;;
208 error_exit "unknown module -- ${o}"
213 if [ "${wait_arg}" = "1" ] ; then
214 error_exit "option requires an argument -- ${wait_opt}"
218 # check installation directory
221 if [ "${prefix}" = "" ] ; then
223 echo "Warning: installation directory is not set."
224 echo "All modules will be installed to ${def_install_dir}."
226 prefix=${def_install_dir}
227 elif [ "`echo ${prefix} | grep -E '^/'`" = "" ] ; then
228 prefix="$(pwd)/${prefix}"
230 echo 'Warning: relative prefix is used.'
231 echo "All the modules will be installed to ${prefix}."
236 # sort modules in proper order according to the dependancies
239 if [ "${modules}" != "" ] ; then
241 for module in ${def_modules} ; do
243 echo ${modules} | grep -e "\<${module}\>" > /dev/null
244 if [ "$?" = "0" ] ; then
245 xmodules="${xmodules} ${module}"
248 modules="${xmodules}"
250 modules="${def_modules}"
254 # print status information (for script debugging purposes)
257 if [ "${DEBUG_SCRIPT}" = "1" ] ; then
259 echo "====== debug script: options: begin ====="
260 echo "prefix=$prefix"
261 echo "nbjobs=$nbjobs"
262 echo "cmake_options=$cmake_options"
263 echo "modules=$modules"
264 echo "is_delete=$is_delete"
265 echo "build_devdocs=$build_devdocs"
266 echo "====== debug script: options: end ======="
274 echo "==========================================================================="
275 echo "SALOME build started at `date`"
276 echo "==========================================================================="
283 env_script=`dirname $0`/env.sh
284 if [ ! -e ${env_script} ] ; then
285 # ... if not found, try env_build.sh
286 env_script=`dirname $0`/env_build.sh
288 if [ ! -e ${env_script} ] ; then
289 # ... if not found, try env_products.sh
290 env_script=`dirname $0`/env_products.sh
292 # source env file, if found
293 if [ -e ${env_script} ] ; then
294 echo ". Source environment script ${env_script}"
298 echo "Warning: environment is not set."
299 echo "No environment file ($(dirname $0)/env.sh, $(dirname $0)/env_build.sh, $(dirname $0)/env_products.sh) is found."
300 echo "Proceed with the current environment."
305 LOG_DIR=${BUILD_DIR}/LOGS
306 if [ "${nbjobs}" != "" ] ; then
311 # create log directory
314 if [ ! -e ${LOG_DIR} ] ; then
319 # loop through all specified modules
322 for module in ${modules} ; do
323 echo "......................"
324 echo ".. ${module} module..."
326 module_src=${module}_SRC_DIR
327 module_src=${!module_src}
328 module_build=${BUILD_DIR}/${module}_BUILD
334 # get CMake options to be applied to the module
337 # get default CMake options
338 def_cmake_options=`get_cmake_options ${module}`
340 # process cmake options specified via command line
341 module_cmake_options=
342 for option in ${def_cmake_options} ; do
343 option_name=`echo $option | sed -e "s%^-D%%g;s%=.*$%%g"`
344 if [ "`echo ${cmake_options} | grep -e '-D${option_name}='`" = "" ] ; then
345 module_cmake_options="${module_cmake_options} ${option}"
348 for option in ${cmake_options} ; do
349 option_name=`echo $option | sed -e "s%^-D%%g;s%=.*$%%g"`
350 if [ "${option_name}" != "CMAKE_INSTALL_PREFIX" ] ; then
351 module_cmake_options="${module_cmake_options} ${option}"
353 if [ "${option}" = "-DSALOME_BUILD_GUI=OFF" ] ; then
359 # check source directory
362 if [ "${module_src}" = "" ] ; then
363 echo "Error: cannot find module sources. ${module}_SRC_DIR environment variable is not set."
367 if [ ! -d ${module_src} ] ; then
368 echo "Error: cannot find module sources directory: ${module_src} does not exist."
373 # remove build directory (if -d option is given)
376 if [ "${is_delete}" = "1" ] && [ -d ${module_build} ] ; then
377 echo ".... Removing ${module_build}"
378 chmod -R +w ${module_build} >& /dev/null && rm -rf ${module_build} >& /dev/null
379 if [ "$?" != "0" ] ; then
380 echo "Warning: cannot remove build directory ${module_build}: permission denied."
385 # create build directory (if it does not exist)
388 if [ ! -d ${module_build} ] ; then
389 echo ".... Creating ${module_build}"
390 mkdir -p ${module_build} >& /dev/null
391 if [ "$?" != "0" ] ; then
392 echo "Error: cannot create build directory ${module_build}: permission denied."
398 # get installation directory for the module
403 if [ -e ${module_src}/CMakeLists.txt ] ; then
404 ver_major=$(grep "SET(\${PROJECT_NAME_UC}_MAJOR_VERSION" ${module_src}/CMakeLists.txt | sed -e "s%.*\([0-9]\+\).*%\1%g")
405 ver_minor=$(grep "SET(\${PROJECT_NAME_UC}_MINOR_VERSION" ${module_src}/CMakeLists.txt | sed -e "s%.*\([0-9]\+\).*%\1%g")
406 ver_patch=$(grep "SET(\${PROJECT_NAME_UC}_PATCH_VERSION" ${module_src}/CMakeLists.txt | sed -e "s%.*\([0-9]\+\).*%\1%g")
407 vx="${ver_major}.${ver_minor}.${ver_patch}"
409 if [ "${vx}" != "" ] ; then
414 px="${prefix}/${module}${vx}"
420 echo ".... Running cmake"
422 # check presence of CMakeLists.txt
423 if [ ! -e ${module_src}/CMakeLists.txt ] ; then
424 echo "Error: ${module_src}/CMakeLists.txt does not exist."
428 # when building without gui support, check that module supports this option
429 if [ "${without_gui}" = "1" ] ; then
430 supports_wogui ${module}
431 if [ "$?" != "0" ] ; then
432 echo "Error: build without gui is not supported."
439 echo "========================================================================" > ${LOG_DIR}/${module}_cmake.log
440 echo "cmake ${module_src} -DCMAKE_INSTALL_PREFIX=${px} ${module_cmake_options}" >> ${LOG_DIR}/${module}_cmake.log
441 echo "========================================================================" >> ${LOG_DIR}/${module}_cmake.log
442 ( cd ${module_build} && cmake ${module_src} -DCMAKE_INSTALL_PREFIX=${px} ${module_cmake_options} >> ${LOG_DIR}/${module}_cmake.log 2>&1 )
445 # stop if there were any errors
446 if [ "${sts}" != "0" ] ; then
447 echo "Error: cmake failed; see ${LOG_DIR}/${module}_cmake.log for more details."
455 echo ".... Running make"
458 echo "========================================================================" > ${LOG_DIR}/${module}_make.log
459 echo "make ${nbjobs}" >> ${LOG_DIR}/${module}_make.log
460 echo "========================================================================" >> ${LOG_DIR}/${module}_make.log
461 ( cd ${module_build} && make ${nbjobs} >> ${LOG_DIR}/${module}_make.log 2>&1 )
464 # stop if there were any errors
465 if [ "${sts}" != "0" ] ; then
466 echo "Error: make failed; see ${LOG_DIR}/${module}_make.log for more details."
471 # run make dev_docs step (if -t option is given)
474 if [ "${build_devdocs}" = "1" ] ; then
475 supports_build_tui ${module}
476 if [ "$?" = "0" ] ; then
477 echo ".... Running make dev_docs"
478 echo "========================================================================" > ${LOG_DIR}/${module}_make_devdocs.log
479 echo "make dev_docs" >> ${LOG_DIR}/${module}_make_devdocs.log
480 echo "========================================================================" >> ${LOG_DIR}/${module}_make_devdocs.log
481 ( cd ${module_build} && make dev_docs >> ${LOG_DIR}/${module}_make_devdocs.log 2>&1 )
484 if [ "${sts}" != "0" ] ; then
485 echo "Warning: make dev_docs failed; see ${LOG_DIR}/${module}_make_devdocs.log for more details."
491 # remove install directory (if -d option is given)
494 if [ "${is_delete}" = "1" ] && [ -d ${px} ] ; then
495 echo ".... Removing ${px}"
496 chmod -R +w ${px} >& /dev/null && rm -rf ${px} >& /dev/null
497 if [ "$?" != "0" ] ; then
498 echo "Warning: cannot remove install directory ${px}: permission denied."
506 echo ".... Running make install"
507 echo "========================================================================" > ${LOG_DIR}/${module}_make_install.log
508 echo "make install" >> ${LOG_DIR}/${module}_make_install.log
509 echo "========================================================================" >> ${LOG_DIR}/${module}_make_install.log
510 ( cd ${module_build} && make install >> ${LOG_DIR}/${module}_make_install.log 2>&1 )
513 if [ "${sts}" != "0" ] ; then
514 echo "Error: make install failed; see ${LOG_DIR}/${module}_make_install.log for more details."
519 # set ${module}_ROOT_DIR environment variable
522 export ${module}_ROOT_DIR=${px}
524 echo ".. Finished ${module} module"
533 echo "==========================================================================="
534 echo "SALOME build finished at `date`"
535 echo "==========================================================================="