-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
138 lines (117 loc) · 5.8 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
cmake_minimum_required(VERSION 2.8.11)
# for FindMatlab support (may require a later version to detect the latest Matlab release)
project (matlab-nlopt)
list (APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
option (BUILD_NLOPT_LIBS "Build NLopt as a shared library and place it along the MEX file" ON)
set(NLOPT_LIB_DIR "" CACHE PATH "If NLopt not built together, specify the location of NLopt library directory")
set(NLOPT_INCLUDE_DIR "" CACHE PATH "If NLopt not built together, specify the location of NLopt include directory")
# Set the default installation directory
if (WIN32)
set(MATLAB_USER_DIR "$ENV{USERPROFILE}/Documents/MATLAB")
else()
set(MATLAB_USER_DIR "$ENV{home}/Documents/MATLAB")
endif()
if (NOT EXISTS ${MATLAB_USER_DIR})
# if not found, show message and use the default CMake install directory
message("Matlab user directory not found at ${MATLAB_USER_DIR}. It will be created if intallation directory not changed.")
elseif (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set (CMAKE_INSTALL_PREFIX "${MATLAB_USER_DIR}" CACHE PATH "Installation directory" FORCE)
endif()
set(MATLAB_NLOPT_TOOLBOX_DIR "nlopt" CACHE PATH "Installation subdirectory for Matlab-NLopt package")
set(MATLAB_NLOPT_EXAMPLE_DIR "nlopt" CACHE PATH "Installation subdirectory for Matlab-NLopt examples")
# set global C++ compilation/linking options
# Look for MATLAB API library paths
find_package(Matlab REQUIRED COMPONENTS MX_LIBRARY)
# Build/find NLopt
add_library(nloptlib SHARED IMPORTED)
if (BUILD_NLOPT_LIBS)
if (WIN32) # build only DLL to be placed on @options directory
set(NLOPT_ROOT "${CMAKE_BINARY_DIR}/nlopt")
if (NOT EXISTS "${NLOPT_ROOT}/build/nlopt.dll") # WIN32 must have it locally
# Download and unpack nlopt at configure time
configure_file(CMakeLists.txt.win32.in nlopt/CMakeLists.txt)
execute_process(COMMAND "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" .
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/nlopt" )
execute_process(COMMAND "${CMAKE_COMMAND}" --build .
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/nlopt" )
# include(ExternalProject)
# ExternalProject_Add(nlopt
# PREFIX ${NLOPT_ROOT}
# GIT_REPOSITORY "https://github.com/stevengj/nlopt.git"
# BINARY_DIR "${NLOPT_ROOT}/build"
# CMAKE_ARGS
# -DCMAKE_BUILD_TYPE=Release
# -DNLOPT_CXX:BOOL=OFF
# -DBUILD_SHARED_LIBS:BOOL=ON
# -DNLOPT_PYTHON:BOOL=OFF
# -DNLOPT_OCTAVE:BOOL=OFF
# -DNLOPT_MATLAB:BOOL=OFF
# -DNLOPT_GUILE:BOOL=OFF
# -DNLOPT_SWIG:BOOL=OFF
# -DCMAKE_INSTALL_PREFIX=${NLOPT_ROOT}
# )
endif()
# set include & library path
set(NLOPT_INCLUDE_DIR "${NLOPT_ROOT}/include")
set(NLOPT_LIBRARY "${NLOPT_ROOT}/lib/nlopt.lib")
message("NLOPT_LIBRAR=${NLOPT_LIBRARY}")
else()
find_package(NLopt) # if installed sets NLOPT_FOUND, NLOPT_INCLUDE_DIR, & NLOPT_LIBRARY
if (NOT NLOPT_FOUND) # install the full package with default options (sans )
configure_file(CMakeLists.txt.in nlopt/CMakeLists.txt)
execute_process(COMMAND "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" .
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/nlopt" )
execute_process(COMMAND "${CMAKE_COMMAND}" --build .
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/nlopt" )
# include(ExternalProject)
# ExternalProject_Add(nlopt
# PREFIX ${NLOPT_ROOT}
# GIT_REPOSITORY "https://github.com/stevengj/nlopt.git"
# BINARY_DIR "${NLOPT_ROOT}/build"
# CMAKE_ARGS
# -DCMAKE_BUILD_TYPE=Release
# -DNLOPT_CXX:BOOL=OFF
# -DBUILD_SHARED_LIBS:BOOL=ON
# )
endif()
endif()
else()
find_package(NLopt REQUIRED) # sets NLOPT_INCLUDE_DIR & NLOPT_LIBRARY
endif()
set_target_properties(nloptlib PROPERTIES IMPORTED_LOCATION ${NLOPT_LIBRARY})
# globally include directories containing the C++ header files of external libraries
include_directories(${NLOPT_INCLUDE_DIR})
include_directories("mexutils/include")
# set globally to ignore MSVC warning on STD library calls
if(WIN32 AND MSVC)
add_compile_options(/wd4996)
endif()
# add the install procedures
install(DIRECTORY +nlopt
DESTINATION ${MATLAB_NLOPT_TOOLBOX_DIR}
FILES_MATCHING
PATTERN "*.m"
PATTERN "+nlopt/@options/options.m" EXCLUDE) # copy all the package m-files
# first we can indicate the documentation build as an option and set it to ON by default
# option(BUILD_DOC "Build documentation" ON)
# documentation build
# find_package(Doxygen) # check if Doxygen is installed
# if (DOXYGEN_FOUND AND CMAKE_BUILD_TYPE MATCHES "^[Rr]elease")
# # set input and output files
# set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile.in)
# set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
# # request to configure the file
# configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY)
# message("Doxygen build started")
# # note the option ALL which allows to build the docs together with the application
# add_custom_target( doc_doxygen ALL
# COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
# WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
# COMMENT "Generating API documentation with Doxygen"
# VERBATIM )
# else ()
# message("Doxygen need to be installed to generate the doxygen documentation")
# endif ()
# traverse subfolders (note mexutils not included as it is a header only library)
add_subdirectory("+nlopt")
add_subdirectory("examples")