cmake src_CSA default -std=legacy
[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 2)
10 set(UNRES_PATCH 1)
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" "+'%D %R:%S'" OUTPUT_VARIABLE ${RESULT})
24         string(REGEX REPLACE "'" ""  ${RESULT} ${${RESULT}})
25         string (STRIP ${${RESULT}} ${RESULT})
26 #        string(TIMESTAMP ${RESULT})
27     ELSE (WIN32)
28         MESSAGE(SEND_ERROR "date not implemented")
29         SET(${RESULT} 000000)
30     ENDIF (WIN32)
31 ENDMACRO (TODAY)
32
33 # foramt variables used in cinfo.f 
34 MACRO (CINFO_FORMAT FN VN VD)
35 # 50 znakowi
36 # 73 w całej linii
37 #        write(iout,*)'INSTALL_DIR = /users/software/mpich-1.2.7p1_int...'
38     string(LENGTH "${VN}" VNLEN)
39     string(LENGTH "${VD}" VDLEN)
40     set(STR "${VN} ${VD}")
41     string(LENGTH "${STR}" SUMA)
42     math(EXPR STRLEN 50-${VNLEN})
43 #    message("lancuch=${STRLEN}") 
44 # Fit in one line?
45 # No.
46     if(SUMA GREATER 50) 
47         string(SUBSTRING "${STR}" 0 50 STR_OUT) 
48 #        message("        write(iout,*)'${VAR} = ${STR_OUT}'") 
49         file(APPEND ${FN} "       write(iout,*)'${STR_OUT}'\n")
50         math(EXPR STRLEN ${SUMA}-50)
51         string(SUBSTRING "${STR}" 50 ${STRLEN} STR)
52         string(LENGTH "${STR}" STRLEN)
53         while(STRLEN GREATER 48)
54 #            message("Przycinam lancuch")
55             string(SUBSTRING "${STR}" 0 48 STR_OUT)  
56             file(APPEND ${FN} "       write(iout,*)'  ${STR_OUT}'\n")
57             math(EXPR STRLEN ${STRLEN}-49)
58             string(SUBSTRING "${STR}" 49 ${STRLEN} STR)
59             string(LENGTH "${STR}" STRLEN)
60         endwhile(STRLEN GREATER 48)   
61         file(APPEND ${FN} "       write(iout,*)'  ${STR}'\n")
62 #        MESSAGE("DLUGOSC = ${VNLEN}; DLUGOSCD = ${VDLEN}; SUMA=${SUMA}; ${VAR} = ${${VAR}} " )
63 # Yes
64     else(SUMA GREATER 50)
65         file(APPEND ${FN} "       write(iout,*)'${STR}'\n")
66     endif(SUMA GREATER 50)
67 ENDMACRO (CINFO_FORMAT)
68
69 # Some MPI wrappers pass double include paths
70 # This macro fixes broken by semicolon occurence in path
71 MACRO (FIX_DBL_INCLUDE RESULT)
72   string(REPLACE ";" " -I" ${RESULT} "${${RESULT}}")
73 ENDMACRO (FIX_DBL_INCLUDE)
74
75 #======================================
76 # CTest stuff
77 #======================================A
78
79 include(CTest)
80 enable_testing()
81  
82
83 #======================================
84 # Fortran compilers stuff
85 #======================================
86 # Get the compiler name
87 get_filename_component (Fortran_COMPILER_NAME ${CMAKE_Fortran_COMPILER} NAME)
88
89 # Altough cmake enables you to set some compiler definitions it seems by default they are ignored.                 
90 # This is a workaround to pass compiler definitions (preprocesor flags) to fortran compilers like ifort
91 SET(CMAKE_Fortran_COMPILE_OBJECT "<CMAKE_Fortran_COMPILER>  ${CMAKE_START_TEMP_FILE} <FLAGS> <DEFINES> -c <SOURCE> -o <OBJECT> ${CMAKE_END_TEMP_FILE}")
92 #set(CPPFLAGS "-DPROCOR -DLINUX -DPGI -DUNRES -DISNAN -DMP -DMPI -DSPLITELE -DLANGO -DCRYST_BOND -DCRYST_THETA -DCRYST_SC" )
93 #add_definitions( ${CPPFLAGS} ) 
94
95    
96 # make sure that the default is a RELEASE
97 if (NOT CMAKE_BUILD_TYPE)
98   set (CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo." FORCE)
99   set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "None" "Debug" "Release" "RelWithDebInfo")
100 endif (NOT CMAKE_BUILD_TYPE)
101
102
103 if (CMAKE_BUILD_TYPE STREQUAL "Release")
104   # Set makefile verbosity off for Release builds
105   set( CMAKE_VERBOSE_MAKEFILE 0 )
106 else()
107   # Set makefile verbosity on for other builds
108   set( CMAKE_VERBOSE_MAKEFILE 1 )
109 endif (CMAKE_BUILD_TYPE STREQUAL "Release")
110
111 # Default Install Path
112
113 set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/bin" CACHE PATH "Binary install directory " FORCE)
114
115 #=======================================  
116 # Set the varous build variables 
117 #=======================================
118
119 # Set force field
120 if (NOT UNRES_FF)
121   set(UNRES_MD_FF "E0LL2Y" CACHE STRING "Choose the force field, options are: GAB E0LL2Y" )
122   set_property(CACHE UNRES_MD_FF PROPERTY STRINGS "GAB" "E0LL2Y")
123 endif (NOT UNRES_FF)
124
125 # Set CSA version force field
126 if (NOT UNRES_CSA_FF)
127   set(UNRES_CSA_FF "E0LL2Y" CACHE STRING "Choose the CSA version force field, options are: CASP3 ALPHA BETA ALPHABETA CASP5 3P 4P" )
128   set_property(CACHE UNRES_CSA_FF PROPERTY STRINGS "CASP3" "ALPHA" "BETA" "ALPHABETA" "CASP5" "3P" "4P" ) 
129 endif (NOT UNRES_CSA_FF)
130
131 # Use of MPI library (default ON)
132 option(UNRES_WITH_MPI "Choose whether or not to use MPI library" ON )
133
134
135 # Piasek cluster devel stuff
136 option(UNRES_NA_MMCE "Kompilujemy na mmmce?" OFF )
137
138 option(UNRES_DFA "Choose whether or not to use DFA" OFF )
139
140 #=================================
141 # MPI stuff
142 #=================================
143
144 # Note for the future - use find package to get MPI 
145 find_package(MPI QUIET)
146
147 if (MPI_Fortran_FOUND)
148   message("MPI found")
149   FIX_DBL_INCLUDE(MPI_Fortran_INCLUDE_PATH)
150 else()
151   message("MPI not found - disabling MPI compile flags ")
152   set ( UNRES_WITH_MPI "OFF")
153 endif(MPI_Fortran_FOUND)        
154
155 #======================================
156 # Detect system architecture
157 #=======================================
158
159 if( CMAKE_SIZEOF_VOID_P EQUAL 4 )
160   set(architektura "32")
161 else (CMAKE_SIZEOF_VOID_P EQUAL 4)
162   set(architektura "64")
163 endif( CMAKE_SIZEOF_VOID_P EQUAL 4 )
164
165 message("Detected ${architektura}-bit architecture")    
166
167 #=======================================
168 # Find other libraries
169 #=======================================
170
171 # used by unres/src_MIN
172 find_package (Threads)
173
174 #=======================================
175 # Add source files
176 #=======================================     
177
178
179 add_subdirectory(source/lib/xdrf)
180
181
182 if(UNRES_NA_MMCE)
183
184   if(UNRES_WITH_MPI)
185     # Brak MPI dla gfortrana, wiec tylko na ifort sie skompiluje
186     if (Fortran_COMPILER_NAME STREQUAL "ifort")
187       add_subdirectory(source/unres/src_MD)
188       add_subdirectory(source/unres/src_MD-M)
189       add_subdirectory(source/unres/src_CSA)
190       add_subdirectory(source/cluster/wham/src)
191       add_subdirectory(source/cluster/wham/src-M)
192     endif (Fortran_COMPILER_NAME STREQUAL "ifort")
193   else()
194     add_subdirectory(source/unres/src_MD)
195     # src_MD-M doesn't work yet witout MPI
196     # add_subdirectory(source/unres/src_MD-M)
197   endif()
198   add_subdirectory(source/unres/src_MIN)
199   add_subdirectory(source/cluster/unres/src)
200   add_subdirectory(source/xdrfpdb/src)
201   add_subdirectory(source/xdrfpdb/src-M)
202 else()
203
204   add_subdirectory(source/unres/src_MD)
205   if(UNRES_WITH_MPI)
206     add_subdirectory(source/unres/src_MD-M)
207     add_subdirectory(source/unres/src_CSA)
208     add_subdirectory(source/wham/src)
209     add_subdirectory(source/wham/src-M)
210     add_subdirectory(source/cluster/wham/src)
211     add_subdirectory(source/cluster/wham/src-M)
212   endif(UNRES_WITH_MPI)
213   add_subdirectory(source/unres/src_MIN)
214   add_subdirectory(source/cluster/unres/src)
215   add_subdirectory(source/xdrfpdb/src)
216   add_subdirectory(source/xdrfpdb/src-M)
217   add_subdirectory(source/unres-dock)
218 endif(UNRES_NA_MMCE)
219