<div dir="auto">Hello,<div dir="auto"><br></div><div dir="auto">You could also concatenate words with gfortran preprocessor using :</div><div dir="auto"><br></div><div dir="auto">#define PASTE(a) a</div><div dir="auto">#define CONCAT(a,b) PASTE(a)b<br></div><div dir="auto"><br></div><div dir="auto">My two cents,</div><div dir="auto"><br></div><div dir="auto">XL</div></div><div class="gmail_extra"><br><div class="gmail_quote">Le 27 juin 2017 4:01 AM, "Juan E. Sanchez" <<a href="mailto:juan.e.sanchez@gmail.com">juan.e.sanchez@gmail.com</a>> a écrit :<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Burlen,<br>
<br>
Thanks for your response, it inspired me to do something similar.<br>
<br>
Starting with the non-processed files, I used the code below.  It also seems to track the mod file dependencies correctly, but I need to thoroughly test it.<br>
<br>
Note that I had to use the cpp command with brew (on mac os x) to concatenate the tokens without spaces.  The linux cpp at work should also be able to handle the traditional-cpp required.<br>
<br>
Regards,<br>
<br>
Juan<br>
<br>
<br>
PROJECT(foo)<br>
ENABLE_LANGUAGE(CXX Fortran)<br>
<br>
SET(TFILES foo baz)<br>
<br>
SET(FFILES "")<br>
FOREACH(I ${TFILES})<br>
  SET(THISFILE ${I}_double.F)<br>
ADD_CUSTOM_COMMAND (<br>
  OUTPUT ${CMAKE_SOURCE_DIR}/${THISFILE<wbr>}<br>
  WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}<br>
  COMMAND /usr/local/bin/cpp-7<br>
  ARGS    -traditional-cpp -P ${I}.F > ${THISFILE}<br>
  DEPENDS ${I}.F<br>
)<br>
LIST(APPEND FFILES ${THISFILE})<br>
ENDFOREACH(I)<br>
<br>
ADD_LIBRARY(flib ${FFILES})<br>
SET_SOURCE_FILES_PROPERTIES(${<wbr>FFILES} PROPERTIES GENERATED TRUE)<br>
MESSAGE(INFO ${FFILES})<br>
<br>
<br>
ADD_EXECUTABLE(main main.cc)<br>
TARGET_LINK_LIBRARIES(main flib)<br>
<br>
<br>
On 6/26/17 6:06 PM, Burlen Loring wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Juan,<br>
<br>
I have faced similar challenges when calling Fortran code from C++ templates.<br>
<br>
In the solution I came up with, I use a marked up Fortran template code and Cmake's configure_file command to generate a module for each combination of C++ types I need. The markup uses a token for each template argument and a decorator that is appended to Fortran symbols and is used in the module and file names to differentiate all of the CMake generated instantiations.<br>
<br>
here is the relevant Cmake code that does all the work, (note: I have two template arguments one for coordinates and variables):<br>
<br>
    set(teca_alg_f90_srcs)<br>
<br>
    set(teca_alg_f90_generics<br>
         gfdl_spline<br>
         gfdl_tc_candidates<br>
         )<br>
<br>
    set(f_type real)<br>
    set(c_types float double)<br>
    foreach(generic_src ${teca_alg_f90_generics})<br>
         foreach(c_type_var ${c_types})<br>
             set(iso_c_type_var "${f_type}(c_${c_type_var})")<br>
             string(SUBSTRING ${c_type_var} 0 1 var_name)<br>
             foreach(c_type_coord ${c_types})<br>
                 string(SUBSTRING ${c_type_coord} 0 1 coord_name)<br>
                 set(decorator "c${coord_name}_v${var_name}")<br>
                 set(iso_c_type_coord "${f_type}(c_${c_type_coord})"<wbr>)<br>
                 configure_file(${generic_src}<wbr>.<a href="http://f90.in" rel="noreferrer" target="_blank">f90.in</a><br>
    ${generic_src}_${decorator}.f9<wbr>0 @ONLY)<br>
                 list(APPEND teca_alg_f90_srcs<br>
    ${generic_src}_${decorator}.f9<wbr>0)<br>
             endforeach()<br>
         endforeach()<br>
    endforeach()<br>
