Hi,
I have some home-grown software that I am trying to compile using CMake. I have included the CMakeLists.txt file below. First let me summarize. The main code I am compiling is calling invA11.f. It uses two subroutine files called invA11_subs.f and pts_subs.f. It also uses two modules. The first is called compile_info.F90, which contains variables identifying the program version, host, and the computer on which the code was compiled (these values are set with pre-processing). The second module is called inv_dims.F90. This module is also pre-processed, and defines the array dimensions of the main variables in the invA11.f program.
I need to have several different versions of this program with different Memory footprints, so I have pre-processor statements in inv_dims.F90 that select different preset memory dimenions depending on the pre-processor -D flag. The array dimension is then included in the name of the executable (ie, invA11_1.5b instead of just invA11).
The current CMakeLists file generates a copy of the inv_dims.F90 file for each desired memory dimension (is copied to inv_dims_M1p5b.F90 for example), then each executable is compiled. The main program invA11.f writes out a summary of the compile date/time, host, version, and memory dimensions as it begins to run.
The CMakeLists.txt file half works. After running cmake, I can then run "make". This compiles all the software without any problems. I can run the executables, and the summary each one displays (array dimensions) correctly reflects the executable name.
The Problem: after running "make", I then run "make install". Rather than just checking each target is built, it remakes all the targets, then installs them in the selected bin dir. However, all the of executables now have the array dimesions of the last target compiled. For example, the versions compiled previously using inv_dims_M1p5b.F90 and inv_dims_M4p0b.F90 now appear to have been compiled using inv_dims_M6p2b.F90. I don't understand where this problem is coming from, because if I don't run "make install", and just "make", then everything is compiled correctly. Any insight would be greatly appreciated. This is my first CMake project, so I'm learning it at the same time.
EDIT: One further point. Every time I run make, despite whether I made any changes to source code or not, I get warnings about modification times of Makefiles being 3000 seconds in the future. Both CMAKE and Make are run on the same computer within 1 minute of each other. Also, some further detail on how it fails compiling.
The following sequence results in executables that do not have the correct dimensions:
make
make install
However, this sequene is ok:
make
make clean
make install
It seems that it fails if there are any files left over from the previous compilation.
Thanks!
------------------------ CMakeLists.txt ----------------------------
Code:
PROJECT(Inv Fortran)
cmake_minimum_required(VERSION 2.6)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
set(CMAKE_BUILD_TYPE "Release")
#-- set install directory
if(NOT ${PREFIX})
set(CMAKE_INSTALL_PREFIX "${PREFIX}")
else(NOT ${PREFIX})
set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_BINARY_DIR}")
endif(NOT ${PREFIX})
#-- Determine Compilation Date/time
EXECUTE_PROCESS(COMMAND date +%d-%b-%Y_%H:%M
TIMEOUT 5
RESULT_VARIABLE DATE_RES
OUTPUT_VARIABLE DATETIME
ERROR_VARIABLE DATE_ERR
OUTPUT_STRIP_TRAILING_WHITESPACE)
#-- Determine Host
EXECUTE_PROCESS(COMMAND hostname
TIMEOUT 5
RESULT_VARIABLE HOST_RES
OUTPUT_VARIABLE HOSTCOMP
ERROR_VARIABLE HOST_ERR
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REGEX REPLACE "\\.[a-zA-Z0-9]*" "" HOSTCOMP "${HOSTCOMP}")
#-- Version Info
set(VERSION_MAJOR "3")
set(VERSION_MINOR "0")
set(VERSION_PATCH "1")
#-- Code Description
set(DESCRITION "Inv Main Codes")
#-- Generate copies of module file that initializes the dimensions of the main variables of invA11.f
set(MemSetInt4 M1p5b M2p1b M3p4b M3p7b M4p0b M5p0b M6p2b)
foreach(mem ${MemSetInt4})
ADD_CUSTOM_COMMAND(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/inv_dims_${mem}.F90
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/include/inv_dims.F90 ${CMAKE_CURRENT_BINARY_DIR}/inv_dims_${mem}.F90
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/include/inv_dims.F90
)
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/inv_dims_${mem}.F90 PROPERTIES COMPILE_FLAGS "-D${mem} -fno-range-check")
endforeach(mem ${MemSetInt4})
#-------------------------------------------------------------#
#-- set source file compile flags
set_source_files_properties(invA11.f include/invA11_subs.f include/pts_subs.f PROPERTIES COMPILE_FLAGS "-mcmodel=large -fno-automatic -finit-local-zero -frecord-marker=8")
set_source_files_properties(compile_info.F90 PROPERTIES COMPILE_FLAGS "-D__CVERSION=\\\"${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}\\\" -D__CDATETIME=\\\"${DATETIME}\\\" -D__CHOST=\\\"${HOSTCOMP}\\\" ")
#-------------------------------------------------------------#
#-------------------------------------------------------------#
#-- Inversions
set(MemSetInt4Triton M1p5b M2p1b M3p4b M3p7b M4p0b)
foreach(MemSet ${MemSetInt4Triton})
string(REGEX REPLACE "^M" "" exectag "${MemSet}")
string(REGEX REPLACE "p" "." exectag "${exectag}")
add_executable(invA11_${exectag} ${CMAKE_CURRENT_BINARY_DIR}/inv_dims_${MemSet}.F90 compile_info.F90 include/invA11_subs.f include/pts_subs.f invA11.f)
install(TARGETS invA11_${exectag} RUNTIME DESTINATION bin)
endforeach(MemSet ${MemSetInt4Triton})