1 # Copyright (C) 2012-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License.
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #----------------------------------------------------------------------------
21 # LIST_CONTAINS is a macro useful for determining whether a list has a
23 #----------------------------------------------------------------------------
24 MACRO(LIST_CONTAINS var value)
26 FOREACH(value2 ${ARGN})
27 IF(${value} STREQUAL "${value2}")
29 ENDIF (${value} STREQUAL "${value2}")
31 ENDMACRO(LIST_CONTAINS)
33 #----------------------------------------------------------------------------
34 # The PARSE_ARGUMENTS macro will take the arguments of another macro and
35 # define several variables.
37 # USAGE: PARSE_ARGUMENTS(prefix arg_names options arg1 arg2...)
41 # prefix: IN: a prefix to put on all variables it creates.
43 # arg_names: IN: a list of names.
44 # For each item in arg_names, PARSE_ARGUMENTS will create a
45 # variable with that name, prefixed with prefix_. Each variable will be filled
46 # with the arguments that occur after the given arg_name is encountered
47 # up to the next arg_name or the end of the arguments. All options are
48 # removed from these lists. PARSE_ARGUMENTS also creates a
49 # prefix_DEFAULT_ARGS variable containing the list of all arguments up
50 # to the first arg_name encountered.
52 # options: IN: a list of options.
53 # For each item in options, PARSE_ARGUMENTS will create a
54 # variable with that name, prefixed with prefix_. So, for example, if prefix is
55 # MY_MACRO and options is OPTION1;OPTION2, then PARSE_ARGUMENTS will
56 # create the variables MY_MACRO_OPTION1 and MY_MACRO_OPTION2. These
57 # variables will be set to true if the option exists in the command line
59 # arg_names and options lists should be quoted.
61 # The rest of PARSE_ARGUMENTS are arguments from another macro to be parsed.
62 #----------------------------------------------------------------------------
63 MACRO(PARSE_ARGUMENTS prefix arg_names option_names)
65 FOREACH(arg_name ${arg_names})
66 SET(${prefix}_${arg_name})
68 FOREACH(option ${option_names})
69 SET(${prefix}_${option} FALSE)
71 SET(current_arg_name DEFAULT_ARGS)
74 LIST_CONTAINS(is_arg_name ${arg} ${arg_names})
76 SET(${prefix}_${current_arg_name} ${current_arg_list})
77 SET(current_arg_name ${arg})
80 LIST_CONTAINS(is_option ${arg} ${option_names})
82 SET(${prefix}_${arg} TRUE)
84 SET(current_arg_list ${current_arg_list} ${arg})
88 SET(${prefix}_${current_arg_name} ${current_arg_list})
89 ENDMACRO(PARSE_ARGUMENTS)
91 #----------------------------------------------------------------------------
92 # SALOME_INSTALL_SCRIPTS is a macro useful for installing scripts.
94 # USAGE: SALOME_INSTALL_SCRIPTS(file_list path [WORKING_DIRECTORY dir] [DEF_PERMS])
97 # file_list: IN : list of files to be installed. This list should be quoted.
98 # path: IN : full pathname for installing.
100 # By default files to be installed as executable scripts.
101 # If DEF_PERMS option is provided, than permissions for installed files are
102 # only OWNER_WRITE, OWNER_READ, GROUP_READ, and WORLD_READ.
103 #----------------------------------------------------------------------------
104 MACRO(SALOME_INSTALL_SCRIPTS file_list path)
105 PARSE_ARGUMENTS(SALOME_INSTALL_SCRIPTS "WORKING_DIRECTORY" "DEF_PERMS" ${ARGN})
106 SET(PERMS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
107 IF(NOT SALOME_INSTALL_SCRIPTS_DEF_PERMS)
108 SET(PERMS ${PERMS} OWNER_EXECUTE GROUP_EXECUTE WORLD_EXECUTE)
109 ENDIF(NOT SALOME_INSTALL_SCRIPTS_DEF_PERMS)
110 FOREACH(file ${file_list})
112 IF(SALOME_INSTALL_SCRIPTS_WORKING_DIRECTORY)
113 SET(PREFIX "${SALOME_INSTALL_SCRIPTS_WORKING_DIRECTORY}/")
114 ENDIF(SALOME_INSTALL_SCRIPTS_WORKING_DIRECTORY)
115 INSTALL(FILES ${PREFIX}${file} DESTINATION ${path} PERMISSIONS ${PERMS})
116 GET_FILENAME_COMPONENT(ext ${file} EXT)
118 INSTALL(CODE "MESSAGE(STATUS \"py compiling ${CMAKE_INSTALL_PREFIX}/${path}/${file}\")")
119 INSTALL(CODE "SET(CMD \"import py_compile ; py_compile.compile('${CMAKE_INSTALL_PREFIX}/${path}/${file}')\")")
120 INSTALL(CODE "EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} -c \"\${CMD}\")")
121 INSTALL(CODE "EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} -O -c \"\${CMD}\")")
122 ENDIF(ext STREQUAL .py)
123 ENDFOREACH(file ${file_list})
124 ENDMACRO(SALOME_INSTALL_SCRIPTS)
126 #----------------------------------------------------------------------------
127 # SALOME_INSTALL_SCRIPTS is a macro useful for installing executable scripts.
129 # PYFILE2COMPINST: IN : list of python files to be installed.
130 # PYFILELOC: IN : full pathname for installing.
131 # Permissions of installed files: OWNER_WRITE, OWNER_READ, GROUP_READ, and WORLD_READ
132 #----------------------------------------------------------------------------
133 MACRO(INSTALL_AND_COMPILE_PYTHON_FILE PYFILE2COMPINST PYFILELOC)
134 INSTALL(CODE "SET(PYTHON_FILE ${f})")
135 FOREACH(input ${PYFILE2COMPINST})
136 GET_FILENAME_COMPONENT(inputname ${input} NAME)
137 INSTALL(FILES ${input} DESTINATION ${CMAKE_INSTALL_PREFIX}/${PYFILELOC})
138 INSTALL(CODE "MESSAGE(STATUS \"py compiling ${CMAKE_INSTALL_PREFIX}/${PYFILELOC}/${inputname}\")")
139 INSTALL(CODE "SET(CMD \"import py_compile ; py_compile.compile('${CMAKE_INSTALL_PREFIX}/${PYFILELOC}/${inputname}')\")")
140 INSTALL(CODE "EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} -c \"\${CMD}\")")
141 INSTALL(CODE "EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} -O -c \"\${CMD}\")")
142 ENDFOREACH(input ${PYFILE2COMPINST})
143 ENDMACRO(INSTALL_AND_COMPILE_PYTHON_FILE PYFILE2COMPINST PYFILELOC)
145 #----------------------------------------------------------------------------
146 # SALOME_CONFIGURE_FILE is a macro useful for copying a file to another location
147 # and modify its contents.
149 # USAGE: SALOME_CONFIGURE_FILE(in_file out_file [INSTALL dir])
152 # in_file: IN : input file with full paths.
153 # out_file: IN : output file with full paths.
154 # If INSTALL is specified, then 'out_file' will be installed to the 'dir' directory.
155 #----------------------------------------------------------------------------
156 MACRO(SALOME_CONFIGURE_FILE IN_FILE OUT_FILE)
157 MESSAGE(STATUS "Creation of ${OUT_FILE}")
158 CONFIGURE_FILE(${IN_FILE} ${OUT_FILE} @ONLY)
159 PARSE_ARGUMENTS(SALOME_CONFIGURE_FILE "INSTALL" "" ${ARGN})
160 IF(SALOME_CONFIGURE_FILE_INSTALL)
161 INSTALL(FILES ${OUT_FILE} DESTINATION ${SALOME_CONFIGURE_FILE_INSTALL})
162 ENDIF(SALOME_CONFIGURE_FILE_INSTALL)
163 ENDMACRO(SALOME_CONFIGURE_FILE)