CMakeLists.txt 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. # -*- coding: utf-8; mode: cmake -*-
  2. # global CMakeLists.txt
  3. # (c) lloda@sarc.name 2019
  4. # This library is free software; you can redistribute it and/or modify it under
  5. # the terms of the GNU Lesser General Public License as published by the Free
  6. # Software Foundation; either version 3 of the License, or (at your option) any
  7. # later version.
  8. # -------------------
  9. # readme
  10. # -------------------
  11. # cd build && FFLAGS=-O3 cmake -DCMAKE_INSTALL_PREFIX=./install .. && VERBOSE=1 make && make test && cmake
  12. # -------------------
  13. # prologue
  14. # -------------------
  15. project (prop_618)
  16. enable_language (Fortran C)
  17. cmake_minimum_required (VERSION 3.5)
  18. set (CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
  19. include_directories (${CMAKE_SOURCE_DIR}/mod)
  20. set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/config)
  21. # -------------------
  22. # body
  23. # -------------------
  24. set (BASE_FFLAGS "-std=f2018 -fopenmp -fdiagnostics-color=always -Wall -Werror \
  25. -fdefault-real-8 -fbounds-check -fimplicit-none -ffpe-summary=invalid,overflow,zero")
  26. set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${BASE_FFLAGS} $ENV{FFLAGS}")
  27. set (BASE_CLAGS " -std=c17 -fopenmp -fdiagnostics-color=always -Wall -Werror")
  28. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${BASE_CFLAGS} $ENV{CFLAGS}")
  29. set (LINK_FLAGS "-fopenmp $ENV{LINKFLAGS}")
  30. include (GNUInstallDirs)
  31. set (PROP_DATADIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/prop-618/")
  32. set (PROP_TEST_DATADIR "${CMAKE_SOURCE_DIR}/data/")
  33. configure_file (src/config.f90.in config.f90)
  34. add_library (prop SHARED src/prop.f90 config.f90)
  35. add_library (atmospheres SHARED src/atmospheres.f90 config.f90)
  36. # -------------------
  37. # bindings
  38. # -------------------
  39. # If Guile isn't available, will rely on committed bindings in mod/.
  40. find_package (Guile)
  41. if (GUILE_EXECUTABLE)
  42. add_custom_target (bindings ALL)
  43. foreach (libname atmospheres prop)
  44. set (source "${CMAKE_SOURCE_DIR}/src/${libname}.f90")
  45. set (generator "${CMAKE_SOURCE_DIR}/config/protos.scm")
  46. set (bindc "${CMAKE_SOURCE_DIR}/mod/${libname}.h")
  47. set (bindpython "${CMAKE_SOURCE_DIR}/mod/prop_618/${libname}.py")
  48. set (bindguile "${CMAKE_SOURCE_DIR}/mod/prop-618/${libname}.scm")
  49. foreach (dest ${bindc} ${bindpython} ${bindguile})
  50. get_filename_component (dest_as_target ${dest} NAME)
  51. add_custom_target (${dest_as_target}
  52. DEPENDS ${source} ${generator}
  53. COMMAND ${GUILE_EXECUTABLE} -s ${generator} ${libname} ${dest} ${source}
  54. BYPRODUCTS ${dest}
  55. COMMENT "Generating binding file ${dest}"
  56. VERBATIM)
  57. add_dependencies (bindings ${dest_as_target})
  58. endforeach ()
  59. endforeach ()
  60. endif ()
  61. # -------------------
  62. # tests
  63. # -------------------
  64. # Fortran, this has the functional tests.
  65. foreach (target test-0)
  66. add_executable (${target} "test/${target}.f90")
  67. target_link_libraries (${target} prop atmospheres)
  68. add_test (${target} ${target})
  69. endforeach ()
  70. # C, just the headers.
  71. foreach (target test-1)
  72. add_executable (${target} "test/${target}.c"
  73. ${CMAKE_SOURCE_DIR}/mod/atmospheres.h
  74. ${CMAKE_SOURCE_DIR}/mod/prop.h)
  75. target_link_libraries (${target} prop atmospheres)
  76. add_test (${target} ${target})
  77. endforeach ()
  78. # Python, just the bindings.
  79. find_package (Python3)
  80. if (Python3_FOUND)
  81. foreach (target test-2)
  82. # FIXME Would like a way to make these depend on mod/*.py
  83. add_test (${target} ${Python3_EXECUTABLE} "${CMAKE_SOURCE_DIR}/test/${target}.py")
  84. set_tests_properties (${target} PROPERTIES ENVIRONMENT
  85. "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/;PYTHONPATH=${CMAKE_SOURCE_DIR}/mod")
  86. endforeach ()
  87. endif ()
  88. # Guile, just test the bindings.
  89. if (GUILE_EXECUTABLE)
  90. foreach (target test-3)
  91. # FIXME Would like a way to make these depend on mod/*.py
  92. add_test (${target} ${GUILE_EXECUTABLE} -q -L "${CMAKE_SOURCE_DIR}/mod" "${CMAKE_SOURCE_DIR}/test/${target}.scm")
  93. set_tests_properties (${target} PROPERTIES ENVIRONMENT
  94. "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}")
  95. endforeach ()
  96. endif ()
  97. # -------------------
  98. # documentation
  99. # -------------------
  100. # add_subdirectory (docs)
  101. # -------------------
  102. # install
  103. # -------------------
  104. install (DIRECTORY "${CMAKE_SOURCE_DIR}/data/"
  105. DESTINATION "${CMAKE_INSTALL_DATADIR}/prop-618")
  106. foreach (module prop atmospheres)
  107. install (TARGETS ${module}
  108. DESTINATION lib)
  109. install (FILES "${CMAKE_CURRENT_BINARY_DIR}/${module}.mod"
  110. DESTINATION include)
  111. install (FILES "${CMAKE_SOURCE_DIR}/mod/${module}.h"
  112. DESTINATION include)
  113. endforeach ()
  114. if (GUILE_FOUND)
  115. foreach (module prop atmospheres)
  116. install (FILES "${CMAKE_SOURCE_DIR}/mod/prop-618/${module}.scm"
  117. DESTINATION "${CMAKE_INSTALL_DATADIR}/guile/site/prop-618")
  118. endforeach ()
  119. endif ()
  120. if (Python3_FOUND)
  121. execute_process(
  122. COMMAND "${Python3_EXECUTABLE}" -c "if True:
  123. from distutils import sysconfig as sc
  124. print(sc.get_python_lib(prefix='', plat_specific=True))"
  125. OUTPUT_VARIABLE Python3_SITE
  126. OUTPUT_STRIP_TRAILING_WHITESPACE)
  127. message ("* Python3 install site: ${Python3_SITE}")
  128. foreach (module prop atmospheres)
  129. install(FILES "${CMAKE_SOURCE_DIR}/mod/prop_618/${module}.py"
  130. DESTINATION "${Python3_SITE}/prop_618") # FIXME maybe I should just change this
  131. endforeach ()
  132. endif ()
  133. # -------------------
  134. # epilogue
  135. # -------------------
  136. enable_testing ()
  137. message ("* Current build type is: ${CMAKE_BUILD_TYPE}")
  138. message ("* Crosscompiling is: ${CMAKE_CROSSCOMPILING}")
  139. message ("* C compiler is: ${CMAKE_C_COMPILER}")
  140. message ("* C flags are: ${CMAKE_C_FLAGS}")
  141. message ("* C++ compiler is: ${CMAKE_CXX_COMPILER}")
  142. message ("* C++ flags are: ${CMAKE_CXX_FLAGS}")
  143. message ("* Fortran compiler is: ${CMAKE_Fortran_COMPILER}")
  144. message ("* Fortran_FLAGS are: ${CMAKE_Fortran_FLAGS}")
  145. message ("* Current binary dir is: ${CMAKE_BINARY_DIR}")
  146. message ("* Install prefix is: ${CMAKE_INSTALL_PREFIX}")