source: trunk/projects/jar2lib/src/main/resources/CMakeLists.vm @ 7750

Revision 7750, 11.8 KB checked in by hinerm, 8 years ago (diff)

Added support for building on Windows platforms

The CMakeLists.txt generated will now have the following changes necessary for building on Windows:

  • Copying dependencies relative to source rather than build (e.g. if your build dir is in a MSVC build type sub-directory)
  • Same as above for proxies and include files
  • Now appropriately set .exe suffix for executables
  • Copy and install the export libraries for .dlls
Line 
1#
2# CMakeLists.txt
3#
4$headerBlock
5# CMake build file for $projectName.
6
7cmake_minimum_required(VERSION 2.8)
8
9project($projectId)
10
11include(jace/CMakeLists.txt)
12
13include_directories("${PROJECT_SOURCE_DIR}/include" "${PROJECT_SOURCE_DIR}/proxies/include" "${PROJECT_SOURCE_DIR}/jace/include" "${PROJECT_SOURCE_DIR}/jtools/include" "${JAVA_INCLUDE_PATH}" "${JAVA_INCLUDE_PATH2}" "${Boost_INCLUDE_DIR}")
14
15file(GLOB_RECURSE PROJECT_SRC "${PROJECT_SOURCE_DIR}/proxies/source/*.cpp")
16
17add_library(jtools SHARED "${PROJECT_SOURCE_DIR}/jtools/source/javaTools.cxx")
18
19add_library($projectId SHARED ${PROJECT_SRC})
20
21target_link_libraries($projectId jace)
22
23target_link_libraries(jtools jace)
24
25if(CMAKE_COMPILER_IS_GNUCXX)
26  set_target_properties($projectId PROPERTIES
27    COMPILE_FLAGS "-fpermissive")
28else(CMAKE_COMPILER_IS_GNUCXX)
29  set_target_properties($projectId PROPERTIES
30    DEFINE_SYMBOL JACE_PROXY_EXPORTS)
31endif(CMAKE_COMPILER_IS_GNUCXX)
32
33#foreach ($sourceFile in $sourceFiles)
34#set ($execName = $q.simpleName($sourceFile))
35#set ($sourceName = $sourceFile.getName())
36add_executable($execName source/$sourceName)
37target_link_libraries($execName $projectId jtools jace "${JAVA_JVM_LIBRARY}")
38#end##foreach $sourceFile
39
40# ---HACK--- Force linker to check working directory for libraries on Unix
41if(UNIX)
42target_link_libraries(jtools -Wl,-rpath,.)
43target_link_libraries($projectId -Wl,-rpath,.)
44#foreach ($sourceFile in $sourceFiles)
45#set ($execName = $q.simpleName($sourceFile))
46target_link_libraries($execName -Wl,-rpath,.)
47#end##foreach $sourceFile
48endif(UNIX)
49
50# post-build copies to dist dir
51if(NOT DEFINED Jar2Lib_JACE_DIR)
52# set(Jar2Lib_JACE_DIR jace)
53endif(NOT DEFINED Jar2Lib_JACE_DIR)
54
55if(NOT DEFINED Jar2Lib_PROXY_DIR)
56  set(Jar2Lib_PROXY_DIR /proxies)
57endif(NOT DEFINED Jar2Lib_PROXY_DIR)
58
59if(NOT DEFINED Jar2Lib_INCLDE_DIR)
60  set(Jar2Lib_INCLDE_DIR ${CMAKE_SOURCE_DIR}/include)
61endif(NOT DEFINED Jar2Lib_INCLDE_DIR)
62
63if(NOT DEFINED Jar2Lib_DEPS_DIR)
64  set(Jar2Lib_DEPS_DIR jar)
65endif(NOT DEFINED Jar2Lib_DEPS_DIR)
66
67if(NOT DEFINED Jar2Lib_DIST_DIR)
68  set(Jar2Lib_DIST_DIR dist/${projectId})
69endif(NOT DEFINED Jar2Lib_DIST_DIR)
70
71if(NOT DEFINED Jar2Lib_DEPS_SRC)
72  set(Jar2Lib_DEPS_SRC ../dependency)
73endif(NOT DEFINED Jar2Lib_DEPS_SRC)
74
75if(NOT DEFINED J2L_BUILD_TYPE)
76  set(J2L_BUILD_TYPE "")
77endif(NOT DEFINED J2L_BUILD_TYPE)
78
79if(NOT DEFINED J2L_LIB_PREFIX)
80  set(J2L_LIB_PREFIX lib)
81endif(NOT DEFINED J2L_LIB_PREFIX)
82
83# Set the appropriate file extension for libraries on each system
84if(APPLE)
85 if(NOT DEFINED J2L_SUFFIX)
86   set(J2L_SUFFIX .dylib)
87 endif(NOT DEFINED J2L_SUFFIX)
88
89 if(NOT DEFINED J2L_JNI_SUFFIX)
90   set(J2L_JNI_SUFFIX .jnilib)
91 endif(NOT DEFINED J2L_JNI_SUFFIX)
92
93 if(NOT DEFINED J2L_EXE_SUFFIX)
94   set(J2L_EXE_SUFFIX "")
95 endif(NOT DEFINED J2L_EXE_SUFFIX)
96
97endif(APPLE)
98
99if(UNIX)
100 if(NOT DEFINED J2L_SUFFIX)
101
102   set(J2L_SUFFIX .so)
103
104 endif(NOT DEFINED J2L_SUFFIX)
105
106 if(NOT DEFINED J2L_EXE_SUFFIX)
107   set(J2L_EXE_SUFFIX "")
108 endif(NOT DEFINED J2L_EXE_SUFFIX)
109
110endif(UNIX)
111
112if(WIN32)
113   set(J2L_LIB_PREFIX "")
114   set(J2L_BUILD_TYPE /Release)
115
116# Building in Debug mode is not currently supported in this script
117#  set(J2L_BUILD TYPE /Debug)
118
119  if(NOT DEFINED J2L_SUFFIX)
120
121    set(J2L_SUFFIX .dll)
122
123  endif(NOT DEFINED J2L_SUFFIX)
124
125 if(NOT DEFINED J2L_EXE_SUFFIX)
126   set(J2L_EXE_SUFFIX .exe)
127 endif(NOT DEFINED J2L_EXE_SUFFIX)
128
129endif(WIN32)
130
131if(WIN64)
132  set(J2L_LIB_PREFIX "")
133  set(J2L_BUILD_TYPE /Release)
134
135#  Builing with Debug mode on Windows is not currently supported in this script.
136#  set(J2L_BUILD TYPE /Debug)
137
138  if(NOT DEFINED J2L_SUFFIX)
139
140    set(J2L_SUFFIX .dll)
141
142  endif(NOT DEFINED J2L_SUFFIX)
143
144 if(NOT DEFINED J2L_EXE_SUFFIX)
145   set(J2L_SUFFIX )
146 endif(NOT DEFINED J2L_EXE_SUFFIX)
147
148endif(WIN64)
149
150
151if(APPLE)
152#make a .dylib version of libjace
153  add_custom_command(
154    TARGET ${projectId}
155    DEPENDS "${CMAKE_BINARY_DIR}/${Jar2Lib_JACE_DIR}${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}jace${J2L_JNI_SUFFIX}"
156    POST_BUILD
157    COMMAND ${CMAKE_COMMAND} -E copy
158    "${CMAKE_BINARY_DIR}/${Jar2Lib_JACE_DIR}${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}jace${J2L_JNI_SUFFIX}"
159    "${CMAKE_BINARY_DIR}/${Jar2Lib_JACE_DIR}${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}jace${J2L_SUFFIX}"
160    VERBATIM
161  )
162
163  add_custom_command(
164    TARGET ${projectId}
165    DEPENDS "${CMAKE_BINARY_DIR}/${Jar2Lib_JACE_DIR}${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}jace${J2L_JNI_SUFFIX}"
166    POST_BUILD
167    COMMAND ${CMAKE_COMMAND} -E copy
168    "${CMAKE_BINARY_DIR}/${Jar2Lib_JACE_DIR}${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}jace${J2L_JNI_SUFFIX}"
169    "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${J2L_LIB_PREFIX}jace${J2L_JNI_SUFFIX}"
170    VERBATIM
171  )
172  install(FILES
173    "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${J2L_LIB_PREFIX}jace${J2L_JNI_SUFFIX}"
174    DESTINATION "."
175  )
176
177  add_custom_command(
178    TARGET ${projectId}
179    DEPENDS "${CMAKE_BINARY_DIR}/${Jar2Lib_JACE_DIR}${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}jace${J2L_JNI_SUFFIX}"
180    POST_BUILD
181    COMMAND ${CMAKE_COMMAND} -E copy
182    "${CMAKE_BINARY_DIR}/${Jar2Lib_JACE_DIR}${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}jace${J2L_JNI_SUFFIX}"
183    "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${J2L_LIB_PREFIX}jace${J2L_SUFFIX}"
184    VERBATIM
185  )
186  install(FILES
187    "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${J2L_LIB_PREFIX}jace${J2L_SUFFIX}"
188    DESTINATION "."
189  )
190endif(APPLE)
191
192# copy jace
193add_custom_command(
194  TARGET ${projectId}
195  DEPENDS "${CMAKE_BINARY_DIR}/${Jar2Lib_JACE_DIR}${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}jace${J2L_SUFFIX}"
196  POST_BUILD
197  COMMAND ${CMAKE_COMMAND} -E copy
198  "${CMAKE_BINARY_DIR}/${Jar2Lib_JACE_DIR}${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}jace${J2L_SUFFIX}"
199  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${J2L_LIB_PREFIX}jace${J2L_SUFFIX}"
200  VERBATIM
201)
202install(FILES
203  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${J2L_LIB_PREFIX}jace${J2L_SUFFIX}"
204  DESTINATION "."
205)
206
207# copy ${projectId}
208add_custom_command(
209  TARGET ${projectId}
210  DEPENDS "${CMAKE_BINARY_DIR}/${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}${projectId}${J2L_SUFFIX}"
211  POST_BUILD
212  COMMAND ${CMAKE_COMMAND} -E copy
213  "${CMAKE_BINARY_DIR}/${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}${projectId}${J2L_SUFFIX}"
214  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${J2L_LIB_PREFIX}${projectId}${J2L_SUFFIX}"
215  VERBATIM
216)
217
218# copy jtools
219add_custom_command(
220  TARGET jtools
221  DEPENDS "${CMAKE_BINARY_DIR}/${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}jtools${J2L_SUFFIX}"
222  POST_BUILD
223  COMMAND ${CMAKE_COMMAND} -E copy
224  "${CMAKE_BINARY_DIR}/${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}jtools${J2L_SUFFIX}"
225  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${J2L_LIB_PREFIX}jtools${J2L_SUFFIX}"
226  VERBATIM
227)
228
229# if Windows, need to copy the export libraries as well
230if(WIN32)
231# copy jace
232add_custom_command(
233  TARGET ${projectId}
234  DEPENDS "${CMAKE_BINARY_DIR}/${Jar2Lib_JACE_DIR}${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}jace.lib"
235  POST_BUILD
236  COMMAND ${CMAKE_COMMAND} -E copy
237  "${CMAKE_BINARY_DIR}/${Jar2Lib_JACE_DIR}${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}jace.lib"
238  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${J2L_LIB_PREFIX}jace.lib"
239  VERBATIM
240)
241install(FILES
242  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${J2L_LIB_PREFIX}jace.lib"
243  DESTINATION "."
244)
245
246# copy ${projectId}
247add_custom_command(
248  TARGET ${projectId}
249  DEPENDS "${CMAKE_BINARY_DIR}/${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}${projectId}.lib"
250  POST_BUILD
251  COMMAND ${CMAKE_COMMAND} -E copy
252  "${CMAKE_BINARY_DIR}/${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}${projectId}.lib"
253  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${J2L_LIB_PREFIX}${projectId}.lib"
254  VERBATIM
255)
256install(FILES
257  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${J2L_LIB_PREFIX}${projectId}.lib"
258  DESTINATION "."
259)
260
261# copy jtools
262add_custom_command(
263  TARGET jtools
264  DEPENDS "${CMAKE_BINARY_DIR}/${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}jtools.lib"
265  POST_BUILD
266  COMMAND ${CMAKE_COMMAND} -E copy
267  "${CMAKE_BINARY_DIR}/${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}jtools.lib"
268  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${J2L_LIB_PREFIX}jtools.lib"
269  VERBATIM
270)
271install(FILES
272  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${J2L_LIB_PREFIX}jtools.lib"
273  DESTINATION "."
274)
275
276endif(WIN32)
277
278# copy jace_runtime.jar
279add_custom_command(
280  TARGET ${projectId}
281  DEPENDS "${CMAKE_BINARY_DIR}/../jace-runtime.jar"
282  POST_BUILD
283  COMMAND ${CMAKE_COMMAND} -E copy
284  "${CMAKE_BINARY_DIR}/../jace-runtime.jar"
285  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${Jar2Lib_DEPS_DIR}/jace-runtime.jar"
286  VERBATIM
287)
288install(FILES
289  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${Jar2Lib_DEPS_DIR}/jace-runtime.jar"
290  DESTINATION "./${Jar2Lib_DEPS_DIR}"
291)
292
293#foreach ($jarFile in $sourceJars)
294#set ($jarName = $jarFile.getName())
295# copy ${jarName}
296add_custom_command(
297  TARGET ${projectId}
298  DEPENDS "${jarFile}"
299  POST_BUILD
300  COMMAND ${CMAKE_COMMAND} -E copy
301  "${jarFile}"
302  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${Jar2Lib_DEPS_DIR}/${jarName}"
303  VERBATIM
304)
305install(FILES
306  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${Jar2Lib_DEPS_DIR}/${jarName}"
307  DESTINATION "./${Jar2Lib_DEPS_DIR}/"
308)
309
310#end##foreach $sourceJars
311
312# copy and install executables
313#foreach ($sourceFile in $sourceFiles)
314#set ($execName = $q.simpleName($sourceFile))
315#set ($sourceName = $sourceFile.getName())
316add_custom_command(
317  TARGET ${execName}
318  DEPENDS "${CMAKE_BINARY_DIR}/${execName}${J2L_EXE_SUFFIX}"
319  POST_BUILD
320  COMMAND ${CMAKE_COMMAND} -E copy
321  "${CMAKE_BINARY_DIR}/${execName}${J2L_EXE_SUFFIX}"
322  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${execName}${J2L_EXE_SUFFIX}"
323  VERBATIM
324)
325#end##foreach $sourceFile
326
327# copy and install dependencies
328add_custom_command(
329  TARGET ${projectId}
330  DEPENDS "${CMAKE_SOURCE_DIR}/${Jar2Lib_DEPS_SRC}"
331  POST_BUILD
332  COMMAND ${CMAKE_COMMAND} -E copy_directory
333  "${CMAKE_SOURCE_DIR}/${Jar2Lib_DEPS_SRC}"
334  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${Jar2Lib_DEPS_DIR}/"
335  VERBATIM
336)
337
338install(DIRECTORY
339  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${Jar2Lib_DEPS_DIR}/"
340  DESTINATION "./${Jar2Lib_DEPS_DIR}/"
341)
342
343# copy dependencies to build directory
344add_custom_command(
345  TARGET ${projectId}
346  DEPENDS "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${Jar2Lib_DEPS_DIR}"
347  POST_BUILD
348  COMMAND ${CMAKE_COMMAND} -E copy_directory
349  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${Jar2Lib_DEPS_DIR}/"
350  "${CMAKE_BINARY_DIR}${J2L_BUILD_TYPE}/${Jar2Lib_DEPS_DIR}"
351  VERBATIM
352)
353
354# copy dependency headers
355add_custom_command(
356  TARGET ${projectId}
357  DEPENDS "${Jar2Lib_INCLDE_DIR}"
358  COMMAND ${CMAKE_COMMAND} -E copy_directory
359  "${Jar2Lib_INCLDE_DIR}"
360  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/include"
361  VERBATIM
362)
363
364# copy and install proxies
365add_custom_command(
366  TARGET ${projectId}
367  DEPENDS "${CMAKE_SOURCE_DIR}/${Jar2Lib_PROXY_DIR}"
368  POST_BUILD
369  COMMAND ${CMAKE_COMMAND} -E copy_directory
370  "${CMAKE_SOURCE_DIR}/${Jar2Lib_PROXY_DIR}/include"
371  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/include"
372  VERBATIM
373)
374
375install(DIRECTORY
376  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/include/"
377  DESTINATION "./include"
378)
379
380# ---HACK--- install(TARGETS ...) destroys linking on Linux but allows portability on OSX
381
382if(APPLE)
383# install targets
384install(TARGETS
385  jtools
386  ${projectId}
387#foreach ($sourceFile in $sourceFiles)
388#set ($execName = $q.simpleName($sourceFile))
389  ${execName}
390#end##foreach $sourceFile
391  RUNTIME DESTINATION .
392  LIBRARY DESTINATION .
393  ARCHIVE DESTINATION .
394)
395elseif(WIN32 OR WIN64)
396# install targets
397install(TARGETS
398  jtools
399  ${projectId}
400#foreach ($sourceFile in $sourceFiles)
401#set ($execName = $q.simpleName($sourceFile))
402  ${execName}
403#end##foreach $sourceFile
404  RUNTIME DESTINATION .
405  LIBRARY DESTINATION .
406  ARCHIVE DESTINATION .
407)
408else(APPLE)
409install(FILES
410  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${J2L_LIB_PREFIX}jtools${J2L_SUFFIX}"
411  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${J2L_LIB_PREFIX}${projectId}${J2L_SUFFIX}"
412  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${J2L_LIB_PREFIX}jtools${J2L_SUFFIX}"
413  DESTINATION "."
414)
415
416#foreach ($sourceFile in $sourceFiles)
417#set ($execName = $q.simpleName($sourceFile))
418install(PROGRAMS
419  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${execName}"
420  DESTINATION "."
421)
422#end##foreach $sourceFile
423endif(APPLE)
424
425
426SET(CPACK_PACKAGE_FILE_NAME "${projectId}")
427SET(CPACK_GENERATOR "TGZ;ZIP")
428INCLUDE( CPack )
429
Note: See TracBrowser for help on using the repository browser.