CMakeLists.txt 9.58 KB
Newer Older
1
2
cmake_minimum_required(VERSION 2.8.12)

Berk Onat's avatar
Berk Onat committed
3
project(molfileplugins)
4

5
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}")
6
7
find_package(EXPAT REQUIRED)
#find_package(TCL)
8
9
include (FindNetCDF.cmake)
set (NETCDF_CXX "YES")
10
11
find_package(NetCDF REQUIRED)
#find_package(NetCDF)
Berk Onat's avatar
Berk Onat committed
12

13
14
15
16
17
18
19
20
21
22
set(TNG_INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/../../external/tng")
message(TNG_DIR= ${TNG_INSTALL_DIR})
#if (EXISTS "${TNG_INSTALL_DIR}/lib/libtng_io.dylib"
#    OR EXISTS "${TNG_INSTALL_DIR}/lib/libtng_io.so"
#    OR EXISTS "${TNG_INSTALL_DIR}/include/tng/tng_io.h")
set(TNGIO_FOUND TRUE)
set(TNGIO_LIBRARIES "${TNG_INSTALL_DIR}/lib/libtng_io.a")
set(TNGIO_LIBRARY_DIRS "${TNG_INSTALL_DIR}/lib/")
set(TNGIO_INCLUDE_DIRS "${TNG_INSTALL_DIR}/include/")
#endif()
23
24
25
26

set(TARGET_ARCH_REGEX "^.*-march[= ]([^ ]+).*$")
string(REGEX MATCH "${TARGET_ARCH_REGEX}" TARGET_ARCH_MATCH "${CMAKE_C_FLAGS}" "${CMAKE_CXX_FLAGS}")
if (TARGET_ARCH_MATCH)
Berk Onat's avatar
Berk Onat committed
27
	string(REGEX REPLACE "${TARGET_ARCH_REGEX}" "\\1" TARGET_ARCH "${CMAKE_C_FLAGS}" "${CMAKE_CXX_FLAGS}")
28
else()
Berk Onat's avatar
Berk Onat committed
29
	set(TARGET_ARCH ${CMAKE_HOST_SYSTEM_PROCESSOR})
30
31
32
33
34
35
endif()
message(TARGET_ARCH= ${TARGET_ARCH})
message(SYS_VER= ${CMAKE_SYSTEM_VERSION})
message(SYS_NAME= ${CMAKE_SYSTEM_NAME})
message(SYS_PROC= ${CMAKE_SYSTEM_PROCESSOR})
message(SYS= ${CMAKE_SYSTEM})
Berk Onat's avatar
Berk Onat committed
36
37
38
39
40
41
      
if(TARGET_ARCH MATCHES "^.*64.*$")
	set(ARCH64BIT TRUE)
endif()

set(LIB_MOLFILE_FILES
42
43
	"${CMAKE_CURRENT_BINARY_DIR}/lib/libmolfile_plugins.a"
	"${CMAKE_CURRENT_BINARY_DIR}/lib/libmolfile_plugins.h")	
Berk Onat's avatar
Berk Onat committed
44
45
46
47
48
49
50
51
52
53
54
55
56
57

if(UNIX AND NOT APPLE)
	set(LINUX TRUE)
endif()

if(WIN32)
   if(MSVS OR MSYS)
      set(WINCOMP TRUE)
   endif()
endif()

if(LINUX)
   if(CMAKE_CXX_COMPILER_ID MATCHES "^.*GNU.*$")
      if(ARCH64BIT)
Berk Onat's avatar
Berk Onat committed
58
59
60
61
62
63
64
65
         set(TARGET_COPT  -fPIC -m64 -o )
         set(TARGET_LOPT  -fPIC -m64 -lstdc++ -o )
	 set(TARGET_CFLAGS  -m64 -O2 -fPIC -Wall )
	 set(TARGET_CXXFLG  -m64 -O2 -fPIC -Wall )
	 #set(TARGET_COPT " -fPIC -m64 -o ")
	 #set(TARGET_LOPT " -fPIC -m64 -lstdc++ -o ")
	 #set(TARGET_CFLAGS " -m64 -O2 -fPIC -Wall ${CMAKE_C_FLAGS}")
	 #set(TARGET_CXXFLG " -m64 -O2 -fPIC -Wall ${CMAKE_CXX_FLAGS}")
Berk Onat's avatar
Berk Onat committed
66
      else()
Berk Onat's avatar
Berk Onat committed
67
68
69
70
         set(TARGET_COPT " -fPIC -m32 -o ")
         set(TARGET_LOPT " -fPIC -m32 -lstdc++ -o ")
	 set(TARGET_CFLAGS " -m32 -O2 -fPIC -Wall ${CMAKE_C_FLAGS}")
	 set(TARGET_CXXFLG " -m32 -O2 -fPIC -Wall ${CMAKE_CXX_FLAGS}")
Berk Onat's avatar
Berk Onat committed
71
72
      endif()
   else()
Berk Onat's avatar
Berk Onat committed
73
74
75
76
         set(TARGET_COPT " -o ")
         set(TARGET_LOPT " -o ")
	 set(TARGET_CFLAGS " -O2 -Wall ${CMAKE_C_FLAGS}")
	 set(TARGET_CXXFLG " -O2 -Wall ${CMAKE_CXX_FLAGS}")
Berk Onat's avatar
Berk Onat committed
77
78
79
80
81
82
83
84
85
86
87
88
   endif()
endif()

if(APPLE)
   if(CMAKE_CXX_COMPILER_ID MATCHES "^.*GNU.*$"
      OR CMAKE_CXX_COMPILER_ID MATCHES "^(Apple)?Clang$") 
      if(ARCH64BIT)
         set(TARGET_COPT -m64;-fPIC;-o)
         set(TARGET_LOPT -m64;-fPIC;-o)
         set(TARGET_CFLAGS -m64;-Os;-Wall;-fPIC;-dynamic;${CMAKE_C_FLAGS})
         set(TARGET_CXXFLG -m64;-Os;-Wall;-fPIC;-dynamic;${CMAKE_CXX_FLAGS})
      else()
89
90
91
92
         set(TARGET_COPT -fPIC;-m32;-o)
         set(TARGET_LOPT -fPIC;-m32;-o)
         set(TARGET_CFLAGS -m32;-Os;-Wall;-fPIC;-dynamic;${CMAKE_C_FLAGS})
         set(TARGET_CXXFLG -m32;-Os;-Wall;-fPIC;-dynamic;${CMAKE_CXX_FLAGS})
Berk Onat's avatar
Berk Onat committed
93
94
      endif()
   else()
95
96
97
98
      set(TARGET_COPT -o)
      set(TARGET_LOPT -o)
      set(TARGET_CFLAGS -O2;-Wall;${CMAKE_C_FLAGS})
      set(TARGET_CXXFLG -O2;-Wall;${CMAKE_CXX_FLAGS})
Berk Onat's avatar
Berk Onat committed
99
100
101
102
103
104
   endif()
endif()

if(UNIX)
   set(TARGET_DEF "-D")
   set(TARGET_SHLD ${CMAKE_CXX_COMPILER} ${CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS})
Berk Onat's avatar
Berk Onat committed
105
106
107
108
109
110
111
   if(APPLE)
      set(TARGET_LIBTOOL libtool;-dynamic)
      set(TARGET_NM ${CMAKE_NM};-p)
   else()
      set(TARGET_LIBTOOL "libtool -dynamic")
      set(TARGET_NM "${CMAKE_NM} -p")
   endif()
Berk Onat's avatar
Berk Onat committed
112
113
114
115
   set(TARGET_AR ${CMAKE_AR})
   set(TARGET_RANLIB ${CMAKE_RANLIB})
   set(TARGET_MOL_LIBS "")
   if(TCL_FOUND)
Berk Onat's avatar
Berk Onat committed
116
117
118
119
120
121
122
123
124
125
126
      if(APPLE)
         set(TCLLDFLAGS -ltcl;-L${TCL_LIBRARY})
         set(TCLINC "-I${TCL_INCLUDE_PATH}")
         set(TCLLIB "-L${TCL_LIBRARY}")
         set(TARGET_MOL_LIBS ${TARGET_MOL_LIBS} \"TCLLDFLAGS=${TCLLDFLAGS}\";\"TCLINC=${TCLINC}\";\"TCLLIB=${TCLLIB}\";)
      else()
         set(TCLLDFLAGS "-ltcl -L${TCL_LIBRARY}")
         set(TCLINC "-I${TCL_INCLUDE_PATH}")
         set(TCLLIB "-L${TCL_LIBRARY}")
         set(TARGET_MOL_LIBS ${TARGET_MOL_LIBS} "\"TCLLDFLAGS=${TCLLDFLAGS}\" \"TCLINC=${TCLINC}\" \"TCLLIB=${TCLLIB}\"")
      endif()
127
      message(TCL_FOUND= ${TCL_LIBRARY})
Berk Onat's avatar
Berk Onat committed
128
129
   endif()
   if(EXPAT_FOUND)
Berk Onat's avatar
Berk Onat committed
130
131
132
133
134
135
136
137
138
139
140
      if(APPLE)
         set(EXPATLDFLAGS ${EXPAT_LIBRARIES})
         set(EXPATINC "-I${EXPAT_INCLUDE_DIRS}")
         set(EXPATLIB "-I${EXPAT_INCLUDE_DIRS}")
         set(TARGET_MOL_LIBS ${TARGET_MOL_LIBS} \"EXPATLDFLAGS=${EXPATLDFLAGS}\";\"EXPATINC=${EXPATINC}\";\"EXPATLIB=${EXPATLIB}\";)
      else()
         set(EXPATLDFLAGS ${EXPAT_LIBRARIES})
         set(EXPATINC "-I${EXPAT_INCLUDE_DIRS}")
         set(EXPATLIB "-I${EXPAT_INCLUDE_DIRS}")
         set(TARGET_MOL_LIBS ${TARGET_MOL_LIBS} \"EXPATLDFLAGS=${EXPATLDFLAGS}\" \"EXPATINC=${EXPATINC}\" \"EXPATLIB=${EXPATLIB}\")
      endif()
141
      message(EXPAT_FOUND= ${EXPAT_LIBRARIES})
Berk Onat's avatar
Berk Onat committed
142
143
   endif()
   if(NETCDF_FOUND)
Berk Onat's avatar
Berk Onat committed
144
145
146
147
148
149
150
151
152
153
154
      if(APPLE)
         set(NETCDFLDFLAGS ${NETCDF_LIBRARIES})
         set(NETCDFINC "-I${NETCDF_INCLUDES}")
         set(NETCDFLIB "-L${NETCDF_INCLUDES}")
         set(TARGET_MOL_LIBS ${TARGET_MOL_LIBS} \"NETCDFLDFLAGS=${NETCDFLDFLAGS}\";\"NETCDFINC=${NETCDFINC}\";\"NETCDFLIB=${NETCDFLIB}\";)
      else()
         set(NETCDFLDFLAGS ${NETCDF_LIBRARIES})
         set(NETCDFINC "-I${NETCDF_INCLUDES}")
         set(NETCDFLIB "-L${NETCDF_INCLUDES}")
         set(TARGET_MOL_LIBS ${TARGET_MOL_LIBS} \"NETCDFLDFLAGS=${NETCDFLDFLAGS}\" \"NETCDFINC=${NETCDFINC}\" \"NETCDFLIB=${NETCDFLIB}\")
      endif()
155
156
      message(NETCDF_FOUND= ${NETCDF_LIBRARIES})
      message(NETCDF_FOUND= ${NETCDF_INCLUDES})
Berk Onat's avatar
Berk Onat committed
157
158
   endif()
   if(TNGIO_FOUND)
Berk Onat's avatar
Berk Onat committed
159
160
161
162
163
164
165
166
167
168
169
      if(APPLE)
         set(TNGIOLDFLAGS ${TNGIO_LIBRARIES})
         set(TNGIOINC "-I${TNGIO_INCLUDE_DIRS}")
         set(TNGIOLIB "-L${TNGIO_LIBRARY_DIRS}")
         set(TARGET_MOL_LIBS ${TARGET_MOL_LIBS} \"TNGLDFLAGS=${TNGIOLDFLAGS}\";\"TNGINC=${TNGIOINC}\";\"TNGLIB=${TNGIOLIB}\";)
      else()
         set(TNGIOLDFLAGS ${TNGIO_LIBRARIES})
         set(TNGIOINC "-I${TNGIO_INCLUDE_DIRS}")
         set(TNGIOLIB "-L${TNGIO_LIBRARY_DIRS}")
         set(TARGET_MOL_LIBS ${TARGET_MOL_LIBS} \"TNGLDFLAGS=${TNGIOLDFLAGS}\" \"TNGINC=${TNGIOINC}\" \"TNGLIB=${TNGIOLIB}\")
      endif()
170
      message(TNGIO_FOUND= ${TNGIO_LIBRARIES})
Berk Onat's avatar
Berk Onat committed
171
   endif()
Berk Onat's avatar
Berk Onat committed
172
   message(MAKE_COMMAND= "make dynlibs staticlibs bins \"ARCH = ${TARGET_ARCH}\" \"COPTO = ${TARGET_COPT} \" \"LOPTO = ${TARGET_LOPT} \" \"CC = ${CMAKE_C_COMPILER} \" \"CXX =     ${CMAKE_CXX_COMPILER} \" \"DEF = ${TARGET_DEF}\" \"CCFLAGS = ${TARGET_CFLAGS} \" \"CXXFLAGS = ${TARGET_CXXFLG} \" \"AR = ${TARGET_AR}\" \"NM = ${TARGET_NM}\" \"RANLIB = ${TARGET_RANLIB}\" \"LIBTOOL = ${TARGET_LIBTOOL} \" ${TARGET_MOL_LIBS}")
Berk Onat's avatar
Berk Onat committed
173
174
175
   add_custom_command( 
      OUTPUT ${LIB_MOLFILE_FILES}
      COMMAND make dynlibs staticlibs bins \"ARCH = ${TARGET_ARCH}\" \"COPTO = ${TARGET_COPT} \" \"LOPTO = ${TARGET_LOPT} \" \"CC = ${CMAKE_C_COMPILER} \" \"CXX = ${CMAKE_CXX_COMPILER} \" \"DEF = ${TARGET_DEF}\" \"CCFLAGS = ${TARGET_CFLAGS} \" \"CXXFLAGS = ${TARGET_CXXFLG} \" \"AR = ${TARGET_AR}\" \"NM = ${TARGET_NM}\" \"RANLIB = ${TARGET_RANLIB}\" \"LIBTOOL = ${TARGET_LIBTOOL} \" ${TARGET_MOL_LIBS}
176
177
      COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/molfile_plugins/compile/lib ${CMAKE_CURRENT_BINARY_DIR}/lib
      COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_SOURCE_DIR}/molfile_plugins/compile/lib 
Berk Onat's avatar
Berk Onat committed
178
      COMMENT "Compiling libmolfile_plugin.a"
Berk Onat's avatar
Berk Onat committed
179
      WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/molfile_plugins/molfile_plugin"
Berk Onat's avatar
Berk Onat committed
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
   ) 
endif()

if(WINCOMP)
   set(TARGET_DEF "/D")
   set(TARGET_AR "${CMAKE_AR}")
   set(TARGET_NM "${CMAKE_NM} -p")
   set(TARGET_RANLIB "${CMAKE_RANLIB}")
   set(TARGET_MOL_LIBS "")
   set(TARGET_SHLDFLAGS "/D\"VMDPLUGIN_EXPORTS\"")
   if(MSVS)
      set(MYMAKE nmake)
   else()
      set(MYMAKE make)
   endif()
   if(ARCH64BIT)
      set(TARGET_SHLD "\"link /DLL /nologo /incremental:no kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib wsock32.lib /MACHINE:X64 /OPT:REF\"")
      set(TARGET_MOL_SETTINGS "\"CC = cl.exe /nologo /MT /DWIN64\"" "\"CXX = cl.exe /nologo /MT /TP /DWIN64\"" "\"CCFLAGS =  /EHsc /Wp64 /wd4996 /O2 /D\\\"_CRT_SECURE_NO_DEPRECATE\\\"\"" "\"CXXFLAGS = /EHsc /Wp64 /wd4996 /O2 /D\\\"_CRT_SECURE_NO_DEPRECATE\\\"\"")
   else()
      set(TARGET_SHLD "\"link /DLL /nologo /incremental:no kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib wsock32.lib /OPT:REF\"")
      set(TARGET_MOL_SETTINGS "\"CC = cl.exe /nologo /MT /DWIN32\"" "\"CXX = cl.exe /nologo /MT /TP /DWIN32\"" "\"CCFLAGS = /O2 /G5\"" "\"CXXFLAGS = /O2 /G5\"")
   endif()
   add_custom_command( 
      OUTPUT ${LIB_MOLFILE_FILES}
      COMMAND ${MYMAKE} dynlibs win32staticlibs "\" ARCH = ${TARGET_ARCH} \"" "\" COPTO = /Fo \"" "\" LOPTO = /OUT: \"" "\" ${TARGET_MOL_SETTINGS} \"" "\" DEF = ${TARGET_DEF} \"" "\" AR = ${TARGET_AR} \"" "\" NM = ${TARGET_NM} \"" "\" RANLIB = ${TARGET_RANLIB} \"" "\" SHLDFLAGS = ${TARGET_SHLDFLAGS} \"" "\"${TARGET_MOL_LIBS}\""
205
206
      COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/molfile_plugins/compile/lib ${CMAKE_CURRENT_BINARY_DIR}/molfile_plugins/compile/lib
      COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_SOURCE_DIR}/molfile_plugins/compile/lib 
Berk Onat's avatar
Berk Onat committed
207
      COMMENT "Compiling libmolfile_plugin.a"
Berk Onat's avatar
Berk Onat committed
208
      WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/molfile_plugins/molfile_plugin"
Berk Onat's avatar
Berk Onat committed
209
210
211
212
213
   ) 
endif()

add_custom_target(molfile_plugins_comp ALL
    DEPENDS ${LIB_MOLFILE_FILES}
214
)
Berk Onat's avatar
Berk Onat committed
215
216


217