From bb55eb97c4b94b43ed32dc8a0494e8544af01697 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Franck=20P=C3=A9rignon?= <franck.perignon@imag.fr>
Date: Tue, 26 Feb 2013 16:55:16 +0000
Subject: [PATCH] Update CMake to include autom. tests (ctest/pytests).

---
 HySoP/CMake/ParmesTests.cmake |  14 ++++
 HySoP/CMakeLists.txt          |  65 +++++++++--------
 HySoP/setup.py.in             | 129 +++++++++++++++++-----------------
 HySoP/src/CMakeLists.txt      |  23 ++++--
 HySoP/src/fftw/fft3d.f90      |   1 -
 5 files changed, 131 insertions(+), 101 deletions(-)
 create mode 100644 HySoP/CMake/ParmesTests.cmake

diff --git a/HySoP/CMake/ParmesTests.cmake b/HySoP/CMake/ParmesTests.cmake
new file mode 100644
index 000000000..3c996f762
--- /dev/null
+++ b/HySoP/CMake/ParmesTests.cmake
@@ -0,0 +1,14 @@
+#configure_file(CTestCustom.ctest.in CTestCustom.ctest)
+#add_test(NAME parmepy_test COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/BUILD_MAIN_PYTEST)
+enable_testing()
+find_python_module(pytest REQUIRED)
+
+add_test(domain py.test -v ${CMAKE_SOURCE_DIR}/parmepy/domain/tests/test_domain.py)
+
+if(USE_MPI)
+  #add_test(NAME topology COMMAND ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} 4 py.test -v ${CMAKE_SOURCE_DIR}/parmepy/mpi/tests/test_topology.py)
+  add_test(NAME topology COMMAND ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} 1 py.test -v ${CMAKE_SOURCE_DIR}/parmepy/mpi/tests/test_topology.py)
+endif()
+
+
+ 
\ No newline at end of file
diff --git a/HySoP/CMakeLists.txt b/HySoP/CMakeLists.txt
index 1e8a086e5..21cf996ca 100644
--- a/HySoP/CMakeLists.txt
+++ b/HySoP/CMakeLists.txt
@@ -29,12 +29,27 @@ include(MyTools)
 option(VERBOSE_MODE "enable verbose mode for cmake exec. Default = on" ON)
 option(DOUBLEPREC "set precision for real numbers to double precision when this mode is enable. Default = on." ON)
 option(USE_MPI "compile and link parmes with mpi when this mode is enable. Default = on." ON)
-option(WITH_SCALES "compile/create parmesscales lib and link it with Parmes. Default = on." ON)
-option(WITH_PPM "link Parmes with PPM library (core component). Default = off." OFF)
-option(WITH_PPMNumerics "link Parmes with PPM-numerics. Default = off" OFF)
-option(WITH_TESTS "Enable testing. Default = off" OFF)
-option(BUILD_SHARED_LIBS "Enable dynamic library build, default = ON" OFF)
+option(WITH_PPM "link Parmes with PPM library (core component) - Deprecated. Default = off." OFF)
+option(WITH_PPMNumerics "link Parmes with PPM-numerics - Deprecated. Default = off" OFF)
+option(WITH_TESTS "Enable testing. Default = off" ON)
+option(BUILD_SHARED_LIBS "Enable dynamic library build, default = OFF." OFF)
+option(WITH_LIB_FORTRAN "Generate libparmes from fortran files in src, wrapped into parmepy.f2py module. Default = ON." ON)
+option(WITH_SCALES "compile/create parmesscales lib and link it with Parmes. Default = ON." ON)
 option(WITH_FFTW "Link with fftw library (required for some Parmes solvers), default = ON" ON)
+option(WITH_MAIN_FORTRAN "Create an executable (test purpose) from fortran sources in src/main, linked with libparmes, default = ON" ON)
+
+if(NOT WITH_LIB_FORTRAN)
+  message(WARNING "You deactivate libparmes (fortran) generation. This will disable fftw and scales fonctionnalities.")
+  set(WITH_FFTW "OFF")
+  set(WITH_SCALES "OFF")
+  set(WITH_MAIN_FORTRAN "OFF")
+endif()
+
+# We can not run scales or fftw without mpi ...
+if(WITH_FFTW OR WITH_SCALES)
+  set(USE_MPI "ON")
+endif()
+
 
 # cmake project name
 set(PROJECT_NAME parmepy)
