force linker settings in cmake

This commit is contained in:
Chen Zhang 2016-03-03 16:09:02 -05:00
parent 2cf5225875
commit 57c8213d9b
2 changed files with 31 additions and 41 deletions

View File

@ -81,8 +81,8 @@ execute_process(COMMAND ${MAKE_EXECUTABLE} -f ${petsc_config_makefile} "extlibs"
OUTPUT_VARIABLE petsc_external_lib
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${MAKE_EXECUTABLE} -f ${petsc_config_makefile} "linker"
RESULT_VARIABLE PETSC_LINK_LIB_RETURN
OUTPUT_VARIABLE PETSC_LINK_LIB
RESULT_VARIABLE PETSC_LINKER_RETURN
OUTPUT_VARIABLE PETSC_LINKER
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${MAKE_EXECUTABLE} -f ${petsc_config_makefile} "compiler"
RESULT_VARIABLE MPIEXEC_RETURN
@ -104,17 +104,17 @@ endforeach(exlib)
message("***Found PETSC_DIR:\n${PETSC_DIR}\n")
message("***Set PETSC_INCLUDES to:\n${PETSC_INCLUDES}\n")
message("***Set PETSC_EXTERNAL_LIB to:\n${PETSC_EXTERNAL_LIB}\n")
message("***Set PETSC_LINK_LIB to:\n${PETSC_LINK_LIB}\n")
message("***Use PETSC wrapped compiler:\n${MPIEXEC}\n")
message("***Found PETSC_INCLUDES:\n${PETSC_INCLUDES}\n")
message("***Found PETSC_EXTERNAL_LIB:\n${PETSC_EXTERNAL_LIB}\n")
message("***Found PETSC_LINKER:\n${PETSC_LINKER}\n")
message("***Found PETSC_MPIEXEC:\n${MPIEXEC}\n")
# set include directories
set (DAMASK_INCLUDE_FLAGS "${DAMASK_INCLUDE_FLAGS} ${PETSC_INCLUDES}" )
set (DAMASK_INCLUDE_FLAGS "${DAMASK_INCLUDE_FLAGS} -I${PROJECT_SOURCE_DIR}/lib")
#set (DAMASK_INCLUDE_FLAGS "${DAMASK_INCLUDE_FLAGS} -I${HDF5_DIR}/include -lm" )
# set link libraries from PETSc
set (DAMASK_LINK_FLAGS "${DAMASK_LINK_FLAGS} ${PETSC_LINK_LIB}" )
set (DAMASK_LINK_FLAGS "${DAMASK_LINK_FLAGS} ${PETSC_LINKER}" )
set (DAMASK_LINK_FLAGS "${DAMASK_LINK_FLAGS} ${PETSC_EXTERNAL_LIB}")
#set (DAMASK_LINK_FLAGS "${DAMASK_LINK_FLAGS} -L${HDF5_DIR}/lib" )
@ -375,13 +375,7 @@ set (PRECISION_gfortran "-fdefault-real-8 -fdefault-double-8")
# set FLAGS
get_filename_component (Fortran_COMPILER_NAME ${CMAKE_Fortran_COMPILER} NAME)
# linker from PETSc goes first
#set (CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} ${DAMASK_LINK_FLAGS}" )
#set (CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${DAMASK_LINK_FLAGS}" )
if (Fortran_COMPILER_NAME MATCHES "ifort.*")
# need the PETSC wrapped version of ifort
set (CMAKE_Fortran_COMPILER "${MPIEXEC}")
# for RELEASE
set (CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE} ${OPENMP_FLAG_ifort}" )
set (CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE} ${STANDARD_CHECK_ifort}" )
@ -389,25 +383,17 @@ if (Fortran_COMPILER_NAME MATCHES "ifort.*")
set (CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE} ${COMPILE_OPTIONS_ifort}")
set (CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE} ${PRECISION_ifort}" )
set (CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} ${PETSC_LINK_LIB}" )
set (CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} ${OPENMP_FLAG_ifort}" )
set (CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} ${LINK_OPTIONS_ifort}" )
set (CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} ${OPTIMIZATION_ifort}" )
set (CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} ${STANDARD_CHECK_ifort}")
set (CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} ${PETSC_EXTERNAL_LIB}" )
#set (CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} ${PETSC_EXTERNAL_LIB}" )
# for DEBUG
set (CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} ${CMAKE_Fortran_FLAGS_RELEASE}")
set (CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} ${DEBUG_OPTIONS_ifort}" )
set (CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${PETSC_LINK_LIB}" )
set (CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${OPENMP_FLAG_ifort}" )
set (CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${LINK_OPTIONS_ifort}" )
set (CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${OPTIMIZATION_ifort}" )
set (CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${STANDARD_CHECK_ifort}")
set (CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${PETSC_EXTERNAL_LIB}" )
set (CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${DEBUG_OPTIONS_ifort}" )
set (CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_RELEASE} ${DEBUG_OPTIONS_ifort}" )
#
elseif (Fortran_COMPILER_NAME MATCHES "gfortran.*")
set (CMAKE_Fortran_COMPILER "${MPIEXEC}")
@ -423,15 +409,10 @@ elseif (Fortran_COMPILER_NAME MATCHES "gfortran.*")
set (CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} ${STANDARD_CHECK_gfortran}")
set (CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} ${OPTIMIZATION_gfortran}" )
# for DEBUG
set (CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} ${COMPILE_OPTIONS_gfortran}")
set (CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} ${PRECISION_gfortran}" )
set (CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} ${CMAKE_Fortran_FLAGS_RELEASE}")
set (CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} ${DEBUG_OPTIONS_gfortran}" )
set (CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${OPENMP_FLAG_gfortran}" )
set (CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${LINK_OPTIONS_gfortran}" )
set (CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${STANDARD_CHECK_gfortran}")
set (CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${OPTIMIZATION_gfortran}" )
set (CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${DEBUG_OPTIONS_gfortran}" )
set (CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_RELEASE} ${DEBUG_OPTIONS_gfortran}")
#
elseif (Fortran_COMPILER_NAME MATCHES "g77")
message (FATAL_ERROR "Fortran 77 is not supported.")
@ -439,9 +420,18 @@ else (Fortran_COMPILER_NAME MATCHES "ifort.*")
message (FATAL_ERROR "Require Fortran90 from GNU or Intel.")
endif (Fortran_COMPILER_NAME MATCHES "ifort.*")
# append includes from PETSC at the end
# Finalizing
set (CMAKE_Fortran_COMPILER "${MPIEXEC}")
set (CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE} ${DAMASK_INCLUDE_FLAGS}")
set (CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} ${DAMASK_INCLUDE_FLAGS}")
set (CMAKE_LINKER "${PETSC_LINKER}")
if (CMAKE_BUILD_TYPE STREQUAL "RELEASE")
set (CMAKE_Fortran_LINK_EXECUTABLE
"${CMAKE_LINKER} ${CMAKE_EXE_LINKER_FLAGS_RELEASE} -o <TARGET> ${DAMASK_EXE} ${PETSC_EXTERNAL_LIB}")
else(CMAKE_BUILD_TYPE STREQUAL "RELEASE")
set (CMAKE_Fortran_LINK_EXECUTABLE
"${CMAKE_LINKER} ${CMAKE_EXE_LINKER_FLAGS_DEBUG} <OBJECTS> -o <TARGET> ${PETSC_EXTERNAL_LIB}")
endif(CMAKE_BUILD_TYPE STREQUAL "RELEASE")
message("***COMPILE FLAGS:\n${CMAKE_Fortran_FLAGS_RELEASE}\n")
message("***LINK FLAGS:\n${CMAKE_EXE_LINKER_FLAGS_RELEASE}\n")

View File

@ -142,11 +142,11 @@ if (SPECTRAL)
"spectral_mech_Basic.f90")
target_link_libraries(DAMASK_SPECTRAL_MECH DAMASK_SPECTRAL_UTILITY)
add_library(DAMASK_SPECTRAL_SOLVER "DAMASK_spectral.f90")
target_link_libraries(DAMASK_SPECTRAL_SOLVER DAMASK_CPFE )
target_link_libraries(DAMASK_SPECTRAL_SOLVER DAMASK_SPECTRAL_BASE)
target_link_libraries(DAMASK_SPECTRAL_SOLVER DAMASK_SPECTRAL_MECH)
add_library(DAMASK_EXE "DAMASK_spectral.f90")
target_link_libraries(DAMASK_EXE DAMASK_CPFE )
target_link_libraries(DAMASK_EXE DAMASK_SPECTRAL_BASE)
target_link_libraries(DAMASK_EXE DAMASK_SPECTRAL_MECH)
add_executable(DAMASKSpectral.exe DAMASK_spectral.f90)
target_link_libraries(DAMASKSpectral.exe DAMASK_SPECTRAL_SOLVER)
add_executable(DAMASKSpectral.exe "DAMASK_spectral.f90")
target_link_libraries(DAMASKSpectral.exe DAMASK_EXE)
endif(SPECTRAL)