Skip to content
Snippets Groups Projects
Commit 16a249b6 authored by Franck Pérignon's avatar Franck Pérignon
Browse files

ppm cmake, suite

parent d03eca80
No related branches found
No related tags found
No related merge requests found
../../CMake
\ No newline at end of file
...@@ -15,12 +15,15 @@ set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMake) ...@@ -15,12 +15,15 @@ set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMake)
# Force out-of-source build # Force out-of-source build
include(OutOfSourceBuild) include(OutOfSourceBuild)
# Some usefull macros # Some usefull macros
include(Tools) include(MyTools)
# User defined options # User defined options
option(VERBOSE_MODE "enable verbose mode for cmake exec" ON) option(VERBOSE_MODE "enable verbose mode for cmake exec" ON)
option(WITH_MPI "enable mpi for ppm_core" ON) option(WITH_MPI "enable mpi for ppm_core" ON)
# default library type
set(BUILD_SHARED_LIBS 1)
# ============= The ppm_core project ============= # ============= The ppm_core project =============
# Set project name and project languages # Set project name and project languages
# => this automatically defines: # => this automatically defines:
...@@ -28,17 +31,15 @@ option(WITH_MPI "enable mpi for ppm_core" ON) ...@@ -28,17 +31,15 @@ option(WITH_MPI "enable mpi for ppm_core" ON)
# - ${PROJECT_NAME}_SOURCE_DIR : where sources (.f and .h and this CMakeLists.txt) are located # - ${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. # Note that because of OutOfSourceBuild, binary_dir and source_dir must be different.
set(PROJECT_NAME ppm_core) set(PROJECT_NAME ppm_core)
project(${PROJECT_NAME} Fortran) project(${PROJECT_NAME} Fortran CXX)
# Set a version number for the project
set(${PROJECT_NAME}_version 1.2)
# set __Linux var in ppm_define.h depending on the OS # set __Linux var in ppm_define.h depending on the OS
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set(__Linux 1) set(__Linux 1)
endif(${CMAKE_SYSTEM_NAME} MATCHES "Linux") endif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
display(CMAKE_SYSTEM_NAME)
display(CMAKE_SYSTEM)
# ============= Prepare compilation ============= # ============= Prepare compilation =============
# Force a default build type if not provided by user # Force a default build type if not provided by user
...@@ -51,16 +52,34 @@ endif (NOT CMAKE_BUILD_TYPE) ...@@ -51,16 +52,34 @@ endif (NOT CMAKE_BUILD_TYPE)
# If the project uses Fortran ... # If the project uses Fortran ...
# Set module files directory (i.e. where .mod will be created) # Set module files directory (i.e. where .mod will be created)
set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/Modules) set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/Modules)
# To add compilation flags: # Add compilation flags:
append_Fortran_FLAGS("-FR -cpp -w") # -free or -ffree-form is required since we compile f90 files that have f ext ...
# To force a specific compiler: include(TestFortranAcceptsFlag)
#set(CMAKE_Fortran_COMPILER mpif90) # Try -ffree-form option (GNU)
CHECK_Fortran_ACCEPTS_FLAG(-ffree-form Fortran_HAVE_ffree_form)
display(Fortran_HAVE_ffree_form)
if(Fortran_HAVE_ffree_form)
set(Fortran_Free_Flag "-ffree-form")
else(Fortran_HAVE_ffree_form)
# Try -free (IFORT)
CHECK_Fortran_ACCEPTS_FLAG(-free Fortran_HAVE_free)
if(Fortran_HAVE_free)
set(Fortran_Free_Flag "-free")
else(Fortran_HAVE_free)
message(FATAL_ERROR "Can not find Fortran compiler free-form flag.")
# No other tests ... todo if we need exotic compilers ...
endif(Fortran_HAVE_free)
endif(Fortran_HAVE_ffree_form)
append_Fortran_FLAGS(${Fortran_Free_Flag})
append_Fortran_FLAGS("-cpp -w")
# -------------------------------------------- # --------------------------------------------
# We search for libraries ppm depends on and # We search for libraries ppm depends on and
# and set the compile/link conf (-I and -L opt) # and set the compile/link conf (-I and -L opt)
# -------------------------------------------- # --------------------------------------------
# Metis # ---- Metis ----
find_package(Metis REQUIRED) find_package(Metis REQUIRED)
# -I # -I
include_directories(${Metis_INCLUDE_DIRS}) include_directories(${Metis_INCLUDE_DIRS})
...@@ -78,17 +97,22 @@ if(Metis_FOUND) ...@@ -78,17 +97,22 @@ if(Metis_FOUND)
set(__METIS 1) set(__METIS 1)
endif(Metis_FOUND) endif(Metis_FOUND)
# MPI # ---- MPI ----
if(WITH_MPI) if(WITH_MPI)
find_package(MPI REQUIRED) find_package(MPI REQUIRED)
# -I find_package(MPI_Fortran REQUIRED)
include_directories(${MPI_INCLUDE_PATH})
# -l if(MPI_Fortran_COMPILER)
set(LIBS ${LIBS} ${MPI_LIBRARIES}) set(CMAKE_Fortran_COMPILER mpif90)
# Add compilatin flags, if required elseif(MPI_Fortran_COMPILER)
append_cxx_flags(${MPI_COMPILE_FLAGS}) # -I
append_Fortran_flags(${MPI_COMPILE_FLAGS}) include_directories(${MPI_Fortran_INCLUDE_PATH})
set(${PROJECT_NAME}_LINK_FLAGS ${${PROJECT_NAME}_LINK_FLAGS} ${MPI_LINK_FLAGS}) # Add compilation flags
append_Fortran_flags(${MPI_Fortran_COMPILE_FLAGS})
set(${PROJECT_NAME}_LINK_FLAGS ${${PROJECT_NAME}_LINK_FLAGS} ${MPI_Fortran_LINK_FLAGS})
endif(MPI_Fortran_COMPILER)
set(LIBS ${LIBS} ${MPI_Fortran_LIBRARIES} )
# for ppm_define.h ... # for ppm_define.h ...
set(__MPI 1) set(__MPI 1)
...@@ -107,12 +131,38 @@ endif(EXISTS ${CMAKE_SOURCE_DIR}/config.h.cmake) ...@@ -107,12 +131,38 @@ endif(EXISTS ${CMAKE_SOURCE_DIR}/config.h.cmake)
# -------------------------------------------- # --------------------------------------------
# We create the ppm_core library # We create the ppm_core library
# -------------------------------------------- # --------------------------------------------
# Source files list: # The list of all dirs containing sources to be compiled for the Parmes lib
file(GLOB ${PROJECT_NAME}_SRC src/ppm_module*.f src/*.h) set(${PROJECT_NAME}_SRCDIRS
# Header files list: src
file(GLOB ${PROJECT_NAME}_HDRS src/*.hpp src/*.h ) )
# Matching expr for files to be compiled.
set(EXTS ppm_module*.f *.h)
set(EXTS_HDRS *.h)
# Note FP : we can also use cmake vars ${CMAKE_Fortran_SOURCE_FILE_EXTENSIONS} ${CMAKE_C_SOURCE_FILE_EXTENSIONS} ${CMAKE_CXX_SOURCE_FILE_EXTENSIONS}
# Source and header files list:
foreach(_DIR ${${PROJECT_NAME}_SRCDIRS})
set(_DIR_FILES)
foreach(_EXT ${EXTS})
file(GLOB _DIR_FILES_EXT ${_DIR}/${_EXT})
if(_DIR_FILES_EXT)
list(APPEND ${PROJECT_NAME}_SRC ${_DIR_FILES_EXT})
endif(_DIR_FILES_EXT)
endforeach(_EXT ${EXTS})
foreach(_EXT ${EXTS_HDRS})
file(GLOB _DIR_FILES_EXT ${_DIR}/${_EXT})
if(_DIR_FILES_EXT)
list(APPEND ${PROJECT_NAME}_HDRS ${_DIR_FILES_EXT})
endif(_DIR_FILES_EXT)
endforeach(_EXT ${EXTS_HDRS})
endforeach(_DIR ${${PROJECT_NAME}_SRCDIRS})
# -I # -I
include_directories(${${PROJECT_NAME}_SOURCE_DIR}/src) include_directories(${${PROJECT_NAME}_SRCDIRS})
include_directories(${CMAKE_Fortran_MODULE_DIRECTORY})
# Create the lib # Create the lib
add_library(${PROJECT_NAME} SHARED ${${PROJECT_NAME}_SRC}) add_library(${PROJECT_NAME} SHARED ${${PROJECT_NAME}_SRC})
...@@ -149,3 +199,4 @@ install(TARGETS ${PROJECT_NAME} ...@@ -149,3 +199,4 @@ install(TARGETS ${PROJECT_NAME}
install(FILES ${${PROJECT_NAME}_HDRS} DESTINATION include) install(FILES ${${PROJECT_NAME}_HDRS} DESTINATION include)
install(DIRECTORY ${CMAKE_BINARY_DIR}/Modules DESTINATION include) install(DIRECTORY ${CMAKE_BINARY_DIR}/Modules DESTINATION include)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment