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

Revision 7925, 12.2 KB checked in by hinerm, 8 years ago (diff)

Updated CMakeLists template for Windows

CMakeLists.txt generated using Jar2Lib will now
include a "J2L_WIN_BUILD_DEBUG" boolean option.

If set to "ON" (default) then Windows builds will
build the Debug version of the application, or Release
if this is set to "OFF".

Also removed instances of double "/".

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
50option(J2L_WIN_BUILD_DEBUG "Build Debug version? If false, builds Release. Windows only." ON)
51
52if(${J2L_WIN_BUILD_DEBUG} STREQUAL "ON")
53  if(NOT DEFINED J2L_BUILD_VALUE)
54    set(J2L_BUILD_VALUE Debug)
55  endif(NOT DEFINED J2L_BUILD_VALUE)
56elseif(${J2L_WIN_BUILD_DEBUG} STREQUAL "OFF")
57  if(NOT DEFINED J2L_BUILD_VALUE)
58    set(J2L_BUILD_VALUE Release)
59  endif(NOT DEFINED J2L_BUILD_VALUE)
60endif(${J2L_WIN_BUILD_DEBUG} STREQUAL "ON")
61
62# post-build copies to dist dir
63if(NOT DEFINED Jar2Lib_JACE_DIR)
64# set(Jar2Lib_JACE_DIR jace)
65endif(NOT DEFINED Jar2Lib_JACE_DIR)
66
67if(NOT DEFINED Jar2Lib_PROXY_DIR)
68  set(Jar2Lib_PROXY_DIR proxies)
69endif(NOT DEFINED Jar2Lib_PROXY_DIR)
70
71if(NOT DEFINED Jar2Lib_INCLDE_DIR)
72  set(Jar2Lib_INCLDE_DIR ${CMAKE_SOURCE_DIR}/include)
73endif(NOT DEFINED Jar2Lib_INCLDE_DIR)
74
75if(NOT DEFINED Jar2Lib_DEPS_DIR)
76  set(Jar2Lib_DEPS_DIR jar)
77endif(NOT DEFINED Jar2Lib_DEPS_DIR)
78
79if(NOT DEFINED Jar2Lib_DIST_DIR)
80  set(Jar2Lib_DIST_DIR dist/${projectId})
81endif(NOT DEFINED Jar2Lib_DIST_DIR)
82
83if(NOT DEFINED Jar2Lib_DEPS_SRC)
84  set(Jar2Lib_DEPS_SRC ../dependency)
85endif(NOT DEFINED Jar2Lib_DEPS_SRC)
86
87if(NOT DEFINED J2L_BUILD_TYPE)
88  set(J2L_BUILD_TYPE "")
89endif(NOT DEFINED J2L_BUILD_TYPE)
90
91if(NOT DEFINED J2L_LIB_PREFIX)
92  set(J2L_LIB_PREFIX lib)
93endif(NOT DEFINED J2L_LIB_PREFIX)
94
95# Set the appropriate file extension for libraries on each system
96if(APPLE)
97 if(NOT DEFINED J2L_SUFFIX)
98   set(J2L_SUFFIX .dylib)
99 endif(NOT DEFINED J2L_SUFFIX)
100
101 if(NOT DEFINED J2L_JNI_SUFFIX)
102   set(J2L_JNI_SUFFIX .jnilib)
103 endif(NOT DEFINED J2L_JNI_SUFFIX)
104
105 if(NOT DEFINED J2L_EXE_SUFFIX)
106   set(J2L_EXE_SUFFIX "")
107 endif(NOT DEFINED J2L_EXE_SUFFIX)
108
109endif(APPLE)
110
111if(UNIX)
112 if(NOT DEFINED J2L_SUFFIX)
113
114   set(J2L_SUFFIX .so)
115
116 endif(NOT DEFINED J2L_SUFFIX)
117
118 if(NOT DEFINED J2L_EXE_SUFFIX)
119   set(J2L_EXE_SUFFIX "")
120 endif(NOT DEFINED J2L_EXE_SUFFIX)
121
122endif(UNIX)
123
124if(WIN32)
125   set(J2L_LIB_PREFIX "")
126
127   if(NOT DEFINED J2L_BUILD_TYPE)
128     set(J2L_BUILD_TYPE ${J2L_BUILD_VALUE})
129   endif(NOT DEFINED J2L_BUILD_TYPE)
130
131  if(NOT DEFINED J2L_SUFFIX)
132    set(J2L_SUFFIX .dll)
133  endif(NOT DEFINED J2L_SUFFIX)
134
135  if(NOT DEFINED J2L_EXE_SUFFIX)
136    set(J2L_EXE_SUFFIX .exe)
137  endif(NOT DEFINED J2L_EXE_SUFFIX)
138
139endif(WIN32)
140
141if(WIN64)
142  set(J2L_LIB_PREFIX "")
143
144  if(NOT DEFINED J2L_BUILD_TYPE)
145    set(J2L_BUILD_TYPE ${J2L_BUILD_VALUE})
146  endif(NOT DEFINED J2L_BUILD_TYPE)
147
148  if(NOT DEFINED J2L_SUFFIX)
149
150    set(J2L_SUFFIX .dll)
151
152  endif(NOT DEFINED J2L_SUFFIX)
153
154 if(NOT DEFINED J2L_EXE_SUFFIX)
155   set(J2L_SUFFIX )
156 endif(NOT DEFINED J2L_EXE_SUFFIX)
157
158endif(WIN64)
159
160
161if(APPLE)
162#make a .dylib version of libjace
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_JACE_DIR}${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}jace${J2L_SUFFIX}"
170    VERBATIM
171  )
172
173  add_custom_command(
174    TARGET ${projectId}
175    DEPENDS "${CMAKE_BINARY_DIR}/${Jar2Lib_JACE_DIR}${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}jace${J2L_JNI_SUFFIX}"
176    POST_BUILD
177    COMMAND ${CMAKE_COMMAND} -E copy
178    "${CMAKE_BINARY_DIR}/${Jar2Lib_JACE_DIR}${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}jace${J2L_JNI_SUFFIX}"
179    "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${J2L_LIB_PREFIX}jace${J2L_JNI_SUFFIX}"
180    VERBATIM
181  )
182  install(FILES
183    "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${J2L_LIB_PREFIX}jace${J2L_JNI_SUFFIX}"
184    DESTINATION "."
185  )
186
187  add_custom_command(
188    TARGET ${projectId}
189    DEPENDS "${CMAKE_BINARY_DIR}/${Jar2Lib_JACE_DIR}${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}jace${J2L_JNI_SUFFIX}"
190    POST_BUILD
191    COMMAND ${CMAKE_COMMAND} -E copy
192    "${CMAKE_BINARY_DIR}/${Jar2Lib_JACE_DIR}${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}jace${J2L_JNI_SUFFIX}"
193    "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${J2L_LIB_PREFIX}jace${J2L_SUFFIX}"
194    VERBATIM
195  )
196  install(FILES
197    "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${J2L_LIB_PREFIX}jace${J2L_SUFFIX}"
198    DESTINATION "."
199  )
200endif(APPLE)
201
202# copy jace
203add_custom_command(
204  TARGET ${projectId}
205  DEPENDS "${CMAKE_BINARY_DIR}/${Jar2Lib_JACE_DIR}${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}jace${J2L_SUFFIX}"
206  POST_BUILD
207  COMMAND ${CMAKE_COMMAND} -E copy
208  "${CMAKE_BINARY_DIR}/${Jar2Lib_JACE_DIR}${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}jace${J2L_SUFFIX}"
209  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${J2L_LIB_PREFIX}jace${J2L_SUFFIX}"
210  VERBATIM
211)
212install(FILES
213  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${J2L_LIB_PREFIX}jace${J2L_SUFFIX}"
214  DESTINATION "."
215)
216
217# copy ${projectId}
218add_custom_command(
219  TARGET ${projectId}
220  DEPENDS "${CMAKE_BINARY_DIR}/${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}${projectId}${J2L_SUFFIX}"
221  POST_BUILD
222  COMMAND ${CMAKE_COMMAND} -E copy
223  "${CMAKE_BINARY_DIR}/${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}${projectId}${J2L_SUFFIX}"
224  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${J2L_LIB_PREFIX}${projectId}${J2L_SUFFIX}"
225  VERBATIM
226)
227
228# copy jtools
229add_custom_command(
230  TARGET jtools
231  DEPENDS "${CMAKE_BINARY_DIR}/${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}jtools${J2L_SUFFIX}"
232  POST_BUILD
233  COMMAND ${CMAKE_COMMAND} -E copy
234  "${CMAKE_BINARY_DIR}/${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}jtools${J2L_SUFFIX}"
235  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${J2L_LIB_PREFIX}jtools${J2L_SUFFIX}"
236  VERBATIM
237)
238
239# if Windows, need to copy the export libraries as well
240if(WIN32)
241# copy jace
242add_custom_command(
243  TARGET ${projectId}
244  DEPENDS "${CMAKE_BINARY_DIR}/${Jar2Lib_JACE_DIR}${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}jace.lib"
245  POST_BUILD
246  COMMAND ${CMAKE_COMMAND} -E copy
247  "${CMAKE_BINARY_DIR}/${Jar2Lib_JACE_DIR}${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}jace.lib"
248  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${J2L_LIB_PREFIX}jace.lib"
249  VERBATIM
250)
251install(FILES
252  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${J2L_LIB_PREFIX}jace.lib"
253  DESTINATION "."
254)
255
256# copy ${projectId}
257add_custom_command(
258  TARGET ${projectId}
259  DEPENDS "${CMAKE_BINARY_DIR}/${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}${projectId}.lib"
260  POST_BUILD
261  COMMAND ${CMAKE_COMMAND} -E copy
262  "${CMAKE_BINARY_DIR}/${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}${projectId}.lib"
263  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${J2L_LIB_PREFIX}${projectId}.lib"
264  VERBATIM
265)
266install(FILES
267  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${J2L_LIB_PREFIX}${projectId}.lib"
268  DESTINATION "."
269)
270
271# copy jtools
272add_custom_command(
273  TARGET jtools
274  DEPENDS "${CMAKE_BINARY_DIR}/${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}jtools.lib"
275  POST_BUILD
276  COMMAND ${CMAKE_COMMAND} -E copy
277  "${CMAKE_BINARY_DIR}/${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}jtools.lib"
278  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${J2L_LIB_PREFIX}jtools.lib"
279  VERBATIM
280)
281install(FILES
282  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${J2L_LIB_PREFIX}jtools.lib"
283  DESTINATION "."
284)
285
286endif(WIN32)
287
288# copy jace_runtime.jar
289add_custom_command(
290  TARGET ${projectId}
291  DEPENDS "${CMAKE_SOURCE_DIR}/jace-runtime.jar"
292  POST_BUILD
293  COMMAND ${CMAKE_COMMAND} -E copy
294  "${CMAKE_SOURCE_DIR}/jace-runtime.jar"
295  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${Jar2Lib_DEPS_DIR}/jace-runtime.jar"
296  VERBATIM
297)
298install(FILES
299  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${Jar2Lib_DEPS_DIR}/jace-runtime.jar"
300  DESTINATION "./${Jar2Lib_DEPS_DIR}"
301)
302
303#foreach ($jarFile in $sourceJars)
304#set( $offset = $jarfile.lastIndexOf('/') + 1 )
305#set ($jarName = $jarFile.substring($offset) )
306# copy ${jarName}
307add_custom_command(
308  TARGET ${projectId}
309  DEPENDS "${jarFile}"
310  POST_BUILD
311  COMMAND ${CMAKE_COMMAND} -E copy
312  "${jarFile}"
313  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${Jar2Lib_DEPS_DIR}/${jarName}"
314  VERBATIM
315)
316install(FILES
317  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${Jar2Lib_DEPS_DIR}/${jarName}"
318  DESTINATION "./${Jar2Lib_DEPS_DIR}/"
319)
320
321#end##foreach $sourceJars
322
323# copy and install executables
324#foreach ($sourceFile in $sourceFiles)
325#set ($execName = $q.simpleName($sourceFile))
326#set ($sourceName = $sourceFile.getName())
327add_custom_command(
328  TARGET ${execName}
329  DEPENDS "${CMAKE_BINARY_DIR}${J2L_BUILD_TYPE}/${execName}${J2L_EXE_SUFFIX}"
330  POST_BUILD
331  COMMAND ${CMAKE_COMMAND} -E copy
332  "${CMAKE_BINARY_DIR}${J2L_BUILD_TYPE}/${execName}${J2L_EXE_SUFFIX}"
333  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${execName}${J2L_EXE_SUFFIX}"
334  VERBATIM
335)
336#end##foreach $sourceFile
337
338# copy and install dependencies
339add_custom_command(
340  TARGET ${projectId}
341  DEPENDS "${CMAKE_SOURCE_DIR}/${Jar2Lib_DEPS_SRC}"
342  POST_BUILD
343  COMMAND ${CMAKE_COMMAND} -E copy_directory
344  "${CMAKE_SOURCE_DIR}/${Jar2Lib_DEPS_SRC}"
345  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${Jar2Lib_DEPS_DIR}/"
346  VERBATIM
347)
348
349install(DIRECTORY
350  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${Jar2Lib_DEPS_DIR}/"
351  DESTINATION "./${Jar2Lib_DEPS_DIR}/"
352)
353
354# copy dependencies to build directory
355add_custom_command(
356  TARGET ${projectId}
357  DEPENDS "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${Jar2Lib_DEPS_DIR}"
358  POST_BUILD
359  COMMAND ${CMAKE_COMMAND} -E copy_directory
360  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${Jar2Lib_DEPS_DIR}/"
361  "${CMAKE_BINARY_DIR}${J2L_BUILD_TYPE}/${Jar2Lib_DEPS_DIR}"
362  VERBATIM
363)
364
365# copy dependency headers
366add_custom_command(
367  TARGET ${projectId}
368  DEPENDS "${Jar2Lib_INCLDE_DIR}"
369  COMMAND ${CMAKE_COMMAND} -E copy_directory
370  "${Jar2Lib_INCLDE_DIR}"
371  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/include"
372  VERBATIM
373)
374
375# copy and install proxies
376add_custom_command(
377  TARGET ${projectId}
378  DEPENDS "${CMAKE_SOURCE_DIR}/${Jar2Lib_PROXY_DIR}"
379  POST_BUILD
380  COMMAND ${CMAKE_COMMAND} -E copy_directory
381  "${CMAKE_SOURCE_DIR}/${Jar2Lib_PROXY_DIR}/include"
382  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/include"
383  VERBATIM
384)
385
386install(DIRECTORY
387  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/include/"
388  DESTINATION "./include"
389)
390
391# ---HACK--- install(TARGETS ...) destroys linking on Linux but allows portability on OSX
392
393if(APPLE)
394# install targets
395install(TARGETS
396  jtools
397  ${projectId}
398#foreach ($sourceFile in $sourceFiles)
399#set ($execName = $q.simpleName($sourceFile))
400  ${execName}
401#end##foreach $sourceFile
402  RUNTIME DESTINATION .
403  LIBRARY DESTINATION .
404  ARCHIVE DESTINATION .
405)
406elseif(WIN32 OR WIN64)
407# install targets
408install(TARGETS
409  jtools
410  ${projectId}
411#foreach ($sourceFile in $sourceFiles)
412#set ($execName = $q.simpleName($sourceFile))
413  ${execName}
414#end##foreach $sourceFile
415  RUNTIME DESTINATION .
416  LIBRARY DESTINATION .
417  ARCHIVE DESTINATION .
418)
419else(APPLE)
420install(FILES
421  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${J2L_LIB_PREFIX}jtools${J2L_SUFFIX}"
422  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${J2L_LIB_PREFIX}${projectId}${J2L_SUFFIX}"
423  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${J2L_LIB_PREFIX}jtools${J2L_SUFFIX}"
424  DESTINATION "."
425)
426
427#foreach ($sourceFile in $sourceFiles)
428#set ($execName = $q.simpleName($sourceFile))
429install(PROGRAMS
430  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${execName}"
431  DESTINATION "."
432)
433#end##foreach $sourceFile
434endif(APPLE)
435
436
437SET(CPACK_PACKAGE_FILE_NAME "${projectId}")
438SET(CPACK_GENERATOR "TGZ;ZIP")
439INCLUDE( CPack )
440
Note: See TracBrowser for help on using the repository browser.