CMakeLists.txt 8.67 KB
Newer Older
1
project(Xdmf)
Ken Leiter (Civ's avatar
Ken Leiter (Civ committed
2
3
4
cmake_minimum_required(VERSION 2.6)

set(BUILD_SHARED_LIBS true)
5
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
6
7
8
9
SET(CMAKE_SKIP_BUILD_RPATH  FALSE)
SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) 
SET(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib)
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
10
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
11
12
set(CMAKE_MODULE_PATH 
	${CMAKE_SOURCE_DIR}/CMake
Brian Panneton's avatar
Brian Panneton committed
13
14
	${CMAKE_SOURCE_DIR}/CMake/TestingSuite
	${CMAKE_SOURCE_DIR}/CMake/VersionSuite
15
) 
Ken Leiter (Civ's avatar
Ken Leiter (Civ committed
16

17
18
19
20
21
22
# Should we build with documentation
option(XDMF_BUILD_DOCUMENTATION OFF)
if(XDMF_BUILD_DOCUMENTATION)
	add_subdirectory(doc)
endif(XDMF_BUILD_DOCUMENTATION)

23
24
25
26
27
28
option(XDMF_BUILD_TESTING ON)
if(XDMF_BUILD_TESTING)
    enable_testing()
    include(CTest)
endif(XDMF_BUILD_TESTING)

29
30
31
32
33
34
35
36
# Wrapper Setup
option(XDMF_WRAP_PYTHON OFF)
option(XDMF_WRAP_JAVA OFF)

# If we are wrapping either, we need swig
if(XDMF_WRAP_PYTHON OR XDMF_WRAP_JAVA)
	find_package(SWIG REQUIRED)
	include(${SWIG_USE_FILE})
37
38
39
	if(${SWIG_VERSION} LESS 2.0.0)
		message(SEND_ERROR "Swig must be version 2.0.0 or greater")
	endif(${SWIG_VERSION} LESS 2.0.0)
40
    set(XDMF_SWIG_EXECUTABLE ${SWIG_EXECUTABLE})
41
42
43
44
endif(XDMF_WRAP_PYTHON OR XDMF_WRAP_JAVA)

# If we are wrapping python, let's include it in the top level
if(XDMF_WRAP_PYTHON)
45
	find_package(PythonInterp REQUIRED)
46
47
	find_package(PythonLibs REQUIRED)
	include_directories(${PYTHON_INCLUDE_DIRS})
48
    set(XDMF_PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE})
49
    set(XDMF_PYTHON_LIBRARIES ${PYTHON_LIBRARIES})
50
51
    set(XDMF_PYTHON_INCLUDE_DIRS ${PYTHON_INCLUDE_DIRS})
 
52
53
54
	# A macro to swig and create the python files
	# Since we essentually do the same thing inside and outside core, it
	# would be easier as a macro
55
56
57
58
59
	# Parameters:
	#	python_name = the name of the intended target to be wrapped
	#	${ARGN} = any dependencies needed by the target
	# Output:
	#	Target Name = the output target name will have ${python_name} as its name
60
61
	MACRO(XDMF_SWIG_PYTHON python_name)
		set(CMAKE_SWIG_OUTDIR ${CMAKE_BINARY_DIR})
62
		set(CMAKE_SWIG_FLAGS "")
63
		set_source_files_properties(${python_name}.i PROPERTIES CPLUSPLUS ON)
64
        set(swig_extra_generated_files "")
65
66
		swig_add_module(${python_name} python ${python_name}.i)
		swig_link_libraries(${python_name} ${python_name} ${PYTHON_LIBRARIES})
67
68
69
70
		set_property(DIRECTORY APPEND PROPERTY
			ADDITIONAL_MAKE_CLEAN_FILES
			${CMAKE_BINARY_DIR}/${python_name}.pyc
		)	
71
72
73
		if("${ARGN}" STRGREATER "")
			add_dependencies(${python_name} "${ARGN}")
		endif("${ARGN}" STRGREATER "")
74
75
76
77
78
79
80
81
82
83

        if(WIN32)
            set_target_properties(${SWIG_MODULE_${python_name}_REAL_NAME}
PROPERTIES 
                    PREFIX ../
                    RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
                    LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
                    ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
            )
        endif(WIN32)
84
85
86
87
    
        string(TOUPPER ${python_name} python_name_upper)
        set(${python_name_upper}_PYTHON_CONFIG
                ${CMAKE_INSTALL_PREFIX}/lib/python/${python_name}.py)
88
89
90
91
		install(FILES ${CMAKE_BINARY_DIR}/${python_name}.py 
                DESTINATION lib/python)
		install(TARGETS ${SWIG_MODULE_${python_name}_REAL_NAME} 
                DESTINATION lib/python)
92
93
94
95
96
97
98
99
100
	ENDMACRO(XDMF_SWIG_PYTHON)
endif(XDMF_WRAP_PYTHON)

# If we are wrapping java, let's include it in the top level
if(XDMF_WRAP_JAVA)
	find_package(Java REQUIRED)
	find_package(JNI REQUIRED)
	include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${JAVA_INCLUDE_PATH} ${JAVA_INCLUDE_PATH2})

101
102
    set(XDMF_JAVA_INCLUDE_PATH ${JAVA_INCLUDE_PATH})
    set(XDMF_JAVA_INCLUDE_PATH2 ${JAVA_INCLUDE_PATH2})
103
    set(XDMF_JAVA_RUNTIME ${JAVA_RUNTIME})
104
105
106
    set(XDMF_JAVA_COMPILE ${JAVA_COMPILE})
    set(XDMF_JAVA_ARCHIVE ${JAVA_ARCHIVE})

107
108
109
	# A macro to swig and create the jar files
	# Since we essentually do the same thing inside and outside core, it
	# would be easier as a macro
110
111
112
113
114
115
	# Parameters:
	#	java_name = the name of the intended target to be wrapped
	#	${ARGN} = any dependencies needed by the target
	# Output:
	#	Target Name	= the output target name will have ${java_name}Java as its name
	#	Target Jar	= the output target jar will have ${java_name}Java.jar as its name
116
	MACRO(XDMF_SWIG_JAVA java_name)
117
118
		set(${java_name}_JAVA_JAR ${CMAKE_BINARY_DIR}/${java_name}.jar)
        set(XDMF_JAVA_PACKAGE_DIR mil/army/arl/xdmf)
119
		set(XDMF_JAVA_DIR ${CMAKE_CURRENT_BINARY_DIR}/${XDMF_JAVA_PACKAGE_DIR})
120
121
122
		set(CMAKE_SWIG_OUTDIR ${XDMF_JAVA_DIR})
		set(CMAKE_SWIG_FLAGS -v -make_default -package mil.army.arl.xdmf)
		set_source_files_properties(${java_name}.i PROPERTIES CPLUSPLUS ON)
123
        set(swig_extra_generated_files "")
124
		swig_add_module(${java_name}Java java ${java_name}.i)
125
		swig_link_libraries(${java_name}Java ${java_name})	
126
127
128
129
130
131
132
133
134

        if(WIN32)
            set_target_properties(${SWIG_MODULE_${java_name}Java_REAL_NAME} 
                PROPERTIES 
                    PREFIX ../
                    RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
                    LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
                    ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
            )
135
            set(java_compile_args -cp "${CMAKE_BINARY_DIR}/*.jar" *.java)
136
137
            set(java_dest "bin")
        else(WIN32)
138
            set(java_compile_args -cp "${CMAKE_BINARY_DIR}/*.jar" ${XDMF_JAVA_DIR}/*.java)
139
140
141
            set(java_dest "lib/java")
        endif(WIN32)

142
143
144
145
146
147
148
149
        add_custom_target(${java_name}_Java_Dir ALL DEPENDS 
                            ${XDMF_JAVA_DIR})
        add_custom_command(OUTPUT ${XDMF_JAVA_DIR}
            COMMAND ${CMAKE_COMMAND} -E make_directory ${XDMF_JAVA_DIR}
        )
        add_custom_target(Compiled_${java_name}_Jar ALL DEPENDS 
                            ${${java_name}_JAVA_JAR})
        add_custom_command(OUTPUT ${${java_name}_JAVA_JAR}
150
151
            COMMAND ${CMAKE_COMMAND} -E chdir ${XDMF_JAVA_PACKAGE_DIR} 
                ${JAVA_COMPILE} ARGS ${java_compile_args}
152
153
154
155
156
            COMMAND ${JAVA_ARCHIVE}
            ARGS    -cvf ${${java_name}_JAVA_JAR}
                    "${XDMF_JAVA_PACKAGE_DIR}/*.class"
        )
        add_dependencies(${java_name}Java ${java_name}_Java_Dir)
157
158
159
160
161
        add_dependencies(Compiled_${java_name}_Jar ${java_name}Java)

        if(NOT ${ARGN} EQUAL "")
            add_dependencies(Compiled_${java_name}_Jar "${ARGN}")
        endif(NOT ${ARGN} EQUAL "")
162

163
164
165
166
167
		set_property(DIRECTORY APPEND PROPERTY
			ADDITIONAL_MAKE_CLEAN_FILES
			${CMAKE_BINARY_DIR}/${java_name}.jar
			${XDMF_JAVA_DIR}
		)
168
169
170
171

        string(TOUPPER ${java_name} java_name_upper)
        set(${java_name_upper}_JAVA_JAR_CONFIG
                     ${CMAKE_INSTALL_PREFIX}/lib/java/${java_name}.jar)
172
173
174
        install(FILES ${CMAKE_BINARY_DIR}/${java_name}.jar 
                DESTINATION lib/java)
       	install(TARGETS ${SWIG_MODULE_${java_name}Java_REAL_NAME}
175
                DESTINATION ${java_dest})
176
177
178
	ENDMACRO(XDMF_SWIG_JAVA)
endif(XDMF_WRAP_JAVA)

179
180
add_subdirectory(core)
include_directories(${XdmfCore_INCLUDE_DIRS})
181

182
183
184
185
186
187
option(XDMF_BUILD_CORE_ONLY OFF)
if(NOT XDMF_BUILD_CORE_ONLY)
	set(XdmfSources
		XdmfAttribute
		XdmfAttributeCenter
		XdmfAttributeType
188
		XdmfCurvilinearGrid
189
190
191
192
193
194
195
196
197
		XdmfDomain
		XdmfGeometry
		XdmfGeometryType
		XdmfGrid
		XdmfGridCollection
		XdmfGridCollectionType
		XdmfItemFactory
		XdmfMap
		XdmfReader
198
199
		XdmfRectilinearGrid
		XdmfRegularGrid
200
201
202
203
204
		XdmfSet
		XdmfSetType
		XdmfTime
		XdmfTopology
		XdmfTopologyType
205
		XdmfUnstructuredGrid
206
207
208
209
	)
	
	add_library(Xdmf ${XdmfSources})
	target_link_libraries(Xdmf XdmfCore)
210
211
212
213
214
215
216
217
218

    if(WIN32)
        set_target_properties(Xdmf PROPERTIES 
                DEFINE_SYMBOL Xdmf_EXPORTS
                PREFIX ../
                RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
                LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
                ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
    endif(WIN32)
219
220
	
	if(XDMF_WRAP_JAVA)
221
		XDMF_SWIG_JAVA(Xdmf Compiled_XdmfCore_Jar)
222
223
	endif(XDMF_WRAP_JAVA)
	
224
225
226
227
	if(XDMF_WRAP_PYTHON)
		XDMF_SWIG_PYTHON(Xdmf XdmfCore)
	endif(XDMF_WRAP_PYTHON)
	
228
	if(BUILD_TESTING)
229
		add_subdirectory(tests)
230
	endif(BUILD_TESTING)
231
232
233
234
235
236
	
	option(XDMF_BUILD_UTILS OFF)
	if(XDMF_BUILD_UTILS)
		add_subdirectory(utils)
	endif(XDMF_BUILD_UTILS)
		
237
    if(WIN32)
238
        set(XDMF_LIBRARY_CONFIG ${CMAKE_INSTALL_PREFIX}/lib/Xdmf.lib)
239
240
241
242
243
    else(WIN32)
        set(XDMF_LIBRARY_CONFIG ${CMAKE_INSTALL_PREFIX}/lib/libXdmf.so)
    endif(WIN32)
	
    file(GLOB XdmfHeaders "*.hpp" "*.tpp" "*.i" "CMake/VersionSuite/*.hpp")
244
	install(FILES ${XdmfHeaders} DESTINATION include)
245
246
247
248
249
    install(TARGETS Xdmf 
        RUNTIME DESTINATION bin
        LIBRARY DESTINATION lib
        ARCHIVE DESTINATION lib
    )
250
endif(NOT XDMF_BUILD_CORE_ONLY)
251
252
253
254

configure_file(${CMAKE_BINARY_DIR}/XdmfConfig.cmake.in
                ${CMAKE_BINARY_DIR}/XdmfConfig.cmake @ONLY)
install(FILES ${CMAKE_BINARY_DIR}/XdmfConfig.cmake DESTINATION .)