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

Revision 7709, 6.1 KB checked in by hinerm, 9 years ago (diff)

Updated Jar2Lib to automatically package jars

Fix for ticket #172

Jar2Lib now automatically copies any generated project
jars, input jars, the jace library and jace-runtime library
to a common /build/dist/project_name directory.

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/Prerequisites.cmake)
12
13add_subdirectory(jace)
14
15include_directories(include "proxies/include" "jace/include"
16  "${JAVA_INCLUDE_PATH}" "${JAVA_INCLUDE_PATH2}" "${Boost_INCLUDE_DIR}")
17
18file(GLOB_RECURSE PROJECT_SRC "proxies/source/*.cpp")
19
20add_library($projectId SHARED ${PROJECT_SRC})
21
22target_link_libraries($projectId jace)
23
24if(CMAKE_COMPILER_IS_GNUCXX)
25  set_target_properties($projectId PROPERTIES
26    COMPILE_FLAGS "-fpermissive")
27else(CMAKE_COMPILER_IS_GNUCXX)
28  set_target_properties($projectId PROPERTIES
29    DEFINE_SYMBOL JACE_PROXY_EXPORTS)
30endif(CMAKE_COMPILER_IS_GNUCXX)
31
32target_link_libraries($projectId jace)
33
34#foreach ($sourceFile in $sourceFiles)
35#set ($execName = $q.simpleName($sourceFile))
36#set ($sourceName = $sourceFile.getName())
37add_executable($execName source/$sourceName)
38target_link_libraries($execName $projectId jace "${JAVA_JVM_LIBRARY}")
39#end##foreach $sourceFile
40
41### post-build copies to dist dir ###
42if(NOT DEFINED Jar2Lib_JACE_DIR)
43  set(Jar2Lib_JACE_DIR jace)
44endif(NOT DEFINED Jar2Lib_JACE_DIR)
45
46if(NOT DEFINED Jar2Lib_DIST_DIR)
47  set(Jar2Lib_DIST_DIR dist/${projectId})
48endif(NOT DEFINED Jar2Lib_DIST_DIR)
49
50if(NOT DEFINED J2L_BUILD_TYPE)
51  set(J2L_BUILD_TYPE "")
52endif(NOT DEFINED J2L_BUILD_TYPE)
53
54if(NOT DEFINED J2L_LIB_PREFIX)
55  set(J2L_LIB_PREFIX lib)
56endif(NOT DEFINED J2L_LIB_PREFIX)
57
58if(APPLE)
59
60 if(NOT DEFINED J2L_SUFFIX)
61   set(J2L_SUFFIX .dylib)
62 endif(NOT DEFINED J2L_SUFFIX)
63
64 if(NOT DEFINED J2L_JNI_SUFFIX)
65   set(J2L_JNI_SUFFIX .jnilib)
66 endif(NOT DEFINED J2L_JNI_SUFFIX)
67
68 if(NOT DEFINED J2L_EXE_SUFFIX)
69   set(J2L_EXE_SUFFIX "")
70 endif(NOT DEFINED J2L_EXE_SUFFIX)
71
72endif(APPLE)
73
74if(UNIX)
75
76 if(NOT DEFINED J2L_SUFFIX)
77
78   set(J2L_SUFFIX .so)
79
80 endif(NOT DEFINED J2L_SUFFIX)
81
82 if(NOT DEFINED J2L_EXE_SUFFIX)
83   set(J2L_EXE_SUFFIX "")
84 endif(NOT DEFINED J2L_EXE_SUFFIX)
85
86endif(UNIX)
87
88if(WIN32)
89   set(J2L_LIB_PREFIX "")
90   set(J2L_BUILD_TYPE /Release)
91
92# Building in Debug mode is not currently supported in this script
93#  set(J2L_BUILD TYPE /Debug)
94
95  if(NOT DEFINED J2L_SUFFIX)
96
97    set(J2L_SUFFIX .dll)
98
99  endif(NOT DEFINED J2L_SUFFIX)
100
101 if(NOT DEFINED J2L_EXE_SUFFIX)
102   set(J2L_EXE_SUFFIX .exe)
103 endif(NOT DEFINED J2L_EXE_SUFFIX)
104
105endif(WIN32)
106
107if(WIN64)
108  set(J2L_LIB_PREFIX "")
109  set(J2L_BUILD_TYPE /Release)
110
111#  Builing with Debug mode on Windows is not currently supported in this script.
112#  set(J2L_BUILD TYPE /Debug)
113
114  if(NOT DEFINED J2L_SUFFIX)
115
116    set(J2L_SUFFIX .dll)
117
118  endif(NOT DEFINED J2L_SUFFIX)
119
120 if(NOT DEFINED J2L_EXE_SUFFIX)
121   set(J2L_SUFFIX )
122 endif(NOT DEFINED J2L_EXE_SUFFIX)
123
124endif(WIN64)
125
126
127if(APPLE)
128#make a .dylib version of libjace
129  add_custom_command(
130    TARGET ${projectId}
131    DEPENDS "${CMAKE_BINARY_DIR}/${Jar2Lib_JACE_DIR}${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}jace${J2L_JNI_SUFFIX}"
132    POST_BUILD
133    COMMAND ${CMAKE_COMMAND} -E copy
134    "${CMAKE_BINARY_DIR}/${Jar2Lib_JACE_DIR}${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}jace${J2L_JNI_SUFFIX}"
135    "${CMAKE_BINARY_DIR}/${Jar2Lib_JACE_DIR}${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}jace${J2L_SUFFIX}"
136    VERBATIM
137  )
138
139  add_custom_command(
140    TARGET ${projectId}
141    DEPENDS "${CMAKE_BINARY_DIR}/${Jar2Lib_JACE_DIR}${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}jace${J2L_JNI_SUFFIX}"
142    POST_BUILD
143    COMMAND ${CMAKE_COMMAND} -E copy
144    "${CMAKE_BINARY_DIR}/${Jar2Lib_JACE_DIR}${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}jace${J2L_JNI_SUFFIX}"
145    "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${J2L_LIB_PREFIX}jace${J2L_JNI_SUFFIX}"
146    VERBATIM
147  )
148  install(FILES
149    "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${J2L_LIB_PREFIX}jace${J2L_JNI_SUFFIX}"
150    DESTINATION "${Jar2Lib_DIST_DIR}"
151  )
152
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_DIST_DIR}/${J2L_LIB_PREFIX}jace${J2L_SUFFIX}"
160    VERBATIM
161  )
162  install(FILES
163    "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${J2L_LIB_PREFIX}jace${J2L_SUFFIX}"
164    DESTINATION "${Jar2Lib_DIST_DIR}"
165  )
166endif(APPLE)
167
168#copy jace
169add_custom_command(
170  TARGET ${projectId}
171  DEPENDS "${CMAKE_BINARY_DIR}/${Jar2Lib_JACE_DIR}${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}jace${J2L_SUFFIX}"
172  POST_BUILD
173  COMMAND ${CMAKE_COMMAND} -E copy
174  "${CMAKE_BINARY_DIR}/${Jar2Lib_JACE_DIR}${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}jace${J2L_SUFFIX}"
175  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${J2L_LIB_PREFIX}jace${J2L_SUFFIX}"
176  VERBATIM
177)
178install(FILES
179  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${J2L_LIB_PREFIX}jace${J2L_SUFFIX}"
180  DESTINATION "${Jar2Lib_DIST_DIR}"
181)
182
183#copy ${projectId}
184add_custom_command(
185  TARGET ${projectId}
186  DEPENDS "${CMAKE_BINARY_DIR}/${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}${projectId}${J2L_SUFFIX}"
187  POST_BUILD
188  COMMAND ${CMAKE_COMMAND} -E copy
189  "${CMAKE_BINARY_DIR}/${J2L_BUILD_TYPE}/${J2L_LIB_PREFIX}${projectId}${J2L_SUFFIX}"
190  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${J2L_LIB_PREFIX}${projectId}${J2L_SUFFIX}"
191  VERBATIM
192)
193install(FILES
194  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${J2L_LIB_PREFIX}${projectId}${J2L_SUFFIX}"
195  DESTINATION "${Jar2Lib_DIST_DIR}"
196)
197
198# copy jace_runtime.jar
199add_custom_command(
200  TARGET ${projectId}
201  DEPENDS "${CMAKE_BINARY_DIR}/../jace-runtime.jar"
202  POST_BUILD
203  COMMAND ${CMAKE_COMMAND} -E copy
204  "${CMAKE_BINARY_DIR}/../jace-runtime.jar"
205  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/jace-runtime.jar"
206  VERBATIM
207)
208install(FILES
209  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/jace-runtime.jar"
210  DESTINATION "${Jar2Lib_DIST_DIR}"
211)
212
213#foreach ($jarFile in $sourceJars)
214#set ($jarName = $jarFile.getName())
215# copy ${jarName}
216add_custom_command(
217  TARGET ${projectId}
218  DEPENDS "${jarFile}"
219  POST_BUILD
220  COMMAND ${CMAKE_COMMAND} -E copy
221  "${jarFile}"
222  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${jarName}"
223  VERBATIM
224)
225install(FILES
226  "${CMAKE_BINARY_DIR}/${Jar2Lib_DIST_DIR}/${jarName}"
227  DESTINATION "${Jar2Lib_DIST_DIR}"
228)
229
230#end##foreach $sourceJars
231
232SET(CPACK_PACKAGE_FILE_NAME "${projectId}")
233SET(CPACK_GENERATOR "TGZ;ZIP")
234INCLUDE( CPack )
Note: See TracBrowser for help on using the repository browser.