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

Revision 7743, 10.3 KB checked in by hinerm, 8 years ago (diff)

Improved control flow of platform specific installation

Previously, platform-specific installation was controlled
by three separate, specific if statements. After learning
that there can be fallthrough on some platforms with multiple
paths being executed, it was revised to an if-then-else pattern
which seems to be much cleaner in execution.

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 ../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
86 if(NOT DEFINED J2L_SUFFIX)
87   set(J2L_SUFFIX .dylib)
88 endif(NOT DEFINED J2L_SUFFIX)
89
90 if(NOT DEFINED J2L_JNI_SUFFIX)
91   set(J2L_JNI_SUFFIX .jnilib)
92 endif(NOT DEFINED J2L_JNI_SUFFIX)
93
94 if(NOT DEFINED J2L_EXE_SUFFIX)
95   set(J2L_EXE_SUFFIX "")
96 endif(NOT DEFINED J2L_EXE_SUFFIX)
97
98endif(APPLE)
99
100if(UNIX)
101
102 if(NOT DEFINED J2L_SUFFIX)
103
104   set(J2L_SUFFIX .so)
105
106 endif(NOT DEFINED J2L_SUFFIX)
107
108 if(NOT DEFINED J2L_EXE_SUFFIX)
109   set(J2L_EXE_SUFFIX "")
110 endif(NOT DEFINED J2L_EXE_SUFFIX)
111
112endif(UNIX)
113
114if(WIN32)
115   set(J2L_LIB_PREFIX "")
116   set(J2L_BUILD_TYPE /Release)
117
118# Building in Debug mode is not currently supported in this script
119#  set(J2L_BUILD TYPE /Debug)
120
121  if(NOT DEFINED J2L_SUFFIX)
122
123    set(J2L_SUFFIX .dll)
124
125  endif(NOT DEFINED J2L_SUFFIX)
126
127 if(NOT DEFINED J2L_EXE_SUFFIX)
128   set(J2L_EXE_SUFFIX .exe)
129 endif(NOT DEFINED J2L_EXE_SUFFIX)
130
131endif(WIN32)
132
133if(WIN64)
134  set(J2L_LIB_PREFIX "")
135  set(J2L_BUILD_TYPE /Release)
136
137#  Builing with Debug mode on Windows is not currently supported in this script.
138#  set(J2L_BUILD TYPE /Debug)
139
140  if(NOT DEFINED J2L_SUFFIX)
141
142    set(J2L_SUFFIX .dll)
143
144  endif(NOT DEFINED J2L_SUFFIX)
145
146 if(NOT DEFINED J2L_EXE_SUFFIX)
147   set(J2L_SUFFIX )
148 endif(NOT DEFINED J2L_EXE_SUFFIX)
149
150endif(WIN64)
151
152
153if(APPLE)
154#make a .dylib version of libjace
155  add_custom_command(
156    TARGET ${projectId}
157    DEPENDS "${CMAKE_BINARY_DIR}/${Jar2Lib_JACE_DIR}${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}jace${J2L_JNI_SUFFIX}"
158    POST_BUILD
159    COMMAND ${CMAKE_COMMAND} -E copy
160    "${CMAKE_BINARY_DIR}/${Jar2Lib_JACE_DIR}${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}jace${J2L_JNI_SUFFIX}"
161    "${CMAKE_BINARY_DIR}/${Jar2Lib_JACE_DIR}${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}jace${J2L_SUFFIX}"
162    VERBATIM
163  )
164
165  add_custom_command(
166    TARGET ${projectId}
167    DEPENDS "${CMAKE_BINARY_DIR}/${Jar2Lib_JACE_DIR}${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}jace${J2L_JNI_SUFFIX}"
168    POST_BUILD
169    COMMAND ${CMAKE_COMMAND} -E copy
170    "${CMAKE_BINARY_DIR}/${Jar2Lib_JACE_DIR}${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}jace${J2L_JNI_SUFFIX}"
171    "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${J2L_LIB_PREFIX}jace${J2L_JNI_SUFFIX}"
172    VERBATIM
173  )
174  install(FILES
175    "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${J2L_LIB_PREFIX}jace${J2L_JNI_SUFFIX}"
176    DESTINATION "."
177  )
178
179  add_custom_command(
180    TARGET ${projectId}
181    DEPENDS "${CMAKE_BINARY_DIR}/${Jar2Lib_JACE_DIR}${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}jace${J2L_JNI_SUFFIX}"
182    POST_BUILD
183    COMMAND ${CMAKE_COMMAND} -E copy
184    "${CMAKE_BINARY_DIR}/${Jar2Lib_JACE_DIR}${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}jace${J2L_JNI_SUFFIX}"
185    "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${J2L_LIB_PREFIX}jace${J2L_SUFFIX}"
186    VERBATIM
187  )
188  install(FILES
189    "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${J2L_LIB_PREFIX}jace${J2L_SUFFIX}"
190    DESTINATION "."
191  )
192endif(APPLE)
193
194# copy jace
195add_custom_command(
196  TARGET ${projectId}
197  DEPENDS "${CMAKE_BINARY_DIR}/${Jar2Lib_JACE_DIR}${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}jace${J2L_SUFFIX}"
198  POST_BUILD
199  COMMAND ${CMAKE_COMMAND} -E copy
200  "${CMAKE_BINARY_DIR}/${Jar2Lib_JACE_DIR}${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}jace${J2L_SUFFIX}"
201  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${J2L_LIB_PREFIX}jace${J2L_SUFFIX}"
202  VERBATIM
203)
204install(FILES
205  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${J2L_LIB_PREFIX}jace${J2L_SUFFIX}"
206  DESTINATION "."
207)
208
209# copy ${projectId}
210add_custom_command(
211  TARGET ${projectId}
212  DEPENDS "${CMAKE_BINARY_DIR}/${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}${projectId}${J2L_SUFFIX}"
213  POST_BUILD
214  COMMAND ${CMAKE_COMMAND} -E copy
215  "${CMAKE_BINARY_DIR}/${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}${projectId}${J2L_SUFFIX}"
216  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${J2L_LIB_PREFIX}${projectId}${J2L_SUFFIX}"
217  VERBATIM
218)
219
220# copy jtools
221add_custom_command(
222  TARGET jtools
223  DEPENDS "${CMAKE_BINARY_DIR}/${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}jtools${J2L_SUFFIX}"
224  POST_BUILD
225  COMMAND ${CMAKE_COMMAND} -E copy
226  "${CMAKE_BINARY_DIR}/${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}jtools${J2L_SUFFIX}"
227  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${J2L_LIB_PREFIX}jtools${J2L_SUFFIX}"
228  VERBATIM
229)
230
231# copy jace_runtime.jar
232add_custom_command(
233  TARGET ${projectId}
234  DEPENDS "${CMAKE_BINARY_DIR}/../jace-runtime.jar"
235  POST_BUILD
236  COMMAND ${CMAKE_COMMAND} -E copy
237  "${CMAKE_BINARY_DIR}/../jace-runtime.jar"
238  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${Jar2Lib_DEPS_DIR}/jace-runtime.jar"
239  VERBATIM
240)
241install(FILES
242  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${Jar2Lib_DEPS_DIR}/jace-runtime.jar"
243  DESTINATION "./${Jar2Lib_DEPS_DIR}"
244)
245
246#foreach ($jarFile in $sourceJars)
247#set ($jarName = $jarFile.getName())
248# copy ${jarName}
249add_custom_command(
250  TARGET ${projectId}
251  DEPENDS "${jarFile}"
252  POST_BUILD
253  COMMAND ${CMAKE_COMMAND} -E copy
254  "${jarFile}"
255  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${Jar2Lib_DEPS_DIR}/${jarName}"
256  VERBATIM
257)
258install(FILES
259  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${Jar2Lib_DEPS_DIR}/${jarName}"
260  DESTINATION "./${Jar2Lib_DEPS_DIR}/"
261)
262
263#end##foreach $sourceJars
264
265# copy and install executables
266#foreach ($sourceFile in $sourceFiles)
267#set ($execName = $q.simpleName($sourceFile))
268#set ($sourceName = $sourceFile.getName())
269add_custom_command(
270  TARGET ${execName}
271  DEPENDS "${CMAKE_BINARY_DIR}/${execName}"
272  POST_BUILD
273  COMMAND ${CMAKE_COMMAND} -E copy
274  "${CMAKE_BINARY_DIR}/${execName}"
275  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${execName}"
276  VERBATIM
277)
278#end##foreach $sourceFile
279
280# copy and install dependencies
281add_custom_command(
282  TARGET ${projectId}
283  DEPENDS "${CMAKE_BINARY_DIR}/${Jar2Lib_DEPS_SRC}"
284  POST_BUILD
285  COMMAND ${CMAKE_COMMAND} -E copy_directory
286  "${CMAKE_BINARY_DIR}/${Jar2Lib_DEPS_SRC}"
287  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${Jar2Lib_DEPS_DIR}/"
288  VERBATIM
289)
290
291install(DIRECTORY
292  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${Jar2Lib_DEPS_DIR}/"
293  DESTINATION "./${Jar2Lib_DEPS_DIR}/"
294)
295
296# copy dependencies to build directory
297add_custom_command(
298  TARGET ${projectId}
299  DEPENDS "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${Jar2Lib_DEPS_DIR}"
300  POST_BUILD
301  COMMAND ${CMAKE_COMMAND} -E copy_directory
302  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${Jar2Lib_DEPS_DIR}/"
303  "${CMAKE_BINARY_DIR}/${Jar2Lib_DEPS_DIR}"
304  VERBATIM
305)
306
307# copy dependency headers
308add_custom_command(
309  TARGET ${projectId}
310  DEPENDS "${Jar2Lib_INCLDE_DIR}"
311  COMMAND ${CMAKE_COMMAND} -E copy_directory
312  "${Jar2Lib_INCLDE_DIR}"
313  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/include"
314  VERBATIM
315)
316
317# copy and install proxies
318add_custom_command(
319  TARGET ${projectId}
320  DEPENDS "${CMAKE_BINARY_DIR}/${Jar2Lib_PROXY_DIR}"
321  POST_BUILD
322  COMMAND ${CMAKE_COMMAND} -E copy_directory
323  "${CMAKE_BINARY_DIR}/${Jar2Lib_PROXY_DIR}/include"
324  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/include"
325  VERBATIM
326)
327
328install(DIRECTORY
329  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/include/"
330  DESTINATION "./include"
331)
332
333# ---HACK--- install(TARGETS ...) destroys linking on Linux but allows portability on OSX
334
335if(APPLE)
336# install targets
337install(TARGETS
338  jtools
339  ${projectId}
340#foreach ($sourceFile in $sourceFiles)
341#set ($execName = $q.simpleName($sourceFile))
342  ${execName}
343#end##foreach $sourceFile
344  RUNTIME DESTINATION .
345  LIBRARY DESTINATION .
346  ARCHIVE DESTINATION .
347)
348elseif(WIN32 OR WIN64)
349# install targets
350install(TARGETS
351  jtools
352  ${projectId}
353#foreach ($sourceFile in $sourceFiles)
354#set ($execName = $q.simpleName($sourceFile))
355  ${execName}
356#end##foreach $sourceFile
357  RUNTIME DESTINATION .
358  LIBRARY DESTINATION .
359  ARCHIVE DESTINATION .
360)
361else(APPLE)
362install(FILES
363  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${J2L_LIB_PREFIX}jtools${J2L_SUFFIX}"
364  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${J2L_LIB_PREFIX}${projectId}${J2L_SUFFIX}"
365  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${J2L_LIB_PREFIX}jtools${J2L_SUFFIX}"
366  DESTINATION "."
367)
368
369#foreach ($sourceFile in $sourceFiles)
370#set ($execName = $q.simpleName($sourceFile))
371install(PROGRAMS
372  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${execName}"
373  DESTINATION "."
374)
375#end##foreach $sourceFile
376endif(APPLE)
377
378
379SET(CPACK_PACKAGE_FILE_NAME "${projectId}")
380SET(CPACK_GENERATOR "TGZ;ZIP")
381INCLUDE( CPack )
382
Note: See TracBrowser for help on using the repository browser.