@@ -52,13 +67,12 @@ set(PROJECT_LIBRARY_NAME ${PROJECT_NAME})
 #   - ${PROJECT_NAME}_BINARY_DIR : where you have run cmake, i.e. the place for compilation
 #   - ${PROJECT_NAME}_SOURCE_DIR : where sources (.f and .h and this CMakeLists.txt) are located
 # Note that because of OutOfSourceBuild, binary_dir and source_dir must be different.
-project(${PROJECT_NAME} Fortran)
+project(${PROJECT_NAME})
 
 # ============= Search for libraries  =============
 # We search for libraries Parmes depends on and
 # set the compile/link conf (-I and -L opt)
 
-
 set(PARMES_LIBRARY_NAME parmes)
 set(PACKAGE_NAME Parmes)
 
@@ -85,20 +99,12 @@ set(CMAKE_INSTALL_PREFIX ${${PROJECT_NAME}_INSTALL_DIR}/${PROJECT_NAME})
 
 if(USE_MPI)
   find_python_module(mpi4py REQUIRED)
-  # Find MPI for C++ and fortran.
-  find_package(MPI REQUIRED)
-  # -I
-  include_directories(${MPI_Fortran_INCLUDE_PATH})
-  # Add compilation flags
-  set(${PARMES_LIBRARY_NAME}_LINK_FLAGS ${${PARMES_LIBRARY_NAME}_LINK_FLAGS} ${MPI_Fortran_LINK_FLAGS})
-  # -I
-  # Add compilation flags
-  append_Fortran_flags(${MPI_Fortran_COMPILE_FLAGS})
-  #set(${PARMES_LIBRARY_NAME}_LINK_FLAGS ${${PARMES_LIBRARY_NAME}_LINK_FLAGS} ${MPI_Fortran_LINK_FLAGS})
-  set(LIBS ${LIBS} ${MPI_Fortran_LIBRARIES} )
-endif(USE_MPI)
-
-add_subdirectory(src)
+endif()
+
+# Deal with src/files to create libparmes and related.
+if(WITH_LIB_FORTRAN)
+  add_subdirectory(src)
+endif()
 
 # ============= Generates setup.py =============
 # The file setup.py will be generated from setup.py.in.
@@ -120,9 +126,14 @@ ADD_CUSTOM_TARGET(python-build ALL COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_
    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMENT "build parmepy package")
 
 # To install python package AND parmes library and modules
-ADD_CUSTOM_TARGET(python-install COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/setup.py install --user config_fc --f90exec=${CMAKE_Fortran_COMPILER}
-  COMMAND make install
-  WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMENT "build/install parmepy package")
+if(WITH_LIB_FORTRAN)
+  ADD_CUSTOM_TARGET(python-install COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/setup.py install --user config_fc --f90exec=${CMAKE_Fortran_COMPILER}
+    COMMAND make install
+    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMENT "build/install parmepy package")
+else()
+  ADD_CUSTOM_TARGET(python-install COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/setup.py install --user config_fc --f90exec=${CMAKE_Fortran_COMPILER}
+    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMENT "build/install parmepy package")
+endif()
 
 ADD_CUSTOM_TARGET(python-cleaninstall COMMAND rm -rf ${${PROJECT_NAME}_INSTALL_DIR}/${PROJECT_NAME}*
   COMMENT "remove parmepy package and its dependencies")
