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

Revision 7775, 11.9 KB checked in by hinerm, 8 years ago (diff)

Added Build path consideration to EXE files

The templated code for exe files in a project were not
considering the build type (in MS visual studio) thus
causing the post-build copies to fail.

This fix included a typo correction for the Debug path
macro, so that either build type can be easily supported.

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( $offset = $jarfile.lastIndexOf('/') + 1 )
295#set ($jarName = $jarFile.substring($offset) )
296# copy ${jarName}
297add_custom_command(
298  TARGET ${projectId}
299  DEPENDS "${jarFile}"
300  POST_BUILD
301  COMMAND ${CMAKE_COMMAND} -E copy
302  "${jarFile}"
303  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${Jar2Lib_DEPS_DIR}/${jarName}"
304  VERBATIM
305)
306install(FILES
307  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${Jar2Lib_DEPS_DIR}/${jarName}"
308  DESTINATION "./${Jar2Lib_DEPS_DIR}/"
309)
310
311#end##foreach $sourceJars
312
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}
319  DEPENDS "${CMAKE_BINARY_DIR}${J2L_BUILD_TYPE}/${execName}${J2L_EXE_SUFFIX}"
320  POST_BUILD
321  COMMAND ${CMAKE_COMMAND} -E copy
322  "${CMAKE_BINARY_DIR}${J2L_BUILD_TYPE}/${execName}${J2L_EXE_SUFFIX}"
323  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${execName}${J2L_EXE_SUFFIX}"
324  VERBATIM
325)
326#end##foreach $sourceFile
327
328# copy and install dependencies
329add_custom_command(
330  TARGET ${projectId}
331  DEPENDS "${CMAKE_SOURCE_DIR}/${Jar2Lib_DEPS_SRC}"
332  POST_BUILD
333  COMMAND ${CMAKE_COMMAND} -E copy_directory
334  "${CMAKE_SOURCE_DIR}/${Jar2Lib_DEPS_SRC}"
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
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}/"
351  "${CMAKE_BINARY_DIR}${J2L_BUILD_TYPE}/${Jar2Lib_DEPS_DIR}"
352  VERBATIM
353)
354
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}
368  DEPENDS "${CMAKE_SOURCE_DIR}/${Jar2Lib_PROXY_DIR}"
369  POST_BUILD
370  COMMAND ${CMAKE_COMMAND} -E copy_directory
371  "${CMAKE_SOURCE_DIR}/${Jar2Lib_PROXY_DIR}/include"
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
381# ---HACK--- install(TARGETS ...) destroys linking on Linux but allows portability on OSX
382
383if(APPLE)
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)
396elseif(WIN32 OR WIN64)
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)
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)
416
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
427SET(CPACK_PACKAGE_FILE_NAME "${projectId}")
428SET(CPACK_GENERATOR "TGZ;ZIP")
429INCLUDE( CPack )
430
Note: See TracBrowser for help on using the repository browser.