Lisandro Dalcin avatar Lisandro Dalcin committed a1ecdcd

Add initial support for CMake

Comments (0)

Files changed (2)

+cmake_minimum_required (VERSION 2.6.2)
+project (PetIGA C)
+
+if (0)
+  # Use Jed Brown's FindPETSc.cmake
+  set (CMAKE_MODULE_PATH ${PetIGA_SOURCE_DIR}/conf/cmake)
+  find_package (PETSc)
+else ()
+  find_path (PETSC_DIR include/petsc.h HINTS ENV PETSC_DIR DOC "PETSc Directory")
+  set (PETSC_ARCH $ENV{PETSC_ARCH})
+  find_path (PETSC_INCLUDE_DIR  petsc.h HINTS "${PETSC_DIR}" PATH_SUFFIXES include NO_DEFAULT_PATH)
+  find_path (PETSC_INCLUDE_CONF petscconf.h HINTS "${PETSC_DIR}" PATH_SUFFIXES "${PETSC_ARCH}/include" NO_DEFAULT_PATH)
+  mark_as_advanced (PETSC_INCLUDE_DIR PETSC_INCLUDE_CONF)
+  set (PETSC_INCLUDES ${PETSC_INCLUDE_CONF} ${PETSC_INCLUDE_DIR} CACHE PATH "PETSc include paths" FORCE)
+  set (PETSC_DEFINITIONS "-D__INSDIR__=" CACHE STRING "PETSc preprocesor definitions" FORCE)
+  find_path (PETSC_LIB_DIR NAMES "" HINTS "${PETSC_DIR}" PATH_SUFFIXES "${PETSC_ARCH}/lib" NO_DEFAULT_PATH)
+  find_library (PETSC_LIBRARY NAMES petsc HINTS "${PETSC_LIB_DIR}" NO_DEFAULT_PATH)
+  set (PETSC_LIBRARIES ${PETSC_LIBRARY} CACHE FILEPATH "PETSc library" FORCE)
+  include (${PETSC_DIR}/${PETSC_ARCH}/conf/PETScConfig.cmake)
+endif()
+
+#set (BUILD_SHARED_LIBS NO)
+
+enable_language (Fortran)
+
+include_directories (${PETSC_INCLUDES} ${PETSC_PACKAGE_INCLUDES} "${PetIGA_SOURCE_DIR}/include")
+add_definitions (${PETSC_DEFINITIONS})
+
+set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PetIGA_BINARY_DIR}/lib" CACHE PATH "Output directory for PetIGA archives")
+set (CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PetIGA_BINARY_DIR}/lib" CACHE PATH "Output directory for PetIGA libraries")
+set (CMAKE_Fortran_MODULE_DIRECTORY "${PetIGA_BINARY_DIR}/include" CACHE PATH "Output directory for fortran *.mod files")
+mark_as_advanced (CMAKE_ARCHIVE_OUTPUT_DIRECTORY CMAKE_LIBRARY_OUTPUT_DIRECTORY CMAKE_Fortran_MODULE_DIRECTORY)
+set (CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
+set (CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
+
+file (GLOB PetIGA_SOURCES_C RELATIVE ${PetIGA_SOURCE_DIR} ${PetIGA_SOURCE_DIR}/src/*.c)
+file (GLOB PetIGA_SOURCES_F RELATIVE ${PetIGA_SOURCE_DIR} ${PetIGA_SOURCE_DIR}/src/*.f90)
+set  (PetIGA_SOURCES_ALL ${PetIGA_SOURCES_C} ${PetIGA_SOURCES_F})
+
+add_library (petiga ${PetIGA_SOURCES_ALL})
+target_link_libraries (petiga ${PETSC_LIBRARIES} ${PETSC_PACKAGE_LIBS})
+
+#if (BUILD_SHARED_LIBS)
+#  add_library (petiga-static STATIC ${PetIGA_SOURCES_ALL})
+#  set_target_properties (petiga-static PROPERTIES OUTPUT_NAME "petiga")
+#  set_target_properties (petiga-static PROPERTIES PREFIX "lib")
+#endif()
 	@${OMAKE} chkpetsc_dir  PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} PETIGA_DIR=${PETIGA_DIR}
 	@${OMAKE} chkpetiga_dir PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} PETIGA_DIR=${PETIGA_DIR}
 	@${OMAKE} all-legacy    PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} PETIGA_DIR=${PETIGA_DIR}
+cmake_cc=-DCMAKE_C_COMPILER:FILEPATH=${PCC}  -DCMAKE_C_FLAGS:STRING='${PETSCFLAGS} ${CPP_FLAGS} ${CPPFLAGS}'
+cmake_fc=-DCMAKE_Fortran_COMPILER:FILEPATH=${FC} -DCMAKE_Fortran_FLAGS:STRING='${PETSCFLAGS} ${FPP_FLAGS} ${FPPFLAGS}'
+${PETIGA_DIR}/${PETSC_ARCH}/CMakeCache.txt:
+	@${MKDIR} ${PETIGA_DIR}/${PETSC_ARCH}/conf
+	@cd ${PETIGA_DIR}/${PETSC_ARCH} && ${CMAKE} ${PETIGA_DIR} ${cmake_cc} ${cmake_fc} 2>&1 > ${PETIGA_DIR}/${PETSC_ARCH}/conf/cmake.log
+all-cmake: ${PETIGA_DIR}/${PETSC_ARCH}/CMakeCache.txt
+	@cd ${PETIGA_DIR}/${PETSC_ARCH} && ${OMAKE} -j ${MAKE_NP} 2>&1 | tee ${PETIGA_DIR}/${PETSC_ARCH}/conf/make.log
 all-legacy:
 	-@${MKDIR} ${PETSC_ARCH}/conf
-	-@${MKDIR} ${PETSC_ARCH}/include
-	-@${MKDIR} ${PETSC_ARCH}/lib
+	-@${MKDIR} ${PETSC_ARCH}/include ${PETSC_ARCH}/lib
 	-@${OMAKE} all_build PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} PETIGA_DIR=${PETIGA_DIR} 2>&1 | tee ./${PETSC_ARCH}/conf/make.log
 all_build: chk_petsc_dir chk_petiga_dir chklib_dir deletelibs deletemods build sharedlibs
-.PHONY: all all-legacy all_build
+.PHONY: all all-cmake all-legacy all_build
 
 #
 # Check if PETSC_DIR variable specified is valid
 build:
 	-@echo "========================================="
 	-@echo "Building PetIGA"
+	-@echo "Using PETIGA_DIR=${PETIGA_DIR}"
 	-@echo "Using PETSC_DIR=${PETSC_DIR}"
 	-@echo "Using PETSC_ARCH=${PETSC_ARCH}"
 	-@echo "========================================="
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.