From 8da50d516fe0a0da42c06b66329b02cf6e44236e Mon Sep 17 00:00:00 2001 From: Julien Schueller Date: Mon, 30 Jul 2018 16:11:41 +0200 Subject: [PATCH 1/1] Enable CXX by default (#198) * Enable CXX by default It's silly not to provide all algorithms by default, c++ compiler are easy to find these days, worst case it can still be disabled Also remove lib suffix * Update doc --- .travis.yml | 8 ++++---- CMakeLists.txt | 9 ++------- appveyor.yml | 2 +- doc/docs/NLopt_Installation.md | 9 ++++----- nlopt.pc.in | 2 +- 5 files changed, 12 insertions(+), 18 deletions(-) diff --git a/.travis.yml b/.travis.yml index 221d3de..55c7f6a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,13 +23,13 @@ matrix: - pip install mkdocs python-markdown-math --user - PATH=$PATH:~/.local/bin mkdocs build - mkdir build && pushd build - - cmake -DCMAKE_INSTALL_PREFIX=~/.local -DNLOPT_CXX=ON -DNLOPT_GUILE=OFF -DNLOPT_MATLAB=OFF .. + - cmake -DCMAKE_INSTALL_PREFIX=~/.local -DNLOPT_GUILE=OFF -DNLOPT_MATLAB=OFF .. - make install -j2 && ctest -j2 --output-on-failure - rm -rf * ~/.local - - cmake -DCMAKE_INSTALL_PREFIX=~/.local -DNLOPT_CXX=ON -DNLOPT_PYTHON=OFF -DNLOPT_OCTAVE=OFF -DNLOPT_GUILE=OFF -DNLOPT_MATLAB=OFF -DCMAKE_TOOLCHAIN_FILE=$PWD/../cmake/toolchain-i686-w64-mingw32.cmake .. + - cmake -DCMAKE_INSTALL_PREFIX=~/.local -DNLOPT_PYTHON=OFF -DNLOPT_OCTAVE=OFF -DNLOPT_GUILE=OFF -DNLOPT_MATLAB=OFF -DCMAKE_TOOLCHAIN_FILE=$PWD/../cmake/toolchain-i686-w64-mingw32.cmake .. - make install -j2 - rm -rf * ~/.local - - cmake -DCMAKE_INSTALL_PREFIX=~/.local -DNLOPT_CXX=ON -DNLOPT_PYTHON=OFF -DNLOPT_OCTAVE=OFF -DNLOPT_GUILE=OFF -DNLOPT_MATLAB=OFF -DCMAKE_TOOLCHAIN_FILE=$PWD/../cmake/toolchain-x86_64-w64-mingw32.cmake .. + - cmake -DCMAKE_INSTALL_PREFIX=~/.local -DNLOPT_PYTHON=OFF -DNLOPT_OCTAVE=OFF -DNLOPT_GUILE=OFF -DNLOPT_MATLAB=OFF -DCMAKE_TOOLCHAIN_FILE=$PWD/../cmake/toolchain-x86_64-w64-mingw32.cmake .. - make install -j2 - os: osx @@ -39,5 +39,5 @@ matrix: - brew install swig octave || echo "nope" script: - mkdir build && pushd build - - cmake -DCMAKE_INSTALL_PREFIX=~/.local -DNLOPT_CXX=ON -DPYTHON_EXECUTABLE=/usr/bin/python .. + - cmake -DCMAKE_INSTALL_PREFIX=~/.local -DPYTHON_EXECUTABLE=/usr/bin/python .. - make install && ctest --output-on-failure diff --git a/CMakeLists.txt b/CMakeLists.txt index d9fb57b..f34bd5d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,7 +37,7 @@ set(SO_PATCH 0) list (APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) -option (NLOPT_CXX "enable cxx routines" OFF) +option (NLOPT_CXX "enable cxx routines" ON) option (BUILD_SHARED_LIBS "Build NLopt as a shared library" ON) option (NLOPT_PYTHON "build python bindings" ON) option (NLOPT_OCTAVE "build octave bindings" ON) @@ -52,11 +52,6 @@ else () option (NLOPT_TESTS "build unit tests" OFF) endif () -set (NLOPT_SUFFIX) -if (NLOPT_CXX) - set (NLOPT_SUFFIX _cxx) -endif () - include (GNUInstallDirs) # Offer the user the choice of overriding the installation directories @@ -226,7 +221,7 @@ endif () install (FILES ${NLOPT_HEADERS} DESTINATION ${RELATIVE_INSTALL_INCLUDE_DIR}) -set (nlopt_lib nlopt${NLOPT_SUFFIX}) +set (nlopt_lib nlopt) add_library (${nlopt_lib} ${NLOPT_SOURCES}) target_link_libraries (${nlopt_lib} ${M_LIBRARY}) diff --git a/appveyor.yml b/appveyor.yml index 4a09c82..3fa6aba 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -17,6 +17,6 @@ install: build_script: - echo Running cmake... - cd c:\projects\nlopt - - cmake -G "%CMAKE_PLATFORM%" -DNLOPT_CXX=ON -DCMAKE_INSTALL_PREFIX="C:\projects\nlopt\install" . + - cmake -G "%CMAKE_PLATFORM%" -DCMAKE_INSTALL_PREFIX="C:\projects\nlopt\install" . - cmake --build . --config %Configuration% --target install - ctest -C %Configuration% --output-on-failure --timeout 100 diff --git a/doc/docs/NLopt_Installation.md b/doc/docs/NLopt_Installation.md index 61c455b..ab68b3e 100644 --- a/doc/docs/NLopt_Installation.md +++ b/doc/docs/NLopt_Installation.md @@ -142,14 +142,13 @@ Note, however, that if you do this then Guile may not know where to load the `nl NLopt with C++ algorithms ------------------------- -NLopt, as-is, is callable from C, C++, and Fortran, with optional Matlab and GNU Octave plugins (and even installs an `nlopt.hpp` C++ header file to allow you to call it in a more C++ style). By default, it includes only subroutines written in C (or written in Fortran and converted to C), to simplify linking. If you configure with: +NLopt, as-is, is callable from C, C++, and Fortran, with optional Matlab and GNU Octave plugins (and even installs an `nlopt.hpp` C++ header file to allow you to call it in a more C++ style). By default, it includes subroutines written in C (or written in Fortran and converted to C) and C++. If you configure with: ```sh -cmake -DNLOPT_CXX=ON .. +cmake -DNLOPT_CXX=OFF .. ``` -however, it will also include algorithms implemented in C++ (currently, just the StoGO algorithm), and the resulting library will be called `libnlopt_cxx` and is linked with `-lnlopt_cxx`. +however, it will disable algorithms implemented in C++ (StoGO and AGS algorithms). -The `libnlopt_cxx` has the *same* interface as the ordinary NLopt library, and can *still* be called from ordinary C and Fortran programs. However, to use it you must also *link* with the C++ standard libraries. The easiest way to do this is to link with the C++ linker: compile your source files into `.o` object files, and then call the C++ compiler to link these `.o` files with `-lnlopt_cxx` into your executable program. +The resulting library has the *same* interface as the ordinary NLopt library, and can *still* be called from ordinary C, C++, and Fortran programs. However, one no longer has to link with the C++ standard libraries, which can sometimes be convenient for non-C++ programs, and allows libnlopt to be compatible with multiple C++ compilers simultaneously. -It is because this linking process is somewhat annoying, and it only adds a single more algorithm (StoGO) to NLopt, that by default we omit StoGO to create a library that does not require the C++ standard libraries to link. diff --git a/nlopt.pc.in b/nlopt.pc.in index 81616df..8d46f07 100644 --- a/nlopt.pc.in +++ b/nlopt.pc.in @@ -6,6 +6,6 @@ includedir=${prefix}/include Name: NLopt Description: nonlinear optimization libary Version: @NLOPT_VERSION_STRING@ -Libs: -L${libdir} -lnlopt@NLOPT_SUFFIX@ +Libs: -L${libdir} -lnlopt Libs.private: -lm Cflags: -I${includedir} -- 2.30.2