X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=CMakeLists.txt;h=dba2f688c436b427f3695a7ed457f31194d62840;hb=743775baaa9b9374834a7aa886087d0e156c30b7;hp=d67675ca5c76dfd4d332c2f6f63fe71d65895f2b;hpb=0573e4bdb36392b9aa1443d5801eba6f836c5cbd;p=nlopt.git diff --git a/CMakeLists.txt b/CMakeLists.txt index d67675c..dba2f68 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,7 @@ # Benoit Scherrer, 2010 CRL, Harvard Medical School # Copyright (c) 2008-2009 Children's Hospital Boston #============================================================================== -cmake_minimum_required (VERSION 3.0) +cmake_minimum_required (VERSION 2.8.11) if (NOT DEFINED CMAKE_BUILD_TYPE) set (CMAKE_BUILD_TYPE Release CACHE STRING "Build type") @@ -20,9 +20,25 @@ endif () project (nlopt) +#============================================================================== +# version +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}") + +# This is the ABI version number, which differes from the API version above +# (it indicates ABI compatibility), but they are typically incremented together. +set(SO_MAJOR 0) +set(SO_MINOR 9) +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 (NLOPT_FORTRAN "enable fortran tests" OFF) 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) @@ -30,9 +46,14 @@ option (NLOPT_MATLAB "build matlab bindings" ON) option (NLOPT_GUILE "build guile bindings" ON) option (NLOPT_SWIG "use SWIG to build bindings" ON) -set (NLOPT_SUFFIX) -if (NLOPT_CXX) - set (NLOPT_SUFFIX _cxx) +if (CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) + option (NLOPT_TESTS "build unit tests" ON) +else () + option (NLOPT_TESTS "build unit tests" OFF) +endif () + +if (NLOPT_FORTRAN) + enable_language (Fortran) endif () include (GNUInstallDirs) @@ -61,6 +82,10 @@ if(POLICY CMP0042) # Set MACOSX_RPATH to ON cmake_policy(SET CMP0042 NEW) endif() +if (POLICY CMP0086) + # UseSWIG honors SWIG_MODULE_NAME via -module flag + cmake_policy(SET CMP0086 NEW) +endif () include (CheckIncludeFiles) include (CheckFunctionExists) @@ -121,7 +146,7 @@ if (NOT DEFINED HAVE_FPCLASSIFY) endif () option (WITH_THREADLOCAL "check thread local keyword" ON) -if (WITH_THREADLOCAL AND NOT DEFINED HAVE_THREAD_LOCAL_STORAGE) +if (WITH_THREADLOCAL AND NOT DEFINED THREADLOCAL) foreach (_THREADLOCAL_KEY "__thread" "__declspec(thread)") unset (HAVE_THREAD_LOCAL_STORAGE CACHE) check_c_source_compiles(" @@ -130,31 +155,28 @@ if (WITH_THREADLOCAL AND NOT DEFINED HAVE_THREAD_LOCAL_STORAGE) int main(void) { return 0; }" HAVE_THREAD_LOCAL_STORAGE) - if (${HAVE_THREAD_LOCAL_STORAGE}) - set (THREADLOCAL ${_THREADLOCAL_KEY}) + if (HAVE_THREAD_LOCAL_STORAGE) + set (THREADLOCAL ${_THREADLOCAL_KEY} CACHE STRING "Thread local keyword") endif () endforeach() endif () + if (NLOPT_CXX OR NLOPT_PYTHON OR NLOPT_GUILE OR NLOPT_OCTAVE) - check_cxx_symbol_exists (_LIBCPP_VERSION string SYSTEM_HAS_LIBCPP) - if (SYSTEM_HAS_LIBCPP) + check_cxx_symbol_exists (__cplusplus ciso646 SYSTEM_HAS_CXX) + if (SYSTEM_HAS_CXX) check_cxx_compiler_flag ("-std=c++11" SUPPORTS_STDCXX11) if (SUPPORTS_STDCXX11) set (CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}") + if (NLOPT_CXX) + set (NLOPT_CXX11 ON) + endif () endif () + else() + message (FATAL_ERROR "The compiler doesn't support CXX.") endif () endif () -#============================================================================== -# version -#============================================================================== -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 nlopt_config.h #============================================================================== @@ -198,17 +220,22 @@ set (NLOPT_SOURCES ) if (NLOPT_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) + list (APPEND NLOPT_SOURCES src/algs/stogo/global.cc src/algs/stogo/linalg.cc src/algs/stogo/local.cc src/algs/stogo/stogo.cc src/algs/stogo/tools.cc + src/algs/stogo/global.h src/algs/stogo/linalg.h src/algs/stogo/local.h src/algs/stogo/stogo_config.h src/algs/stogo/stogo.h src/algs/stogo/tools.h) +endif () +if (NLOPT_CXX11) + list (APPEND NLOPT_SOURCES src/algs/ags/data_types.hpp src/algs/ags/evolvent.hpp src/algs/ags/evolvent.cc src/algs/ags/solver.hpp src/algs/ags/solver.cc + src/algs/ags/local_optimizer.hpp src/algs/ags/local_optimizer.cc src/algs/ags/ags.h src/algs/ags/ags.cc) 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}) -set_target_properties (${nlopt_lib} PROPERTIES SOVERSION 0) -set_target_properties (${nlopt_lib} PROPERTIES VERSION 0.9.0) +set_target_properties (${nlopt_lib} PROPERTIES SOVERSION ${SO_MAJOR}) +set_target_properties (${nlopt_lib} PROPERTIES VERSION "${SO_MAJOR}.${SO_MINOR}.${SO_PATCH}") #============================================================================== # INCLUDE DIRECTORIES @@ -217,6 +244,7 @@ target_include_directories (${nlopt_lib} PRIVATE ${PROJECT_BINARY_DIR}/src/api ${PROJECT_BINARY_DIR} src/algs/stogo + src/algs/ags src/util src/algs/direct src/algs/cdirect @@ -239,8 +267,8 @@ get_target_property (NLOPT_PRIVATE_INCLUDE_DIRS ${nlopt_lib} INCLUDE_DIRECTORIES target_include_directories (${nlopt_lib} INTERFACE "$" "$/${CMAKE_INSTALL_INCLUDEDIR}>") if (BUILD_SHARED_LIBS) - target_compile_definitions (${nlopt_lib} PUBLIC -DNLOPT_DLL) - target_compile_definitions (${nlopt_lib} PRIVATE -DNLOPT_DLL_EXPORT) + target_compile_definitions (${nlopt_lib} PUBLIC NLOPT_DLL) + target_compile_definitions (${nlopt_lib} PRIVATE NLOPT_DLL_EXPORT) endif () # pass -fPIC in case swig module is built with static library @@ -289,10 +317,11 @@ endif () if (NLOPT_SWIG) find_package (SWIG) + if (SWIG_FOUND) + add_subdirectory (src/swig) + endif () endif () -add_subdirectory (src/swig) - if (NLOPT_OCTAVE) find_package (Octave) endif () @@ -305,18 +334,20 @@ if (OCTAVE_FOUND OR Matlab_FOUND) add_subdirectory (src/octave) endif () -enable_testing () -add_subdirectory (test) +if (NLOPT_TESTS) + enable_testing () + add_subdirectory (test) +endif () 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_BINARY_STGZ OFF CACHE BOOL "STGZ") +set (CPACK_BINARY_TBZ2 ON CACHE BOOL "TBZ2") +set (CPACK_BINARY_TGZ ON CACHE BOOL "TGZ") +set (CPACK_BINARY_TZ OFF CACHE BOOL "TZ") set (CPACK_SOURCE_IGNORE_FILES ".git;/build;.*~;${CPACK_SOURCE_IGNORE_FILES}") set (CPACK_SOURCE_PACKAGE_FILE_NAME ${CPACK_PACKAGE_NAME}-${NLOPT_VERSION_STRING})