Salome HOME
spns #40729: MeshGems 2024.1 - windows
[tools/sat_salome.git] / products / env_scripts / MeshGems.py
1 #!/usr/bin/env python
2 #-*- coding:utf-8 -*-
3
4 import os.path
5 import platform
6 from distutils.version import LooseVersion
7
8 def set_distene_licence(env):
9   try:
10     license_file = env.environ.get_value("LICENCE_FILE")
11   except Exception as e:
12     return
13
14   if os.path.exists(license_file):
15     env.add_line(1)
16     env.add_comment("Set DISTENE License")
17     env.set('DISTENE_LICENSE_FILE', 'Use global envvar: DLIM8VAR')
18
19     if os.access(license_file, os.R_OK):
20       lines = open(license_file, "r").readlines()
21       for line in lines:
22         id1=line.find('r"dlim8')
23         if id1 != -1:
24           # on a trouvĂ© la clĂ© dlim8 dans line, on extrait sa valeur
25           id2=line.find('"', id1+2)
26           if id2 != -1:
27            env.set("DLIM8VAR", line[id1+2:id2])
28            break
29   return
30
31 def set_DASSAULT_license(env, version):
32   try:
33     license_file_prefix = env.environ.get_value("LICENCE_FILE")
34     linux_dist = env.environ.get_value("sat_dist")
35   except Exception as e:
36     return
37   env.add_comment("DASSAULT MeshGems KeyGenerator based License")
38   if platform.system() == "Windows" :
39     license_file_name=license_file_prefix + '-' + version + '.dll'
40   else:
41     license_file_name=license_file_prefix + '-' + version + '-' + linux_dist + '.so'
42
43   if not os.path.exists(license_file_name):
44      print("\nWARNING : DASSAULT license file %s not found!" % license_file_name) 
45
46   env.set('SALOME_MG_KEYGEN_LIB_PATH', license_file_name)
47   return
48
49 def set_env_build(env, prereq_dir, version):
50   env.set('MESHGEMSHOME', prereq_dir)
51   env.set('MESHGEMS_ROOT_DIR', prereq_dir)    # update for cmake
52
53   env.prepend('PATH', os.path.join(prereq_dir, 'bin'))
54
55   if platform.system() == "Windows" :
56     env.prepend('PATH', os.path.join(prereq_dir, 'lib'))
57   else :
58     libdir = "Linux_64"
59     env.prepend('PATH', os.path.join(prereq_dir, 'bin', libdir))
60     env.prepend('LD_LIBRARY_PATH', os.path.join(prereq_dir, 'lib', libdir))
61
62 def set_env(env, prereq_dir, version):
63   env.add_comment("Here you can define your license parameters for MeshGems")
64   if LooseVersion(version) > LooseVersion('2.12-1'):
65     set_DASSAULT_license(env,version)
66   else:
67     env.add_comment("DISTENE license")
68     if not env.forBuild:
69       # we don't need licence keys at compile time
70       set_distene_licence(env)
71   set_env_build(env, prereq_dir, version)
72   #
73   Mmp = list(map(str, version.replace('-','.').split('.')))
74   M,m=Mmp[0:2]
75   if len(Mmp) > 2:
76     p=Mmp[2]
77   else:
78     p='0'
79   env.set('MESHGEMS_VERSION', version)
80   env.set('MESHGEMS_VERSION_MAJOR',M)
81   env.set('MESHGEMS_VERSION_MINOR',m)
82   env.set('MESHGEMS_VERSION_PATCH',p)
83
84 def set_nativ_env(env):
85   pass