-
Notifications
You must be signed in to change notification settings - Fork 43
/
CMakeLists.txt
53 lines (49 loc) · 2.04 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# CMake build script for the AMPL/JaCoP solver.
check_module(jacop build_jacop EXTERNAL)
if (build_jacop)
file(GLOB JACOP_JAR_PATH ${PROJECT_SOURCE_DIR}/thirdparty/jacop/jacop-*.jar)
get_filename_component(jar ${JACOP_JAR_PATH} NAME)
set(JACOP_JAR ${jar} CACHE STRING "JaCoP JAR file name.")
if (CMAKE_SIZEOF_VOID_P EQUAL 4)
# Set CMAKE_SYSTEM_PROCESSOR to make sure FindJNI finds the correct
# AWT and JVM libraries.
set(CMAKE_SYSTEM_PROCESSOR i586)
endif ()
find_package(JNI)
find_package(Java)
if (JNI_FOUND AND JAVA_FOUND)
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
# Add libmawt.so to JNI_LIBRARIES to avoid linkage errors on Ubuntu 10.04.
find_library(JAVA_MAWT_LIBRARY mawt
PATHS ${JAVA_AWT_LIBRARY_DIRECTORIES} PATH_SUFFIXES xawt)
if (JAVA_MAWT_LIBRARY)
set(JNI_LIBRARIES ${JNI_LIBRARIES} ${JAVA_MAWT_LIBRARY})
endif ()
endif ()
add_ampl_solver(jacop jacop.cc jacop.h java.cc java.h
INCLUDE_DIRS ${JNI_INCLUDE_DIRS} LIBRARIES ${JNI_LIBRARIES})
if (MSVC)
target_link_libraries(jacop PRIVATE -DELAYLOAD:jvm.dll delayimp)
endif ()
add_custom_command(TARGET jacop
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${JACOP_JAR_PATH} $<TARGET_FILE_DIR:jacop>)
# Get jacop version.
if (JACOP_JAR MATCHES "jacop-(.*)\\.jar")
set(JACOP_VERSION ${CMAKE_MATCH_1})
else ()
message(FATAL_ERROR "Cannot determine JaCoP version.")
endif ()
target_compile_definitions(ampljacop-static
PRIVATE JACOP_VERSION=\"${JACOP_VERSION}\")
include(UseJava)
set(CMAKE_JAVA_INCLUDE_PATH ${JACOP_JAR_PATH})
set(CMAKE_JAVA_COMPILE_FLAGS -source 1.7 -target 1.7 -Xlint:-options)
add_jar(ampljacop-java InterruptingListener.java SolutionListener.java
OUTPUT_NAME ampljacop OUTPUT_DIR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
add_custom_command(TARGET ampljacop-java
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ampljacop.jar
$<TARGET_FILE_DIR:jacop>)
endif ()
endif ()