@@ -130,7 +141,6 @@ ADD_CUSTOM_TARGET(python-cleaninstall COMMAND rm -rf ${${PROJECT_NAME}_INSTALL_D
 add_dependencies(python-build ${PARMES_LIBRARY_NAME})
 add_dependencies(python-install ${PARMES_LIBRARY_NAME})
 
-
 # ============= RPATH =============
 # Concerning rpath see for example http://www.itk.org/Wiki/CMake_RPATH_handling
 
@@ -148,9 +158,7 @@ set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
 
 # ============= Tests =============
 if(WITH_TESTS)
-    enable_testing()
-    configure_file(CTestCustom.ctest.in CTestCustom.ctest)
-    add_test(NAME parmepy_test COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/BUILD_MAIN_PYTEST)
+  include(ParmesTests)
 endif(WITH_TESTS)
 
 
@@ -165,7 +173,6 @@ if(VERBOSE_MODE)
   message(STATUS " Project uses MPI : ${USE_MPI}")
   message(STATUS " Project uses Scales : ${WITH_SCALES}")
   message(STATUS " Project uses FFTW : ${WITH_FFTW}")
-  message(STATUS " Project uses PPM : ${WITH_PPM}")
   message(STATUS " Python packages will be installed in ${${PROJECT_NAME}_INSTALL_DIR}")
   message(STATUS "====================== ======= ======================")
 endif()
diff --git a/HySoP/setup.py.in b/HySoP/setup.py.in
index 8aa805304..2d04ab1e1 100644
--- a/HySoP/setup.py.in
+++ b/HySoP/setup.py.in
@@ -8,86 +8,83 @@ from numpy.distutils.core import setup, Extension
 from numpy.distutils.misc_util import Configuration
 import os
 import glob
-import sys
-# List of all directories for sources
-#os.listdir(os.path.join('ParMePy','New_ParmePy'))
 
 # Full package name
 name = '@PYPACKAGE_NAME@'
 # List of modules (directories) to be included
 packages = ['parmepy',
             'parmepy.domain',
-            'parmepy.fields',
-            'parmepy.obstacle',
-            'parmepy.operator',
-            'parmepy.problem',
-            'parmepy.particular_solvers',
-            'parmepy.particular_solvers.integrator',
-            'parmepy.physics',
-            'parmepy.tools',
-            'parmepy.test',
-            'parmepy.test.test_domain',
-            'parmepy.test.test_field',
-            'parmepy.test.test_operator',
-            'parmepy.test.test_particular_solvers']
+            'parmepy.domain.tests',
+            ## 'parmepy.fields',
+            ## 'parmepy.obstacle',
+            ## 'parmepy.operator',
+            ## 'parmepy.problem',
+            ## 'parmepy.particular_solvers',
+            ## 'parmepy.particular_solvers.integrator',
+            ## 'parmepy.physics',
+            ## 'parmepy.tools',
+            ## 'parmepy.test',
+            ## 'parmepy.test.test_domain',
+            ## 'parmepy.test.test_field',
+            ## 'parmepy.test.test_operator',
+            ## 'parmepy.test.test_particular_solvers',
+            ## 'parmepy.solvers'
+            ]
 #            'examples']
 
+if("@USE_MPI@" is "ON"):
+    packages.append('parmepy.mpi')
+
 # Enable this to get debug info
 # DISTUTILS_DEBUG=1
-inc_dir = '@MPI_Fortran_INCLUDE_PATH@'.split(';')
-while inc_dir.count('') >0:
-    inc_dir.remove('') # To avoid -I -I in compiler call. Result in a bug.
-parmes_dir = '@CMAKE_BINARY_DIR@/Modules'
-inc_dir.append(parmes_dir)
-parmes_libdir = ['@CMAKE_BINARY_DIR@/src']
-parmeslib = ['@PARMES_LIBRARY_NAME@']
-f2py_options = ['--no-lower']
 
-## scales_src = glob.glob('@CMAKE_SOURCE_DIR@/parmepy/scales2py/*.f90')
-## scalesModule = Extension(name='parmepy.scales2py',
-##                          f2py_options=f2py_options,
-##                          sources=scales_src,
-##                          include_dirs=inc_dir,
-##                          library_dirs=parmes_libdir,
-##                          libraries=parmeslib,
-##                          define_macros=[('F2PY_REPORT_ON_ARRAY_COPY', '1')])
+ext_modules =[]
 
-## ext_modules=[scalesModule]
+# Check if libparmes was created
+enable_fortran = "@WITH_LIB_FORTRAN@"
 
-ext_modules =[]
-fortran_dir = '@CMAKE_SOURCE_DIR@/parmepy/f2py/'
-enable_fortran = False
-withfftw = "@WITH_FFTW@"
-if(withfftw is "ON"):
-    #fortran_src = glob.glob('@CMAKE_SOURCE_DIR@/parmepy/f2py/*.f90')
+if(enable_fortran is "ON"):
+    inc_dir = '@MPI_Fortran_INCLUDE_PATH@'.split(';')
+    while inc_dir.count('') >0:
+        inc_dir.remove('') # To avoid -I -I in compiler call. Result in a bug.
 
-    fortran_src = [fortran_dir+'parameters.f90',fortran_dir+'fftw2py.f90']
-    enable_fortran = True
-    fftwdir = '@FFTWLIB@'
-    fftwdir = os.path.split(fftwdir)[0]
-    parmeslib.append('fftw3')
-    parmeslib.append('fftw3_mpi')
-    parmes_libdir.append(fftwdir)
-    #fftwdir_incdir = fftwdir+"/../include"
-    #inc_dir.append(fftwdir_incdir)
+    parmes_dir = '@CMAKE_BINARY_DIR@/Modules'
+    inc_dir.append(parmes_dir)
+    fortran_dir = '@CMAKE_SOURCE_DIR@/parmepy/f2py/'
+    parmes_libdir = ['@CMAKE_BINARY_DIR@/src']
+    parmeslib = ['@PARMES_LIBRARY_NAME@']
+    f2py_options = ['--no-lower']
 
-withscales = '@WITH_SCALES@'
-if(withscales is "ON"):
-    fortran_src.append(fortran_dir+'scales2py.f90')
-    enable_fortran = True
+    withfftw = "@WITH_FFTW@"
+    if(withfftw is "ON"):
+        fortran_src = [fortran_dir+'parameters.f90',fortran_dir+'fftw2py.f90']
+        fftwdir = '@FFTWLIB@'
+        fftwdir = os.path.split(fftwdir)[0]
+        parmeslib.append('fftw3')
+        parmeslib.append('fftw3_mpi')
+        parmes_libdir.append(fftwdir)
+ 
+    withscales = '@WITH_SCALES@'
+    if(withscales is "ON"):
+        fortran_src.append(fortran_dir+'scales2py.f90')
 
-if(enable_fortran):
-#    rep = '@CMAKE_SOURCE_DIR@/parmepy/f2py/'
-#   fortran_src.insert(0,rep+'/parameters.f90')
+    options = [('F2PY_REPORT_ON_ARRAY_COPY', '1')]
+    if(os.uname()[0] == 'Linux'):
+        options.append(('F2PY_REPORT_ATEXIT','1'))
+        
     parpyModule = Extension(name='parmepy.f2py',
                             f2py_options=f2py_options,
                             sources=fortran_src,
                             include_dirs=inc_dir,
                             library_dirs=parmes_libdir,
                             libraries=parmeslib,
-                            define_macros=[('F2PY_REPORT_ON_ARRAY_COPY', '1'),('F2PY_REPORT_ATEXIT','1')])
+                            define_macros=options)
     ext_modules.append(parpyModule)
