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