forked from rljacobson/MathLine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
62 lines (56 loc) · 2.6 KB
/
CMakeLists.txt
File metadata and controls
62 lines (56 loc) · 2.6 KB
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
54
55
56
57
58
59
60
61
62
# Create the project.
cmake_minimum_required(VERSION 2.6)
project(mathline)
add_executable(mathline ${CMAKE_SOURCE_DIR}/src/main.cpp ${CMAKE_SOURCE_DIR}/src/mlbridge.cpp ${CMAKE_SOURCE_DIR}/src/linenoise.c)
include_directories("${CMAKE_SOURCE_DIR}/src" "${CMAKE_SOURCE_DIR}/build")
# Enable C++11 extensions.
target_compile_features(mathline PRIVATE cxx_constexpr)
#### FindMathematica ####
cmake_policy(SET CMP0012 OLD) # Silences warnings from FindMathematica
cmake_policy(SET CMP0011 NEW) # Silences warnings from FindMathematica
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMake/Mathematica" ${CMAKE_MODULE_PATH})
# Dynamically linking to MathLink introduces a nondeterministic malloc error upon
# exit. Statically linking seems to solve this problem.
set(Mathematica_USE_LIBCXX_LIBRARIES OFF)
set(Mathematica_USE_STATIC_LIBRARIES ON)
find_package(Mathematica COMPONENTS WSTP MathLink)
# The following is only relevant for linking dynamically to MathLink on Mac OS X.
# We record it here for future reference.
# Fix MathLink shared library references under Mac OS X:
# Mathematica_ABSOLUTIZE_LIBRARY_DEPENDENCIES(mathline)
# Choose between WSTP and MathLink.
if(Mathematica_WSTP_FOUND)
set(WSTP true)
set(ML_PREFIX WS)
include_directories(${Mathematica_WSTP_INCLUDE_DIR})
target_link_libraries(mathline ${Mathematica_WSTP_LIBRARY})
message("WSTP library is: ${Mathematica_WSTP_LIBRARY}")
elseif(Mathematica_MathLink_FOUND)
set(WSTP false)
set(ML_PREFIX ML)
include_directories(${Mathematica_MathLink_INCLUDE_DIR})
target_link_libraries(mathline ${Mathematica_MathLink_LIBRARY})
endif()
# Link to the correct stdlib.
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
# We're on macOS X.
# TODO: Prior to version 10.4, use -lstdc++ in EXTRA_LIBS to link against libstdc++ instead of libc++.
# MathLink requires we link to CoreFoundation
find_library(COREFOUNDATION_LIBRARY CoreFoundation)
target_link_libraries(mathline ${COREFOUNDATION_LIBRARY})
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
# Using GCC. MathLink requires additional libraries.
target_link_libraries(mathline m pthread c++ dl)
endif()
else()
# The libuuid library is special. On (at least) Ubuntu libuuid.so isn't
# symlinked to libuuid.so.1 if libuuid-dev isn't installed, so ld can't
# find -luuid.
find_library(UUID_LIBRARY REQUIRED NAMES uuid libuuid.so.1)
target_link_libraries(mathline m pthread rt stdc++ dl ${UUID_LIBRARY})
endif()
# Configure a header file to pass some of the CMake settings
# to the source code
configure_file("${CMAKE_SOURCE_DIR}/src/config.h.in" "${CMAKE_SOURCE_DIR}/build/config.h")
# Installation
install(TARGETS mathline DESTINATION bin)