unres
[unres.git] / CMakeLists.txt
1 #
2 # CMake project file for UNRES 
3 #
4 cmake_minimum_required(VERSION 2.8)
5    
6 project(UNRESPACK Fortran C)
7
8 set(UNRES_MAJOR 3)
9 set(UNRES_MINOR 1)
10 set(UNRES_PATCH 0)
11 set(UNRES_VERSION ${UNRES_MAJOR}.${UNRES_MINOR}.${UNRES_PATCH})
12
13 #======================================
14 # MACROS
15 #======================================
16
17 # Get system date
18 MACRO (TODAY RESULT)
19     IF (WIN32)
20         EXECUTE_PROCESS(COMMAND "date" "/T" OUTPUT_VARIABLE ${RESULT})
21         string(REGEX REPLACE "(..)/(..)/..(..).*" "\\3\\2\\1" ${RESULT} ${${RESULT}})
22     ELSEIF(UNIX)
23         EXECUTE_PROCESS(COMMAND "date" OUTPUT_VARIABLE ${RESULT})
24         string(REGEX REPLACE "(...) (...) (.+) (..:..:..) (.+) (....).*" "\\1 \\2 \\3 \\4 \\5 \\6" ${RESULT} ${${RESULT}})
25     ELSE (WIN32)
26         MESSAGE(SEND_ERROR "date not implemented")
27         SET(${RESULT} 000000)
28     ENDIF (WIN32)
29 ENDMACRO (TODAY)
30
31 # foramt variables used in cinfo.f 
32 MACRO (CINFO_FORMAT FN VN VD)
33 # 50 znakowi
34 # 73 w całej linii
35 #        write(iout,*)'INSTALL_DIR = /users/software/mpich-1.2.7p1_int...'
36     string(LENGTH "${VN}" VNLEN)
37     string(LENGTH "${VD}" VDLEN)
38     set(STR "${VN} ${VD}")
39     string(LENGTH "${STR}" SUMA)
40     math(EXPR STRLEN 50-${VNLEN})
41 #    message("lancuch=${STRLEN}") 
42 # Fit in one line?
43 # No.
44     if(SUMA GREATER 50) 
45         string(SUBSTRING "${STR}" 0 50 STR_OUT) 
46 #        message("        write(iout,*)'${VAR} = ${STR_OUT}'") 
47         file(APPEND ${FN} "       write(iout,*)'${STR_OUT}'\n")
48         math(EXPR STRLEN ${SUMA}-50)
49         string(SUBSTRING "${STR}" 50 ${STRLEN} STR)
50         string(LENGTH "${STR}" STRLEN)
51         while(STRLEN GREATER 48)
52 #            message("Przycinam lancuch")
53             string(SUBSTRING "${STR}" 0 48 STR_OUT)  
54             file(APPEND ${FN} "       write(iout,*)'  ${STR_OUT}'\n")
55             math(EXPR STRLEN ${STRLEN}-49)
56             string(SUBSTRING "${STR}" 49 ${STRLEN} STR)
57             string(LENGTH "${STR}" STRLEN)
58         endwhile(STRLEN GREATER 48)   
59         file(APPEND ${FN} "       write(iout,*)'  ${STR}'\n")
60 #        MESSAGE("DLUGOSC = ${VNLEN}; DLUGOSCD = ${VDLEN}; SUMA=${SUMA}; ${VAR} = ${${VAR}} " )
61 # Yes
62     else(SUMA GREATER 50)
63         file(APPEND ${FN} "       write(iout,*)'${STR}'\n")
64     endif(SUMA GREATER 50)
65 ENDMACRO (CINFO_FORMAT)
66 #======================================
67 # CTest stuff
68 #======================================A
69
70 include(CTest)
71 enable_testing()
72  
73 # Set makefile verbose on
74 set( CMAKE_VERBOSE_MAKEFILE 1 )
75
76 #======================================
77 # Fortran compilers stuff
78 #======================================
79 # Get the compiler name
80 get_filename_component (Fortran_COMPILER_NAME ${CMAKE_Fortran_COMPILER} NAME)
81
82 # Altough cmake enables you to set some compiler definitions it seems by default they are ignored.                 
83 # This is a workaround to pass compiler definitions (preprocesor flags) to fortran compilers like ifort
84 SET(CMAKE_Fortran_COMPILE_OBJECT "<CMAKE_Fortran_COMPILER>  ${CMAKE_START_TEMP_FILE} <FLAGS> <DEFINES> -c <SOURCE> -o <OBJECT> ${CMAKE_END_TEMP_FILE}")
85 #set(CPPFLAGS "-DPROCOR -DLINUX -DPGI -DUNRES -DISNAN -DMP -DMPI -DSPLITELE -DLANGO -DCRYST_BOND -DCRYST_THETA -DCRYST_SC" )
86 #add_definitions( ${CPPFLAGS} ) 
87
88    
89 # make sure that the default is a RELEASE
90 if (NOT CMAKE_BUILD_TYPE)
91   set (CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: None Debug Release." FORCE)
92   set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "None" "Debug" "Release" )
93 endif (NOT CMAKE_BUILD_TYPE)
94    
95 #=======================================  
96 # Set the varous build variables 
97 #=======================================
98
99 # Set force field
100 if (NOT UNRES_FF)
101   set(UNRES_MD_FF "GAB" CACHE STRING "Choose the force field, options are: GAB E0LL2Y" )
102   set_property(CACHE UNRES_MD_FF PROPERTY STRINGS "GAB" "E0LL2Y")
103 endif (NOT UNRES_FF)
104
105 # Set CSA version force field
106 if (NOT UNRES_CSA_FF)
107   set(UNRES_CSA_FF "4P" CACHE STRING "Choose the CSA version force field, options are: CASP3 ALPHA BETA ALPHABETA CASP5 3P 4P" )
108   set_property(CACHE UNRES_CSA_FF PROPERTY STRINGS "CASP3" "ALPHA" "BETA" "ALPHABETA" "CASP5" "3P" "4P" ) 
109 endif (NOT UNRES_CSA_FF)
110
111 # Use of MPI library (default ON)
112 option(UNRES_WITH_MPI "Choose whether or not to use MPI library" ON )
113
114
115 # Piasek cluster devel stuff
116 option(UNRES_NA_MMCE "Kompilujemy na mmmce?" OFF )
117
118
119 #=================================
120 # MPI stuff
121 #=================================
122
123 # Note for the future - use finde package to get MPI 
124 find_package(MPI)
125
126 #if(MPI_LIBRARY)
127
128 #MPI_INCLUDE_PATH
129
130
131 if(MPIF_LOCAL_DIR)
132   find_library(MPIF_LIBRARY NAMES libmpich.a  NO_DEFAULT_PATH  PATHS  ${MPIF_LOCAL_DIR}/lib)
133   find_path( MPIF_INCLUDE_DIRECTORIES  NAMES mpif.h  NO_DEFAULT_PATH  PATHS  ${MPIF_LOCAL_DIR}/include  )
134 else(MPIF_LOCAL_DIR)
135   find_library(MPIF_LIBRARY NAMES mpi mpich PATHS 
136         ${MPI_LIBRARY}
137         ${MPI_LIBRARY}/../
138         ${MPI_EXTRA_LIBRARY}
139         /users/local/mpi64/mpich-1.2.7p1/lib 
140         /usr/lib
141         /usr/local/lib
142         /usr/local/mpi/lib
143   )
144   find_path( MPIF_INCLUDE_DIRECTORIES NAMES  mpif.h PATHS
145         ${MPI_INCLUDE_PATH}
146         /users/local/mpi64/mpich-1.2.7p1/include
147         /usr/include
148         /usr/local/include   
149         /usr/include/mpi
150         /usr/local/mpi/include
151   )
152 endif(MPIF_LOCAL_DIR)
153
154 set( MPIF_LIBRARIES  ${MPIF_LIBRARY})
155
156 if ( MPIF_INCLUDE_DIRECTORIES )
157   set( MPIF_FOUND TRUE )
158   message("MPI found")
159 else ( MPIF_INCLUDE_DIRECTORIES )
160   set( MPIF_FOUND FALSE )
161   message("MPI not found - disabling MPI compile flags ")
162   set ( UNRES_WITH_MPI "OFF")
163 endif ( MPIF_INCLUDE_DIRECTORIES )
164
165 if (MPIF_FOUND)
166   message("MPIF_LIBRARIES=${MPIF_LIBRARY}")
167   message("MPIF_INCLUDE_DIRECTORIES=${MPIF_INCLUDE_DIRECTORIES}" )
168 endif(MPIF_FOUND) 
169
170
171
172 #======================================
173 # Detect system architecture
174 #=======================================
175
176 if( CMAKE_SIZEOF_VOID_P EQUAL 4 )
177   set(architektura "32")
178 else (CMAKE_SIZEOF_VOID_P EQUAL 4)
179   set(architektura "64")
180 endif( CMAKE_SIZEOF_VOID_P EQUAL 4 )
181
182 message("Detected ${architektura}-bit architecture")    
183
184 #=======================================
185 # Find other libraries
186 #=======================================
187
188 # used by unres/src_MIN
189 find_package (Threads)
190
191
192
193 #=======================================
194 #  Create diractories for build targets
195 #=======================================
196 #execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/bin/unres/MD )
197
198 #=======================================
199 # Add source files
200 #=======================================     
201
202
203 add_subdirectory(source/lib/xdrf)
204
205
206 if(UNRES_NA_MMCE)
207
208   if(UNRES_WITH_MPI)
209     # Brak MPI dla gfortrana, wiec tylko na ifort sie skompiluje
210     if (Fortran_COMPILER_NAME STREQUAL "ifort")
211       add_subdirectory(source/unres/src_MD)
212       add_subdirectory(source/unres/src_MD_DFA)
213       add_subdirectory(source/unres/src_MD-M)
214       add_subdirectory(source/unres/src_CSA)
215       add_subdirectory(source/unres/src_CSA_DiL)
216       add_subdirectory(source/cluster/wham/src)
217       add_subdirectory(source/cluster/wham/src-M)
218     endif (Fortran_COMPILER_NAME STREQUAL "ifort")
219   else()
220     add_subdirectory(source/unres/src_MD)
221     # src_MD-M doesn't work yet witout MPI
222     # add_subdirectory(source/unres/src_MD-M)
223   endif()
224   add_subdirectory(source/unres/src_MIN)
225   add_subdirectory(source/cluster/unres/src)
226   add_subdirectory(source/xdrfpdb/src)
227   add_subdirectory(source/xdrfpdb/src-M)
228   add_subdirectory(source/maxlik/src_CSA)
229 else()
230
231   add_subdirectory(source/unres/src_MD)
232   if(UNRES_WITH_MPI)
233     add_subdirectory(source/unres/src_MD-M)
234     add_subdirectory(source/unres/src_MD_DFA)
235     add_subdirectory(source/unres/src_CSA)
236     add_subdirectory(source/unres/src_CSA_DiL)
237     add_subdirectory(source/wham/src)
238     add_subdirectory(source/wham/src-M)
239     add_subdirectory(source/cluster/wham/src)
240     add_subdirectory(source/cluster/wham/src-M)
241   endif(UNRES_WITH_MPI)
242   add_subdirectory(source/unres/src_MIN)
243   add_subdirectory(source/cluster/unres/src)
244   add_subdirectory(source/xdrfpdb/src)
245   add_subdirectory(source/xdrfpdb/src-M)
246   add_subdirectory(source/maxlik/src_CSA)
247 endif(UNRES_NA_MMCE)
248