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

Revision 7998, 12.3 KB checked in by hinerm, 8 years ago (diff)

Corrected Debug/Release path settings

The variable specifying Debug/Release was mistakenly always being set to ""
(as it should be for *nix) thus preventing it from being properly set when
running on Windows.

This has been corrected.

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