From 16a249b64d3d9e97b38fb6725b768b6d0f3f50e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franck=20P=C3=A9rignon?= <franck.perignon@imag.fr> Date: Mon, 21 Mar 2011 15:18:05 +0000 Subject: [PATCH] ppm cmake, suite --- CMake-for-ppm/Core/CMake | 1 + CMake-for-ppm/Core/CMakeLists.txt | 101 ++++++++++++++++++++++-------- 2 files changed, 77 insertions(+), 25 deletions(-) create mode 120000 CMake-for-ppm/Core/CMake diff --git a/CMake-for-ppm/Core/CMake b/CMake-for-ppm/Core/CMake new file mode 120000 index 000000000..af160f912 --- /dev/null +++ b/CMake-for-ppm/Core/CMake @@ -0,0 +1 @@ +../../CMake \ No newline at end of file diff --git a/CMake-for-ppm/Core/CMakeLists.txt b/CMake-for-ppm/Core/CMakeLists.txt index 013ed0295..de1f3dafa 100644 --- a/CMake-for-ppm/Core/CMakeLists.txt +++ b/CMake-for-ppm/Core/CMakeLists.txt @@ -15,12 +15,15 @@ set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMake) # Force out-of-source build include(OutOfSourceBuild) # Some usefull macros -include(Tools) +include(MyTools) # User defined options option(VERBOSE_MODE "enable verbose mode for cmake exec" ON) option(WITH_MPI "enable mpi for ppm_core" ON) +# default library type +set(BUILD_SHARED_LIBS 1) + # ============= The ppm_core project ============= # Set project name and project languages # => this automatically defines: @@ -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 # Note that because of OutOfSourceBuild, binary_dir and source_dir must be different. 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 if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") set(__Linux 1) endif(${CMAKE_SYSTEM_NAME} MATCHES "Linux") -display(CMAKE_SYSTEM_NAME) -display(CMAKE_SYSTEM) - # ============= Prepare compilation ============= # Force a default build type if not provided by user @@ -51,16 +52,34 @@ endif (NOT CMAKE_BUILD_TYPE) # If the project uses Fortran ... # Set module files directory (i.e. where .mod will be created) set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/Modules) -# To add compilation flags: -append_Fortran_FLAGS("-FR -cpp -w") -# To force a specific compiler: -#set(CMAKE_Fortran_COMPILER mpif90) +# Add compilation flags: +# -free or -ffree-form is required since we compile f90 files that have f ext ... +include(TestFortranAcceptsFlag) +# 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 # and set the compile/link conf (-I and -L opt) # -------------------------------------------- -# Metis +# ---- Metis ---- find_package(Metis REQUIRED) # -I include_directories(${Metis_INCLUDE_DIRS}) @@ -78,17 +97,22 @@ if(Metis_FOUND) set(__METIS 1) endif(Metis_FOUND) -# MPI +# ---- MPI ---- if(WITH_MPI) find_package(MPI REQUIRED) - # -I - include_directories(${MPI_INCLUDE_PATH}) - # -l - set(LIBS ${LIBS} ${MPI_LIBRARIES}) - # Add compilatin flags, if required - append_cxx_flags(${MPI_COMPILE_FLAGS}) - append_Fortran_flags(${MPI_COMPILE_FLAGS}) - set(${PROJECT_NAME}_LINK_FLAGS ${${PROJECT_NAME}_LINK_FLAGS} ${MPI_LINK_FLAGS}) + find_package(MPI_Fortran REQUIRED) + + if(MPI_Fortran_COMPILER) + set(CMAKE_Fortran_COMPILER mpif90) + elseif(MPI_Fortran_COMPILER) + # -I + include_directories(${MPI_Fortran_INCLUDE_PATH}) + # 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 ... set(__MPI 1) @@ -107,12 +131,38 @@ endif(EXISTS ${CMAKE_SOURCE_DIR}/config.h.cmake) # -------------------------------------------- # We create the ppm_core library # -------------------------------------------- -# Source files list: -file(GLOB ${PROJECT_NAME}_SRC src/ppm_module*.f src/*.h) -# Header files list: -file(GLOB ${PROJECT_NAME}_HDRS src/*.hpp src/*.h ) +# The list of all dirs containing sources to be compiled for the Parmes lib +set(${PROJECT_NAME}_SRCDIRS +src +) + +# 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 -include_directories(${${PROJECT_NAME}_SOURCE_DIR}/src) +include_directories(${${PROJECT_NAME}_SRCDIRS}) +include_directories(${CMAKE_Fortran_MODULE_DIRECTORY}) + # Create the lib add_library(${PROJECT_NAME} SHARED ${${PROJECT_NAME}_SRC}) @@ -149,3 +199,4 @@ install(TARGETS ${PROJECT_NAME} install(FILES ${${PROJECT_NAME}_HDRS} DESTINATION include) install(DIRECTORY ${CMAKE_BINARY_DIR}/Modules DESTINATION include) + -- GitLab