6868# make sure sys.argv is correct for setuptools
6969sys .argv = [__file__ ] + args
7070
71- ################################################
72- # compiler identification
73- ################################################
74-
75- candidates = ["g++" , "g++-12" , "g++-11" , "g++-10" , "g++-9" , "g++-8" , "g++-7" , "g++-6.1" , "clang++" , "clang++-3.9" ]
76-
77- def determineCompiler (candidates , std , flags ):
78- sample = open ("sample.cpp" , "w" )
79- sample .write ("""
80- #include <omp.h>
81- #include <iostream>
82- void helloWorld() {
83- std::cout << "Hello world" << std::endl;
84- }
85- int main (int argc, char *argv[]) {
86- helloWorld();
87- int nthreads, tid;
88- #pragma omp parallel private(nthreads, tid)
89- {
90- tid = omp_get_thread_num();
91- std::cout << \" Hello World from thread = \" << tid << std::endl;
92- if (tid == 0) {
93- nthreads = omp_get_num_threads();
94- std::cout << \" Number of threads = \" << nthreads << std::endl;
95- }
96- }
97- }""" )
98- sample .close ()
99-
100- for compiler in candidates :
101- cmd = [compiler ,"-o" ,"test_build" ,"-std={}" .format (std )]
102- cmd .extend (flags )
103- cmd .append ("sample.cpp" )
104- try :
105- my_env = os .environ .copy ()
106- if subprocess .call (cmd ,stdout = subprocess .DEVNULL , stderr = subprocess .DEVNULL , env = my_env ) == 0 :
107- os .remove ("sample.cpp" )
108- os .remove ("test_build" )
109- return compiler
110- except :
111- pass
112- try :
113- os .remove ("sample.cpp" )
114- except :
115- pass
116- return None
117-
118- # only check for a compiler if none is specified
119- if cmakeCompiler is None :
120- if sys .platform == "darwin" :
121- # homebrew's "libomp" is used as a default package for AppleClang.
122- # For arm64 macOS, homebrew is installed in /opt/homebrew by default, therefore it is not on include/lib path.
123- try :
124- proc = subprocess .run (['brew' ,'--prefix' ], stdout = subprocess .PIPE )
125- brewPrefix = proc .stdout .decode ('utf-8' ).strip ()
126- cmakeCompiler = determineCompiler (["c++" ], "c++17" , ["-Xpreprocessor" , "-fopenmp" , "-I" + str (brewPrefix ) + "/include" , "-L" + str (brewPrefix ) + "/lib" , "-lomp" ])
127- except :
128- pass
129- if sys .platform == "win32" :
130- # On "win32"-systems compiler detection is not easy, since paths are only set by enabling vcvarsall.bat
131- # (for default compiler cl.exe). We assume that Visual Studio is installed and activated.
132- cmakeCompiler = "cl"
133- print ("The default for Windows is to use cl.exe (MSVC), be sure to install and activate Visual Studio command line tools." )
134- if cmakeCompiler is None :
135- cmakeCompiler = determineCompiler (candidates , "c++17" , ["-fopenmp" ])
136- if cmakeCompiler is None :
137- print ("ERROR: No suitable compiler found. Install any of these: " , candidates )
138- print (" If you have a suitable compiler installed, which is not a standard path, you can override detection by setting 'export NETWORKIT_OVERRIDE_CXX=<compiler-path>'" )
139- if sys .platform == "darwin" :
140- print ("If using AppleClang, OpenMP is needed. Use brew or macports to install libomp." )
141- exit (1 )
142-
14371################################################
14472# functions for cythonizing and building networkit
14573################################################
@@ -153,7 +81,8 @@ def buildNetworKit(install_prefix, externalCore=False, externalTlx=None, withTes
15381 abs_prefix = os .path .join (os .getcwd (), install_prefix )
15482 comp_cmd = ["cmake" ,"-DCMAKE_BUILD_TYPE=Release" ]
15583 comp_cmd .append ("-DCMAKE_INSTALL_PREFIX=" + abs_prefix )
156- comp_cmd .append ("-DCMAKE_CXX_COMPILER=" + cmakeCompiler )
84+ if cmakeCompiler :
85+ comp_cmd .append ("-DCMAKE_CXX_COMPILER=" + cmakeCompiler )
15786 comp_cmd .append ("-DNETWORKIT_FLATINSTALL=ON" )
15887 from sysconfig import get_paths , get_config_var
15988 # The following cmake parameters set Python-variables. This is done to avoid differences between the
0 commit comments