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

Revision 7755, 11.8 KB checked in by hinerm, 9 years ago (diff)

Moved String conversion code to CMake

Instead of the Jar2Lib trying to change incoming jar paths, replacing "\" with "/"
the code has been moved to CMake.

RevLine 
[6806]1#
2# CMakeLists.txt
3#
4$headerBlock
5# CMake build file for $projectName.
6
7cmake_minimum_required(VERSION 2.8)
8
9project($projectId)
10
[7733]11include(jace/CMakeLists.txt)
[6806]12
[7733]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}")
[6806]14
[7733]15file(GLOB_RECURSE PROJECT_SRC "${PROJECT_SOURCE_DIR}/proxies/source/*.cpp")
[6806]16
[7733]17add_library(jtools SHARED "${PROJECT_SOURCE_DIR}/jtools/source/javaTools.cxx")
[6806]18
19add_library($projectId SHARED ${PROJECT_SRC})
20
21target_link_libraries($projectId jace)
22
[7713]23target_link_libraries(jtools jace)
24
[6806]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
[7635]33#foreach ($sourceFile in $sourceFiles)
34#set ($execName = $q.simpleName($sourceFile))
35#set ($sourceName = $sourceFile.getName())
36add_executable($execName source/$sourceName)
[7727]37target_link_libraries($execName $projectId jtools jace "${JAVA_JVM_LIBRARY}")
[7635]38#end##foreach $sourceFile
[7709]39
[7733]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
[7709]51if(NOT DEFINED Jar2Lib_JACE_DIR)
[7733]52# set(Jar2Lib_JACE_DIR jace)
[7709]53endif(NOT DEFINED Jar2Lib_JACE_DIR)
54
[7731]55if(NOT DEFINED Jar2Lib_PROXY_DIR)
[7750]56  set(Jar2Lib_PROXY_DIR /proxies)
[7731]57endif(NOT DEFINED Jar2Lib_PROXY_DIR)
58
59if(NOT DEFINED Jar2Lib_INCLDE_DIR)
[7750]60  set(Jar2Lib_INCLDE_DIR ${CMAKE_SOURCE_DIR}/include)
[7731]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
[7709]67if(NOT DEFINED Jar2Lib_DIST_DIR)
68  set(Jar2Lib_DIST_DIR dist/${projectId})
69endif(NOT DEFINED Jar2Lib_DIST_DIR)
70
[7731]71if(NOT DEFINED Jar2Lib_DEPS_SRC)
[7750]72  set(Jar2Lib_DEPS_SRC ../dependency)
[7731]73endif(NOT DEFINED Jar2Lib_DEPS_SRC)
74
[7709]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
[7733]83# Set the appropriate file extension for libraries on each system
[7709]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}"
[7731]174    DESTINATION "."
[7709]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}"
[7731]188    DESTINATION "."
[7709]189  )
190endif(APPLE)
191
[7733]192# copy jace
[7709]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}"
[7731]204  DESTINATION "."
[7709]205)
206
[7733]207# copy ${projectId}
[7709]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
[7733]218# copy jtools
[7713]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
[7750]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
[7709]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"
[7731]285  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${Jar2Lib_DEPS_DIR}/jace-runtime.jar"
[7709]286  VERBATIM
287)
288install(FILES
[7731]289  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${Jar2Lib_DEPS_DIR}/jace-runtime.jar"
290  DESTINATION "./${Jar2Lib_DEPS_DIR}"
[7709]291)
292
293#foreach ($jarFile in $sourceJars)
294#set ($jarName = $jarFile.getName())
295# copy ${jarName}
[7755]296STRING(REGEX REPLACE "\\\\" "/" jarName ${jarName})
[7709]297add_custom_command(
298  TARGET ${projectId}
299  DEPENDS "${jarFile}"
300  POST_BUILD
301  COMMAND ${CMAKE_COMMAND} -E copy
302  "${jarFile}"
[7731]303  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${Jar2Lib_DEPS_DIR}/${jarName}"
[7709]304  VERBATIM
305)
306install(FILES
[7731]307  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${Jar2Lib_DEPS_DIR}/${jarName}"
308  DESTINATION "./${Jar2Lib_DEPS_DIR}/"
[7709]309)
310
311#end##foreach $sourceJars
312
[7731]313# copy and install executables
314#foreach ($sourceFile in $sourceFiles)
315#set ($execName = $q.simpleName($sourceFile))
316#set ($sourceName = $sourceFile.getName())
317add_custom_command(
318  TARGET ${execName}
[7750]319  DEPENDS "${CMAKE_BINARY_DIR}/${execName}${J2L_EXE_SUFFIX}"
[7731]320  POST_BUILD
321  COMMAND ${CMAKE_COMMAND} -E copy
[7750]322  "${CMAKE_BINARY_DIR}/${execName}${J2L_EXE_SUFFIX}"
323  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${execName}${J2L_EXE_SUFFIX}"
[7731]324  VERBATIM
325)
326#end##foreach $sourceFile
327
328# copy and install dependencies
329add_custom_command(
330  TARGET ${projectId}
[7750]331  DEPENDS "${CMAKE_SOURCE_DIR}/${Jar2Lib_DEPS_SRC}"
[7731]332  POST_BUILD
333  COMMAND ${CMAKE_COMMAND} -E copy_directory
[7750]334  "${CMAKE_SOURCE_DIR}/${Jar2Lib_DEPS_SRC}"
[7731]335  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${Jar2Lib_DEPS_DIR}/"
336  VERBATIM
337)
338
339install(DIRECTORY
340  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${Jar2Lib_DEPS_DIR}/"
341  DESTINATION "./${Jar2Lib_DEPS_DIR}/"
342)
343
[7733]344# copy dependencies to build directory
345add_custom_command(
346  TARGET ${projectId}
347  DEPENDS "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${Jar2Lib_DEPS_DIR}"
348  POST_BUILD
349  COMMAND ${CMAKE_COMMAND} -E copy_directory
350  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${Jar2Lib_DEPS_DIR}/"
[7750]351  "${CMAKE_BINARY_DIR}${J2L_BUILD_TYPE}/${Jar2Lib_DEPS_DIR}"
[7733]352  VERBATIM
353)
354
[7731]355# copy dependency headers
356add_custom_command(
357  TARGET ${projectId}
358  DEPENDS "${Jar2Lib_INCLDE_DIR}"
359  COMMAND ${CMAKE_COMMAND} -E copy_directory
360  "${Jar2Lib_INCLDE_DIR}"
361  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/include"
362  VERBATIM
363)
364
365# copy and install proxies
366add_custom_command(
367  TARGET ${projectId}
[7750]368  DEPENDS "${CMAKE_SOURCE_DIR}/${Jar2Lib_PROXY_DIR}"
[7731]369  POST_BUILD
370  COMMAND ${CMAKE_COMMAND} -E copy_directory
[7750]371  "${CMAKE_SOURCE_DIR}/${Jar2Lib_PROXY_DIR}/include"
[7731]372  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/include"
373  VERBATIM
374)
375
376install(DIRECTORY
377  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/include/"
378  DESTINATION "./include"
379)
380
[7733]381# ---HACK--- install(TARGETS ...) destroys linking on Linux but allows portability on OSX
382
383if(APPLE)
[7731]384# install targets
385install(TARGETS
386  jtools
387  ${projectId}
388#foreach ($sourceFile in $sourceFiles)
389#set ($execName = $q.simpleName($sourceFile))
390  ${execName}
391#end##foreach $sourceFile
392  RUNTIME DESTINATION .
393  LIBRARY DESTINATION .
394  ARCHIVE DESTINATION .
395)
[7743]396elseif(WIN32 OR WIN64)
[7733]397# install targets
398install(TARGETS
399  jtools
400  ${projectId}
401#foreach ($sourceFile in $sourceFiles)
402#set ($execName = $q.simpleName($sourceFile))
403  ${execName}
404#end##foreach $sourceFile
405  RUNTIME DESTINATION .
406  LIBRARY DESTINATION .
407  ARCHIVE DESTINATION .
408)
[7743]409else(APPLE)
410install(FILES
411  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${J2L_LIB_PREFIX}jtools${J2L_SUFFIX}"
412  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${J2L_LIB_PREFIX}${projectId}${J2L_SUFFIX}"
413  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${J2L_LIB_PREFIX}jtools${J2L_SUFFIX}"
414  DESTINATION "."
415)
[7733]416
[7743]417#foreach ($sourceFile in $sourceFiles)
418#set ($execName = $q.simpleName($sourceFile))
419install(PROGRAMS
420  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${execName}"
421  DESTINATION "."
422)
423#end##foreach $sourceFile
424endif(APPLE)
425
426
[7709]427SET(CPACK_PACKAGE_FILE_NAME "${projectId}")
428SET(CPACK_GENERATOR "TGZ;ZIP")
429INCLUDE( CPack )
[7731]430
Note: See TracBrowser for help on using the repository browser.