<br>
    add_library(teca_alg ${teca_alg_cxx_srcs} ${teca_alg_f90_srcs})<br>
<br>
And here is a link to an example marked up Fortran template code.<br>
<br>
    <a href="https://github.com/LBL-EESA/TECA/blob/master/alg/gfdl_tc_candidates.f90.in" rel="noreferrer" target="_blank">https://github.com/LBL-EESA/TE<wbr>CA/blob/master/alg/gfdl_tc_can<wbr>didates.f90.in</a><br>
<br>
 From C++ I use macros to declare decorated Fortran functions and define C++ overloads that call them.<br>
<br>
    <a href="https://github.com/LBL-EESA/TECA/blob/master/alg/gfdl_tc_candidates.h" rel="noreferrer" target="_blank">https://github.com/LBL-EESA/TE<wbr>CA/blob/master/alg/gfdl_tc_can<wbr>didates.h</a><br>
<br>
It's a bit of a heavy handed solution, but I think you can solve your problem in a similar way. I'm interested in hearing of other approaches that have worked.<br>
<br>
Burlen<br>
<br>
<br>
On 06/26/2017 01:40 PM, Juan E. Sanchez wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi,<br>
<br>
It seems like cmake cannot handle the case where the module name is the result of a macro.  I am using this approach to compile the same code for different floating point precision.  Any advice appreciated.  This approach would apply to hundreds of files.<br>
<br>
The error is:<br>
Error copying Fortran module "concat".  Tried "CONCAT.mod" and "concat.mod".<br>
make[2]: *** [CMakeFiles/flib.dir/<a href="http://baz.o.pro">baz.o.pro</a><wbr>vides.build] Error 1<br>
make[1]: *** [CMakeFiles/flib.dir/all] Error 2<br>
make: *** [all] Error 2<br>
<br>
<br>
Regards,<br>
<br>
Juan<br>
<br>
<br>
baz.F:<br>
#include "fmacros.inc"<br>
<br>
      module CONCAT(baz)<br>
      contains<br>
      subroutine car(t3)<br>
      end subroutine<br>
      end module CONCAT(baz)<br>
<br>
foo.F:<br>
#include "fmacros.inc"<br>
<br>
      module CONCAT(foo)<br>
      contains<br>
      subroutine bar(t1, t2)<br>
      use CONCAT(baz)<br>
      implicit none<br>
      REAL(kind=8) t1<br>
      REAL(kind=DWIDTH) t2<br>
      call baz(t2)<br>
      end subroutine<br>
      end module CONCAT(foo)<br>
<br>
fmacros.inc:<br>
<br>
#define CONCAT(a) a/**/_double<br>
#define DWIDTH 8<br>
<br>
main.cc:<br>
extern "C" {<br>
void<br>
}<br>
<br>
CMakeLists.txt:<br>
<br>
PROJECT(foo)<br>
ENABLE_LANGUAGE(CXX Fortran)<br>
<br>
ADD_LIBRARY(flib foo.F baz.F)<br>
<br>
<br>
<br>
</blockquote>
<br>
</blockquote>
<br>
-- <br>
<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" rel="noreferrer" target="_blank">http://www.cmake.org/Wiki/CMak<wbr>e_FAQ</a><br>
<br>
Kitware offers various services to support the CMake community. For more information on each offering, please visit:<br>
<br>
CMake Support: <a href="http://cmake.org/cmake/help/support.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/su<wbr>pport.html</a><br>
CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/co<wbr>nsulting.html</a><br>
CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/tr<wbr>aining.html</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensou<wbr>rce/opensource.html</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/cmake" rel="noreferrer" target="_blank">http://public.kitware.com/mail<wbr>man/listinfo/cmake</a><br>
</blockquote></div></div>