CMakeLists.txt 6.46 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
cmake_minimum_required(VERSION 2.8.12)

project(molfileplugins)

find_package(EXPAT)
find_package(NetCDF)
find_package(TCL)

set(TARGET_ARCH_REGEX "^.*-march[= ]([^ ]+).*$")
string(REGEX MATCH "${TARGET_ARCH_REGEX}" TARGET_ARCH_MATCH "${CMAKE_C_FLAGS}" "${CMAKE_CXX_FLAGS}")
if (TARGET_ARCH_MATCH)
	string(REGEX REPLACE "${TARGET_ARCH_REGEX}" "\\1" TARGET_ARCH "${CMAKE_C_FLAGS}" "${CMAKE_CXX_FLAGS}")
else()
	set(TARGET_ARCH ${CMAKE_HOST_SYSTEM_PROCESSOR})
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})
      
if(TARGET_ARCH MATCHES "^.*64.*$")
	set(ARCH64BIT TRUE)
endif()

set(LIB_MOLFILE_FILES
    "${CMAKE_CURRENT_BINARY_DIR}/lib/libmolfile_plugins.a"
    "${CMAKE_CURRENT_BINARY_DIR}/lib/libmolfile_plugins.h")

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)
         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}")
      else()
         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}")
      endif()
   else()
         set(TARGET_COPT "-o ")
         set(TARGET_LOPT "-o ")
	 set(TARGET_CFLAGS "-O2 -Wall " "${CMAKE_C_FLAGS}")
	 set(TARGET_CXXFLG "-O2 -Wall " "${CMAKE_CXX_FLAGS}")
   endif()
endif()

if(APPLE)
   if(CMAKE_CXX_COMPILER_ID MATCHES "^.*GNU.*$"
      OR CMAKE_CXX_COMPILER_ID MATCHES "^(Apple)?Clang$") 
      if(ARCH64BIT)
         set(TARGET_COPT " -fPIC -m64 -o ")
         set(TARGET_LOPT " -fPIC -m64 -o ")
	 set(TARGET_CFLAGS " -m64 -Os -Wall -fPIC -dynamic " "${CMAKE_C_FLAGS}")
	 set(TARGET_CXXFLG " -m64 -Os -Wall -fPIC -dynamic " "${CMAKE_CXX_FLAGS}")
      else()
         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}")
      endif()
   else()
      set(TARGET_COPT " -o ")
      set(TARGET_LOPT " -o ")
      set(TARGET_CFLAGS " -O2 -Wall " "${CMAKE_C_FLAGS}")
      set(TARGET_CXXFLG " -O2 -Wall " "${CMAKE_CXX_FLAGS}")
   endif()
endif()

if(UNIX)
   set(TARGET_DEF "-D")
   set(TARGET_SHLD "${CMAKE_CXX_COMPILER}" "${CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS}")
   set(TARGET_LIBTOOL "libtool -dynamic")
   set(TARGET_AR "${CMAKE_AR}")
   set(TARGET_NM "${CMAKE_NM} -p")
   set(TARGET_RANLIB "${CMAKE_RANLIB}")
   set(TARGET_MOL_LIBS "")
   if(TCL_FOUND)
      set(TCLLDFLAGS "-l${TCL_LIBRARY}")
      set(TCLINC "-I${TCL_INCLUDE_PATH}")
      set(TCLLIB "-I${TCL_INCLUDE_PATH}")
      set(TARGET_MOL_LIBS "${TARGET_MOL_LIBS}" "TCLLDFLAGS = ${TCLLDFLAGS}" "TCLINC = ${TCLINC}" "TCLLIB = ${TCLLIB}")
   endif()
   if(EXPAT_FOUND)
      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()
   if(NETCDF_FOUND)
      set(NETCDFLDFLAGS "${NETCDF_LIBRARY}")
      set(NETCDFINC "-I${NETCDF_INCLUDE_DIRS}")
      set(NETCDFLIB "-I${NETCDF_INCLUDE_DIRS}")
      set(TARGET_MOL_LIBS "${TARGET_MOL_LIBS}" "NETCDFLDFLAGS = ${NETCDFLDFLAGS}" "NETCDFINC = ${NETCDFINC}" "NETCDFLIB = ${NETCDFLIB}")
   endif()
   message(MOL_C= "${CMAKE_C_COMPILER}")
   message(MOL_CXX= "${CMAKE_CXX_COMPILER}")
   message(MOL_CFLAGS= "${CMAKE_C_FLAGS}")
   message(MOL_CXXFLAGS= "${CMAKE_CXX_FLAGS}")
   add_custom_command( 
      OUTPUT ${LIB_MOLFILE_FILES}
      COMMAND make dynlibs staticlibs "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}"
      COMMENT "Compiling libmolfile_plugin.a"
      WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../molfile_plugin"
   ) 
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}\""
      COMMENT "Compiling libmolfile_plugin.a"
      WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../molfile_plugin"
   ) 
endif()

add_custom_target(molfile_plugins_comp ALL
    DEPENDS ${LIB_MOLFILE_FILES}
)

add_library(molfile_plugins INTERFACE)

target_include_directories(molfile_plugins INTERFACE "${CMAKE_CURRENT_BINARY_DIR}/lib/") 
target_link_libraries(molfile_plugins INTERFACE ${MOLFILE_LIBRARIES})

#add_dependencies(molfile_plugin_comp)