From 6bec09f843f5ffd7e1cce55937e91c46dc577536 Mon Sep 17 00:00:00 2001 From: Julien Schueller Date: Fri, 4 Sep 2015 08:25:18 +0200 Subject: [PATCH 01/29] cmake: set default Release build type --- CMakeLists.txt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1c7a67c0..3b705c1b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,3 @@ -PROJECT(NLOPT) - #============================================================================== # NLOPT CMake file # @@ -14,9 +12,15 @@ PROJECT(NLOPT) # Benoit Scherrer, 2010 CRL, Harvard Medical School # Copyright (c) 2008-2009 Children's Hospital Boston #============================================================================== +cmake_minimum_required (VERSION 2.6) + +if (NOT DEFINED CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type") +endif () + +project (nlopt C) -CMAKE_MINIMUM_REQUIRED(VERSION 2.6) INCLUDE(CheckIncludeFiles) INCLUDE(CheckFunctionExists) INCLUDE(CheckTypeSize) From ec83297fc97fdb22a669c6604bc4f611de2b867b Mon Sep 17 00:00:00 2001 From: Julien Schueller Date: Fri, 4 Sep 2015 08:30:28 +0200 Subject: [PATCH 02/29] cmake: optionally enable cxx --- CMakeLists.txt | 11 ++++++++++- config.cmake.h.in | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3b705c1b..d1505bee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,11 @@ endif () project (nlopt C) +option (WITH_CXX "enable cxx routines" OFF) + +if (WITH_CXX) + enable_language (CXX) +endif () INCLUDE(CheckIncludeFiles) INCLUDE(CheckFunctionExists) @@ -144,9 +149,13 @@ SET ( NLOPT_SOURCES esch/esch.c esch/esch.h api/general.c api/options.c api/optimize.c api/deprecated.c api/nlopt-internal.h api/nlopt.h api/f77api.c api/f77funcs.h api/f77funcs_.h api/nlopt.hpp api/nlopt-in.hpp util/mt19937ar.c util/sobolseq.c util/soboldata.h util/timer.c util/stop.c util/nlopt-util.h util/redblack.c util/redblack.h util/qsort_r.c util/rescale.c - stogo/global.cc stogo/linalg.cc stogo/local.cc stogo/stogo.cc stogo/tools.cc stogo/global.h stogo/linalg.h stogo/local.h stogo/stogo_config.h stogo/stogo.h stogo/tools.h ) +if (WITH_CXX) + list (APPEND NLOPT_SOURCES stogo/global.cc stogo/linalg.cc stogo/local.cc stogo/stogo.cc stogo/tools.cc stogo/global.h stogo/linalg.h stogo/local.h stogo/stogo_config.h stogo/stogo.h stogo/tools.h) +endif () + + OPTION(BUILD_SHARED_LIBS "Build NLOPT as a shared library" OFF ) if (BUILD_SHARED_LIBS) diff --git a/config.cmake.h.in b/config.cmake.h.in index 0dce2dba..28d0ddeb 100644 --- a/config.cmake.h.in +++ b/config.cmake.h.in @@ -142,7 +142,7 @@ #undef VERSION /* Define if compiled including C++-based routines */ -#undef WITH_CXX +#cmakedefine WITH_CXX /* Define if we have the non-free Nocedal LBFGS code */ #undef WITH_NOCEDAL From 087d93edbadc1438c4bc1be4ff99d2b9dd1d2555 Mon Sep 17 00:00:00 2001 From: Julien Schueller Date: Fri, 4 Sep 2015 08:33:20 +0200 Subject: [PATCH 03/29] cmake: enable bindings with static library --- CMakeLists.txt | 18 +++++++++++++++--- swig/CMakeLists.txt | 2 +- swig/Makefile.am | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d1505bee..2db99a69 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,7 @@ endif () project (nlopt C) option (WITH_CXX "enable cxx routines" OFF) +option (BUILD_SHARED_LIBS "Build NLOPT as a shared library" OFF) if (WITH_CXX) enable_language (CXX) @@ -29,7 +30,7 @@ endif () INCLUDE(CheckIncludeFiles) INCLUDE(CheckFunctionExists) INCLUDE(CheckTypeSize) - +include (CheckCCompilerFlag) #============================================================================== # COMPILATION CHECKINGS and CONFIGURATION GENERATION @@ -156,8 +157,6 @@ if (WITH_CXX) endif () -OPTION(BUILD_SHARED_LIBS "Build NLOPT as a shared library" OFF ) - if (BUILD_SHARED_LIBS) ADD_DEFINITIONS(-DNLOPT_DLL) ADD_DEFINITIONS(-DNLOPT_DLL_EXPORT ) @@ -172,6 +171,19 @@ INSTALL ( FILES ${NLOPT_HEADERS} DESTINATION include ) ADD_LIBRARY (nlopt ${NLOPT_SOURCES} ) +# pass -fPIC in case swig module is built with static library +if (NOT BUILD_SHARED_LIBS) + if (CMAKE_VERSION VERSION_LESS 2.8.9) + check_c_compiler_flag (-fPIC HAS_FPIC) + if (HAS_FPIC) + set (CMAKE_C_FLAGS "-fPIC ${CMAKE_C_FLAGS}") + set (CMAKE_CXX_FLAGS "-fPIC ${CMAKE_CXX_FLAGS}") + endif () + else () + set_target_properties (${nlopt_library} PROPERTIES POSITION_INDEPENDENT_CODE ON) + endif () +endif () + # parse configure.ac for lib version STRING( REGEX MATCH "SHARED_VERSION_INFO=\"[0-9]+:[0-9]+:[0-9]+\"" _VERSION_INFO_LINE "${CONFIG_AUTOMAKE}") IF (_VERSION_INFO_LINE) diff --git a/swig/CMakeLists.txt b/swig/CMakeLists.txt index d2fa84d5..4d41aef7 100644 --- a/swig/CMakeLists.txt +++ b/swig/CMakeLists.txt @@ -7,7 +7,7 @@ if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/nlopt-python.cpp) find_package (SWIG) endif () -if (BUILD_PYTHON AND PYTHONINTERP_FOUND AND PYTHONLIBS_FOUND AND (SWIG_FOUND OR (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/nlopt-python.cpp)) AND BUILD_SHARED_LIBS) +if (BUILD_PYTHON AND PYTHONINTERP_FOUND AND PYTHONLIBS_FOUND AND (SWIG_FOUND OR (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/nlopt-python.cpp))) include_directories (${CMAKE_SOURCE_DIR}/api) include_directories (${PYTHON_INCLUDE_DIRS}) diff --git a/swig/Makefile.am b/swig/Makefile.am index cbba1648..7960c1d5 100644 --- a/swig/Makefile.am +++ b/swig/Makefile.am @@ -1,5 +1,5 @@ SWIG_SRC = nlopt.i nlopt-exceptions.i nlopt-enum-renames.i -EXTRA_DIST = $(SWIG_SRC) nlopt-guile.i nlopt-python.i nlopt.scm.in nlopt.py numpy.i +EXTRA_DIST = $(SWIG_SRC) nlopt-guile.i nlopt-python.i nlopt.scm.in nlopt.py numpy.i CMakeLists.txt BUILT_SOURCES = nlopt-guile.cpp nlopt-python.cpp nlopt-enum-renames.i nlopt.scm.in From b565b8c03c5209fd5fb7e8f27e94ebd7517223ba Mon Sep 17 00:00:00 2001 From: Julien Schueller Date: Fri, 4 Sep 2015 09:01:10 +0200 Subject: [PATCH 04/29] cmake: build testopt --- .travis.yml | 3 ++- CMakeLists.txt | 21 +++++++++++++++++++++ swig/CMakeLists.txt | 14 +------------- test/CMakeLists.txt | 32 ++++++++++++++++++++++++++++++++ test/Makefile.am | 2 +- 5 files changed, 57 insertions(+), 15 deletions(-) create mode 100644 test/CMakeLists.txt diff --git a/.travis.yml b/.travis.yml index efa2bde7..0e99de8e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,4 +21,5 @@ script: - rm -rf * ~/.local - cmake -DCMAKE_INSTALL_PREFIX=~/.local -DBUILD_SHARED_LIBS=ON .. - make install -j2 - - python ../test/test_std.py + - make tests -j2 + - ctest -j2 --output-on-failure diff --git a/CMakeLists.txt b/CMakeLists.txt index 2db99a69..f54b8957 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,7 @@ project (nlopt C) option (WITH_CXX "enable cxx routines" OFF) option (BUILD_SHARED_LIBS "Build NLOPT as a shared library" OFF) +option (BUILD_PYTHON "build python bindings" ON) if (WITH_CXX) enable_language (CXX) @@ -202,4 +203,24 @@ INSTALL ( TARGETS nlopt ARCHIVE DESTINATION lib${LIB_SUFFIX} ) +if (BUILD_PYTHON) + find_package (PythonInterp) + find_package (PythonLibs) +endif () + +if (PYTHONINTERP_FOUND) + execute_process ( COMMAND ${PYTHON_EXECUTABLE} -c "from distutils import sysconfig; print(sysconfig.get_python_lib(plat_specific=True, prefix='${CMAKE_INSTALL_PREFIX}'))" + OUTPUT_VARIABLE _ABS_PYTHON_MODULE_PATH + OUTPUT_STRIP_TRAILING_WHITESPACE ) + + get_filename_component (_ABS_PYTHON_MODULE_PATH ${_ABS_PYTHON_MODULE_PATH} ABSOLUTE) + file (RELATIVE_PATH _REL_PYTHON_MODULE_PATH ${CMAKE_INSTALL_PREFIX} ${_ABS_PYTHON_MODULE_PATH}) + + set (PYTHON_MODULE_PATH ${_REL_PYTHON_MODULE_PATH}) + +endif () + add_subdirectory (swig) + +enable_testing () +add_subdirectory (test) diff --git a/swig/CMakeLists.txt b/swig/CMakeLists.txt index 4d41aef7..c4a4d851 100644 --- a/swig/CMakeLists.txt +++ b/swig/CMakeLists.txt @@ -1,13 +1,9 @@ -option (BUILD_PYTHON "build python bindings" ON) - -find_package (PythonInterp) -find_package (PythonLibs) if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/nlopt-python.cpp) find_package (SWIG) endif () -if (BUILD_PYTHON AND PYTHONINTERP_FOUND AND PYTHONLIBS_FOUND AND (SWIG_FOUND OR (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/nlopt-python.cpp))) +if (PYTHONINTERP_FOUND AND PYTHONLIBS_FOUND AND (SWIG_FOUND OR (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/nlopt-python.cpp))) include_directories (${CMAKE_SOURCE_DIR}/api) include_directories (${PYTHON_INCLUDE_DIRS}) @@ -30,14 +26,6 @@ if (BUILD_PYTHON AND PYTHONINTERP_FOUND AND PYTHONLIBS_FOUND AND (SWIG_FOUND OR swig_link_libraries (nlopt nlopt) swig_link_libraries (nlopt ${PYTHON_LIBRARIES}) endif () - execute_process ( COMMAND ${PYTHON_EXECUTABLE} -c "from distutils import sysconfig; print(sysconfig.get_python_lib(plat_specific=True, prefix='${CMAKE_INSTALL_PREFIX}'))" - OUTPUT_VARIABLE _ABS_PYTHON_MODULE_PATH - OUTPUT_STRIP_TRAILING_WHITESPACE ) - - get_filename_component (_ABS_PYTHON_MODULE_PATH ${_ABS_PYTHON_MODULE_PATH} ABSOLUTE) - file (RELATIVE_PATH _REL_PYTHON_MODULE_PATH ${CMAKE_INSTALL_PREFIX} ${_ABS_PYTHON_MODULE_PATH}) - - set (PYTHON_MODULE_PATH ${_REL_PYTHON_MODULE_PATH}) install ( FILES ${CMAKE_CURRENT_BINARY_DIR}/nlopt.py DESTINATION ${PYTHON_MODULE_PATH} ) install ( TARGETS ${SWIG_MODULE_nlopt_REAL_NAME} LIBRARY DESTINATION ${PYTHON_MODULE_PATH} ) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 00000000..99499362 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,32 @@ +add_custom_target (tests) + +add_executable (testopt EXCLUDE_FROM_ALL testfuncs.c testfuncs.h testopt.cpp) +target_link_libraries (testopt nlopt) +add_dependencies (tests testopt) + +foreach (algo_index RANGE 29)# 42 + foreach (obj_index RANGE 1)# 21 + set (enable_ TRUE) + # cxx stogo + if (NOT WITH_CXX) + if (algo_index STREQUAL 8 OR algo_index STREQUAL 9) + set (enable_ FALSE) + endif () + endif () + # L-BFGS + if (algo_index STREQUAL 10) + set (enable_ FALSE) + endif () + if (enable_) + add_test (NAME testopt_algo${algo_index}_obj${obj_index} COMMAND testopt -a ${algo_index} -o ${obj_index}) + endif () + endforeach () +endforeach () + +if (PYTHONINTERP_FOUND) + set (PYINSTALLCHECK_ENVIRONMENT "LD_LIBRARY_PATH=${INSTALL_DESTDIR}${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}:$ENV{LD_LIBRARY_PATH}" + "PYTHONPATH=${INSTALL_DESTDIR}${CMAKE_INSTALL_PREFIX}/${PYTHON_MODULE_PATH}${PATH_SEP}$ENV{PYTHONPATH}" + ) + add_test (NAME test_std_python COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_std.py) + set_tests_properties (test_std_python PROPERTIES ENVIRONMENT "${PYINSTALLCHECK_ENVIRONMENT}") +endif () diff --git a/test/Makefile.am b/test/Makefile.am index f0b3f471..d75a0201 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -4,5 +4,5 @@ noinst_PROGRAMS = testopt testopt_SOURCES = testfuncs.c testfuncs.h testopt.cpp testopt_LDADD = $(top_builddir)/libnlopt@NLOPT_SUFFIX@.la -EXTRA_DIST = test_std.py +EXTRA_DIST = test_std.py CMakeLists.txt From 06c6b0a928c0e39ecaa7f0b1afe841cb20699f7b Mon Sep 17 00:00:00 2001 From: Julien Schueller Date: Fri, 4 Sep 2015 09:02:08 +0200 Subject: [PATCH 05/29] cmake: enable cxx for python bindings --- CMakeLists.txt | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f54b8957..4bd7e981 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,7 @@ option (WITH_CXX "enable cxx routines" OFF) option (BUILD_SHARED_LIBS "Build NLOPT as a shared library" OFF) option (BUILD_PYTHON "build python bindings" ON) -if (WITH_CXX) +if (WITH_CXX OR BUILD_PYTHON) enable_language (CXX) endif () @@ -174,14 +174,10 @@ ADD_LIBRARY (nlopt ${NLOPT_SOURCES} ) # pass -fPIC in case swig module is built with static library if (NOT BUILD_SHARED_LIBS) - if (CMAKE_VERSION VERSION_LESS 2.8.9) - check_c_compiler_flag (-fPIC HAS_FPIC) - if (HAS_FPIC) - set (CMAKE_C_FLAGS "-fPIC ${CMAKE_C_FLAGS}") - set (CMAKE_CXX_FLAGS "-fPIC ${CMAKE_CXX_FLAGS}") - endif () - else () - set_target_properties (${nlopt_library} PROPERTIES POSITION_INDEPENDENT_CODE ON) + check_c_compiler_flag (-fPIC HAS_FPIC) + if (HAS_FPIC) + set (CMAKE_C_FLAGS "-fPIC ${CMAKE_C_FLAGS}") + set (CMAKE_CXX_FLAGS "-fPIC ${CMAKE_CXX_FLAGS}") endif () endif () From bc3e5621ee01ec47f3e9c06269b495288ce4cd9d Mon Sep 17 00:00:00 2001 From: Julien Schueller Date: Fri, 4 Sep 2015 09:05:54 +0200 Subject: [PATCH 06/29] cmake: install nlopt.pc --- CMakeLists.txt | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4bd7e981..ba688c2d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -79,6 +79,7 @@ IF(${NLOPT_AUTOMAKE_LINE_VERSION} MATCHES ".*[0-9]+\\.[0-9]+\\.[0-9]+") STRING( REGEX REPLACE ".*([0-9]+)\\.[0-9]+\\.[0-9]*.*" "\\1" NLOPT_MAJOR_VERSION "${NLOPT_AUTOMAKE_LINE_VERSION}") STRING( REGEX REPLACE ".*[0-9]+\\.([0-9]+)\\.[0-9]*.*" "\\1" NLOPT_MINOR_VERSION "${NLOPT_AUTOMAKE_LINE_VERSION}") STRING( REGEX REPLACE ".*[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" NLOPT_BUGFIX_VERSION "${NLOPT_AUTOMAKE_LINE_VERSION}") + set (NLOPT_VERSION_STRING ${NLOPT_MAJOR_VERSION}.${NLOPT_MINOR_VERSION}.${NLOPT_BUGFIX_VERSION}) #--------------------------------- # Else (consider that version matches 'X.X') #--------------------------------- @@ -86,10 +87,10 @@ ELSE(${NLOPT_AUTOMAKE_LINE_VERSION} MATCHES ".*[0-9]+\\.[0-9]+\\.[0-9]+") STRING( REGEX REPLACE ".*([0-9]+)\\.[0-9]+.*" "\\1" NLOPT_MAJOR_VERSION "${NLOPT_AUTOMAKE_LINE_VERSION}") STRING( REGEX REPLACE ".*[0-9]+\\.([0-9]+).*" "\\1" NLOPT_MINOR_VERSION "${NLOPT_AUTOMAKE_LINE_VERSION}") SET (NLOPT_BUGFIX_VERSION "0") -ENDIF(${NLOPT_AUTOMAKE_LINE_VERSION} MATCHES ".*[0-9]+\\.[0-9]+\\.[0-9]+") - -MESSAGE(STATUS "NLOPT: Version number ${NLOPT_MAJOR_VERSION}.${NLOPT_MINOR_VERSION}.${NLOPT_BUGFIX_VERSION} found in configure.ac" ) + set (NLOPT_VERSION_STRING ${NLOPT_MAJOR_VERSION}.${NLOPT_MINOR_VERSION}) +endif() +message (STATUS "NLOPT: Version number ${NLOPT_VERSION_STRING} found in configure.ac" ) #============================================================================== # CREATE config.h @@ -97,6 +98,14 @@ MESSAGE(STATUS "NLOPT: Version number ${NLOPT_MAJOR_VERSION}.${NLOPT_MINOR_VERSI CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.cmake.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h IMMEDIATE ) +# pkgconfig file +set (prefix "${CMAKE_INSTALL_PREFIX}") +set (exec_prefix "\${prefix}") +set (libdir "\${exec_prefix}/lib") +set (includedir "\${prefix}/include") +set (VERSION "${NLOPT_VERSION_STRING}") +configure_file (${CMAKE_CURRENT_SOURCE_DIR}/nlopt.pc.in ${CMAKE_CURRENT_BINARY_DIR}/nlopt.pc @ONLY) +install (FILES ${CMAKE_CURRENT_BINARY_DIR}/nlopt.pc DESTINATION lib/pkgconfig) #============================================================================== # INCLUDE DIRECTORIES From 46075cebdd46cb928a808fa017430c7baae86d29 Mon Sep 17 00:00:00 2001 From: Julien Schueller Date: Fri, 4 Sep 2015 10:31:53 +0200 Subject: [PATCH 07/29] cmake: added missing compiler checks --- CMakeLists.txt | 90 +++++++++++++++++++++++++++++++---------------- config.cmake.h.in | 29 +++++++-------- util/timer.c | 4 +-- 3 files changed, 77 insertions(+), 46 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ba688c2d..8ba56e40 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,41 +28,71 @@ if (WITH_CXX OR BUILD_PYTHON) enable_language (CXX) endif () -INCLUDE(CheckIncludeFiles) -INCLUDE(CheckFunctionExists) -INCLUDE(CheckTypeSize) +include (CheckIncludeFiles) +include (CheckFunctionExists) +include (CheckTypeSize) include (CheckCCompilerFlag) #============================================================================== # COMPILATION CHECKINGS and CONFIGURATION GENERATION #============================================================================== -CHECK_INCLUDE_FILES( unistd.h HAVE_UNISTD_H) -CHECK_INCLUDE_FILES( string.h HAVE_STRING_H) -CHECK_INCLUDE_FILES( strings.h HAVE_STRINGS_H) -CHECK_INCLUDE_FILES( sys/stat.h HAVE_SYS_STAT_H) -CHECK_INCLUDE_FILES( inttypes.h HAVE_INTTYPES_H) -CHECK_INCLUDE_FILES( memory.h HAVE_MEMORY_H) -CHECK_INCLUDE_FILES( stdlib.h HAVE_STDLIB_H) -CHECK_INCLUDE_FILES( stdint.h HAVE_STDINT_H) - -CHECK_INCLUDE_FILES( sys/types.h HAVE_SYS_TYPES_H) -CHECK_INCLUDE_FILES( sys/types.h HAVE_SYS_TYPES_H) -CHECK_INCLUDE_FILES( sys/types.h HAVE_SYS_TYPES_H) - -CHECK_FUNCTION_EXISTS( isinf HAVE_ISINF) -CHECK_FUNCTION_EXISTS( isinf HAVE_ISNAN) -CHECK_FUNCTION_EXISTS( gettimeofday HAVE_GETTIMEOFDAY) -CHECK_FUNCTION_EXISTS( qsort_r HAVE_QSORT_R) -CHECK_FUNCTION_EXISTS( time HAVE_TIME) -CHECK_FUNCTION_EXISTS( copysign HAVE_COPYSIGN) - -CHECK_TYPE_SIZE(uint32_t UINT32_T) -IF(NOT HAVE_UINT32_T) - IF(MSVC) - SET(uint32_t "unsigned int") - SET(SIZEOF_UNSIGNED_INT 4) - ENDIF(MSVC) -ENDIF(NOT HAVE_UINT32_T) +check_include_file (dlfcn.h HAVE_DLFCN_H) +check_include_file (getopt.h HAVE_GETOPT_H) +check_include_file (unistd.h HAVE_UNISTD_H) +check_include_file (string.h HAVE_STRING_H) +check_include_file (strings.h HAVE_STRINGS_H) +check_include_file (inttypes.h HAVE_INTTYPES_H) +check_include_file (memory.h HAVE_MEMORY_H) +check_include_file (stdlib.h HAVE_STDLIB_H) +check_include_file (stdint.h HAVE_STDINT_H) +check_include_file (time.h HAVE_TIME_H) +check_include_file (sys/types.h HAVE_SYS_TYPES_H) +check_include_file (sys/stat.h HAVE_SYS_STAT_H) +check_include_file (sys/time.h HAVE_SYS_TIME_H) +if (HAVE_TIME_H AND HAVE_SYS_TIME_H) + set (TIME_WITH_SYS_TIME TRUE) +endif () +check_function_exists (getpid HAVE_GETPID) +check_function_exists (syscall HAVE_GETTID_SYSCALL) +check_function_exists (isinf HAVE_ISINF) +check_function_exists (isnan HAVE_ISNAN) +check_function_exists (gettimeofday HAVE_GETTIMEOFDAY) +check_function_exists (qsort_r HAVE_QSORT_R) +check_function_exists (time HAVE_TIME) +check_function_exists (copysign HAVE_COPYSIGN) +check_type_size ("uint32_t" SIZEOF_UINT32_T) +set (HAVE_UINT32_T ${SIZEOF_UINT32_T}) +check_type_size ("unsigned int" SIZEOF_UNSIGNED_INT) +check_type_size ("unsigned long" SIZEOF_UNSIGNED_LONG) + +if (NOT DEFINED HAVE_FPCLASSIFY) + message(STATUS "Looking for fpclassify") + file (WRITE ${CMAKE_BINARY_DIR}/fpclassify.c "#include \n") + file (APPEND ${CMAKE_BINARY_DIR}/fpclassify.c "int main(void) {\n") + file (APPEND ${CMAKE_BINARY_DIR}/fpclassify.c "if (!fpclassify(3.14159)) fpclassify(2.7183);\n") + file (APPEND ${CMAKE_BINARY_DIR}/fpclassify.c " return 0; }\n") + try_compile (HAVE_FPCLASSIFY + ${CMAKE_BINARY_DIR}/build_fpclassify + ${CMAKE_BINARY_DIR}/fpclassify.c + CMAKE_FLAGS -DLINK_LIBRARIES=m) + message(STATUS "Looking for fpclassify - ${HAVE_FPCLASSIFY}") +endif () + +option (WITH_THREADLOCAL "check thread local keyword" ON) +if (WITH_THREADLOCAL AND NOT DEFINED HAVE_THREAD_LOCAL_STORAGE) + foreach (_THREADLOCAL_KEY "__thread" "__declspec(thread)") + unset (HAVE_THREAD_LOCAL_STORAGE CACHE) + check_c_source_compiles(" + ${_THREADLOCAL_KEY} int tls; + + int main(void) { + return 0; + }" HAVE_THREAD_LOCAL_STORAGE) + if (${HAVE_THREAD_LOCAL_STORAGE}) + set (THREADLOCAL ${_THREADLOCAL_KEY}) + endif () + endforeach() +endif () #============================================================================== # LOOK FOR THE VERSION NUMBER IN configure.ac diff --git a/config.cmake.h.in b/config.cmake.h.in index 28d0ddeb..0937ab73 100644 --- a/config.cmake.h.in +++ b/config.cmake.h.in @@ -25,14 +25,20 @@ /* Define to 1 if you have the `BSDgettimeofday' function. */ #undef HAVE_BSDGETTIMEOFDAY +/* Define if the copysign function/macro is available. */ +#cmakedefine HAVE_COPYSIGN + /* Define to 1 if you have the header file. */ -#undef HAVE_DLFCN_H +#cmakedefine HAVE_DLFCN_H + +/* Define if the fpclassify() function/macro is available. */ +#cmakedefine HAVE_FPCLASSIFY /* Define to 1 if you have the header file. */ -#undef HAVE_GETOPT_H +#cmakedefine HAVE_GETOPT_H /* Define to 1 if you have the `getpid' function. */ -#undef HAVE_GETPID +#cmakedefine HAVE_GETPID /* Define if syscall(SYS_gettid) available. */ #undef HAVE_GETTID_SYSCALL @@ -40,9 +46,6 @@ /* Define to 1 if you have the `gettimeofday' function. */ #cmakedefine HAVE_GETTIMEOFDAY -/* Define if the copysign function/macro is available. */ -#cmakedefine HAVE_COPYSIGN - /* Define to 1 if you have the header file. */ #cmakedefine HAVE_INTTYPES_H @@ -79,6 +82,9 @@ /* Define to 1 if you have the header file. */ #cmakedefine HAVE_SYS_TYPES_H +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_TIME_H + /* Define to 1 if you have the `time' function. */ #cmakedefine HAVE_TIME @@ -126,17 +132,17 @@ #define SIZEOF_UNSIGNED_INT @SIZEOF_UNSIGNED_INT@ /* The size of `unsigned long', as computed by sizeof. */ -#undef SIZEOF_UNSIGNED_LONG +#define SIZEOF_UNSIGNED_LONG @SIZEOF_UNSIGNED_LONG@ /* Define to 1 if you have the ANSI C header files. */ #undef STDC_HEADERS /* Define to C thread-local keyword, or to nothing if this is not supported in your compiler. */ -#define THREADLOCAL +#define THREADLOCAL @THREADLOCAL@ /* Define to 1 if you can safely include both and . */ -#undef TIME_WITH_SYS_TIME +#cmakedefine TIME_WITH_SYS_TIME /* Version number of package */ #undef VERSION @@ -144,9 +150,6 @@ /* Define if compiled including C++-based routines */ #cmakedefine WITH_CXX -/* Define if we have the non-free Nocedal LBFGS code */ -#undef WITH_NOCEDAL - /* Define to empty if `const' does not conform to ANSI C. */ #undef const @@ -155,5 +158,3 @@ #ifndef __cplusplus #undef inline #endif - - diff --git a/util/timer.c b/util/timer.c index 8019d982..7eb7f291 100644 --- a/util/timer.c +++ b/util/timer.c @@ -22,11 +22,11 @@ #include "nlopt-util.h" -#if TIME_WITH_SYS_TIME +#ifdef TIME_WITH_SYS_TIME # include # include #else -# if HAVE_SYS_TIME_H +# ifdef HAVE_SYS_TIME_H # include # else # include From 06984ff40610c7fb9958bd6b8dec80e31c787a8a Mon Sep 17 00:00:00 2001 From: Julien Schueller Date: Fri, 4 Sep 2015 11:02:46 +0200 Subject: [PATCH 08/29] cmake: add octave support --- CMakeLists.txt | 11 +++ Makefile.am | 2 +- cmake/FindOctave.cmake | 209 +++++++++++++++++++++++++++++++++++++++++ octave/CMakeLists.txt | 25 +++++ octave/Makefile.am | 2 +- 5 files changed, 247 insertions(+), 2 deletions(-) create mode 100644 cmake/FindOctave.cmake create mode 100644 octave/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 8ba56e40..3a5a8450 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,9 +20,12 @@ endif () project (nlopt C) +list (APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) + option (WITH_CXX "enable cxx routines" OFF) option (BUILD_SHARED_LIBS "Build NLOPT as a shared library" OFF) option (BUILD_PYTHON "build python bindings" ON) +option (BUILD_OCTAVE "build octave bindings" ON) if (WITH_CXX OR BUILD_PYTHON) enable_language (CXX) @@ -257,5 +260,13 @@ endif () add_subdirectory (swig) +if (BUILD_OCTAVE) + find_package (Octave) +endif () + +if (OCTAVE_FOUND) + add_subdirectory (octave) +endif () + enable_testing () add_subdirectory (test) diff --git a/Makefile.am b/Makefile.am index 9cf85fa2..06bcfdcc 100644 --- a/Makefile.am +++ b/Makefile.am @@ -9,7 +9,7 @@ CXX_LIBS = stogo/libstogo.la endif SUBDIRS = util direct cdirect $(CXX_DIRS) praxis luksan crs mlsl mma cobyla newuoa neldermead auglag bobyqa isres slsqp esch api . octave test swig -EXTRA_DIST = autogen.sh nlopt.pc.in m4 CMakeLists.txt config.cmake.h.in +EXTRA_DIST = autogen.sh nlopt.pc.in m4 CMakeLists.txt config.cmake.h.in cmake/FindOctave.cmake libnlopt@NLOPT_SUFFIX@_la_SOURCES = if WITH_CXX diff --git a/cmake/FindOctave.cmake b/cmake/FindOctave.cmake new file mode 100644 index 00000000..6796254e --- /dev/null +++ b/cmake/FindOctave.cmake @@ -0,0 +1,209 @@ +# - Find Octave +# GNU Octave is a high-level interpreted language, primarily intended for numerical computations. +# available at http://www.gnu.org/software/octave/ +# +# This module defines: +# OCTAVE_EXECUTABLE - octave interpreter +# OCTAVE_INCLUDE_DIRS - include path for mex.h, mexproto.h +# OCTAVE_LIBRARIES - required libraries: octinterp, octave, cruft +# OCTAVE_OCTINTERP_LIBRARY - path to the library octinterp +# OCTAVE_OCTAVE_LIBRARY - path to the library octave +# OCTAVE_CRUFT_LIBRARY - path to the library cruft +# OCTAVE_VERSION_STRING - octave version string +# OCTAVE_MAJOR_VERSION - major version +# OCTAVE_MINOR_VERSION - minor version +# OCTAVE_PATCH_VERSION - patch version +# OCTAVE_OCT_FILE_DIR - object files that will be dynamically loaded +# OCTAVE_OCT_LIB_DIR - oct libraries +# OCTAVE_ROOT_DIR - octave prefix +# OCTAVE_M_SITE_DIR - .m files site dir +# OCTAVE_OCT_SITE_DIR - .oct files site dir +# +# The macro octave_add_oct allows to create compiled modules. +# octave_add_oct (target_name +# [SOURCES] source1 [source2 ...] +# [LINK_LIBRARIES lib1 [lib2 ...]] +# [EXTENSION ext] +#) +# +# To install it, you can the use the variable OCTAVE_OCT_FILE_DIR as follow: +# file (RELATIVE_PATH PKG_OCTAVE_OCT_SITE_DIR ${OCTAVE_ROOT_DIR} ${OCTAVE_OCT_SITE_DIR}) +# install ( +# TARGETS target_name +# DESTINATION ${PKG_OCTAVE_OCT_SITE_DIR} +# ) + + +#============================================================================= +# Copyright 2013, Julien Schueller +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# The views and conclusions contained in the software and documentation are those +# of the authors and should not be interpreted as representing official policies, +# either expressed or implied, of the FreeBSD Project. +#============================================================================= + +find_program(OCTAVE_CONFIG_EXECUTABLE + NAMES octave-config + ) + + +if (OCTAVE_CONFIG_EXECUTABLE) + execute_process (COMMAND ${OCTAVE_CONFIG_EXECUTABLE} -p PREFIX + OUTPUT_VARIABLE OCTAVE_ROOT_DIR + OUTPUT_STRIP_TRAILING_WHITESPACE) + + execute_process (COMMAND ${OCTAVE_CONFIG_EXECUTABLE} --m-site-dir + OUTPUT_VARIABLE OCTAVE_M_SITE_DIR + OUTPUT_STRIP_TRAILING_WHITESPACE) + + execute_process (COMMAND ${OCTAVE_CONFIG_EXECUTABLE} --oct-site-dir + OUTPUT_VARIABLE OCTAVE_OCT_SITE_DIR + OUTPUT_STRIP_TRAILING_WHITESPACE) + + execute_process (COMMAND ${OCTAVE_CONFIG_EXECUTABLE} -p BINDIR + OUTPUT_VARIABLE OCTAVE_BIN_PATHS + OUTPUT_STRIP_TRAILING_WHITESPACE) + + execute_process (COMMAND ${OCTAVE_CONFIG_EXECUTABLE} -p OCTINCLUDEDIR + OUTPUT_VARIABLE OCTAVE_INCLUDE_PATHS + OUTPUT_STRIP_TRAILING_WHITESPACE) + + execute_process (COMMAND ${OCTAVE_CONFIG_EXECUTABLE} -p OCTLIBDIR + OUTPUT_VARIABLE OCTAVE_LIBRARIES_PATHS + OUTPUT_STRIP_TRAILING_WHITESPACE) + + execute_process (COMMAND ${OCTAVE_CONFIG_EXECUTABLE} -p OCTFILEDIR + OUTPUT_VARIABLE OCTAVE_OCT_FILE_DIR + OUTPUT_STRIP_TRAILING_WHITESPACE) + + execute_process (COMMAND ${OCTAVE_CONFIG_EXECUTABLE} -p OCTLIBDIR + OUTPUT_VARIABLE OCTAVE_OCT_LIB_DIR + OUTPUT_STRIP_TRAILING_WHITESPACE) + + execute_process (COMMAND ${OCTAVE_CONFIG_EXECUTABLE} -v + OUTPUT_VARIABLE OCTAVE_VERSION_STRING + OUTPUT_STRIP_TRAILING_WHITESPACE) + + if (OCTAVE_VERSION_STRING) + string (REGEX REPLACE "([0-9]+)\\..*" "\\1" OCTAVE_MAJOR_VERSION ${OCTAVE_VERSION_STRING}) + string (REGEX REPLACE "[0-9]+\\.([0-9]+).*" "\\1" OCTAVE_MINOR_VERSION ${OCTAVE_VERSION_STRING}) + string (REGEX REPLACE "[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" OCTAVE_PATCH_VERSION ${OCTAVE_VERSION_STRING}) + endif () +endif () + + +find_program(OCTAVE_EXECUTABLE + HINTS ${OCTAVE_BIN_PATHS} + NAMES octave + ) + +find_program(OCTAVE_MKOCTFILE + HINTS ${OCTAVE_BIN_PATHS} + NAMES mkoctfile + ) + +find_library(OCTAVE_OCTINTERP_LIBRARY + NAMES octinterp liboctinterp + HINTS ${OCTAVE_LIBRARIES_PATHS} + ) +find_library(OCTAVE_OCTAVE_LIBRARY + NAMES octave liboctave + HINTS ${OCTAVE_LIBRARIES_PATHS} + ) +find_library(OCTAVE_CRUFT_LIBRARY + NAMES cruft libcruft + HINTS ${OCTAVE_LIBRARIES_PATHS} + ) + +set (OCTAVE_LIBRARIES ${OCTAVE_OCTINTERP_LIBRARY}) +list (APPEND OCTAVE_LIBRARIES ${OCTAVE_OCTAVE_LIBRARY}) +list (APPEND OCTAVE_LIBRARIES ${OCTAVE_CRUFT_LIBRARY}) + +find_path (OCTAVE_INCLUDE_DIR + NAMES mex.h + HINTS ${OCTAVE_INCLUDE_PATHS} + "${OCTAVE_INCLUDE_PATHS}/octave" + ) + +set (OCTAVE_INCLUDE_DIRS ${OCTAVE_INCLUDE_DIR}) + + +macro (octave_add_oct FUNCTIONNAME) + set (_CMD SOURCES) + set (_SOURCES) + set (_LINK_LIBRARIES) + set (_EXTENSION) + set (_OCT_EXTENSION oct) + foreach (_ARG ${ARGN}) + if (${_ARG} MATCHES SOURCES) + set (_CMD SOURCES) + elseif (${_ARG} MATCHES LINK_LIBRARIES ) + set (_CMD LINK_LIBRARIES ) + elseif (${_ARG} MATCHES EXTENSION) + set (_CMD EXTENSION) + else () + if (${_CMD} MATCHES SOURCES) + list (APPEND _SOURCES "${_ARG}") + elseif (${_CMD} MATCHES LINK_LIBRARIES ) + list (APPEND _LINK_LIBRARIES "${_ARG}") + elseif (${_CMD} MATCHES EXTENSION) + set (_OCT_EXTENSION ${_ARG}) + endif () + endif () + endforeach () + add_library (${FUNCTIONNAME} SHARED ${_SOURCES}) + target_link_libraries (${FUNCTIONNAME} ${OCTAVE_LIBRARIES} ${_LINK_LIBRARIES}) + set_target_properties (${FUNCTIONNAME} PROPERTIES + PREFIX "" + SUFFIX ".${_OCT_EXTENSION}" + ) +endmacro () + + +# handle REQUIRED and QUIET options +include (FindPackageHandleStandardArgs) +if (CMAKE_VERSION LESS 2.8.3) + find_package_handle_standard_args (Octave DEFAULT_MSG OCTAVE_EXECUTABLE OCTAVE_ROOT_DIR OCTAVE_INCLUDE_DIRS OCTAVE_LIBRARIES OCTAVE_VERSION_STRING) +else () + find_package_handle_standard_args (Octave REQUIRED_VARS OCTAVE_EXECUTABLE OCTAVE_ROOT_DIR OCTAVE_INCLUDE_DIRS OCTAVE_LIBRARIES VERSION_VAR OCTAVE_VERSION_STRING) +endif () + + +mark_as_advanced ( + OCTAVE_OCT_FILE_DIR + OCTAVE_OCT_LIB_DIR + OCTAVE_OCTINTERP_LIBRARY + OCTAVE_OCTAVE_LIBRARY + OCTAVE_CRUFT_LIBRARY + OCTAVE_LIBRARIES + OCTAVE_INCLUDE_DIR + OCTAVE_INCLUDE_DIRS + OCTAVE_ROOT_DIR + OCTAVE_VERSION_STRING + OCTAVE_MAJOR_VERSION + OCTAVE_MINOR_VERSION + OCTAVE_PATCH_VERSION +) + + + diff --git a/octave/CMakeLists.txt b/octave/CMakeLists.txt new file mode 100644 index 00000000..c9be0074 --- /dev/null +++ b/octave/CMakeLists.txt @@ -0,0 +1,25 @@ + +file (WRITE ${CMAKE_CURRENT_BINARY_DIR}/nlopt_optimize_usage.h "#define NLOPT_OPTIMIZE_USAGE \\\n") +file (STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/nlopt_optimize.m INPUT_LINES) +foreach (INPUT_LINE ${INPUT_LINES}) + string (REGEX REPLACE "^% " "" INPUT_LINE ${INPUT_LINE}) + string (REGEX REPLACE "^%" "" INPUT_LINE ${INPUT_LINE}) + foreach (repl_expr "tolerance" "help NLOPT_LN_SBPLX" "population") + string (REGEX REPLACE "\"${repl_expr}\"" "${repl_expr}" INPUT_LINE "${INPUT_LINE}") + endforeach () + file (APPEND ${CMAKE_CURRENT_BINARY_DIR}/nlopt_optimize_usage.h "\"${INPUT_LINE}\\n\" \\\n") +endforeach () +file (APPEND ${CMAKE_CURRENT_BINARY_DIR}/nlopt_optimize_usage.h "\n") + +include_directories (${OCTAVE_INCLUDE_DIRS}) +include_directories (${CMAKE_CURRENT_BINARY_DIR}) +octave_add_oct (nlopt_optimize SOURCES nlopt_optimize-oct.cc ${CMAKE_CURRENT_BINARY_DIR}/nlopt_optimize_usage.h) + +file (RELATIVE_PATH PKG_OCTAVE_OCT_SITE_DIR ${OCTAVE_ROOT_DIR} ${OCTAVE_OCT_SITE_DIR}) +install (TARGETS nlopt_optimize DESTINATION ${PKG_OCTAVE_OCT_SITE_DIR}) + +set (MFILES NLOPT_GN_DIRECT.m NLOPT_GN_DIRECT_L.m NLOPT_GN_DIRECT_L_RAND.m NLOPT_GN_DIRECT_NOSCAL.m NLOPT_GN_DIRECT_L_NOSCAL.m NLOPT_GN_DIRECT_L_RAND_NOSCAL.m NLOPT_GN_ORIG_DIRECT.m NLOPT_GN_ORIG_DIRECT_L.m NLOPT_GD_STOGO.m NLOPT_GD_STOGO_RAND.m NLOPT_LD_LBFGS_NOCEDAL.m NLOPT_LD_LBFGS.m NLOPT_LN_PRAXIS.m NLOPT_LD_VAR1.m NLOPT_LD_VAR2.m NLOPT_LD_TNEWTON.m NLOPT_LD_TNEWTON_RESTART.m NLOPT_LD_TNEWTON_PRECOND.m NLOPT_LD_TNEWTON_PRECOND_RESTART.m NLOPT_GN_CRS2_LM.m NLOPT_GN_MLSL.m NLOPT_GD_MLSL.m NLOPT_GN_MLSL_LDS.m NLOPT_GD_MLSL_LDS.m NLOPT_LD_MMA.m NLOPT_LN_COBYLA.m NLOPT_LN_NEWUOA.m NLOPT_LN_NEWUOA_BOUND.m NLOPT_LN_NELDERMEAD.m NLOPT_LN_SBPLX.m NLOPT_LN_AUGLAG.m NLOPT_LD_AUGLAG.m NLOPT_LN_AUGLAG_EQ.m NLOPT_LD_AUGLAG_EQ.m NLOPT_LN_BOBYQA.m NLOPT_GN_ISRES.m NLOPT_AUGLAG.m NLOPT_AUGLAG_EQ.m NLOPT_G_MLSL.m NLOPT_G_MLSL_LDS.m NLOPT_LD_SLSQP.m NLOPT_LD_CCSAQ.m NLOPT_GN_ESCH.m) +set (M_DATA ${MFILES} nlopt_minimize.m nlopt_minimize_constrained.m nlopt_optimize.m) + +file (RELATIVE_PATH PKG_OCTAVE_M_SITE_DIR ${OCTAVE_ROOT_DIR} ${OCTAVE_M_SITE_DIR}) +install (FILES ${M_DATA} DESTINATION ${PKG_OCTAVE_M_SITE_DIR}) diff --git a/octave/Makefile.am b/octave/Makefile.am index 695491cb..25ad75a2 100644 --- a/octave/Makefile.am +++ b/octave/Makefile.am @@ -38,6 +38,6 @@ nlopt_optimize.$(MEXSUFF): nlopt_optimize-mex.c $(top_builddir)/.libs/libnlopt@N ####################################################################### -EXTRA_DIST = nlopt_optimize-oct.cc nlopt_optimize-mex.c $(MFILES) nlopt_minimize.m nlopt_minimize_constrained.m nlopt_optimize.m nlopt_optimize_usage.h +EXTRA_DIST = nlopt_optimize-oct.cc nlopt_optimize-mex.c $(MFILES) nlopt_minimize.m nlopt_minimize_constrained.m nlopt_optimize.m nlopt_optimize_usage.h CMakeLists.txt CLEANFILES = nlopt_optimize.oct nlopt_optimize.h nlopt_optimize.$(MEXSUFF) nlopt_optimize-oct.o From 599ad7b2c746d813ac93947bc77ac444acf7d008 Mon Sep 17 00:00:00 2001 From: Julien Schueller Date: Fri, 4 Sep 2015 14:12:54 +0200 Subject: [PATCH 09/29] cmake: add guile bindings --- .travis.yml | 10 +++-- CMakeLists.txt | 37 ++++++++++------ Makefile.am | 2 +- cmake/FindGuile.cmake | 97 ++++++++++++++++++++++++++++++++++++++++++ cmake/FindOctave.cmake | 24 +++++------ octave/CMakeLists.txt | 2 +- swig/CMakeLists.txt | 62 +++++++++++++++++++++++++-- test/CMakeLists.txt | 2 +- 8 files changed, 201 insertions(+), 35 deletions(-) create mode 100644 cmake/FindGuile.cmake diff --git a/.travis.yml b/.travis.yml index 0e99de8e..b974bd78 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,9 @@ language: cpp -sudo: false +# sudo: false addons: apt: + sources: packages: - swig - python-dev @@ -11,15 +12,18 @@ addons: - octave3.2-headers - cmake +install: + - sudo apt-get -qq install guile-2.0-dev octave3.2-headers + script: - ./autogen.sh --no-configure - mkdir build && pushd build - - ../configure --prefix=$HOME/.local --enable-shared --enable-maintainer-mode --enable-cxx + - ../configure --prefix=$HOME/.local --enable-shared --enable-maintainer-mode --with-cxx --without-guile - make -j2 - make install - python ../test/test_std.py - rm -rf * ~/.local - - cmake -DCMAKE_INSTALL_PREFIX=~/.local -DBUILD_SHARED_LIBS=ON .. + - cmake -DCMAKE_INSTALL_PREFIX=~/.local -DBUILD_SHARED_LIBS=ON -DWITH_CXX=ON .. - make install -j2 - make tests -j2 - ctest -j2 --output-on-failure diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a5a8450..33339bdb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,6 +26,12 @@ option (WITH_CXX "enable cxx routines" OFF) option (BUILD_SHARED_LIBS "Build NLOPT as a shared library" OFF) option (BUILD_PYTHON "build python bindings" ON) option (BUILD_OCTAVE "build octave bindings" ON) +option (BUILD_GUILE "build guile bindings" ON) + +set (NLOPT_SUFFIX) +if (WITH_CXX) + set (NLOPT_SUFFIX _cxx) +endif () if (WITH_CXX OR BUILD_PYTHON) enable_language (CXX) @@ -212,7 +218,8 @@ endif () INSTALL ( FILES ${NLOPT_HEADERS} DESTINATION include ) -ADD_LIBRARY (nlopt ${NLOPT_SOURCES} ) +set (nlopt_lib nlopt${NLOPT_SUFFIX}) +add_library (${nlopt_lib} ${NLOPT_SOURCES}) # pass -fPIC in case swig module is built with static library if (NOT BUILD_SHARED_LIBS) @@ -224,18 +231,18 @@ if (NOT BUILD_SHARED_LIBS) endif () # parse configure.ac for lib version -STRING( REGEX MATCH "SHARED_VERSION_INFO=\"[0-9]+:[0-9]+:[0-9]+\"" _VERSION_INFO_LINE "${CONFIG_AUTOMAKE}") -IF (_VERSION_INFO_LINE) - STRING( REGEX REPLACE "SHARED_VERSION_INFO=\"([0-9]+):[0-9]+:[0-9]+\"" "\\1" _VERSION_INFO_CURRENT "${_VERSION_INFO_LINE}") - STRING( REGEX REPLACE "SHARED_VERSION_INFO=\"[0-9]+:([0-9]+):[0-9]+\"" "\\1" _VERSION_INFO_REVISION "${_VERSION_INFO_LINE}") - STRING( REGEX REPLACE "SHARED_VERSION_INFO=\"[0-9]+:[0-9]+:([0-9]+)\"" "\\1" _VERSION_INFO_AGE "${_VERSION_INFO_LINE}") - MATH(EXPR _INFO_SOVERSION "${_VERSION_INFO_CURRENT} - ${_VERSION_INFO_AGE} ") - SET(_INFO_VERSION "${_INFO_SOVERSION}.${_VERSION_INFO_AGE}.${_VERSION_INFO_REVISION}") - SET_TARGET_PROPERTIES(nlopt PROPERTIES SOVERSION ${_INFO_SOVERSION}) - SET_TARGET_PROPERTIES(nlopt PROPERTIES VERSION ${_INFO_VERSION} ) -ENDIF () - -INSTALL ( TARGETS nlopt +string (REGEX MATCH "SHARED_VERSION_INFO=\"[0-9]+:[0-9]+:[0-9]+\"" _VERSION_INFO_LINE "${CONFIG_AUTOMAKE}") +if (_VERSION_INFO_LINE) + string (REGEX REPLACE "SHARED_VERSION_INFO=\"([0-9]+):[0-9]+:[0-9]+\"" "\\1" _VERSION_INFO_CURRENT "${_VERSION_INFO_LINE}") + string (REGEX REPLACE "SHARED_VERSION_INFO=\"[0-9]+:([0-9]+):[0-9]+\"" "\\1" _VERSION_INFO_REVISION "${_VERSION_INFO_LINE}") + string (REGEX REPLACE "SHARED_VERSION_INFO=\"[0-9]+:[0-9]+:([0-9]+)\"" "\\1" _VERSION_INFO_AGE "${_VERSION_INFO_LINE}") + math (EXPR _INFO_SOVERSION "${_VERSION_INFO_CURRENT} - ${_VERSION_INFO_AGE} ") + set (_INFO_VERSION "${_INFO_SOVERSION}.${_VERSION_INFO_AGE}.${_VERSION_INFO_REVISION}") + set_target_properties (${nlopt_lib} PROPERTIES SOVERSION ${_INFO_SOVERSION}) + set_target_properties (${nlopt_lib} PROPERTIES VERSION ${_INFO_VERSION} ) +endif () + +install ( TARGETS ${nlopt_lib} RUNTIME DESTINATION bin LIBRARY DESTINATION lib${LIB_SUFFIX} ARCHIVE DESTINATION lib${LIB_SUFFIX} @@ -258,6 +265,10 @@ if (PYTHONINTERP_FOUND) endif () +if (BUILD_GUILE) + find_package (Guile) +endif () + add_subdirectory (swig) if (BUILD_OCTAVE) diff --git a/Makefile.am b/Makefile.am index 06bcfdcc..029006d4 100644 --- a/Makefile.am +++ b/Makefile.am @@ -9,7 +9,7 @@ CXX_LIBS = stogo/libstogo.la endif SUBDIRS = util direct cdirect $(CXX_DIRS) praxis luksan crs mlsl mma cobyla newuoa neldermead auglag bobyqa isres slsqp esch api . octave test swig -EXTRA_DIST = autogen.sh nlopt.pc.in m4 CMakeLists.txt config.cmake.h.in cmake/FindOctave.cmake +EXTRA_DIST = autogen.sh nlopt.pc.in m4 CMakeLists.txt config.cmake.h.in cmake/FindOctave.cmake cmake/FindGuile.cmake libnlopt@NLOPT_SUFFIX@_la_SOURCES = if WITH_CXX diff --git a/cmake/FindGuile.cmake b/cmake/FindGuile.cmake new file mode 100644 index 00000000..c2862d0c --- /dev/null +++ b/cmake/FindGuile.cmake @@ -0,0 +1,97 @@ +# Copyright (c) 2008, 2014 OpenCog.org (http://opencog.org) +# +# Redistribution and use is allowed according to the terms of the BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. + +# - Try to find Guile; Once done this will define +# +# GUILE_FOUND - system has the GUILE library +# GUILE_INCLUDE_DIRS - the GUILE include directory +# GUILE_LIBRARIES - The libraries needed to use GUILE +# GUILE_VERSION_STRING - Version +# GUILE_SITE_DIR - site dir +# GUILE_EXTENSION_DIR - extension dir +# GUILE_ROOT_DIR - prefix dir + +# Look for the header file +# Look for guile-2.2 first, then 2.0, then 1.8 +# Macports for OSX puts things in /opt/local +find_path (GUILE_INCLUDE_DIR libguile.h + PATH_SUFFIXES + guile/2.2 + guile/2.0 + guile/1.8 + libguile + guile + HINTS /opt/local/include +) + +# Look for the library +find_library (GUILE_LIBRARY NAMES guile-2.2 guile-2.0 guile + HINTS + /opt/local/lib +) + + +set (GUILE_LIBRARIES ${GUILE_LIBRARY}) +set (GUILE_INCLUDE_DIRS ${GUILE_INCLUDE_DIR}) + + +# check guile's version if we're using cmake >= 2.6 +if (GUILE_INCLUDE_DIR) + SET(GUILE_VERSION_MAJOR 0) + SET(GUILE_VERSION_MINOR 0) + SET(GUILE_VERSION_PATCH 0) + + IF(NOT EXISTS "${GUILE_INCLUDE_DIR}/libguile/version.h") + MESSAGE(FATAL_ERROR "Found ${GUILE_INCLUDE_DIR}/libguile.h but not version.h; check your guile installation!") + ENDIF(NOT EXISTS "${GUILE_INCLUDE_DIR}/libguile/version.h") + + # Extract the libguile version from the 'version.h' file + SET(GUILE_MAJOR_VERSION 0) + FILE(READ "${GUILE_INCLUDE_DIR}/libguile/version.h" _GUILE_VERSION_H_CONTENTS) + + STRING(REGEX MATCH "#define SCM_MAJOR_VERSION[ ]+([0-9])" _MATCH "${_GUILE_VERSION_H_CONTENTS}") + SET(GUILE_VERSION_MAJOR ${CMAKE_MATCH_1}) + STRING(REGEX MATCH "#define SCM_MINOR_VERSION[ ]+([0-9]+)" _MATCH "${_GUILE_VERSION_H_CONTENTS}") + SET(GUILE_VERSION_MINOR ${CMAKE_MATCH_1}) + STRING(REGEX MATCH "#define SCM_MICRO_VERSION[ ]+([0-9]+)" _MATCH "${_GUILE_VERSION_H_CONTENTS}") + SET(GUILE_VERSION_PATCH ${CMAKE_MATCH_1}) + + SET(GUILE_VERSION_STRING "${GUILE_VERSION_MAJOR}.${GUILE_VERSION_MINOR}.${GUILE_VERSION_PATCH}") + +endif () + +find_program(GUILE_CONFIG_EXECUTABLE + NAMES guile-config + ) + + +if (GUILE_CONFIG_EXECUTABLE) + execute_process (COMMAND ${GUILE_CONFIG_EXECUTABLE} info prefix + OUTPUT_VARIABLE GUILE_ROOT_DIR + OUTPUT_STRIP_TRAILING_WHITESPACE) + + execute_process (COMMAND ${GUILE_CONFIG_EXECUTABLE} info sitedir + OUTPUT_VARIABLE GUILE_SITE_DIR + OUTPUT_STRIP_TRAILING_WHITESPACE) + + execute_process (COMMAND ${GUILE_CONFIG_EXECUTABLE} info extensiondir + OUTPUT_VARIABLE GUILE_EXTENSION_DIR + OUTPUT_STRIP_TRAILING_WHITESPACE) +endif () + +# IF(GUILE_FOUND AND GUILE_VERSION_MAJOR EQUAL 2) +# ADD_DEFINITIONS(-DHAVE_GUILE2) +# ENDIF(GUILE_FOUND AND GUILE_VERSION_MAJOR EQUAL 2) + +# handle REQUIRED and QUIET options +include (FindPackageHandleStandardArgs) +if (CMAKE_VERSION LESS 2.8.3) + find_package_handle_standard_args (Guile DEFAULT_MSG GUILE_ROOT_DIR GUILE_INCLUDE_DIRS GUILE_LIBRARIES GUILE_VERSION_STRING) +else () + find_package_handle_standard_args (Guile REQUIRED_VARS GUILE_ROOT_DIR GUILE_INCLUDE_DIRS GUILE_LIBRARIES VERSION_VAR GUILE_VERSION_STRING) +endif () + + +MARK_AS_ADVANCED(GUILE_INCLUDE_DIR GUILE_LIBRARY) diff --git a/cmake/FindOctave.cmake b/cmake/FindOctave.cmake index 6796254e..021339db 100644 --- a/cmake/FindOctave.cmake +++ b/cmake/FindOctave.cmake @@ -31,7 +31,7 @@ # install ( # TARGETS target_name # DESTINATION ${PKG_OCTAVE_OCT_SITE_DIR} -# ) +#) #============================================================================= @@ -64,7 +64,7 @@ find_program(OCTAVE_CONFIG_EXECUTABLE NAMES octave-config - ) + ) if (OCTAVE_CONFIG_EXECUTABLE) @@ -115,25 +115,25 @@ endif () find_program(OCTAVE_EXECUTABLE HINTS ${OCTAVE_BIN_PATHS} NAMES octave - ) + ) find_program(OCTAVE_MKOCTFILE HINTS ${OCTAVE_BIN_PATHS} NAMES mkoctfile - ) + ) find_library(OCTAVE_OCTINTERP_LIBRARY NAMES octinterp liboctinterp HINTS ${OCTAVE_LIBRARIES_PATHS} - ) + ) find_library(OCTAVE_OCTAVE_LIBRARY NAMES octave liboctave HINTS ${OCTAVE_LIBRARIES_PATHS} - ) + ) find_library(OCTAVE_CRUFT_LIBRARY NAMES cruft libcruft HINTS ${OCTAVE_LIBRARIES_PATHS} - ) + ) set (OCTAVE_LIBRARIES ${OCTAVE_OCTINTERP_LIBRARY}) list (APPEND OCTAVE_LIBRARIES ${OCTAVE_OCTAVE_LIBRARY}) @@ -143,7 +143,7 @@ find_path (OCTAVE_INCLUDE_DIR NAMES mex.h HINTS ${OCTAVE_INCLUDE_PATHS} "${OCTAVE_INCLUDE_PATHS}/octave" - ) + ) set (OCTAVE_INCLUDE_DIRS ${OCTAVE_INCLUDE_DIR}) @@ -157,14 +157,14 @@ macro (octave_add_oct FUNCTIONNAME) foreach (_ARG ${ARGN}) if (${_ARG} MATCHES SOURCES) set (_CMD SOURCES) - elseif (${_ARG} MATCHES LINK_LIBRARIES ) - set (_CMD LINK_LIBRARIES ) + elseif (${_ARG} MATCHES LINK_LIBRARIES) + set (_CMD LINK_LIBRARIES) elseif (${_ARG} MATCHES EXTENSION) set (_CMD EXTENSION) else () if (${_CMD} MATCHES SOURCES) list (APPEND _SOURCES "${_ARG}") - elseif (${_CMD} MATCHES LINK_LIBRARIES ) + elseif (${_CMD} MATCHES LINK_LIBRARIES) list (APPEND _LINK_LIBRARIES "${_ARG}") elseif (${_CMD} MATCHES EXTENSION) set (_OCT_EXTENSION ${_ARG}) @@ -176,7 +176,7 @@ macro (octave_add_oct FUNCTIONNAME) set_target_properties (${FUNCTIONNAME} PROPERTIES PREFIX "" SUFFIX ".${_OCT_EXTENSION}" - ) +) endmacro () diff --git a/octave/CMakeLists.txt b/octave/CMakeLists.txt index c9be0074..54534623 100644 --- a/octave/CMakeLists.txt +++ b/octave/CMakeLists.txt @@ -13,7 +13,7 @@ file (APPEND ${CMAKE_CURRENT_BINARY_DIR}/nlopt_optimize_usage.h "\n") include_directories (${OCTAVE_INCLUDE_DIRS}) include_directories (${CMAKE_CURRENT_BINARY_DIR}) -octave_add_oct (nlopt_optimize SOURCES nlopt_optimize-oct.cc ${CMAKE_CURRENT_BINARY_DIR}/nlopt_optimize_usage.h) +octave_add_oct (nlopt_optimize SOURCES nlopt_optimize-oct.cc ${CMAKE_CURRENT_BINARY_DIR}/nlopt_optimize_usage.h LINK_LIBRARIES ${nlopt_lib}) file (RELATIVE_PATH PKG_OCTAVE_OCT_SITE_DIR ${OCTAVE_ROOT_DIR} ${OCTAVE_OCT_SITE_DIR}) install (TARGETS nlopt_optimize DESTINATION ${PKG_OCTAVE_OCT_SITE_DIR}) diff --git a/swig/CMakeLists.txt b/swig/CMakeLists.txt index c4a4d851..3434e3e5 100644 --- a/swig/CMakeLists.txt +++ b/swig/CMakeLists.txt @@ -1,6 +1,17 @@ -if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/nlopt-python.cpp) - find_package (SWIG) +if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/nlopt-enum-renames.i) + file (WRITE ${CMAKE_CURRENT_BINARY_DIR}/nlopt-enum-renames.i "// AUTOMATICALLY GENERATED -- DO NOT EDIT\n") + file (STRINGS ${CMAKE_SOURCE_DIR}/api/nlopt.h NLOPT_H_LINES REGEX " NLOPT_[A-Z0-9_]+") + foreach (NLOPT_H_LINE ${NLOPT_H_LINES}) + string (REGEX REPLACE ".*NLOPT_([A-Z0-9_]+).*" "%rename(NLOPT_\\1) nlopt::\\1;\n" ENUM_LINE ${NLOPT_H_LINE}) + file (APPEND ${CMAKE_CURRENT_BINARY_DIR}/nlopt-enum-renames.i "${ENUM_LINE}") + endforeach () +endif () + +if (BUILD_OCTAVE) + if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/nlopt-python.cpp) + find_package (SWIG) + endif () endif () if (PYTHONINTERP_FOUND AND PYTHONLIBS_FOUND AND (SWIG_FOUND OR (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/nlopt-python.cpp))) @@ -11,7 +22,7 @@ if (PYTHONINTERP_FOUND AND PYTHONLIBS_FOUND AND (SWIG_FOUND OR (EXISTS ${CMAKE_C if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/nlopt-python.cpp) set (SWIG_MODULE_nlopt_REAL_NAME _nlopt) add_library (${SWIG_MODULE_nlopt_REAL_NAME} MODULE nlopt-python.cpp) - target_link_libraries(${SWIG_MODULE_nlopt_REAL_NAME} nlopt) + target_link_libraries(${SWIG_MODULE_nlopt_REAL_NAME} ${nlopt_lib}) target_link_libraries(${SWIG_MODULE_nlopt_REAL_NAME} ${PYTHON_LIBRARIES}) set_target_properties (${SWIG_MODULE_nlopt_REAL_NAME} PROPERTIES PREFIX "") if (NOT CMAKE_SOURCE_DIR MATCHES CMAKE_BINARY_DIR) @@ -23,10 +34,53 @@ if (PYTHONINTERP_FOUND AND PYTHONLIBS_FOUND AND (SWIG_FOUND OR (EXISTS ${CMAKE_C set (SWIG_MODULE_nlopt_EXTRA_DEPS nlopt-python.i numpy.i ${CMAKE_SOURCE_DIR}/api/nlopt.hpp) swig_add_module (nlopt python nlopt.i) - swig_link_libraries (nlopt nlopt) + swig_link_libraries (nlopt ${nlopt_lib}) swig_link_libraries (nlopt ${PYTHON_LIBRARIES}) endif () install ( FILES ${CMAKE_CURRENT_BINARY_DIR}/nlopt.py DESTINATION ${PYTHON_MODULE_PATH} ) install ( TARGETS ${SWIG_MODULE_nlopt_REAL_NAME} LIBRARY DESTINATION ${PYTHON_MODULE_PATH} ) endif () + +if (BUILD_GUILE) + if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/nlopt-guile.cpp) + find_package (SWIG) + endif () +endif () + +# guile bindings with gcc only ok with swig >= 2.0.10 +if (GUILE_FOUND AND ((SWIG_FOUND AND SWIG_VERSION VERSION_GREATER 2.0.9) OR (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/nlopt-guile.cpp))) + include_directories (${GUILE_INCLUDE_DIRS}) + + if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/nlopt-guile.cpp) + set (guile_cpp_source ${CMAKE_CURRENT_SOURCE_DIR}/nlopt-guile.cpp) + else () + file (WRITE ${CMAKE_CURRENT_BINARY_DIR}/GenericConfigureFile.cmake "configure_file (\${INFILE} \${OUTFILE} @ONLY)") + + set (guile_cpp_source ${CMAKE_CURRENT_BINARY_DIR}/nlopt-guile.cpp) + add_custom_command (OUTPUT ${guile_cpp_source} nlopt.scm.in + COMMAND ${SWIG_EXECUTABLE} -I${CMAKE_SOURCE_DIR}/api -outdir ${CMAKE_CURRENT_BINARY_DIR} -c++ -guile -scmstub -o ${guile_cpp_source} ${CMAKE_CURRENT_SOURCE_DIR}/nlopt.i + COMMAND ${CMAKE_COMMAND} -E rename ${CMAKE_CURRENT_BINARY_DIR}/nlopt.scm ${CMAKE_CURRENT_BINARY_DIR}/nlopt.scm.in + COMMAND ${CMAKE_COMMAND} -DINFILE=${CMAKE_CURRENT_BINARY_DIR}/nlopt.scm.in -DOUTFILE=${CMAKE_CURRENT_BINARY_DIR}/nlopt.scm -DNLOPT_SUFFIX=${NLOPT_SUFFIX} -P ${CMAKE_CURRENT_BINARY_DIR}/GenericConfigureFile.cmake) + endif () + + if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/nlopt.scm.in) + configure_file (${CMAKE_CURRENT_SOURCE_DIR}/nlopt.scm.in ${CMAKE_CURRENT_BINARY_DIR}/nlopt.scm @ONLY) + endif () + + set (SWIG_MODULE_nlopt_guile_REAL_NAME nlopt_guile) + add_library (${SWIG_MODULE_nlopt_guile_REAL_NAME} MODULE ${guile_cpp_source}) + target_link_libraries(${SWIG_MODULE_nlopt_guile_REAL_NAME} ${nlopt_lib}) + target_link_libraries(${SWIG_MODULE_nlopt_guile_REAL_NAME} ${GUILE_LIBRARIES}) + + set_target_properties (${SWIG_MODULE_nlopt_guile_REAL_NAME} PROPERTIES SOVERSION ${_INFO_SOVERSION}) + set_target_properties (${SWIG_MODULE_nlopt_guile_REAL_NAME} PROPERTIES VERSION ${_INFO_VERSION} ) + + file (RELATIVE_PATH _REL_GUILE_SITE_PATH ${GUILE_ROOT_DIR} ${GUILE_SITE_DIR}) + set (GUILE_SITE_PATH ${_REL_GUILE_SITE_PATH}) + install (FILES ${CMAKE_CURRENT_BINARY_DIR}/nlopt.scm DESTINATION ${GUILE_SITE_PATH}) + + file (RELATIVE_PATH _REL_GUILE_EXTENSION_PATH ${GUILE_ROOT_DIR} ${GUILE_EXTENSION_DIR}) + set (GUILE_EXTENSION_PATH ${_REL_GUILE_EXTENSION_PATH}) + install (TARGETS ${SWIG_MODULE_nlopt_guile_REAL_NAME} LIBRARY DESTINATION ${GUILE_EXTENSION_PATH}) +endif () diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 99499362..4f286216 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,7 +1,7 @@ add_custom_target (tests) add_executable (testopt EXCLUDE_FROM_ALL testfuncs.c testfuncs.h testopt.cpp) -target_link_libraries (testopt nlopt) +target_link_libraries (testopt ${nlopt_lib}) add_dependencies (tests testopt) foreach (algo_index RANGE 29)# 42 From 0c2298c67181aca8ec34f550bbed55375b302d9c Mon Sep 17 00:00:00 2001 From: Julien Schueller Date: Sat, 5 Sep 2015 12:34:36 +0200 Subject: [PATCH 10/29] cmake: provide package_source target --- CMakeLists.txt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 33339bdb..6e717991 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -281,3 +281,18 @@ endif () enable_testing () add_subdirectory (test) + +set (CPACK_PACKAGE_NAME "${CMAKE_PROJECT_NAME}") +set (CPACK_PACKAGE_VERSION_MAJOR "${NLOPT_MAJOR_VERSION}") +set (CPACK_PACKAGE_VERSION_MINOR "${NLOPT_MINOR_VERSION}") +set (CPACK_PACKAGE_VERSION_PATCH "${NLOPT_BUGFIX_VERSION}") +set (CPACK_SOURCE_GENERATOR "TBZ2;TGZ" ) +set (CPACK_BINARY_STGZ "OFF" ) +set (CPACK_BINARY_TBZ2 "ON" ) +set (CPACK_BINARY_TGZ "ON" ) +set (CPACK_BINARY_TZ "OFF" ) +set (CPACK_SOURCE_IGNORE_FILES ".git;/build;.*~;${CPACK_SOURCE_IGNORE_FILES}") + +set (CPACK_SOURCE_PACKAGE_FILE_NAME ${CPACK_PACKAGE_NAME}-${NLOPT_VERSION_STRING}) + +include (CPack) \ No newline at end of file From d9e38ea37927510205e909fe2ef114720cda1f99 Mon Sep 17 00:00:00 2001 From: Julien Schueller Date: Sat, 5 Sep 2015 16:53:44 +0200 Subject: [PATCH 11/29] cmake: generate api headers --- CMakeLists.txt | 50 +++++++++++++++--------------- api/CMakeLists.txt | 74 +++++++++++++++++++++++++++++++++++++++++++++ api/Makefile.am | 2 +- swig/CMakeLists.txt | 5 ++- 4 files changed, 103 insertions(+), 28 deletions(-) create mode 100644 api/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 6e717991..5bc6c41b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -149,28 +149,28 @@ install (FILES ${CMAKE_CURRENT_BINARY_DIR}/nlopt.pc DESTINATION lib/pkgconfig) #============================================================================== # INCLUDE DIRECTORIES #============================================================================== -SET(${INCLUDE_DIRECTORIES} "") -INCLUDE_DIRECTORIES ( - ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_CURRENT_BINARY_DIR} - stogo - util - direct - cdirect - praxis - luksan - crs - mlsl - mma - cobyla - newuoa - neldermead - auglag - bobyqa - isres - slsqp - esch - api ) +set (${INCLUDE_DIRECTORIES} "") +include_directories ( + ${CMAKE_BINARY_DIR}/api + ${CMAKE_BINARY_DIR} + stogo + util + direct + cdirect + praxis + luksan + crs + mlsl + mma + cobyla + newuoa + neldermead + auglag + bobyqa + isres + slsqp + esch + api) #============================================================================== @@ -178,7 +178,7 @@ INCLUDE_DIRECTORIES ( #============================================================================== SET ( NLOPT_HEADERS - api/nlopt.h api/nlopt.hpp api/nlopt.f + api/nlopt.h ${CMAKE_BINARY_DIR}/api/nlopt.hpp ${CMAKE_BINARY_DIR}/api/nlopt.f ) SET ( NLOPT_SOURCES @@ -216,7 +216,7 @@ if (BUILD_SHARED_LIBS) endif () endif () -INSTALL ( FILES ${NLOPT_HEADERS} DESTINATION include ) +install (FILES ${NLOPT_HEADERS} DESTINATION include) set (nlopt_lib nlopt${NLOPT_SUFFIX}) add_library (${nlopt_lib} ${NLOPT_SOURCES}) @@ -248,6 +248,8 @@ install ( TARGETS ${nlopt_lib} ARCHIVE DESTINATION lib${LIB_SUFFIX} ) +add_subdirectory (api) + if (BUILD_PYTHON) find_package (PythonInterp) find_package (PythonLibs) diff --git a/api/CMakeLists.txt b/api/CMakeLists.txt new file mode 100644 index 00000000..bf8ce34d --- /dev/null +++ b/api/CMakeLists.txt @@ -0,0 +1,74 @@ +# generate nlopt.f from nlopt.h enums +if (NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/nlopt.f) + file (WRITE ${CMAKE_CURRENT_BINARY_DIR}/nlopt.f "") + file (STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/nlopt.h NLOPT_H_LINES REGEX " NLOPT_[A-Z0-9_]+") + set (i 0) + foreach (NLOPT_H_LINE ${NLOPT_H_LINES}) + if (NOT NLOPT_H_LINE MATCHES "NLOPT_NUM_") + string (REGEX REPLACE ".*NLOPT_([A-Z0-9_]+).*" "\\1" ENUM_STRING ${NLOPT_H_LINE}) + string (REGEX REPLACE ".*NLOPT_[A-Z0-9_]+ = (-?[0-9]+).*" "\\1" ENUM_VAL ${NLOPT_H_LINE}) + if (ENUM_VAL MATCHES "^-?[0-9]+$") + set (i ${ENUM_VAL}) + endif () + set (ENUM_LINE " integer NLOPT_${ENUM_STRING}\n parameter (NLOPT_${ENUM_STRING}=${i})\n") + file (APPEND ${CMAKE_CURRENT_BINARY_DIR}/nlopt.f "${ENUM_LINE}") + + # https://public.kitware.com/Bug/print_bug_page.php?bug_id=8996 + if (i MATCHES "^-") + math (EXPR i "1 ${i}") + else () + math (EXPR i "${i} + 1") + endif () + endif () + endforeach () +endif () + +# generate nlopt.hpp from nlopt-in.hpp +if (NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/nlopt.hpp) + file (WRITE ${CMAKE_CURRENT_BINARY_DIR}/nlopt.hpp "") + file (STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/nlopt-in.hpp NLOPT_HPP_LINES) + foreach (NLOPT_HPP_LINE ${NLOPT_HPP_LINES}) + list(LENGTH NLOPT_HPP_LINE line_len) + # handling trailing backlashes in "file (STRINGS" is a little tricky + if (line_len VERSION_LESS 8) + file (APPEND ${CMAKE_CURRENT_BINARY_DIR}/nlopt.hpp "${NLOPT_HPP_LINE}\n") + else () + set (prev_inst FALSE) + foreach(NLOPT_HPP_SUBLINE ${NLOPT_HPP_LINE}) + # test is we need to add the eaten semicolon + if (NLOPT_HPP_SUBLINE MATCHES "\\)$" OR NLOPT_HPP_SUBLINE MATCHES "return") + set (new_inst TRUE) + else () + set (new_inst FALSE) + endif () + if (NOT prev_inst) + file (APPEND ${CMAKE_CURRENT_BINARY_DIR}/nlopt.hpp "${NLOPT_HPP_SUBLINE}") + if (new_inst) + file (APPEND ${CMAKE_CURRENT_BINARY_DIR}/nlopt.hpp ";") + endif () + list (FIND NLOPT_HPP_LINE "${NLOPT_HPP_SUBLINE}" index) + math (EXPR index "${index} + 1") + list (LENGTH NLOPT_HPP_LINE total) + if (NOT index STREQUAL total) + file (APPEND ${CMAKE_CURRENT_BINARY_DIR}/nlopt.hpp " \\") + endif () + file (APPEND ${CMAKE_CURRENT_BINARY_DIR}/nlopt.hpp "\n") + endif () + set (prev_inst ${new_inst}) + endforeach () + endif () + if (NLOPT_HPP_LINE MATCHES "GEN_ENUMS_HERE") + file (APPEND ${CMAKE_CURRENT_BINARY_DIR}/nlopt.hpp " enum algorithm {\n") + file (STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/nlopt.h NLOPT_H_LINES REGEX " NLOPT_[A-Z0-9_]+") + foreach (NLOPT_H_LINE ${NLOPT_H_LINES}) + string (REGEX REPLACE "NLOPT_" "" ENUM_LINE ${NLOPT_H_LINE}) + file (APPEND ${CMAKE_CURRENT_BINARY_DIR}/nlopt.hpp "${ENUM_LINE}\n") + if (NLOPT_H_LINE MATCHES "NLOPT_NUM_ALGORITHMS") + file (APPEND ${CMAKE_CURRENT_BINARY_DIR}/nlopt.hpp " };\n enum result {\n") + elseif (NLOPT_H_LINE MATCHES "NLOPT_MAXTIME_REACHED") + file (APPEND ${CMAKE_CURRENT_BINARY_DIR}/nlopt.hpp " };\n") + endif () + endforeach () + endif () + endforeach () +endif () diff --git a/api/Makefile.am b/api/Makefile.am index d4d08d29..bff5314e 100644 --- a/api/Makefile.am +++ b/api/Makefile.am @@ -8,7 +8,7 @@ libapi_la_SOURCES = general.c options.c optimize.c deprecated.c \ nlopt-internal.h nlopt.h f77api.c f77funcs.h f77funcs_.h BUILT_SOURCES = nlopt.f nlopt.hpp -EXTRA_DIST = nlopt-in.hpp +EXTRA_DIST = nlopt-in.hpp CMakeLists.txt if MAINTAINER_MODE # convert constants to F77 parameter statements & C++ diff --git a/swig/CMakeLists.txt b/swig/CMakeLists.txt index 3434e3e5..0fcb0ab3 100644 --- a/swig/CMakeLists.txt +++ b/swig/CMakeLists.txt @@ -16,7 +16,6 @@ endif () if (PYTHONINTERP_FOUND AND PYTHONLIBS_FOUND AND (SWIG_FOUND OR (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/nlopt-python.cpp))) - include_directories (${CMAKE_SOURCE_DIR}/api) include_directories (${PYTHON_INCLUDE_DIRS}) if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/nlopt-python.cpp) @@ -31,7 +30,7 @@ if (PYTHONINTERP_FOUND AND PYTHONLIBS_FOUND AND (SWIG_FOUND OR (EXISTS ${CMAKE_C else () include (UseSWIG) set_source_files_properties (nlopt.i PROPERTIES CPLUSPLUS ON) - set (SWIG_MODULE_nlopt_EXTRA_DEPS nlopt-python.i numpy.i ${CMAKE_SOURCE_DIR}/api/nlopt.hpp) + set (SWIG_MODULE_nlopt_EXTRA_DEPS nlopt-python.i numpy.i) swig_add_module (nlopt python nlopt.i) swig_link_libraries (nlopt ${nlopt_lib}) @@ -59,7 +58,7 @@ if (GUILE_FOUND AND ((SWIG_FOUND AND SWIG_VERSION VERSION_GREATER 2.0.9) OR (EXI set (guile_cpp_source ${CMAKE_CURRENT_BINARY_DIR}/nlopt-guile.cpp) add_custom_command (OUTPUT ${guile_cpp_source} nlopt.scm.in - COMMAND ${SWIG_EXECUTABLE} -I${CMAKE_SOURCE_DIR}/api -outdir ${CMAKE_CURRENT_BINARY_DIR} -c++ -guile -scmstub -o ${guile_cpp_source} ${CMAKE_CURRENT_SOURCE_DIR}/nlopt.i + COMMAND ${SWIG_EXECUTABLE} -I${CMAKE_BINARY_DIR}/api -outdir ${CMAKE_CURRENT_BINARY_DIR} -c++ -guile -scmstub -o ${guile_cpp_source} ${CMAKE_CURRENT_SOURCE_DIR}/nlopt.i COMMAND ${CMAKE_COMMAND} -E rename ${CMAKE_CURRENT_BINARY_DIR}/nlopt.scm ${CMAKE_CURRENT_BINARY_DIR}/nlopt.scm.in COMMAND ${CMAKE_COMMAND} -DINFILE=${CMAKE_CURRENT_BINARY_DIR}/nlopt.scm.in -DOUTFILE=${CMAKE_CURRENT_BINARY_DIR}/nlopt.scm -DNLOPT_SUFFIX=${NLOPT_SUFFIX} -P ${CMAKE_CURRENT_BINARY_DIR}/GenericConfigureFile.cmake) endif () From c0252ad1024f0e4da641a644434ca94f900554c8 Mon Sep 17 00:00:00 2001 From: Julien Schueller Date: Tue, 5 Jul 2016 17:24:01 +0200 Subject: [PATCH 12/29] Add Appveyor config file --- appveyor.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 appveyor.yml diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 00000000..8750e06a --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,23 @@ +version: 1.0.{build} +os: Visual Studio 2015 +clone_folder: C:\projects\nlopt +test: off +configuration: + - Release +branches: + only: + - master +environment: + matrix: + - CMAKE_PLATFORM: "Visual Studio 14 2015" + - CMAKE_PLATFORM: "Visual Studio 14 2015 Win64" +install: + - cinstall: python + - choco install swig +build_script: + - echo Running cmake... + - cd c:\projects\nlopt + - cmake -G "%CMAKE_PLATFORM%" -DCMAKE_INSTALL_PREFIX="C:\projects\nlopt\install" . + - cmake --build . --config %Configuration% --target install + - cmake --build . --config %Configuration% --target tests + - ctest -C %Configuration% --output-on-failure --timeout 100 From f377e07589c3a4d41d2b15f94df89a2b4c1ceec9 Mon Sep 17 00:00:00 2001 From: Julien Schueller Date: Tue, 5 Jul 2016 17:26:25 +0200 Subject: [PATCH 13/29] Test MinGW build --- .travis.yml | 21 ++++++++++------ CMakeLists.txt | 3 ++- cmake/toolchain-i686-w64-mingw32.cmake | 32 ++++++++++++++++++++++++ cmake/toolchain-x86_64-w64-mingw32.cmake | 32 ++++++++++++++++++++++++ test/CMakeLists.txt | 3 ++- 5 files changed, 82 insertions(+), 9 deletions(-) create mode 100644 cmake/toolchain-i686-w64-mingw32.cmake create mode 100644 cmake/toolchain-x86_64-w64-mingw32.cmake diff --git a/.travis.yml b/.travis.yml index b974bd78..4a55fdd9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ language: cpp -# sudo: false +sudo: false addons: apt: @@ -11,9 +11,12 @@ addons: - guile-2.0-dev - octave3.2-headers - cmake - -install: - - sudo apt-get -qq install guile-2.0-dev octave3.2-headers + - g++-mingw-w64-i686 + - gcc-mingw-w64-i686 + - binutils-mingw-w64-i686 + - g++-mingw-w64-x86-64 + - gcc-mingw-w64-x86-64 + - binutils-mingw-w64-x86-64 script: - ./autogen.sh --no-configure @@ -24,6 +27,10 @@ script: - python ../test/test_std.py - rm -rf * ~/.local - cmake -DCMAKE_INSTALL_PREFIX=~/.local -DBUILD_SHARED_LIBS=ON -DWITH_CXX=ON .. - - make install -j2 - - make tests -j2 - - ctest -j2 --output-on-failure + - make install -j2 && make tests -j2 && ctest -j2 --output-on-failure + - rm -rf * ~/.local + - cmake -DCMAKE_INSTALL_PREFIX=~/.local -DBUILD_SHARED_LIBS=ON -DWITH_CXX=ON -DBUILD_PYTHON=OFF -DBUILD_OCTAVE=OFF -DBUILD_GUILE=OFF -DCMAKE_TOOLCHAIN_FILE=$PWD/../cmake/toolchain-i686-w64-mingw32.cmake .. + - make install -j2 && make tests -j2 + - rm -rf * ~/.local + - cmake -DCMAKE_INSTALL_PREFIX=~/.local -DBUILD_SHARED_LIBS=ON -DWITH_CXX=ON -DBUILD_PYTHON=OFF -DBUILD_OCTAVE=OFF -DBUILD_GUILE=OFF -DCMAKE_TOOLCHAIN_FILE=$PWD/../cmake/toolchain-x86_64-w64-mingw32.cmake .. + - make install -j2 && make tests -j2 diff --git a/CMakeLists.txt b/CMakeLists.txt index 5bc6c41b..08b770a3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -297,4 +297,5 @@ set (CPACK_SOURCE_IGNORE_FILES ".git;/build;.*~;${CPACK_SOURCE_IGNORE_FILES}") set (CPACK_SOURCE_PACKAGE_FILE_NAME ${CPACK_PACKAGE_NAME}-${NLOPT_VERSION_STRING}) -include (CPack) \ No newline at end of file +include (CPack) + diff --git a/cmake/toolchain-i686-w64-mingw32.cmake b/cmake/toolchain-i686-w64-mingw32.cmake new file mode 100644 index 00000000..ff9b450a --- /dev/null +++ b/cmake/toolchain-i686-w64-mingw32.cmake @@ -0,0 +1,32 @@ +set (CMAKE_SYSTEM_NAME Windows) + +# specify the cross compiler +set (CMAKE_C_COMPILER i686-w64-mingw32-gcc) +set (CMAKE_CXX_COMPILER i686-w64-mingw32-g++) + +# where is the target environment +set (CMAKE_FIND_ROOT_PATH /usr/i686-w64-mingw32) + +# search for programs in the build host directories +set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +# for libraries and headers in the target directories +set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +set (CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) + +# Make sure Qt can be detected by CMake +set (QT_BINARY_DIR /usr/i686-w64-mingw32/bin /usr/bin) +set (QT_INCLUDE_DIRS_NO_SYSTEM ON) + +# set the resource compiler (RHBZ #652435) +set (CMAKE_RC_COMPILER i686-w64-mingw32-windres) +set (CMAKE_MC_COMPILER i686-w64-mingw32-windmc) + +# override boost thread component suffix as mingw-w64-boost is compiled with threadapi=win32 +set (Boost_THREADAPI win32) + +# These are needed for compiling lapack (RHBZ #753906) +set (CMAKE_Fortran_COMPILER i686-w64-mingw32-gfortran) +set (CMAKE_AR:FILEPATH i686-w64-mingw32-ar) +set (CMAKE_RANLIB:FILEPATH i686-w64-mingw32-ranlib) + diff --git a/cmake/toolchain-x86_64-w64-mingw32.cmake b/cmake/toolchain-x86_64-w64-mingw32.cmake new file mode 100644 index 00000000..470b4782 --- /dev/null +++ b/cmake/toolchain-x86_64-w64-mingw32.cmake @@ -0,0 +1,32 @@ +set (CMAKE_SYSTEM_NAME Windows) + +# specify the cross compiler +set (CMAKE_C_COMPILER x86_64-w64-mingw32-gcc) +set (CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++) + +# where is the target environment +set (CMAKE_FIND_ROOT_PATH /usr/x86_64-w64-mingw32) + +# search for programs in the build host directories +set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +# for libraries and headers in the target directories +set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +set (CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) + +# Make sure Qt can be detected by CMake +set (QT_BINARY_DIR /usr/x86_64-w64-mingw32/bin /usr/bin) +set (QT_INCLUDE_DIRS_NO_SYSTEM ON) + +# set the resource compiler (RHBZ #652435) +set (CMAKE_RC_COMPILER x86_64-w64-mingw32-windres) +set (CMAKE_MC_COMPILER x86_64-w64-mingw32-windmc) + +# override boost thread component suffix as mingw-w64-boost is compiled with threadapi=win32 +set (Boost_THREADAPI win32) + +# These are needed for compiling lapack (RHBZ #753906) +set (CMAKE_Fortran_COMPILER x86_64-w64-mingw32-gfortran) +set (CMAKE_AR:FILEPATH x86_64-w64-mingw32-ar) +set (CMAKE_RANLIB:FILEPATH x86_64-w64-mingw32-ranlib) + diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 4f286216..5179ef93 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,6 +1,7 @@ add_custom_target (tests) -add_executable (testopt EXCLUDE_FROM_ALL testfuncs.c testfuncs.h testopt.cpp) +# have to add timer.c and mt19937ar.c as symbols are declared extern +add_executable (testopt EXCLUDE_FROM_ALL testfuncs.c testfuncs.h testopt.cpp ${CMAKE_SOURCE_DIR}/util/timer.c ${CMAKE_SOURCE_DIR}/util/mt19937ar.c) target_link_libraries (testopt ${nlopt_lib}) add_dependencies (tests testopt) From 0219a2ec0541d77cc1d23144c774a77fa6615ad2 Mon Sep 17 00:00:00 2001 From: Julien Schueller Date: Tue, 5 Jul 2016 18:44:57 +0200 Subject: [PATCH 14/29] Removed autotools --- .gitignore | 25 --- .travis.yml | 6 - CMakeLists.txt | 54 +---- Makefile.am | 35 ---- README.md | 11 +- api/Makefile.am | 24 --- auglag/Makefile.am | 6 - autogen.sh | 39 ---- bobyqa/Makefile.am | 6 - cdirect/Makefile.am | 6 - cobyla/Makefile.am | 6 - configure.ac | 448 ----------------------------------------- cquad/Makefile.am | 6 - crs/Makefile.am | 6 - direct/Makefile.am | 7 - esch/Makefile.am | 6 - isres/Makefile.am | 6 - luksan/Makefile.am | 6 - m4/ax_c_threadlocal.m4 | 47 ----- mlsl/Makefile.am | 6 - mma/Makefile.am | 6 - neldermead/Makefile.am | 6 - newuoa/Makefile.am | 6 - nlopt.pc.in | 10 +- octave/Makefile.am | 43 ---- praxis/Makefile.am | 6 - slsqp/Makefile.am | 6 - stogo/Makefile.am | 8 - subplex/Makefile.am | 6 - swig/CMakeLists.txt | 4 +- swig/Makefile.am | 59 ------ test/Makefile.am | 8 - util/Makefile.am | 8 - 33 files changed, 22 insertions(+), 910 deletions(-) delete mode 100644 Makefile.am delete mode 100644 api/Makefile.am delete mode 100644 auglag/Makefile.am delete mode 100755 autogen.sh delete mode 100644 bobyqa/Makefile.am delete mode 100644 cdirect/Makefile.am delete mode 100644 cobyla/Makefile.am delete mode 100644 configure.ac delete mode 100644 cquad/Makefile.am delete mode 100644 crs/Makefile.am delete mode 100644 direct/Makefile.am delete mode 100644 esch/Makefile.am delete mode 100644 isres/Makefile.am delete mode 100644 luksan/Makefile.am delete mode 100644 m4/ax_c_threadlocal.m4 delete mode 100644 mlsl/Makefile.am delete mode 100644 mma/Makefile.am delete mode 100644 neldermead/Makefile.am delete mode 100644 newuoa/Makefile.am delete mode 100644 octave/Makefile.am delete mode 100644 praxis/Makefile.am delete mode 100644 slsqp/Makefile.am delete mode 100644 stogo/Makefile.am delete mode 100644 subplex/Makefile.am delete mode 100644 swig/Makefile.am delete mode 100644 test/Makefile.am delete mode 100644 util/Makefile.am diff --git a/.gitignore b/.gitignore index fd664958..4f6557bc 100644 --- a/.gitignore +++ b/.gitignore @@ -30,28 +30,3 @@ mingw64 octave/dummy test/testopt util/redblack_test - -# autotools stuff -Makefile -Makefile.in -.deps -.libs -stamp-h1 -install-sh -libtool -ltmain.sh -m4/libtool.m4 -m4/ltoptions.m4 -m4/ltsugar.m4 -m4/ltversion.m4 -m4/lt~obsolete.m4 -configure -config.* -autom4te.cache -INSTALL -README -aclocal.m4 -depcomp -missing -py-compile -compile diff --git a/.travis.yml b/.travis.yml index 4a55fdd9..24394691 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,13 +19,7 @@ addons: - binutils-mingw-w64-x86-64 script: - - ./autogen.sh --no-configure - mkdir build && pushd build - - ../configure --prefix=$HOME/.local --enable-shared --enable-maintainer-mode --with-cxx --without-guile - - make -j2 - - make install - - python ../test/test_std.py - - rm -rf * ~/.local - cmake -DCMAKE_INSTALL_PREFIX=~/.local -DBUILD_SHARED_LIBS=ON -DWITH_CXX=ON .. - make install -j2 && make tests -j2 && ctest -j2 --output-on-failure - rm -rf * ~/.local diff --git a/CMakeLists.txt b/CMakeLists.txt index 08b770a3..ec76bc5f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -104,45 +104,21 @@ if (WITH_THREADLOCAL AND NOT DEFINED HAVE_THREAD_LOCAL_STORAGE) endif () #============================================================================== -# LOOK FOR THE VERSION NUMBER IN configure.ac +# version #============================================================================== - -FILE( READ configure.ac CONFIG_AUTOMAKE ) - -STRING( REGEX MATCH "AC_INIT\\(nlopt, ([0-9]+\\.[0-9]+\\.?[0-9]*)" NLOPT_AUTOMAKE_LINE_VERSION "${CONFIG_AUTOMAKE}") - -#--------------------------------- -# If version matches 'X.X.X' -#--------------------------------- -IF(${NLOPT_AUTOMAKE_LINE_VERSION} MATCHES ".*[0-9]+\\.[0-9]+\\.[0-9]+") - STRING( REGEX REPLACE ".*([0-9]+)\\.[0-9]+\\.[0-9]*.*" "\\1" NLOPT_MAJOR_VERSION "${NLOPT_AUTOMAKE_LINE_VERSION}") - STRING( REGEX REPLACE ".*[0-9]+\\.([0-9]+)\\.[0-9]*.*" "\\1" NLOPT_MINOR_VERSION "${NLOPT_AUTOMAKE_LINE_VERSION}") - STRING( REGEX REPLACE ".*[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" NLOPT_BUGFIX_VERSION "${NLOPT_AUTOMAKE_LINE_VERSION}") - set (NLOPT_VERSION_STRING ${NLOPT_MAJOR_VERSION}.${NLOPT_MINOR_VERSION}.${NLOPT_BUGFIX_VERSION}) -#--------------------------------- -# Else (consider that version matches 'X.X') -#--------------------------------- -ELSE(${NLOPT_AUTOMAKE_LINE_VERSION} MATCHES ".*[0-9]+\\.[0-9]+\\.[0-9]+") - STRING( REGEX REPLACE ".*([0-9]+)\\.[0-9]+.*" "\\1" NLOPT_MAJOR_VERSION "${NLOPT_AUTOMAKE_LINE_VERSION}") - STRING( REGEX REPLACE ".*[0-9]+\\.([0-9]+).*" "\\1" NLOPT_MINOR_VERSION "${NLOPT_AUTOMAKE_LINE_VERSION}") - SET (NLOPT_BUGFIX_VERSION "0") - set (NLOPT_VERSION_STRING ${NLOPT_MAJOR_VERSION}.${NLOPT_MINOR_VERSION}) -endif() - -message (STATUS "NLOPT: Version number ${NLOPT_VERSION_STRING} found in configure.ac" ) +set (NLOPT_MAJOR_VERSION "2") +set (NLOPT_MINOR_VERSION "5") +set (NLOPT_BUGFIX_VERSION "0") +set (NLOPT_VERSION_STRING ${NLOPT_MAJOR_VERSION}.${NLOPT_MINOR_VERSION}.${NLOPT_BUGFIX_VERSION}) +message (STATUS "NLopt version ${NLOPT_VERSION_STRING}") #============================================================================== # CREATE config.h #============================================================================== -CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.cmake.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h IMMEDIATE ) +configure_file (${CMAKE_CURRENT_SOURCE_DIR}/config.cmake.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h IMMEDIATE) # pkgconfig file -set (prefix "${CMAKE_INSTALL_PREFIX}") -set (exec_prefix "\${prefix}") -set (libdir "\${exec_prefix}/lib") -set (includedir "\${prefix}/include") -set (VERSION "${NLOPT_VERSION_STRING}") configure_file (${CMAKE_CURRENT_SOURCE_DIR}/nlopt.pc.in ${CMAKE_CURRENT_BINARY_DIR}/nlopt.pc @ONLY) install (FILES ${CMAKE_CURRENT_BINARY_DIR}/nlopt.pc DESTINATION lib/pkgconfig) @@ -220,6 +196,10 @@ install (FILES ${NLOPT_HEADERS} DESTINATION include) set (nlopt_lib nlopt${NLOPT_SUFFIX}) add_library (${nlopt_lib} ${NLOPT_SOURCES}) +set (LIB_SOVERSION 0) +set (LIB_VERSION 0.9.0) +set_target_properties (${nlopt_lib} PROPERTIES SOVERSION ${LIB_SOVERSION}) +set_target_properties (${nlopt_lib} PROPERTIES VERSION ${LIB_VERSION}) # pass -fPIC in case swig module is built with static library if (NOT BUILD_SHARED_LIBS) @@ -230,18 +210,6 @@ if (NOT BUILD_SHARED_LIBS) endif () endif () -# parse configure.ac for lib version -string (REGEX MATCH "SHARED_VERSION_INFO=\"[0-9]+:[0-9]+:[0-9]+\"" _VERSION_INFO_LINE "${CONFIG_AUTOMAKE}") -if (_VERSION_INFO_LINE) - string (REGEX REPLACE "SHARED_VERSION_INFO=\"([0-9]+):[0-9]+:[0-9]+\"" "\\1" _VERSION_INFO_CURRENT "${_VERSION_INFO_LINE}") - string (REGEX REPLACE "SHARED_VERSION_INFO=\"[0-9]+:([0-9]+):[0-9]+\"" "\\1" _VERSION_INFO_REVISION "${_VERSION_INFO_LINE}") - string (REGEX REPLACE "SHARED_VERSION_INFO=\"[0-9]+:[0-9]+:([0-9]+)\"" "\\1" _VERSION_INFO_AGE "${_VERSION_INFO_LINE}") - math (EXPR _INFO_SOVERSION "${_VERSION_INFO_CURRENT} - ${_VERSION_INFO_AGE} ") - set (_INFO_VERSION "${_INFO_SOVERSION}.${_VERSION_INFO_AGE}.${_VERSION_INFO_REVISION}") - set_target_properties (${nlopt_lib} PROPERTIES SOVERSION ${_INFO_SOVERSION}) - set_target_properties (${nlopt_lib} PROPERTIES VERSION ${_INFO_VERSION} ) -endif () - install ( TARGETS ${nlopt_lib} RUNTIME DESTINATION bin LIBRARY DESTINATION lib${LIB_SUFFIX} diff --git a/Makefile.am b/Makefile.am deleted file mode 100644 index 029006d4..00000000 --- a/Makefile.am +++ /dev/null @@ -1,35 +0,0 @@ -OPTIONS_AUTOMAKE=gnu -lib_LTLIBRARIES = libnlopt@NLOPT_SUFFIX@.la - -ACLOCAL_AMFLAGS=-I m4 - -if WITH_CXX -CXX_DIRS = stogo -CXX_LIBS = stogo/libstogo.la -endif - -SUBDIRS = util direct cdirect $(CXX_DIRS) praxis luksan crs mlsl mma cobyla newuoa neldermead auglag bobyqa isres slsqp esch api . octave test swig -EXTRA_DIST = autogen.sh nlopt.pc.in m4 CMakeLists.txt config.cmake.h.in cmake/FindOctave.cmake cmake/FindGuile.cmake - -libnlopt@NLOPT_SUFFIX@_la_SOURCES = -if WITH_CXX -# Dummy C++ source to cause C++ linking -nodist_EXTRA_libnlopt@NLOPT_SUFFIX@_la_SOURCES = dummy.cxx -endif -libnlopt@NLOPT_SUFFIX@_la_LIBADD = direct/libdirect.la \ -cdirect/libcdirect.la $(CXX_LIBS) praxis/libpraxis.la \ -luksan/libluksan.la crs/libcrs.la mlsl/libmlsl.la mma/libmma.la \ -cobyla/libcobyla.la newuoa/libnewuoa.la neldermead/libneldermead.la \ -auglag/libauglag.la bobyqa/libbobyqa.la isres/libisres.la \ -slsqp/libslsqp.la esch/libesch.la api/libapi.la util/libutil.la - -libnlopt@NLOPT_SUFFIX@_la_LDFLAGS = -no-undefined -version-info @SHARED_VERSION_INFO@ -pkgconfigdir = $(libdir)/pkgconfig -pkgconfig_DATA = nlopt.pc - -if MAINTAINER_MODE - -README: README.md - cp -f $(srcdir)/README.md $@ - -endif diff --git a/README.md b/README.md index a8c34af8..d954ffa6 100644 --- a/README.md +++ b/README.md @@ -8,11 +8,9 @@ nonlinear optimization libraries. The latest release and a complete manual may be found at the NLopt home page: http://ab-initio.mit.edu/nlopt -It is compiled and installed with the standard GNU autoconf/automake -commands: +It is compiled and installed with CMake build system: - ./configure - make + cmake . make install See `./configure --help` or the `INSTALL` file for other options. To @@ -20,11 +18,10 @@ build the latest development sources: git clone git://github.com/stevengj/nlopt cd nlopt - sh autogen.sh + cmake . make -(To build from git, you will need GNU autoconf, automake, and libtool -installed, along with SWIG and Unix tools such as m4, perl, and sed.) +(To build from git, you will need SWIG.) Once it is installed, `#include ` in your C/C++ programs and link it with `-lnlopt -lm`. You may need to use the C++ compiler to link diff --git a/api/Makefile.am b/api/Makefile.am deleted file mode 100644 index bff5314e..00000000 --- a/api/Makefile.am +++ /dev/null @@ -1,24 +0,0 @@ -AM_CPPFLAGS = -I$(top_srcdir)/cdirect -I$(top_srcdir)/direct -I$(top_srcdir)/stogo -I$(top_srcdir)/praxis -I$(top_srcdir)/lbfgs -I$(top_srcdir)/luksan -I$(top_srcdir)/crs -I$(top_srcdir)/mlsl -I$(top_srcdir)/mma -I$(top_srcdir)/cobyla -I$(top_srcdir)/newuoa -I$(top_srcdir)/neldermead -I$(top_srcdir)/auglag -I$(top_srcdir)/bobyqa -I$(top_srcdir)/isres -I$(top_srcdir)/slsqp -I$(top_srcdir)/esch -I$(top_srcdir)/util - -include_HEADERS = nlopt.h nlopt.f nlopt.hpp -noinst_LTLIBRARIES = libapi.la -dist_man_MANS = nlopt.3 - -libapi_la_SOURCES = general.c options.c optimize.c deprecated.c \ -nlopt-internal.h nlopt.h f77api.c f77funcs.h f77funcs_.h - -BUILT_SOURCES = nlopt.f nlopt.hpp -EXTRA_DIST = nlopt-in.hpp CMakeLists.txt - -if MAINTAINER_MODE -# convert constants to F77 parameter statements & C++ - -nlopt.f: nlopt.h - rm -f $@ - (i=0; egrep 'NLOPT_[LG][DN]|NLOPT_AUGLAG|NLOPT_G_MLSL' $(srcdir)/nlopt.h | tr -d ' =0,' | while read n; do echo " integer $$n"; echo " parameter ($$n=$$i)"; i=`expr $$i + 1`; done; tail -n +`grep -n enum $(srcdir)/nlopt.h |cut -d: -f1 |tail -n 1` $(srcdir)/nlopt.h | grep NLOPT | egrep -v 'EXTERN|DEPRECATED|MINF_MAX' | cut -d, -f1 | tr -d ' ' | perl -pe 's/([A-Za-z0-9_]+)=([-+0-9]+)/ integer \1\n parameter (\1=\2)/') > $(srcdir)/$@ - -nlopt.hpp: nlopt.h nlopt-in.hpp - rm -f $@ - (n=`grep -n GEN_ENUMS_HERE $(srcdir)/nlopt-in.hpp | cut -d: -f1`; head -n $$n $(srcdir)/nlopt-in.hpp; echo " enum algorithm {"; egrep 'NLOPT_[LG][DN]|NLOPT_AUGLAG|NLOPT_G_MLSL|NLOPT_NUM_ALGORITHMS' $(srcdir)/nlopt.h | sed 's/NLOPT_//g'; echo " };"; echo " enum result {"; egrep 'NLOPT_[A-Z_]* =' $(srcdir)/nlopt.h | egrep -v 'NLOPT_[LG][DN]' | sed 's/NLOPT_//g'; echo " };"; tail -n +$$n $(srcdir)/nlopt-in.hpp) > $(srcdir)/$@ - -endif diff --git a/auglag/Makefile.am b/auglag/Makefile.am deleted file mode 100644 index 77954152..00000000 --- a/auglag/Makefile.am +++ /dev/null @@ -1,6 +0,0 @@ -AM_CPPFLAGS = -I$(top_srcdir)/util -I$(top_srcdir)/api - -noinst_LTLIBRARIES = libauglag.la -libauglag_la_SOURCES = auglag.c auglag.h - -EXTRA_DIST = README diff --git a/autogen.sh b/autogen.sh deleted file mode 100755 index 05b709b9..00000000 --- a/autogen.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/sh - -configure_args="" -configure="yes" - -while test $# -ge 1; do - case $1 in - --verbose) verbose=yes ;; - --enable-*) configure_args="$configure_args $1" ;; - --disable-*) configure_args="$configure_args $1" ;; - --with-*) configure_args="$configure_args $1" ;; - --without-*) configure_args="$configure_args $1" ;; - --no-configure) configure="no" ;; - *) echo "unknown argument $1"; exit 1 ;; - esac - shift -done - -touch swig/nlopt.scm.in - -cp README.md README - -# paranoia: sometimes autoconf doesn't get things right the first time -autoreconf --verbose --install --symlink --force -autoreconf --verbose --install --symlink --force -autoreconf --verbose --install --symlink --force - -if test "$configure" = "yes" -then - config=good # hackery so darcs_test still outputs config.log w/failed configure - - ./configure --enable-maintainer-mode $configure_args || config=bad - - if test x$verbose = xyes; then - cat config.log - fi - - test $config = bad && exit 1 -fi \ No newline at end of file diff --git a/bobyqa/Makefile.am b/bobyqa/Makefile.am deleted file mode 100644 index 71f2d9b4..00000000 --- a/bobyqa/Makefile.am +++ /dev/null @@ -1,6 +0,0 @@ -AM_CPPFLAGS = -I$(top_srcdir)/util -I$(top_srcdir)/api - -noinst_LTLIBRARIES = libbobyqa.la -libbobyqa_la_SOURCES = bobyqa.c bobyqa.h - -EXTRA_DIST = README README.orig COPYRIGHT diff --git a/cdirect/Makefile.am b/cdirect/Makefile.am deleted file mode 100644 index b5695e72..00000000 --- a/cdirect/Makefile.am +++ /dev/null @@ -1,6 +0,0 @@ -AM_CPPFLAGS = -I$(top_srcdir)/util -I$(top_srcdir)/api - -noinst_LTLIBRARIES = libcdirect.la -libcdirect_la_SOURCES = cdirect.c hybrid.c cdirect.h - -EXTRA_DIST = README diff --git a/cobyla/Makefile.am b/cobyla/Makefile.am deleted file mode 100644 index 2c5752a3..00000000 --- a/cobyla/Makefile.am +++ /dev/null @@ -1,6 +0,0 @@ -AM_CPPFLAGS = -I$(top_srcdir)/util -I$(top_srcdir)/api - -noinst_LTLIBRARIES = libcobyla.la -libcobyla_la_SOURCES = cobyla.c cobyla.h - -EXTRA_DIST = README COPYRIGHT README.orig diff --git a/configure.ac b/configure.ac deleted file mode 100644 index 7e3cc218..00000000 --- a/configure.ac +++ /dev/null @@ -1,448 +0,0 @@ -dnl Process this file with autoconf to produce a configure script. -AC_INIT(nlopt, 2.5, stevenj@alum.mit.edu) -AC_CONFIG_SRCDIR(api/nlopt.h) -SHARED_VERSION_INFO="9:0:9" # CURRENT:REVISION:AGE - -AM_INIT_AUTOMAKE(1.7) -AM_CONFIG_HEADER(config.h) -AC_CONFIG_MACRO_DIR([m4]) -AM_MAINTAINER_MODE -AC_SUBST(SHARED_VERSION_INFO) -AC_DISABLE_SHARED dnl shared libraries are a PITA, disable by default - -dnl Checks for programs. -AC_PROG_CC -AC_PROG_CC_STDC -AC_PROG_INSTALL -AC_PROG_LN_S -AC_PROG_MAKE_SET -AC_LIBTOOL_WIN32_DLL -AC_PROG_LIBTOOL - -NLOPT_SUFFIX="" -AC_ARG_WITH(cxx, - [AC_HELP_STRING([--with-cxx], [include C++-based routines])], - with_cxx=$withval,with_cxx=no) -AM_CONDITIONAL(WITH_CXX, test "x$with_cxx" = xyes) -AC_PROG_CXX -if test "x$with_cxx" = xyes; then - AC_DEFINE([WITH_CXX], 1, [Define if compiled including C++-based routines]) - NLOPT_SUFFIX="_cxx" - CC=$CXX - CFLAGS=$CXXFLAGS -fi -AC_SUBST(NLOPT_SUFFIX) - -AC_ARG_WITH(mthreads, - [AC_HELP_STRING([--with-mthreads], [use -mthreads compiler flag])], - with_mthrads=$withval,with_mthreads=no) -if test "x$with_mthreads" = xyes; then - CFLAGS="$CFLAGS -mthreads" - CXXFLAGS="$CXXFLAGS -mthreads" -fi - -dnl Checks for typedefs, structures, and compiler characteristics. -AC_HEADER_STDC -AC_HEADER_TIME -AC_CHECK_HEADERS([unistd.h getopt.h stdint.h]) -AC_C_CONST -AC_C_INLINE -AX_C_THREADLOCAL - -dnl find 32-bit unsigned integer type for random-number generator -AC_CHECK_SIZEOF(unsigned int) -AC_CHECK_SIZEOF(unsigned long) -AC_CHECK_TYPES(uint32_t, [], [], [$ac_includes_default -#ifdef HAVE_STDINT_H -# include -#endif]) - -dnl Checks for libraries and functions -AC_CHECK_LIB(m, sin) -AC_CHECK_FUNCS([BSDgettimeofday gettimeofday time qsort_r getpid]) - -AC_MSG_CHECKING([for gettid syscall]) -AC_TRY_LINK([#include -#include -], [syscall(SYS_gettid);], [ok=yes], [ok=no]) -if test "$ok" = "yes"; then - AC_DEFINE(HAVE_GETTID_SYSCALL,1,[Define if syscall(SYS_gettid) available.]) -fi -AC_MSG_RESULT(${ok}) - -AC_MSG_CHECKING([for isnan]) -AC_TRY_LINK([#include -], [if (!isnan(3.14159)) isnan(2.7183);], ok=yes, ok=no) -if test "$ok" = "yes"; then - AC_DEFINE(HAVE_ISNAN,1,[Define if the isnan() function/macro is available.]) -fi -AC_MSG_RESULT(${ok}) - -AC_MSG_CHECKING([for isinf]) -AC_TRY_LINK([#include -], [if (!isinf(3.14159)) isinf(2.7183);], ok=yes, ok=no) -if test "$ok" = "yes"; then - AC_DEFINE(HAVE_ISINF,1,[Define if the isinf() function/macro is available.]) -fi -AC_MSG_RESULT(${ok}) - -AC_MSG_CHECKING([for fpclassify]) -AC_TRY_LINK([#include -], [if (!fpclassify(3.14159)) fpclassify(2.7183);], ok=yes, ok=no) -if test "$ok" = "yes"; then - AC_DEFINE(HAVE_FPCLASSIFY,1,[Define if the fpclassify() function/macro is available.]) -fi -AC_MSG_RESULT(${ok}) - -AC_MSG_CHECKING([for copysign]) -AC_TRY_LINK([#include -], [double x = copysign(3.14159, -2.7183);], ok=yes, ok=no) -if test "$ok" = "yes"; then - AC_DEFINE(HAVE_COPYSIGN,1,[Define if the copysign function/macro is available.]) -fi -AC_MSG_RESULT(${ok}) - -dnl ----------------------------------------------------------------------- -dnl SWIG wrappers - -AC_ARG_WITH(guile, - [AC_HELP_STRING([--without-guile], [don't compile Guile plugin])], - with_guile=$withval,with_guile=yes) -AC_ARG_WITH(python, - [AC_HELP_STRING([--without-python], [don't compile Python plugin])], - with_python=$withval,with_python=yes) - -if test "$enable_shared" = no; then - AC_MSG_WARN([Python and Guile wrappers require --enable-shared; disabling]) - GUILE_CONFIG=unknown - have_python=no -else - -if test "x$with_guile" = xno; then - GUILE_CONFIG=unknown -else - -dnl Guile: -AC_ARG_VAR(GUILE_INSTALL_DIR, [where to install Guile plug-ins]) -AC_CHECK_PROG(GUILE_CONFIG, guile-config, guile-config, unknown) -if test "x$GUILE_CONFIG" = "xunknown"; then - AC_MSG_WARN([can't find guile-config, disabling Guile wrapper]) -else - save_CPPFLAGS=$CPPFLAGS - save_LIBS=$LIBS - GUILE_CPPFLAGS=`$GUILE_CONFIG compile` - GUILE_LIBS=`$GUILE_CONFIG link` - CPPFLAGS="$CPPFLAGS $GUILE_CPPFLAGS" - LIBS="$GUILE_LIBS $LIBS" - AC_MSG_CHECKING([if linking to guile works]) - AC_TRY_LINK_FUNC(scm_is_vector, [AC_MSG_RESULT(yes)], [AC_MSG_RESULT(no) - AC_MSG_WARN(guile-config is broken, disabling Guile wrapper) - GUILE_CONFIG="unknown"]) - CPPFLAGS=$save_CPPFLAGS - LIBS=$save_LIBS -fi -AC_CHECK_PROG(GUILE, guile, guile, unknown) -if test "x$GUILE" = xunknown; then - AC_MSG_WARN([can't find guile, disabling Guile wrapper]) - GUILE_CONFIG=unknown -elif test x"$GUILE_INSTALL_DIR" = "x"; then - AC_CHECK_PROGS(GUILE_CONFIG, guile-config, echo) - AC_MSG_CHECKING(guile prefix) - GUILE_PREFIX=`$GUILE_CONFIG info prefix` - AC_MSG_RESULT($GUILE_PREFIX) - AC_MSG_CHECKING([for Guile installation directory]) - GUILE_INSTALL_DIR=`guile -c '(display (%site-dir))'` - if test "$prefix" != "NONE"; then - # strip guile install path to honor prefix - GUILE_INSTALL_DIR=`echo "$GUILE_INSTALL_DIR" | sed "s|$GUILE_PREFIX|$prefix|g"` - fi - - AC_MSG_RESULT([$GUILE_INSTALL_DIR]) -fi - -fi # with_guile - -if test "x$with_python" = xno; then - have_python=no -else - -dnl Python: -AM_PATH_PYTHON([],[have_python=yes],[have_python=no]) -if test $have_python = yes; then - AC_ARG_VAR([PYTHON_CONFIG], [python-config program]) - AC_PATH_PROGS([PYTHON_CONFIG], [python$PYTHON_VERSION-config python-config], - [unknown], [`dirname $PYTHON`:$PATH]) - AC_MSG_CHECKING([for Python include flags]) - if test "x$PYTHON_CONFIG" = "xunknown"; then - pinc=-I`echo "import distutils.sysconfig; print (distutils.sysconfig.get_python_inc())" | $PYTHON - 2>/dev/null` - test "x$pinc" = "x-I" && pinc="" - else - pinc=`$PYTHON_CONFIG --includes 2>/dev/null` - fi - AC_MSG_RESULT([${pinc:-unknown}]) - PYTHON_INCLUDES="$pinc" - PYTHON_LIBS=`$PYTHON_CONFIG --libs 2>/dev/null` - save_CPPFLAGS=$CPPFLAGS - CPPFLAGS="$CPPFLAGS $PYTHON_INCLUDES" - AC_CHECK_HEADER([Python.h], [], [AC_MSG_WARN([disabling Python wrappers]) - have_python=no]) - if test $have_python = yes; then - AC_MSG_CHECKING([for Numpy include directory]) - pinc=`echo "import numpy; print (numpy.get_include())" | $PYTHON - 2>/dev/null` - AC_MSG_RESULT([${pinc:-unknown}]) - test -n "$pinc" && PYTHON_INCLUDES="$PYTHON_INCLUDES -I$pinc" - CPPFLAGS="$save_CPPFLAGS $PYTHON_INCLUDES" - AC_CHECK_HEADER([numpy/arrayobject.h],[],[ - AC_MSG_WARN([disabling Python wrappers]) - have_python=no],[#include ]) - fi - CPPFLAGS=$save_CPPFLAGS -fi - -fi # with_python - -fi # if enable_shared - -AC_SUBST(GUILE_INSTALL_DIR) -AC_SUBST(GUILE_CPPFLAGS) -AC_SUBST(GUILE_LIBS) -AC_SUBST(PYTHON_INCLUDES) -AC_SUBST(PYTHON_LIBS) -AM_CONDITIONAL(WITH_GUILE, test x"$GUILE_CONFIG" != "xunknown") -AM_CONDITIONAL(WITH_PYTHON, test x"$have_python" = "xyes") - -dnl ----------------------------------------------------------------------- -dnl Compiling Octave plug-in - -AC_ARG_VAR(OCT_INSTALL_DIR, [where to install GNU Octave .oct plug-ins]) -AC_ARG_VAR(M_INSTALL_DIR, [where to install GNU Octave .m plug-ins]) -AC_ARG_VAR(MKOCTFILE, [name of mkoctfile program to compile Octave plug-ins]) - -AC_ARG_WITH(octave, - [AC_HELP_STRING([--without-octave], [don't compile Octave plugin])], - with_octave=$withval,with_octave=yes) - -AC_CHECK_PROGS(MKOCTFILE, mkoctfile, echo) - -if test x"$with_octave" = xno; then - OCT_INSTALL_DIR="" -elif test "$MKOCTFILE" = "echo"; then - AC_MSG_WARN([can't find mkoctfile: won't be able to compile GNU Octave plugin]) - OCT_INSTALL_DIR="" -elif test x"$OCT_INSTALL_DIR" = "x"; then - # try to find installation directory - AC_CHECK_PROGS(OCTAVE, octave, echo) - AC_CHECK_PROGS(OCTAVE_CONFIG, octave-config, echo) - - AC_MSG_CHECKING(octave prefix) - OCTAVE_PREFIX=`$OCTAVE_CONFIG --print PREFIX 2> /dev/null` - AC_MSG_RESULT($OCTAVE_PREFIX) - - AC_MSG_CHECKING(where octave plugins go) - OCT_INSTALL_DIR=`$OCTAVE_CONFIG --oct-site-dir 2> /dev/null | grep '/'` - if test -z "$OCT_INSTALL_DIR"; then - OCT_INSTALL_DIR=`$OCTAVE_CONFIG --print OCTFILEDIR 2> /dev/null | grep '/'` - fi - if test -z "$OCT_INSTALL_DIR"; then - OCT_INSTALL_DIR=`echo "path" | $OCTAVE -q 2> /dev/null | grep "/oct/" | head -1` - fi - if test -z "$OCT_INSTALL_DIR"; then - OCT_INSTALL_DIR=`echo "DEFAULT_LOADPATH" | $OCTAVE -q 2> /dev/null | tr ':' '\n' | grep "site/oct" | head -1` - fi - if test -n "$OCT_INSTALL_DIR"; then - if test "$prefix" != "NONE"; then - # strip octave install path to honor prefix - OCT_INSTALL_DIR=`echo "$OCT_INSTALL_DIR" | sed "s|$OCTAVE_PREFIX|$prefix|g"` - fi - AC_MSG_RESULT($OCT_INSTALL_DIR) - else - AC_MSG_RESULT(unknown) - AC_MSG_WARN([can't find where to install octave plugins: won't be able to compile octave plugin]) - fi - - AC_MSG_CHECKING(where octave scripts go) - M_INSTALL_DIR=`$OCTAVE_CONFIG --m-site-dir 2> /dev/null | grep '/'` - if test -z "$M_INSTALL_DIR"; then - M_INSTALL_DIR=`$OCTAVE_CONFIG --print FCNFILEDIR 2> /dev/null | grep '/'` - fi - if test -z "$M_INSTALL_DIR"; then - M_INSTALL_DIR=`echo "path" | $OCTAVE -q 2> /dev/null | grep "/m" | head -1` - fi - if test -z "$M_INSTALL_DIR"; then - M_INSTALL_DIR=`echo "DEFAULT_LOADPATH" | $OCTAVE -q 2> /dev/null | tr ':' '\n' | grep "site/m" | head -1` - fi - if test -n "$M_INSTALL_DIR"; then - if test "$prefix" != "NONE"; then - # strip octave install path to honor prefix - M_INSTALL_DIR=`echo "$M_INSTALL_DIR" | sed "s|$OCTAVE_PREFIX|$prefix|g"` - fi - AC_MSG_RESULT($M_INSTALL_DIR) - else - AC_MSG_RESULT(unknown) - AC_MSG_WARN([can't find where to install octave scripts: won't be able to install octave plugin]) - OCT_INSTALL_DIR="" - fi -elif test x"$M_INSTALL_DIR" = "x"; then # user-specified OCT_INSTALL_DIR - M_INSTALL_DIR=$OCT_INSTALL_DIR -fi - -if test x"$OCT_INSTALL_DIR" != "x"; then -if test "$enable_shared" = no; then - AC_MSG_WARN([mkoctfile requires --enable-shared; won't compile Octave plugin]) - OCT_INSTALL_DIR="" -fi -fi - -AM_CONDITIONAL(WITH_OCTAVE, test x"$OCT_INSTALL_DIR" != "x") -AC_SUBST(OCT_INSTALL_DIR) -AC_SUBST(M_INSTALL_DIR) -AC_SUBST(MKOCTFILE) - -dnl ----------------------------------------------------------------------- -dnl Compiling Matlab plug-in - -AC_ARG_WITH(matlab, - [AC_HELP_STRING([--without-matlab], [don't compile Matlab plugin])], - with_matlab=$withval,with_matlab=yes) - -AC_ARG_VAR(MEX_INSTALL_DIR, [where to install Matlab .mex plug-ins]) -AC_ARG_VAR(MEX, [name of mex program to compile Matlab plug-ins]) -AC_CHECK_PROGS(MEX, mex, echo) -if test x"$with_matlab" = xno; then - MEX_INSTALL_DIR="" -elif test "$MEX" = "echo"; then - AC_MSG_WARN([can't find mex: won't be able to compile Matlab plugin]) - MEX_INSTALL_DIR="" -else - AC_MSG_CHECKING([for extension of compiled mex files]) - rm -f conftest* - cat > conftest.c < -void mexFunction(int nlhs, mxArray *plhs[[]], - int nrhs, const mxArray *prhs[[]]) { } -EOF - if $MEX conftest.c >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD; then - MEXSUFF=`ls conftest.m* | head -1 | cut -d'.' -f2` - AC_MSG_RESULT($MEXSUFF) - AC_CHECK_PROGS(MATLAB, matlab, echo) - else - AC_MSG_WARN([$MEX failed to compile a simple file; won't compile Matlab plugin]) - MEX_INSTALL_DIR="" - MATLAB=echo - fi - - if test x"$MATLAB" != xecho; then - if test "$enable_shared" = no; then - AC_MSG_RESULT(no) - AC_MSG_WARN([mex requires --enable-shared; won't compile Matlab plugin]) - MEX_INSTALL_DIR="" - MATLAB=echo - fi - fi - - if test x"$MATLAB" != xecho; then - # try to find installation directory - if test x"$MEX_INSTALL_DIR" = "x"; then - AC_MSG_CHECKING(for MATLAB mex installation dir) - MEX_INSTALL_DIR=`matlab -nodisplay -nodesktop -nojvm -r 'path;quit' | grep toolbox/local |sed 's,^[[^/]]*,,g' |sort |head -1` - AC_MSG_RESULT($MEX_INSTALL_DIR) - if test x`basename "$MEX_INSTALL_DIR"` != xlocal; then - MEX_INSTALL_DIR="" - fi - if test x"$MEX_INSTALL_DIR" = "x"; then - AC_MSG_WARN([can't find reasonable Matlab installation directory; Matlab plugins will not be compiled unless you manually specify MEX_INSTALL_DIR]) - fi - fi - else - MEX_INSTALL_DIR="" - fi -fi -AM_CONDITIONAL(WITH_MATLAB, test x"$MEX_INSTALL_DIR" != "x") -AC_SUBST(MEX_INSTALL_DIR) -AC_SUBST(MEX) -AC_SUBST(MEXSUFF) - -dnl ----------------------------------------------------------------------- -dnl Check for broken Solaris HUGE_VAL macro under gcc 3.4.x and similar - -AC_MSG_CHECKING([for working HUGE_VAL]) -AC_TRY_COMPILE([#include ], [double x = -HUGE_VAL;], -[AC_MSG_RESULT([ok])], -[AC_TRY_COMPILE([#include -#ifdef __GNUC__ -#undef HUGE_VAL -#define HUGE_VAL __builtin_huge_val() -#endif], [double x = -HUGE_VAL;], -[AC_MSG_RESULT([__builtin_huge_val()]) -AC_DEFINE(REPLACEMENT_HUGE_VAL,[__builtin_huge_val()], - [replacement for broken HUGE_VAL macro, if needed])], -[AC_MSG_RESULT([unknown]) -AC_MSG_ERROR([broken HUGE_VAL macro with this compiler, unknown workaround])])]) - -dnl ----------------------------------------------------------------------- -dnl Debugging - -AC_ARG_ENABLE(debug, [AC_HELP_STRING([--enable-debug],[compile with extra runtime checks for debugging])], ok=$enableval, ok=no) -if test "$ok" = "yes"; then - AC_DEFINE(DEBUG,1,[Define to enable extra debugging code.]) -fi - -dnl override CFLAGS selection when debugging -if test "${enable_debug}" = "yes"; then - CFLAGS="-g" - CXXFLAGS="-g" - FFLAGS="-g" -fi - -dnl add gcc warnings, in debug/maintainer mode only -if test "$enable_debug" = yes || test "$USE_MAINTAINER_MODE" = yes; then -if test $ac_cv_prog_gcc = yes; then - if test "$ac_test_CFLAGS" != "set"; then - CFLAGS="$CFLAGS -Wall -W -Wcast-qual -Wpointer-arith -Wcast-align -Wno-long-long -pedantic -Wshadow -Wbad-function-cast -Wwrite-strings -Wstrict-prototypes -Wredundant-decls -Wnested-externs -Wundef -Wconversion -Wmissing-prototypes -Wmissing-declarations" - fi - if test "$ac_test_CXXFLAGS" != "set"; then - CXXFLAGS="$CXXFLAGS -Wall -W -Wcast-qual -Wpointer-arith -Wcast-align -Wno-long-long -pedantic -Wshadow -Wwrite-strings -Wredundant-decls -Wundef -Wconversion" - fi - if test "x$with_cxx" = xyes; then - CFLAGS=$CXXFLAGS - fi -fi -fi - -vers=`echo ${VERSION}.0.0 | cut -d. -f1` -AC_DEFINE_UNQUOTED(MAJOR_VERSION, $vers, [Major version number.]) -vers=`echo ${VERSION}.0.0 | cut -d. -f2` -AC_DEFINE_UNQUOTED(MINOR_VERSION, $vers, [Minor version number.]) -vers=`echo ${VERSION}.0.0 | cut -d. -f3` -AC_DEFINE_UNQUOTED(BUGFIX_VERSION, $vers, [Bugfix version number.]) - -dnl ----------------------------------------------------------------------- - -AC_CONFIG_FILES([ - Makefile - nlopt.pc - api/Makefile - util/Makefile - octave/Makefile - direct/Makefile - cdirect/Makefile - stogo/Makefile - praxis/Makefile - luksan/Makefile - crs/Makefile - mlsl/Makefile - mma/Makefile - cobyla/Makefile - newuoa/Makefile - neldermead/Makefile - auglag/Makefile - bobyqa/Makefile - isres/Makefile - slsqp/Makefile - esch/Makefile - test/Makefile - swig/Makefile - swig/nlopt.scm -]) - -AC_OUTPUT diff --git a/cquad/Makefile.am b/cquad/Makefile.am deleted file mode 100644 index 9a9016a3..00000000 --- a/cquad/Makefile.am +++ /dev/null @@ -1,6 +0,0 @@ -AM_CPPFLAGS = -I$(top_srcdir)/util -I$(top_srcdir)/api - -noinst_LTLIBRARIES = libcquad.la -libcquad_la_SOURCES = cquad.c cquad.h - -EXTRA_DIST = README diff --git a/crs/Makefile.am b/crs/Makefile.am deleted file mode 100644 index 14ff7cbc..00000000 --- a/crs/Makefile.am +++ /dev/null @@ -1,6 +0,0 @@ -AM_CPPFLAGS = -I$(top_srcdir)/util -I$(top_srcdir)/api - -noinst_LTLIBRARIES = libcrs.la -libcrs_la_SOURCES = crs.c crs.h - -EXTRA_DIST = README diff --git a/direct/Makefile.am b/direct/Makefile.am deleted file mode 100644 index 161dded9..00000000 --- a/direct/Makefile.am +++ /dev/null @@ -1,7 +0,0 @@ -AM_CPPFLAGS = -I$(top_srcdir)/util -I$(top_srcdir)/api - -noinst_LTLIBRARIES = libdirect.la -libdirect_la_SOURCES = DIRect.c direct_wrap.c DIRserial.c DIRsubrout.c \ -direct-internal.h direct.h - -EXTRA_DIST = README AUTHORS COPYING DIRparallel.c tstc.c userguide.pdf diff --git a/esch/Makefile.am b/esch/Makefile.am deleted file mode 100644 index 377c00ff..00000000 --- a/esch/Makefile.am +++ /dev/null @@ -1,6 +0,0 @@ -AM_CPPFLAGS = -I$(top_srcdir)/util -I$(top_srcdir)/api - -noinst_LTLIBRARIES = libesch.la -libesch_la_SOURCES = esch.c esch.h - -EXTRA_DIST = README COPYRIGHT diff --git a/isres/Makefile.am b/isres/Makefile.am deleted file mode 100644 index d8192483..00000000 --- a/isres/Makefile.am +++ /dev/null @@ -1,6 +0,0 @@ -AM_CPPFLAGS = -I$(top_srcdir)/util -I$(top_srcdir)/api - -noinst_LTLIBRARIES = libisres.la -libisres_la_SOURCES = isres.c isres.h - -EXTRA_DIST = README diff --git a/luksan/Makefile.am b/luksan/Makefile.am deleted file mode 100644 index f302a795..00000000 --- a/luksan/Makefile.am +++ /dev/null @@ -1,6 +0,0 @@ -AM_CPPFLAGS = -I$(top_srcdir)/util -I$(top_srcdir)/api - -noinst_LTLIBRARIES = libluksan.la -libluksan_la_SOURCES = plis.c plip.c pnet.c mssubs.c pssubs.c luksan.h - -EXTRA_DIST = README COPYRIGHT plis.txt v999-07.pdf diff --git a/m4/ax_c_threadlocal.m4 b/m4/ax_c_threadlocal.m4 deleted file mode 100644 index 0fdb30e5..00000000 --- a/m4/ax_c_threadlocal.m4 +++ /dev/null @@ -1,47 +0,0 @@ -dnl @synopsis AX_C_THREADLOCAL([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) -dnl @summary determine C keyword for threadlocal storage -dnl -dnl This macro tries to discover a C keyword to declare variables -dnl as having thread-local storage. Most commonly, this is either -dnl __thread [gcc] or __declspec(thread) [Windows]. -dnl -dnl On success, it #defines the THREADLOCAL preprocessor symbol to -dnl the appropriate keyword. You would then use it in C code as, e.g.: -dnl THREADLOCAL int myvariable; -dnl -dnl ACTION-IF-FOUND is a list of shell commands to run if an thread-local -dnl keyword is found, and ACTION-IF-NOT-FOUND is a list of commands -dnl to run it if one is not found. If ACTION-IF-FOUND is not specified, -dnl the default action does nothing. -dnl -dnl @version 2010-05-28 -dnl @license GPLWithACException -dnl @author Steven G. Johnson -AC_DEFUN([AX_C_THREADLOCAL], -[AC_ARG_WITH(threadlocal, - [AC_HELP_STRING([--without-threadlocal], [no thread-local storage keyword])], - with_ax_c_threadlocal=$withval, with_ax_c_threadlocal=yes) - AC_CACHE_CHECK([for C thread-local keyword], ax_cv_c_threadlocal, -[if test "x$with_ax_c_threadlocal" = xno; then - ax_cv_c_threadlocal=disabled - else - ax_cv_c_threadlocal=unsupported - AC_LANG_SAVE - AC_LANG_C - for ax_kw in __thread "__declspec(thread)"; do - AC_TRY_COMPILE([], [static $ax_kw int x = 0;], - [ax_cv_c_threadlocal=$ax_kw; break]) - done - AC_LANG_RESTORE - fi -]) - ax_kw="$ax_cv_c_threadlocal" - if test "x$ax_kw" = xunsupported; then ax_kw=""; fi - if test "x$ax_kw" = xdisabled; then ax_kw=""; fi - AC_DEFINE_UNQUOTED(THREADLOCAL, $ax_kw, [Define to C thread-local keyword, or to nothing if this is not supported in your compiler.]) - if test "$ax_cv_c_threadlocal" = unsupported; then - m4_default([$2],:) - else - m4_default([$1],:) - fi -]) diff --git a/mlsl/Makefile.am b/mlsl/Makefile.am deleted file mode 100644 index b019c2c2..00000000 --- a/mlsl/Makefile.am +++ /dev/null @@ -1,6 +0,0 @@ -AM_CPPFLAGS = -I$(top_srcdir)/util -I$(top_srcdir)/api - -noinst_LTLIBRARIES = libmlsl.la -libmlsl_la_SOURCES = mlsl.c mlsl.h - -EXTRA_DIST = README diff --git a/mma/Makefile.am b/mma/Makefile.am deleted file mode 100644 index f453b75a..00000000 --- a/mma/Makefile.am +++ /dev/null @@ -1,6 +0,0 @@ -AM_CPPFLAGS = -I$(top_srcdir)/util -I$(top_srcdir)/api - -noinst_LTLIBRARIES = libmma.la -libmma_la_SOURCES = mma.c ccsa_quadratic.c mma.h - -EXTRA_DIST = README diff --git a/neldermead/Makefile.am b/neldermead/Makefile.am deleted file mode 100644 index 1c9ed8a3..00000000 --- a/neldermead/Makefile.am +++ /dev/null @@ -1,6 +0,0 @@ -AM_CPPFLAGS = -I$(top_srcdir)/util -I$(top_srcdir)/api - -noinst_LTLIBRARIES = libneldermead.la -libneldermead_la_SOURCES = nldrmd.c neldermead.h sbplx.c - -EXTRA_DIST = README diff --git a/newuoa/Makefile.am b/newuoa/Makefile.am deleted file mode 100644 index 74abf1af..00000000 --- a/newuoa/Makefile.am +++ /dev/null @@ -1,6 +0,0 @@ -AM_CPPFLAGS = -I$(top_srcdir)/util -I$(top_srcdir)/api - -noinst_LTLIBRARIES = libnewuoa.la -libnewuoa_la_SOURCES = newuoa.c newuoa.h - -EXTRA_DIST = README README.orig COPYRIGHT diff --git a/nlopt.pc.in b/nlopt.pc.in index 28f051be..81d96299 100644 --- a/nlopt.pc.in +++ b/nlopt.pc.in @@ -1,10 +1,10 @@ -prefix=@prefix@ -exec_prefix=@exec_prefix@ -libdir=@libdir@ -includedir=@includedir@ +prefix=@CMAKE_INSTALL_PREFIX@ +exec_prefix=${prefix} +libdir=${exec_prefix}/lib +includedir=${prefix}/include Name: NLopt Description: nonlinear optimization libary -Version: @VERSION@ +Version: @NLOPT_VERSION_STRING@ Libs: -L${libdir} -lnlopt@NLOPT_SUFFIX@ -lm Cflags: -I${includedir} diff --git a/octave/Makefile.am b/octave/Makefile.am deleted file mode 100644 index 25ad75a2..00000000 --- a/octave/Makefile.am +++ /dev/null @@ -1,43 +0,0 @@ -AM_CPPFLAGS = -I$(top_srcdir)/api -I$(top_srcdir)/util - -MFILES = NLOPT_GN_DIRECT.m NLOPT_GN_DIRECT_L.m NLOPT_GN_DIRECT_L_RAND.m NLOPT_GN_DIRECT_NOSCAL.m NLOPT_GN_DIRECT_L_NOSCAL.m NLOPT_GN_DIRECT_L_RAND_NOSCAL.m NLOPT_GN_ORIG_DIRECT.m NLOPT_GN_ORIG_DIRECT_L.m NLOPT_GD_STOGO.m NLOPT_GD_STOGO_RAND.m NLOPT_LD_LBFGS_NOCEDAL.m NLOPT_LD_LBFGS.m NLOPT_LN_PRAXIS.m NLOPT_LD_VAR1.m NLOPT_LD_VAR2.m NLOPT_LD_TNEWTON.m NLOPT_LD_TNEWTON_RESTART.m NLOPT_LD_TNEWTON_PRECOND.m NLOPT_LD_TNEWTON_PRECOND_RESTART.m NLOPT_GN_CRS2_LM.m NLOPT_GN_MLSL.m NLOPT_GD_MLSL.m NLOPT_GN_MLSL_LDS.m NLOPT_GD_MLSL_LDS.m NLOPT_LD_MMA.m NLOPT_LN_COBYLA.m NLOPT_LN_NEWUOA.m NLOPT_LN_NEWUOA_BOUND.m NLOPT_LN_NELDERMEAD.m NLOPT_LN_SBPLX.m NLOPT_LN_AUGLAG.m NLOPT_LD_AUGLAG.m NLOPT_LN_AUGLAG_EQ.m NLOPT_LD_AUGLAG_EQ.m NLOPT_LN_BOBYQA.m NLOPT_GN_ISRES.m NLOPT_AUGLAG.m NLOPT_AUGLAG_EQ.m NLOPT_G_MLSL.m NLOPT_G_MLSL_LDS.m NLOPT_LD_SLSQP.m NLOPT_LD_CCSAQ.m NLOPT_GN_ESCH.m - -####################################################################### -# dummy C program to fool automake into making sure that CPPFLAGS etc. -# are all defined -noinst_PROGRAMS = dummy -dummy_SOURCES = dummy.c - -####################################################################### -octdir = $(OCT_INSTALL_DIR) -mdir = $(M_INSTALL_DIR) -if WITH_OCTAVE -oct_DATA = nlopt_optimize.oct -m_DATA = $(MFILES) nlopt_minimize.m nlopt_minimize_constrained.m nlopt_optimize.m -endif - -nlopt_optimize.oct: nlopt_optimize-oct.cc nlopt_optimize_usage.h $(top_builddir)/.libs/libnlopt@NLOPT_SUFFIX@.la - $(MKOCTFILE) -o $@ $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(srcdir)/nlopt_optimize-oct.cc $(LDFLAGS) -L$(top_builddir)/.libs -lnlopt@NLOPT_SUFFIX@ - -BUILT_SOURCES = nlopt_optimize_usage.h -MAINTAINERCLEANFILES = $(BUILT_SOURCES) - -nlopt_optimize_usage.h: $(srcdir)/nlopt_optimize.m - echo "#define NLOPT_OPTIMIZE_USAGE \\" > $@ - sed 's/\"/\\"/g' $(srcdir)/nlopt_optimize.m | sed 's,^% ,\",;s,^%,\",;s,$$,\\n\" \\,' >> $@ - echo "" >> $@ - -####################################################################### -mexdir = $(MEX_INSTALL_DIR) -if WITH_MATLAB -mex_DATA = nlopt_optimize.$(MEXSUFF) $(MFILES) nlopt_minimize.m nlopt_minimize_constrained.m nlopt_optimize.m -endif - -nlopt_optimize.$(MEXSUFF): nlopt_optimize-mex.c $(top_builddir)/.libs/libnlopt@NLOPT_SUFFIX@.la - $(MEX) -output nlopt_optimize -O $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(srcdir)/nlopt_optimize-mex.c $(LDFLAGS) -L$(top_builddir)/.libs -lnlopt@NLOPT_SUFFIX@ - -####################################################################### - -EXTRA_DIST = nlopt_optimize-oct.cc nlopt_optimize-mex.c $(MFILES) nlopt_minimize.m nlopt_minimize_constrained.m nlopt_optimize.m nlopt_optimize_usage.h CMakeLists.txt - -CLEANFILES = nlopt_optimize.oct nlopt_optimize.h nlopt_optimize.$(MEXSUFF) nlopt_optimize-oct.o diff --git a/praxis/Makefile.am b/praxis/Makefile.am deleted file mode 100644 index c6c1e214..00000000 --- a/praxis/Makefile.am +++ /dev/null @@ -1,6 +0,0 @@ -AM_CPPFLAGS = -I$(top_srcdir)/util -I$(top_srcdir)/api - -noinst_LTLIBRARIES = libpraxis.la -libpraxis_la_SOURCES = praxis.c praxis.h - -EXTRA_DIST = README diff --git a/slsqp/Makefile.am b/slsqp/Makefile.am deleted file mode 100644 index ff7e8131..00000000 --- a/slsqp/Makefile.am +++ /dev/null @@ -1,6 +0,0 @@ -AM_CPPFLAGS = -I$(top_srcdir)/util -I$(top_srcdir)/api - -noinst_LTLIBRARIES = libslsqp.la -libslsqp_la_SOURCES = slsqp.c slsqp.h - -EXTRA_DIST = README COPYRIGHT diff --git a/stogo/Makefile.am b/stogo/Makefile.am deleted file mode 100644 index 3defc18e..00000000 --- a/stogo/Makefile.am +++ /dev/null @@ -1,8 +0,0 @@ -AM_CPPFLAGS = -I$(top_srcdir)/util -I$(top_srcdir)/api - -noinst_LTLIBRARIES = libstogo.la -libstogo_la_SOURCES = global.cc linalg.cc local.cc stogo.cc tools.cc \ -global.h linalg.h local.h stogo_config.h stogo.h tools.h - -EXTRA_DIST = testros.cc tst.cc tstc.c prog.cc testfun.h rosen.h README \ -paper.pdf techreport.pdf COPYRIGHT diff --git a/subplex/Makefile.am b/subplex/Makefile.am deleted file mode 100644 index bae7d9c8..00000000 --- a/subplex/Makefile.am +++ /dev/null @@ -1,6 +0,0 @@ -AM_CPPFLAGS = -I$(top_srcdir)/util - -noinst_LTLIBRARIES = libsubplex.la -libsubplex_la_SOURCES = subplex.c subplex.h - -EXTRA_DIST = README diff --git a/swig/CMakeLists.txt b/swig/CMakeLists.txt index 0fcb0ab3..30dfc746 100644 --- a/swig/CMakeLists.txt +++ b/swig/CMakeLists.txt @@ -72,8 +72,8 @@ if (GUILE_FOUND AND ((SWIG_FOUND AND SWIG_VERSION VERSION_GREATER 2.0.9) OR (EXI target_link_libraries(${SWIG_MODULE_nlopt_guile_REAL_NAME} ${nlopt_lib}) target_link_libraries(${SWIG_MODULE_nlopt_guile_REAL_NAME} ${GUILE_LIBRARIES}) - set_target_properties (${SWIG_MODULE_nlopt_guile_REAL_NAME} PROPERTIES SOVERSION ${_INFO_SOVERSION}) - set_target_properties (${SWIG_MODULE_nlopt_guile_REAL_NAME} PROPERTIES VERSION ${_INFO_VERSION} ) + set_target_properties (${SWIG_MODULE_nlopt_guile_REAL_NAME} PROPERTIES SOVERSION ${LIB_SOVERSION}) + set_target_properties (${SWIG_MODULE_nlopt_guile_REAL_NAME} PROPERTIES VERSION ${LIB_VERSION}) file (RELATIVE_PATH _REL_GUILE_SITE_PATH ${GUILE_ROOT_DIR} ${GUILE_SITE_DIR}) set (GUILE_SITE_PATH ${_REL_GUILE_SITE_PATH}) diff --git a/swig/Makefile.am b/swig/Makefile.am deleted file mode 100644 index 7960c1d5..00000000 --- a/swig/Makefile.am +++ /dev/null @@ -1,59 +0,0 @@ -SWIG_SRC = nlopt.i nlopt-exceptions.i nlopt-enum-renames.i -EXTRA_DIST = $(SWIG_SRC) nlopt-guile.i nlopt-python.i nlopt.scm.in nlopt.py numpy.i CMakeLists.txt - -BUILT_SOURCES = nlopt-guile.cpp nlopt-python.cpp nlopt-enum-renames.i nlopt.scm.in - -HDR = $(top_srcdir)/api/nlopt.hpp - -############################################################################## -# Guile wrapper - -libnlopt@NLOPT_SUFFIX@_guile_la_SOURCES = nlopt-guile.cpp -libnlopt@NLOPT_SUFFIX@_guile_la_LIBADD = ../libnlopt@NLOPT_SUFFIX@.la @GUILE_LIBS@ -libnlopt@NLOPT_SUFFIX@_guile_la_LDFLAGS = -version-info @SHARED_VERSION_INFO@ -libnlopt@NLOPT_SUFFIX@_guile_la_CPPFLAGS = $(GUILE_CPPFLAGS) -I$(top_srcdir)/api - -guiledir = $(GUILE_INSTALL_DIR) -if WITH_GUILE -guile_DATA = nlopt.scm -guilelib = libnlopt@NLOPT_SUFFIX@_guile.la -endif - -############################################################################## -# Python wrapper - -_nlopt_la_SOURCES = nlopt-python.cpp -_nlopt_la_LIBADD = ../libnlopt@NLOPT_SUFFIX@.la @PYTHON_LIBS@ -_nlopt_la_LDFLAGS = -module -version-info @SHARED_VERSION_INFO@ -_nlopt_la_CPPFLAGS = $(PYTHON_INCLUDES) -I$(top_srcdir)/api -if WITH_PYTHON -python_PYTHON = nlopt.py -pyexec_LTLIBRARIES = _nlopt.la -endif - -############################################################################## - - -lib_LTLIBRARIES = $(guilelib) - -############################################################################## -# Generate wrappers via SWIG: - -if MAINTAINER_MODE - -nlopt-guile.cpp: $(SWIG_SRC) nlopt-guile.i $(HDR) - swig -I$(top_srcdir)/api -outdir $(builddir) -c++ -guile -scmstub -o $@ $(srcdir)/nlopt.i - rm -f nlopt.scm.in - mv nlopt.scm nlopt.scm.in - -nlopt.scm.in: nlopt-guile.cpp - -nlopt-python.cpp: $(SWIG_SRC) nlopt-python.i numpy.i $(HDR) - swig -I$(top_srcdir)/api -outdir $(builddir) -c++ -python -o $@ $(srcdir)/nlopt.i - -nlopt.py: nlopt-python.cpp - -nlopt-enum-renames.i: $(top_srcdir)/api/nlopt.h - (echo "// AUTOMATICALLY GENERATED -- DO NOT EDIT"; egrep 'NLOPT_[LG][DN]|NLOPT_AUGLAG|NLOPT_G_MLSL|NLOPT_NUM_ALGORITHMS' $(top_srcdir)/api/nlopt.h | sed 's/NLOPT_//g' |tr -d ' ' |tr '/' ',' |tr '=' ',' |cut -d, -f1 |while read name; do echo "%rename(NLOPT_$$name) nlopt::$$name;"; done; egrep 'NLOPT_[A-Z_]* =' $(top_srcdir)/api/nlopt.h | egrep -v 'NLOPT_[LG][DN]|NLOPT_AUGLAG|NLOPT_G_MLSL' | sed 's/NLOPT_//g' |tr -d ' ' |cut -d'=' -f1 | while read name; do echo "%rename(NLOPT_$$name) nlopt::$$name;"; done) > $@ - -endif diff --git a/test/Makefile.am b/test/Makefile.am deleted file mode 100644 index d75a0201..00000000 --- a/test/Makefile.am +++ /dev/null @@ -1,8 +0,0 @@ -AM_CPPFLAGS = -I$(top_srcdir)/api -I$(top_srcdir)/util - -noinst_PROGRAMS = testopt - -testopt_SOURCES = testfuncs.c testfuncs.h testopt.cpp -testopt_LDADD = $(top_builddir)/libnlopt@NLOPT_SUFFIX@.la -EXTRA_DIST = test_std.py CMakeLists.txt - diff --git a/util/Makefile.am b/util/Makefile.am deleted file mode 100644 index ca4dff9a..00000000 --- a/util/Makefile.am +++ /dev/null @@ -1,8 +0,0 @@ -AM_CPPFLAGS = -I$(top_srcdir)/api - -noinst_LTLIBRARIES = libutil.la -libutil_la_SOURCES = mt19937ar.c sobolseq.c soboldata.h timer.c stop.c nlopt-util.h redblack.c redblack.h qsort_r.c rescale.c - -noinst_PROGRAMS = redblack_test -redblack_test_SOURCES = redblack_test.c -redblack_test_LDADD = libutil.la From 743d58132d8491146af912a637aad7f56f40cf77 Mon Sep 17 00:00:00 2001 From: Julien Schueller Date: Tue, 5 Jul 2016 19:14:17 +0200 Subject: [PATCH 15/29] cmake: install man --- api/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/api/CMakeLists.txt b/api/CMakeLists.txt index bf8ce34d..fc907a64 100644 --- a/api/CMakeLists.txt +++ b/api/CMakeLists.txt @@ -1,3 +1,7 @@ + +# install man +install (FILES nlopt.3 DESTINATION share/man/man3) + # generate nlopt.f from nlopt.h enums if (NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/nlopt.f) file (WRITE ${CMAKE_CURRENT_BINARY_DIR}/nlopt.f "") From 8f9f9884b49669bea92e524a8caa28be94c7ae0c Mon Sep 17 00:00:00 2001 From: Julien Schueller Date: Tue, 5 Jul 2016 19:31:30 +0200 Subject: [PATCH 16/29] re-implement getopt for test --- test/testopt.cpp | 70 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/test/testopt.cpp b/test/testopt.cpp index 2400ebee..cfef0e03 100644 --- a/test/testopt.cpp +++ b/test/testopt.cpp @@ -32,6 +32,76 @@ #endif #ifdef HAVE_GETOPT_H # include +#else +int opterr = 1, /* if error message should be printed */ + optind = 1, /* index into parent argv vector */ + optopt, /* character checked for validity */ + optreset; /* reset getopt */ +char *optarg; /* argument associated with option */ + +#define BADCH (int)'?' +#define BADARG (int)':' +#define EMSG "" + +/* +* getopt -- +* Parse argc/argv argument vector. +*/ +int + getopt(int nargc, char * const nargv[], const char *ostr) +{ + static char *place = EMSG; /* option letter processing */ + const char *oli; /* option letter list index */ + + if (optreset || !*place) { /* update scanning pointer */ + optreset = 0; + if (optind >= nargc || *(place = nargv[optind]) != '-') { + place = EMSG; + return (-1); + } + if (place[1] && *++place == '-') { /* found "--" */ + ++optind; + place = EMSG; + return (-1); + } + } /* option letter okay? */ + if ((optopt = (int)*place++) == (int)':' || + !(oli = strchr(ostr, optopt))) { + /* + * if the user didn't specify '-' as an option, + * assume it means -1. + */ + if (optopt == (int)'-') + return (-1); + if (!*place) + ++optind; + if (opterr && *ostr != ':') + (void)printf("illegal option -- %c\n", optopt); + return (BADCH); + } + if (*++oli != ':') { /* don't need argument */ + optarg = NULL; + if (!*place) + ++optind; + } + else { /* need an argument */ + if (*place) /* no white space */ + optarg = place; + else if (nargc <= ++optind) { /* no arg */ + place = EMSG; + if (*ostr == ':') + return (BADARG); + if (opterr) + (void)printf("option requires an argument -- %c\n", optopt); + return (BADCH); + } + else /* white space */ + optarg = nargv[optind]; + place = EMSG; + ++optind; + } + return (optopt); /* dump back option letter */ +} #endif #define USE_FEENABLEEXCEPT 0 From e908b5c1eb1a2978760af41e6c94165a2b458b87 Mon Sep 17 00:00:00 2001 From: Julien Schueller Date: Tue, 5 Jul 2016 21:05:58 +0200 Subject: [PATCH 17/29] travis: +osx --- .travis.yml | 62 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 26 deletions(-) diff --git a/.travis.yml b/.travis.yml index 24394691..1f334544 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,30 +1,40 @@ language: cpp sudo: false -addons: - apt: - sources: - packages: - - swig - - python-dev - - python-numpy - - guile-2.0-dev - - octave3.2-headers - - cmake - - g++-mingw-w64-i686 - - gcc-mingw-w64-i686 - - binutils-mingw-w64-i686 - - g++-mingw-w64-x86-64 - - gcc-mingw-w64-x86-64 - - binutils-mingw-w64-x86-64 +matrix: + include: + - os: linux + addons: + apt: + packages: + - swig + - python-dev + - python-numpy + - guile-2.0-dev + - octave3.2-headers + - cmake + - g++-mingw-w64-i686 + - gcc-mingw-w64-i686 + - binutils-mingw-w64-i686 + - g++-mingw-w64-x86-64 + - gcc-mingw-w64-x86-64 + - binutils-mingw-w64-x86-64 + script: + - mkdir build && pushd build + - cmake -DCMAKE_INSTALL_PREFIX=~/.local -DBUILD_SHARED_LIBS=ON -DWITH_CXX=ON .. + - make install -j2 && make tests -j2 && ctest -j2 --output-on-failure + - rm -rf * ~/.local + - cmake -DCMAKE_INSTALL_PREFIX=~/.local -DBUILD_SHARED_LIBS=ON -DWITH_CXX=ON -DBUILD_PYTHON=OFF -DBUILD_OCTAVE=OFF -DBUILD_GUILE=OFF -DCMAKE_TOOLCHAIN_FILE=$PWD/../cmake/toolchain-i686-w64-mingw32.cmake .. + - make install -j2 && make tests -j2 + - rm -rf * ~/.local + - cmake -DCMAKE_INSTALL_PREFIX=~/.local -DBUILD_SHARED_LIBS=ON -DWITH_CXX=ON -DBUILD_PYTHON=OFF -DBUILD_OCTAVE=OFF -DBUILD_GUILE=OFF -DCMAKE_TOOLCHAIN_FILE=$PWD/../cmake/toolchain-x86_64-w64-mingw32.cmake .. + - make install -j2 && make tests -j2 -script: - - mkdir build && pushd build - - cmake -DCMAKE_INSTALL_PREFIX=~/.local -DBUILD_SHARED_LIBS=ON -DWITH_CXX=ON .. - - make install -j2 && make tests -j2 && ctest -j2 --output-on-failure - - rm -rf * ~/.local - - cmake -DCMAKE_INSTALL_PREFIX=~/.local -DBUILD_SHARED_LIBS=ON -DWITH_CXX=ON -DBUILD_PYTHON=OFF -DBUILD_OCTAVE=OFF -DBUILD_GUILE=OFF -DCMAKE_TOOLCHAIN_FILE=$PWD/../cmake/toolchain-i686-w64-mingw32.cmake .. - - make install -j2 && make tests -j2 - - rm -rf * ~/.local - - cmake -DCMAKE_INSTALL_PREFIX=~/.local -DBUILD_SHARED_LIBS=ON -DWITH_CXX=ON -DBUILD_PYTHON=OFF -DBUILD_OCTAVE=OFF -DBUILD_GUILE=OFF -DCMAKE_TOOLCHAIN_FILE=$PWD/../cmake/toolchain-x86_64-w64-mingw32.cmake .. - - make install -j2 && make tests -j2 + - os: osx + install: + - brew tap homebrew/python + - brew install swig python + script: + - mkdir build && pushd build + - cmake -DCMAKE_INSTALL_PREFIX=~/.local -DBUILD_SHARED_LIBS=ON -DWITH_CXX=ON .. + - make install && make tests && ctest --output-on-failure \ No newline at end of file From 43951cb0e23ff2a2a32ff1b240722149b2c8cc93 Mon Sep 17 00:00:00 2001 From: Julien Schueller Date: Tue, 5 Jul 2016 21:06:19 +0200 Subject: [PATCH 18/29] cmake: man/pkgconfig unix only --- CMakeLists.txt | 6 ++++-- api/CMakeLists.txt | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ec76bc5f..b7948bab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -119,8 +119,10 @@ message (STATUS "NLopt version ${NLOPT_VERSION_STRING}") configure_file (${CMAKE_CURRENT_SOURCE_DIR}/config.cmake.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h IMMEDIATE) # pkgconfig file -configure_file (${CMAKE_CURRENT_SOURCE_DIR}/nlopt.pc.in ${CMAKE_CURRENT_BINARY_DIR}/nlopt.pc @ONLY) -install (FILES ${CMAKE_CURRENT_BINARY_DIR}/nlopt.pc DESTINATION lib/pkgconfig) +if (UNIX) + configure_file (${CMAKE_CURRENT_SOURCE_DIR}/nlopt.pc.in ${CMAKE_CURRENT_BINARY_DIR}/nlopt.pc @ONLY) + install (FILES ${CMAKE_CURRENT_BINARY_DIR}/nlopt.pc DESTINATION lib/pkgconfig) +endif () #============================================================================== # INCLUDE DIRECTORIES diff --git a/api/CMakeLists.txt b/api/CMakeLists.txt index fc907a64..0ea4f158 100644 --- a/api/CMakeLists.txt +++ b/api/CMakeLists.txt @@ -1,6 +1,8 @@ # install man -install (FILES nlopt.3 DESTINATION share/man/man3) +if (UNIX) + install (FILES nlopt.3 DESTINATION share/man/man3) +endif () # generate nlopt.f from nlopt.h enums if (NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/nlopt.f) From 0c64230268ecfcb3b529a7714a17dc7c3ec2b219 Mon Sep 17 00:00:00 2001 From: Julien Schueller Date: Tue, 5 Jul 2016 21:06:37 +0200 Subject: [PATCH 19/29] add only Python test if built --- test/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 5179ef93..553ac570 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -24,7 +24,7 @@ foreach (algo_index RANGE 29)# 42 endforeach () endforeach () -if (PYTHONINTERP_FOUND) +if (PYTHONINTERP_FOUND AND PYTHONLIBS_FOUND AND (SWIG_FOUND OR (EXISTS ${CMAKE_SOURCE_DIR}/swig/nlopt-python.cpp))) set (PYINSTALLCHECK_ENVIRONMENT "LD_LIBRARY_PATH=${INSTALL_DESTDIR}${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}:$ENV{LD_LIBRARY_PATH}" "PYTHONPATH=${INSTALL_DESTDIR}${CMAKE_INSTALL_PREFIX}/${PYTHON_MODULE_PATH}${PATH_SEP}$ENV{PYTHONPATH}" ) From 2dad3ff5d6566bc32a7a8379920d85438470185d Mon Sep 17 00:00:00 2001 From: Julien Schueller Date: Tue, 5 Jul 2016 21:35:45 +0200 Subject: [PATCH 20/29] cmake: pkgconfig on mingw --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b7948bab..77166f5e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -119,7 +119,7 @@ message (STATUS "NLopt version ${NLOPT_VERSION_STRING}") configure_file (${CMAKE_CURRENT_SOURCE_DIR}/config.cmake.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h IMMEDIATE) # pkgconfig file -if (UNIX) +if (UNIX OR MINGW) configure_file (${CMAKE_CURRENT_SOURCE_DIR}/nlopt.pc.in ${CMAKE_CURRENT_BINARY_DIR}/nlopt.pc @ONLY) install (FILES ${CMAKE_CURRENT_BINARY_DIR}/nlopt.pc DESTINATION lib/pkgconfig) endif () From 4eec9de563d575aafea7a4a1351ee84bfed4688c Mon Sep 17 00:00:00 2001 From: Julien Schueller Date: Tue, 5 Jul 2016 22:05:37 +0200 Subject: [PATCH 21/29] Fix octave include --- cmake/FindOctave.cmake | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/cmake/FindOctave.cmake b/cmake/FindOctave.cmake index 021339db..2363f1c7 100644 --- a/cmake/FindOctave.cmake +++ b/cmake/FindOctave.cmake @@ -136,13 +136,14 @@ find_library(OCTAVE_CRUFT_LIBRARY ) set (OCTAVE_LIBRARIES ${OCTAVE_OCTINTERP_LIBRARY}) -list (APPEND OCTAVE_LIBRARIES ${OCTAVE_OCTAVE_LIBRARY}) -list (APPEND OCTAVE_LIBRARIES ${OCTAVE_CRUFT_LIBRARY}) +list (APPEND OCTAVE_LIBRARIES ${OCTAVE_OCTAVE_LIBRARY}) +if (OCTAVE_CRUFT_LIBRARY) + list (APPEND OCTAVE_LIBRARIES ${OCTAVE_CRUFT_LIBRARY}) +endif () find_path (OCTAVE_INCLUDE_DIR - NAMES mex.h - HINTS ${OCTAVE_INCLUDE_PATHS} - "${OCTAVE_INCLUDE_PATHS}/octave" + NAMES octave/oct.h + PATHS "${OCTAVE_INCLUDE_PATHS}/.." ) set (OCTAVE_INCLUDE_DIRS ${OCTAVE_INCLUDE_DIR}) From 6e7efd6a1ff2e162785cf1f6a6ad2590625523dd Mon Sep 17 00:00:00 2001 From: Julien Schueller Date: Tue, 5 Jul 2016 22:13:11 +0200 Subject: [PATCH 22/29] Find numpy includes --- CMakeLists.txt | 1 + cmake/FindNumPy.cmake | 100 ++++++++++++++++++++++++++++++++++++++++++ swig/CMakeLists.txt | 3 +- test/CMakeLists.txt | 2 +- 4 files changed, 104 insertions(+), 2 deletions(-) create mode 100644 cmake/FindNumPy.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 77166f5e..be0cf775 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -223,6 +223,7 @@ add_subdirectory (api) if (BUILD_PYTHON) find_package (PythonInterp) find_package (PythonLibs) + find_package (NumPy) endif () if (PYTHONINTERP_FOUND) diff --git a/cmake/FindNumPy.cmake b/cmake/FindNumPy.cmake new file mode 100644 index 00000000..58bb531f --- /dev/null +++ b/cmake/FindNumPy.cmake @@ -0,0 +1,100 @@ +# - Find the NumPy libraries +# This module finds if NumPy is installed, and sets the following variables +# indicating where it is. +# +# TODO: Update to provide the libraries and paths for linking npymath lib. +# +# NUMPY_FOUND - was NumPy found +# NUMPY_VERSION - the version of NumPy found as a string +# NUMPY_VERSION_MAJOR - the major version number of NumPy +# NUMPY_VERSION_MINOR - the minor version number of NumPy +# NUMPY_VERSION_PATCH - the patch version number of NumPy +# NUMPY_VERSION_DECIMAL - e.g. version 1.6.1 is 10601 +# NUMPY_INCLUDE_DIRS - path to the NumPy include files + +#============================================================================ +# Copyright 2012 Continuum Analytics, Inc. +# +# MIT License +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files +# (the "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to permit +# persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR +# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. +# +#============================================================================ + +# Finding NumPy involves calling the Python interpreter +if(NumPy_FIND_REQUIRED) + find_package(PythonInterp REQUIRED) +else() + find_package(PythonInterp) +endif() + +if(NOT PYTHONINTERP_FOUND) + set(NUMPY_FOUND FALSE) + return() +endif() + +execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c" + "import numpy as n; print(n.__version__); print(n.get_include());" + RESULT_VARIABLE _NUMPY_SEARCH_SUCCESS + OUTPUT_VARIABLE _NUMPY_VALUES_OUTPUT + ERROR_VARIABLE _NUMPY_ERROR_VALUE + OUTPUT_STRIP_TRAILING_WHITESPACE) + +if(NOT _NUMPY_SEARCH_SUCCESS MATCHES 0) + if(NumPy_FIND_REQUIRED) + message(FATAL_ERROR + "NumPy import failure:\n${_NUMPY_ERROR_VALUE}") + endif() + set(NUMPY_FOUND FALSE) + return() +endif() + +# Convert the process output into a list +string(REGEX REPLACE ";" "\\\\;" _NUMPY_VALUES ${_NUMPY_VALUES_OUTPUT}) +string(REGEX REPLACE "\n" ";" _NUMPY_VALUES ${_NUMPY_VALUES}) +list(GET _NUMPY_VALUES 0 NUMPY_VERSION) +list(GET _NUMPY_VALUES 1 NUMPY_INCLUDE_DIRS) + +string(REGEX MATCH "^[0-9]+\\.[0-9]+\\.[0-9]+" _VER_CHECK "${NUMPY_VERSION}") +if("${_VER_CHECK}" STREQUAL "") + # The output from Python was unexpected. Raise an error always + # here, because we found NumPy, but it appears to be corrupted somehow. + message(FATAL_ERROR + "Requested version and include path from NumPy, got instead:\n${_NUMPY_VALUES_OUTPUT}\n") + return() +endif() + +# Make sure all directory separators are '/' +string(REGEX REPLACE "\\\\" "/" NUMPY_INCLUDE_DIRS ${NUMPY_INCLUDE_DIRS}) + +# Get the major and minor version numbers +string(REGEX REPLACE "\\." ";" _NUMPY_VERSION_LIST ${NUMPY_VERSION}) +list(GET _NUMPY_VERSION_LIST 0 NUMPY_VERSION_MAJOR) +list(GET _NUMPY_VERSION_LIST 1 NUMPY_VERSION_MINOR) +list(GET _NUMPY_VERSION_LIST 2 NUMPY_VERSION_PATCH) +string(REGEX MATCH "[0-9]*" NUMPY_VERSION_PATCH ${NUMPY_VERSION_PATCH}) +math(EXPR NUMPY_VERSION_DECIMAL + "(${NUMPY_VERSION_MAJOR} * 10000) + (${NUMPY_VERSION_MINOR} * 100) + ${NUMPY_VERSION_PATCH}") + +find_package_message(NUMPY + "Found NumPy: version \"${NUMPY_VERSION}\" ${NUMPY_INCLUDE_DIRS}" + "${NUMPY_INCLUDE_DIRS}${NUMPY_VERSION}") + +set(NUMPY_FOUND TRUE) diff --git a/swig/CMakeLists.txt b/swig/CMakeLists.txt index 30dfc746..421aec4f 100644 --- a/swig/CMakeLists.txt +++ b/swig/CMakeLists.txt @@ -14,9 +14,10 @@ if (BUILD_OCTAVE) endif () endif () -if (PYTHONINTERP_FOUND AND PYTHONLIBS_FOUND AND (SWIG_FOUND OR (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/nlopt-python.cpp))) +if (NUMPY_FOUND AND PYTHONLIBS_FOUND AND (SWIG_FOUND OR (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/nlopt-python.cpp))) include_directories (${PYTHON_INCLUDE_DIRS}) + include_directories (${NUMPY_INCLUDE_DIRS}) if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/nlopt-python.cpp) set (SWIG_MODULE_nlopt_REAL_NAME _nlopt) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 553ac570..8067edb6 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -24,7 +24,7 @@ foreach (algo_index RANGE 29)# 42 endforeach () endforeach () -if (PYTHONINTERP_FOUND AND PYTHONLIBS_FOUND AND (SWIG_FOUND OR (EXISTS ${CMAKE_SOURCE_DIR}/swig/nlopt-python.cpp))) +if (NUMPY_FOUND AND PYTHONLIBS_FOUND AND (SWIG_FOUND OR (EXISTS ${CMAKE_SOURCE_DIR}/swig/nlopt-python.cpp))) set (PYINSTALLCHECK_ENVIRONMENT "LD_LIBRARY_PATH=${INSTALL_DESTDIR}${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}:$ENV{LD_LIBRARY_PATH}" "PYTHONPATH=${INSTALL_DESTDIR}${CMAKE_INSTALL_PREFIX}/${PYTHON_MODULE_PATH}${PATH_SEP}$ENV{PYTHONPATH}" ) From 9bcc6a4a64c2b55c7a5ea92207add0dc9760fd3c Mon Sep 17 00:00:00 2001 From: Julien Schueller Date: Tue, 5 Jul 2016 22:27:30 +0200 Subject: [PATCH 23/29] Detect SWIG at top-level --- CMakeLists.txt | 5 +++++ swig/CMakeLists.txt | 10 ---------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index be0cf775..8e62bf8f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,7 @@ option (BUILD_SHARED_LIBS "Build NLOPT as a shared library" OFF) option (BUILD_PYTHON "build python bindings" ON) option (BUILD_OCTAVE "build octave bindings" ON) option (BUILD_GUILE "build guile bindings" ON) +option (USE_SWIG "use SWIG to build bindings" ON) set (NLOPT_SUFFIX) if (WITH_CXX) @@ -242,6 +243,10 @@ if (BUILD_GUILE) find_package (Guile) endif () +if (USE_SWIG) + find_package (SWIG) +endif () + add_subdirectory (swig) if (BUILD_OCTAVE) diff --git a/swig/CMakeLists.txt b/swig/CMakeLists.txt index 421aec4f..8ff6c0d0 100644 --- a/swig/CMakeLists.txt +++ b/swig/CMakeLists.txt @@ -8,11 +8,6 @@ if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/nlopt-enum-renames.i) endforeach () endif () -if (BUILD_OCTAVE) - if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/nlopt-python.cpp) - find_package (SWIG) - endif () -endif () if (NUMPY_FOUND AND PYTHONLIBS_FOUND AND (SWIG_FOUND OR (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/nlopt-python.cpp))) @@ -42,11 +37,6 @@ if (NUMPY_FOUND AND PYTHONLIBS_FOUND AND (SWIG_FOUND OR (EXISTS ${CMAKE_CURRENT_ install ( TARGETS ${SWIG_MODULE_nlopt_REAL_NAME} LIBRARY DESTINATION ${PYTHON_MODULE_PATH} ) endif () -if (BUILD_GUILE) - if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/nlopt-guile.cpp) - find_package (SWIG) - endif () -endif () # guile bindings with gcc only ok with swig >= 2.0.10 if (GUILE_FOUND AND ((SWIG_FOUND AND SWIG_VERSION VERSION_GREATER 2.0.9) OR (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/nlopt-guile.cpp))) From d9de59085e30c2d601cd2e431e274d40e919f5ae Mon Sep 17 00:00:00 2001 From: Julien Schueller Date: Tue, 5 Jul 2016 22:37:29 +0200 Subject: [PATCH 24/29] cmake: RPATH policy --- CMakeLists.txt | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8e62bf8f..62a453a8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,13 @@ endif () project (nlopt C) +set (CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}) +set (CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) +if(POLICY CMP0042) + # Set MACOSX_RPATH to ON + cmake_policy(SET CMP0042 NEW) +endif() + list (APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) option (WITH_CXX "enable cxx routines" OFF) @@ -186,13 +193,8 @@ endif () if (BUILD_SHARED_LIBS) - ADD_DEFINITIONS(-DNLOPT_DLL) - ADD_DEFINITIONS(-DNLOPT_DLL_EXPORT ) - - if (NOT CMAKE_INSTALL_PREFIX MATCHES "^/usr") - set (CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}) - set (CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) - endif () + add_definitions (-DNLOPT_DLL) + add_definitions (-DNLOPT_DLL_EXPORT) endif () install (FILES ${NLOPT_HEADERS} DESTINATION include) From 901abca4e7c1af5598d7f2cb7d611c2fec7e7639 Mon Sep 17 00:00:00 2001 From: Julien Schueller Date: Wed, 6 Jul 2016 09:18:33 +0200 Subject: [PATCH 25/29] appveyor: shared build --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 8750e06a..573a6ae4 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -17,7 +17,7 @@ install: build_script: - echo Running cmake... - cd c:\projects\nlopt - - cmake -G "%CMAKE_PLATFORM%" -DCMAKE_INSTALL_PREFIX="C:\projects\nlopt\install" . + - cmake -G "%CMAKE_PLATFORM%" -DBUILD_SHARED_LIBS=ON -DWITH_CXX=ON -DCMAKE_INSTALL_PREFIX="C:\projects\nlopt\install" . - cmake --build . --config %Configuration% --target install - cmake --build . --config %Configuration% --target tests - ctest -C %Configuration% --output-on-failure --timeout 100 From 77cea184f1a898404bf21cbb6a525d1b196a51e1 Mon Sep 17 00:00:00 2001 From: Julien Schueller Date: Sat, 9 Jul 2016 11:01:00 +0200 Subject: [PATCH 26/29] Add cmake config files --- .gitignore | 1 + CMakeLists.txt | 76 ++++++++++++++++++++++++------- cmake/NLoptConfig.cmake.in | 26 +++++++++++ cmake/NLoptConfigVersion.cmake.in | 12 +++++ swig/CMakeLists.txt | 3 -- test/CMakeLists.txt | 2 +- 6 files changed, 100 insertions(+), 20 deletions(-) create mode 100644 cmake/NLoptConfig.cmake.in create mode 100644 cmake/NLoptConfigVersion.cmake.in diff --git a/.gitignore b/.gitignore index 4f6557bc..6175391f 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ *.mex* *.oct *.zip +build # generated code api/nlopt.f diff --git a/CMakeLists.txt b/CMakeLists.txt index 62a453a8..1cf877f9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,17 +20,10 @@ endif () project (nlopt C) -set (CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}) -set (CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) -if(POLICY CMP0042) - # Set MACOSX_RPATH to ON - cmake_policy(SET CMP0042 NEW) -endif() - list (APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) option (WITH_CXX "enable cxx routines" OFF) -option (BUILD_SHARED_LIBS "Build NLOPT as a shared library" OFF) +option (BUILD_SHARED_LIBS "Build NLOPT as a shared library" ON) option (BUILD_PYTHON "build python bindings" ON) option (BUILD_OCTAVE "build octave bindings" ON) option (BUILD_GUILE "build guile bindings" ON) @@ -45,6 +38,31 @@ if (WITH_CXX OR BUILD_PYTHON) enable_language (CXX) endif () + +# Offer the user the choice of overriding the installation directories +set (INSTALL_LIB_DIR lib${LIB_SUFFIX} CACHE PATH "Installation directory for libraries") +set (INSTALL_BIN_DIR bin CACHE PATH "Installation directory for executables") +set (INSTALL_INCLUDE_DIR include CACHE PATH "Installation directory for header files") +set (INSTALL_DATA_DIR share/nlopt CACHE PATH "Installation directory for data files") +set (INSTALL_CMAKE_DIR ${INSTALL_LIB_DIR}/cmake/nlopt CACHE PATH "Installation directory for cmake config files") + +# Make relative paths absolute (needed later on) +foreach(p LIB BIN INCLUDE DATA CMAKE) + set(var INSTALL_${p}_DIR) + set(RELATIVE_INSTALL_${p}_DIR ${INSTALL_${p}_DIR}) + if(NOT IS_ABSOLUTE "${${var}}") + set(${var} "${CMAKE_INSTALL_PREFIX}/${${var}}") + endif() +endforeach() + + +set (CMAKE_INSTALL_RPATH ${INSTALL_LIB_DIR}) +set (CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) +if(POLICY CMP0042) + # Set MACOSX_RPATH to ON + cmake_policy(SET CMP0042 NEW) +endif() + include (CheckIncludeFiles) include (CheckFunctionExists) include (CheckTypeSize) @@ -129,7 +147,7 @@ configure_file (${CMAKE_CURRENT_SOURCE_DIR}/config.cmake.h.in ${CMAKE_CURRENT_BI # pkgconfig file if (UNIX OR MINGW) configure_file (${CMAKE_CURRENT_SOURCE_DIR}/nlopt.pc.in ${CMAKE_CURRENT_BINARY_DIR}/nlopt.pc @ONLY) - install (FILES ${CMAKE_CURRENT_BINARY_DIR}/nlopt.pc DESTINATION lib/pkgconfig) + install (FILES ${CMAKE_CURRENT_BINARY_DIR}/nlopt.pc DESTINATION ${RELATIVE_INSTALL_LIB_DIR}/pkgconfig) endif () #============================================================================== @@ -201,10 +219,8 @@ install (FILES ${NLOPT_HEADERS} DESTINATION include) set (nlopt_lib nlopt${NLOPT_SUFFIX}) add_library (${nlopt_lib} ${NLOPT_SOURCES}) -set (LIB_SOVERSION 0) -set (LIB_VERSION 0.9.0) -set_target_properties (${nlopt_lib} PROPERTIES SOVERSION ${LIB_SOVERSION}) -set_target_properties (${nlopt_lib} PROPERTIES VERSION ${LIB_VERSION}) +set_target_properties (${nlopt_lib} PROPERTIES SOVERSION 0) +set_target_properties (${nlopt_lib} PROPERTIES VERSION 0.9.0) # pass -fPIC in case swig module is built with static library if (NOT BUILD_SHARED_LIBS) @@ -216,9 +232,10 @@ if (NOT BUILD_SHARED_LIBS) endif () install ( TARGETS ${nlopt_lib} - RUNTIME DESTINATION bin - LIBRARY DESTINATION lib${LIB_SUFFIX} - ARCHIVE DESTINATION lib${LIB_SUFFIX} + EXPORT NLoptLibraryDepends + RUNTIME DESTINATION ${RELATIVE_INSTALL_BIN_DIR} + LIBRARY DESTINATION ${RELATIVE_INSTALL_LIB_DIR} + ARCHIVE DESTINATION ${RELATIVE_INSTALL_LIB_DIR} ) add_subdirectory (api) @@ -277,3 +294,30 @@ set (CPACK_SOURCE_PACKAGE_FILE_NAME ${CPACK_PACKAGE_NAME}-${NLOPT_VERSION_STRING include (CPack) +# configuration files +export (TARGETS ${nlopt_lib} FILE ${PROJECT_BINARY_DIR}/NLoptLibraryDepends.cmake) + +# Install the export set for use with the install-tree +install(EXPORT NLoptLibraryDepends + DESTINATION ${RELATIVE_INSTALL_CMAKE_DIR} + COMPONENT Development) + +# Create a NLOPTConfig.cmake file for the use from the install tree +# and install it +set (NLOPT_LIBRARIES ${nlopt_lib}) + +set (NLOPT_CMAKE_DIR "${INSTALL_CMAKE_DIR}") +file (RELATIVE_PATH rel_include_dir "${NLOPT_CMAKE_DIR}" "${INSTALL_INCLUDE_DIR}") +list (APPEND RELATIVE_NLOPT_INCLUDE_DIRS ${rel_include_dir}) + +file (RELATIVE_PATH rel_lib_dir "${NLOPT_CMAKE_DIR}" "${INSTALL_LIB_DIR}") +list (APPEND RELATIVE_NLOPT_LIB_DIR ${rel_lib_dir}) + +configure_file (cmake/NLoptConfig.cmake.in NLoptConfig.cmake @ONLY) +configure_file (cmake/NLoptConfigVersion.cmake.in NLoptConfigVersion.cmake @ONLY) +install (FILES + ${CMAKE_CURRENT_BINARY_DIR}/NLoptConfig.cmake + ${CMAKE_CURRENT_BINARY_DIR}/NLoptConfigVersion.cmake + DESTINATION ${RELATIVE_INSTALL_CMAKE_DIR} + COMPONENT Development) + diff --git a/cmake/NLoptConfig.cmake.in b/cmake/NLoptConfig.cmake.in new file mode 100644 index 00000000..541808bb --- /dev/null +++ b/cmake/NLoptConfig.cmake.in @@ -0,0 +1,26 @@ + +# defined since 2.8.3 +if (CMAKE_VERSION VERSION_LESS 2.8.3) + get_filename_component (CMAKE_CURRENT_LIST_DIR ${CMAKE_CURRENT_LIST_FILE} PATH) +endif () + +# Tell the user project where to find our headers and libraries + +set (NLOPT_INCLUDE_DIRS "${CMAKE_CURRENT_LIST_DIR}/@RELATIVE_NLOPT_INCLUDE_DIRS@") +set (NLOPT_LIBRARY_DIRS "${CMAKE_CURRENT_LIST_DIR}/@RELATIVE_NLOPT_LIB_DIR@") + +# Allows loading NLOPT settings from another project +set (NLOPT_CONFIG_FILE "${CMAKE_CURRENT_LIST_FILE}") + +# List of compilation flags -DTOTO to export +set (NLOPT_DEFINITIONS "@NLOPT_DEFINITIONS@") + +# Our library dependencies (contains definitions for IMPORTED targets) +include ("${CMAKE_CURRENT_LIST_DIR}/NLoptLibraryDepends.cmake") + +# These are IMPORTED targets created by NLOPTLibraryDepends.cmake +set (NLOPT_LIBRARIES "@NLOPT_LIBRARIES@") + +if (CMAKE_VERSION VERSION_LESS 2.8.3) + set (CMAKE_CURRENT_LIST_DIR) +endif () diff --git a/cmake/NLoptConfigVersion.cmake.in b/cmake/NLoptConfigVersion.cmake.in new file mode 100644 index 00000000..ee4df4e1 --- /dev/null +++ b/cmake/NLoptConfigVersion.cmake.in @@ -0,0 +1,12 @@ + +set (PACKAGE_VERSION "@NLOPT_VERSION_STRING@") + +# Check whether the requested PACKAGE_FIND_VERSION is compatible +if ("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}") + set (PACKAGE_VERSION_COMPATIBLE FALSE) +else () + set (PACKAGE_VERSION_COMPATIBLE TRUE) + if ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}") + set (PACKAGE_VERSION_EXACT TRUE) + endif () +endif () diff --git a/swig/CMakeLists.txt b/swig/CMakeLists.txt index 8ff6c0d0..6eb98737 100644 --- a/swig/CMakeLists.txt +++ b/swig/CMakeLists.txt @@ -63,9 +63,6 @@ if (GUILE_FOUND AND ((SWIG_FOUND AND SWIG_VERSION VERSION_GREATER 2.0.9) OR (EXI target_link_libraries(${SWIG_MODULE_nlopt_guile_REAL_NAME} ${nlopt_lib}) target_link_libraries(${SWIG_MODULE_nlopt_guile_REAL_NAME} ${GUILE_LIBRARIES}) - set_target_properties (${SWIG_MODULE_nlopt_guile_REAL_NAME} PROPERTIES SOVERSION ${LIB_SOVERSION}) - set_target_properties (${SWIG_MODULE_nlopt_guile_REAL_NAME} PROPERTIES VERSION ${LIB_VERSION}) - file (RELATIVE_PATH _REL_GUILE_SITE_PATH ${GUILE_ROOT_DIR} ${GUILE_SITE_DIR}) set (GUILE_SITE_PATH ${_REL_GUILE_SITE_PATH}) install (FILES ${CMAKE_CURRENT_BINARY_DIR}/nlopt.scm DESTINATION ${GUILE_SITE_PATH}) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 8067edb6..4b5ae239 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -25,7 +25,7 @@ foreach (algo_index RANGE 29)# 42 endforeach () if (NUMPY_FOUND AND PYTHONLIBS_FOUND AND (SWIG_FOUND OR (EXISTS ${CMAKE_SOURCE_DIR}/swig/nlopt-python.cpp))) - set (PYINSTALLCHECK_ENVIRONMENT "LD_LIBRARY_PATH=${INSTALL_DESTDIR}${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}:$ENV{LD_LIBRARY_PATH}" + set (PYINSTALLCHECK_ENVIRONMENT "LD_LIBRARY_PATH=${INSTALL_DESTDIR}${INSTALL_LIB_DIR}:$ENV{LD_LIBRARY_PATH}" "PYTHONPATH=${INSTALL_DESTDIR}${CMAKE_INSTALL_PREFIX}/${PYTHON_MODULE_PATH}${PATH_SEP}$ENV{PYTHONPATH}" ) add_test (NAME test_std_python COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_std.py) From 547f3a3ea16a457fe4df278181f04e8c55d6539e Mon Sep 17 00:00:00 2001 From: Julien Schueller Date: Wed, 6 Jul 2016 09:20:17 +0200 Subject: [PATCH 27/29] travis: shared builds --- .travis.yml | 8 ++++---- appveyor.yml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1f334544..92021c4c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,13 +21,13 @@ matrix: - binutils-mingw-w64-x86-64 script: - mkdir build && pushd build - - cmake -DCMAKE_INSTALL_PREFIX=~/.local -DBUILD_SHARED_LIBS=ON -DWITH_CXX=ON .. + - cmake -DCMAKE_INSTALL_PREFIX=~/.local -DWITH_CXX=ON .. - make install -j2 && make tests -j2 && ctest -j2 --output-on-failure - rm -rf * ~/.local - - cmake -DCMAKE_INSTALL_PREFIX=~/.local -DBUILD_SHARED_LIBS=ON -DWITH_CXX=ON -DBUILD_PYTHON=OFF -DBUILD_OCTAVE=OFF -DBUILD_GUILE=OFF -DCMAKE_TOOLCHAIN_FILE=$PWD/../cmake/toolchain-i686-w64-mingw32.cmake .. + - cmake -DCMAKE_INSTALL_PREFIX=~/.local -DWITH_CXX=ON -DBUILD_PYTHON=OFF -DBUILD_OCTAVE=OFF -DBUILD_GUILE=OFF -DCMAKE_TOOLCHAIN_FILE=$PWD/../cmake/toolchain-i686-w64-mingw32.cmake .. - make install -j2 && make tests -j2 - rm -rf * ~/.local - - cmake -DCMAKE_INSTALL_PREFIX=~/.local -DBUILD_SHARED_LIBS=ON -DWITH_CXX=ON -DBUILD_PYTHON=OFF -DBUILD_OCTAVE=OFF -DBUILD_GUILE=OFF -DCMAKE_TOOLCHAIN_FILE=$PWD/../cmake/toolchain-x86_64-w64-mingw32.cmake .. + - cmake -DCMAKE_INSTALL_PREFIX=~/.local -DWITH_CXX=ON -DBUILD_PYTHON=OFF -DBUILD_OCTAVE=OFF -DBUILD_GUILE=OFF -DCMAKE_TOOLCHAIN_FILE=$PWD/../cmake/toolchain-x86_64-w64-mingw32.cmake .. - make install -j2 && make tests -j2 - os: osx @@ -36,5 +36,5 @@ matrix: - brew install swig python script: - mkdir build && pushd build - - cmake -DCMAKE_INSTALL_PREFIX=~/.local -DBUILD_SHARED_LIBS=ON -DWITH_CXX=ON .. + - cmake -DCMAKE_INSTALL_PREFIX=~/.local -DWITH_CXX=ON .. - make install && make tests && ctest --output-on-failure \ No newline at end of file diff --git a/appveyor.yml b/appveyor.yml index 573a6ae4..c2ee486c 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -17,7 +17,7 @@ install: build_script: - echo Running cmake... - cd c:\projects\nlopt - - cmake -G "%CMAKE_PLATFORM%" -DBUILD_SHARED_LIBS=ON -DWITH_CXX=ON -DCMAKE_INSTALL_PREFIX="C:\projects\nlopt\install" . + - cmake -G "%CMAKE_PLATFORM%" -DWITH_CXX=ON -DCMAKE_INSTALL_PREFIX="C:\projects\nlopt\install" . - cmake --build . --config %Configuration% --target install - cmake --build . --config %Configuration% --target tests - ctest -C %Configuration% --output-on-failure --timeout 100 From a9da8829fc9e7b520deee8c7757aa04ab0e78bbe Mon Sep 17 00:00:00 2001 From: Julien Schueller Date: Wed, 6 Jul 2016 09:39:27 +0200 Subject: [PATCH 28/29] appveyor: no shared builds --- appveyor.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index c2ee486c..6c378f47 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -11,13 +11,13 @@ environment: matrix: - CMAKE_PLATFORM: "Visual Studio 14 2015" - CMAKE_PLATFORM: "Visual Studio 14 2015 Win64" -install: - - cinstall: python - - choco install swig +#install: + #- cinstall: python + #- choco install swig build_script: - echo Running cmake... - cd c:\projects\nlopt - - cmake -G "%CMAKE_PLATFORM%" -DWITH_CXX=ON -DCMAKE_INSTALL_PREFIX="C:\projects\nlopt\install" . + - cmake -G "%CMAKE_PLATFORM%" -DBUILD_SHARED_LIBS=OFF -DWITH_CXX=ON -DCMAKE_INSTALL_PREFIX="C:\projects\nlopt\install" . - cmake --build . --config %Configuration% --target install - cmake --build . --config %Configuration% --target tests - ctest -C %Configuration% --output-on-failure --timeout 100 From 5b02e52885dfe7d1a49110091497955f22a9d19a Mon Sep 17 00:00:00 2001 From: Julien Schueller Date: Wed, 6 Jul 2016 10:34:38 +0200 Subject: [PATCH 29/29] BUILD-MINGWXX.sh are superseeded by toolchain files --- BUILD-MINGW32.sh | 85 ------------------------------------------------ BUILD-MINGW64.sh | 85 ------------------------------------------------ 2 files changed, 170 deletions(-) delete mode 100755 BUILD-MINGW32.sh delete mode 100755 BUILD-MINGW64.sh diff --git a/BUILD-MINGW32.sh b/BUILD-MINGW32.sh deleted file mode 100755 index b5ce3682..00000000 --- a/BUILD-MINGW32.sh +++ /dev/null @@ -1,85 +0,0 @@ -#!/bin/sh -set -ev - -rm -rf mingw32 -make distclean || true - -echo "COMPILING..." - -./configure --prefix=`pwd`/mingw32 --host=i686-w64-mingw32 --enable-shared --disable-static --without-matlab --without-octave --without-python --without-guile --without-threadlocal && make -j4 && make install - -echo "POST-PROCESSING..." - -cd mingw32/bin -for dll in *.dll; do - def=`basename $dll .dll`.def - echo "LIBRARY $dll" > $def - echo EXPORTS >> $def - i686-w64-mingw32-nm $dll | grep ' T _' | sed 's/.* T _//' | egrep 'nlopt|nlo_' >> $def -done -cd ../.. - -perl -pi -e 's,^ * #define NLOPT_DLL,*/\n#define NLOPT_DLL\n/*,' mingw32/include/nlopt.h - -cat > README-WINDOWS <> README-WINDOWS - -# grep -v "nlopt-util.h" octave/nlopt_minimize_constrained-mex.c > mingw32/nlopt_minimize_constrained.c - -nlopt_vers=`grep PACKAGE_VERSION config.h |cut -d" " -f3 |tr -d \"` - -mkdir mingw32/matlab -cd octave -cp `grep 'MFILES =' Makefile.am | cut -d= -f2` ../mingw32/matlab -cp `grep 'm_DATA =' Makefile.am | cut -d\) -f2` ../mingw32/matlab -cp nlopt_optimize-mex.c ../mingw32/matlab/nlopt_optimize.c -cd .. - -mkdir mingw32/python -cp swig/nlopt.py swig/nlopt-python.cpp mingw32/python -cat > mingw32/python/setup.py < $def - echo EXPORTS >> $def - x86_64-w64-mingw32-nm $dll | grep ' T ' | sed 's/.* T //' | egrep 'nlopt|nlo_' >> $def -done -cd ../.. - -perl -pi -e 's,^ * #define NLOPT_DLL,*/\n#define NLOPT_DLL\n/*,' mingw64/include/nlopt.h - -cat > README-WINDOWS <> README-WINDOWS - -# grep -v "nlopt-util.h" octave/nlopt_minimize_constrained-mex.c > mingw64/nlopt_minimize_constrained.c - -nlopt_vers=`grep PACKAGE_VERSION config.h |cut -d" " -f3 |tr -d \"` - -mkdir mingw64/matlab -cd octave -cp `grep 'MFILES =' Makefile.am | cut -d= -f2` ../mingw64/matlab -cp `grep 'm_DATA =' Makefile.am | cut -d\) -f2` ../mingw64/matlab -cp nlopt_optimize-mex.c ../mingw64/matlab/nlopt_optimize.c -cd .. - -mkdir mingw64/python -cp swig/nlopt.py swig/nlopt-python.cpp mingw64/python -cat > mingw64/python/setup.py <