-
+else:
+    packages.append('parmepy.f2py')
+    packages.append('parmepy.f2py.scales2py')
+    packages.append('parmepy.f2py.fftw2py')
+        
 config = Configuration(name=name,
       version='@PYPACKAGE_VERSION@',
       description='Particular Methods implementation in Python',
@@ -107,13 +104,13 @@ config = Configuration(name=name,
 setup(**config.todict())
 
 # In case of cmake WITH_TESTS=ON
-if('@WITH_TESTS@' is "ON"):
-    cTestFile = open('@CMAKE_CURRENT_BINARY_DIR@/CTestTestfile.cmake','r')
-    cTestStr = ""
-    for line in cTestFile:
-        cTestStr += line.replace('BUILD_MAIN_PYTEST', config.get_build_temp_dir().replace('temp','lib')+'/parmepy/test/main_unit_tests.py')
-    cTestFile.close()
-    cTestFile = open('@CMAKE_CURRENT_BINARY_DIR@/CTestTestfile.cmake','w')
-    cTestFile.write(cTestStr)
-    cTestFile.close()
+## if('@WITH_TESTS@' is "ON"):
+##     cTestFile = open('@CMAKE_CURRENT_BINARY_DIR@/CTestTestfile.cmake','r')
+##     cTestStr = ""
+##     for line in cTestFile:
+##         cTestStr += line.replace('BUILD_MAIN_PYTEST', config.get_build_temp_dir().replace('temp','lib')+'/parmepy/test/main_unit_tests.py')
+##     cTestFile.close()
+##     cTestFile = open('@CMAKE_CURRENT_BINARY_DIR@/CTestTestfile.cmake','w')
+##     cTestFile.write(cTestStr)
+##     cTestFile.close()
 
diff --git a/HySoP/src/CMakeLists.txt b/HySoP/src/CMakeLists.txt
index 702c3b3db..ab96f8dc6 100644
--- a/HySoP/src/CMakeLists.txt
+++ b/HySoP/src/CMakeLists.txt
@@ -76,6 +76,21 @@ set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/Modules)
 #  Add compilation flags:
 append_Fortran_FLAGS("-Wall -fPIC")
 
+if(USE_MPI)
+  # Find MPI for C++ and fortran.
+  find_package(MPI REQUIRED)
+  # -I
+  include_directories(${MPI_Fortran_INCLUDE_PATH})
+  # Add compilation flags
+  set(${PARMES_LIBRARY_NAME}_LINK_FLAGS ${${PARMES_LIBRARY_NAME}_LINK_FLAGS} ${MPI_Fortran_LINK_FLAGS})
+  # -I
+  # Add compilation flags
+  append_Fortran_flags(${MPI_Fortran_COMPILE_FLAGS})
+  #set(${PARMES_LIBRARY_NAME}_LINK_FLAGS ${${PARMES_LIBRARY_NAME}_LINK_FLAGS} ${MPI_Fortran_LINK_FLAGS})
+  set(LIBS ${LIBS} ${MPI_Fortran_LIBRARIES} )
+endif(USE_MPI)
+
+
 # --- PPM ---
 if(WITH_PPM)
   add_subdirectory(ppmInterface)
@@ -88,14 +103,12 @@ if(WITH_FFTW)
   # for python setup.py
   set(FFTWLIB ${FFTW_LIBRARY} PARENT_SCOPE)
 endif()
+
 # ============= Generates ParmesConfig.hpp =============
 # The file PARMES_LIBRARY_NAME_defines.hpp will be generated from config.hpp.cmake;
 if(EXISTS ${CMAKE_SOURCE_DIR}/config.hpp.cmake)
-  if(NOT CONFIG_H_GLOBAL_CONFIGURED)
-   set(CONFIG_H_GLOBAL_CONFIGURED 1 CACHE BOOL "Parmes_defines.hpp generation." )
-   configure_file(${CMAKE_SOURCE_DIR}/config.hpp.cmake ${PARMES_LIBRARY_NAME}_defines.hpp)
- endif()
- include_directories(${CMAKE_BINARY_DIR})
+  configure_file(${CMAKE_SOURCE_DIR}/config.hpp.cmake ${PARMES_LIBRARY_NAME}_defines.hpp)
+  include_directories(${CMAKE_BINARY_DIR})
 endif()
 
 # ============= Source and header files list =============
diff --git a/HySoP/src/fftw/fft3d.f90 b/HySoP/src/fftw/fft3d.f90
index 5f8ed18c8..0c26cc53d 100755
--- a/HySoP/src/fftw/fft3d.f90
+++ b/HySoP/src/fftw/fft3d.f90
@@ -573,7 +573,6 @@ contains
     do j = 1,local_resolution(c_Y)
        do k = 1, fft_resolution(c_Z)
           do i = 1, local_resolution(c_X)
-             !!coeff = Icmplx/(1. + nudt * kx(i)**2+ky(j)**2+kz(k)**2)
              coeff = Icmplx/(1. + nudt * (kx(i)**2+ky(j)**2+kz(k)**2))
              buffer1 = dataout1(i,k,j)
              buffer2 = dataout2(i,k,j)
-- 
GitLab