chiark / gitweb /
Merge pull request #108 from jdumas/master
authorJulien Schueller <schueller@phimeca.com>
Sat, 5 Aug 2017 06:47:03 +0000 (08:47 +0200)
committerGitHub <noreply@github.com>
Sat, 5 Aug 2017 06:47:03 +0000 (08:47 +0200)
Prefer target_include_directories in CMake build script

.travis.yml
CMakeLists.txt
swig/CMakeLists.txt
test/CMakeLists.txt

index 1228f1ea017ccc23ffdf80353eda3b4880e843c1..a7efc2a8088611abb88929023653c6505b5f9026 100644 (file)
@@ -6,6 +6,8 @@ matrix:
     - os: linux
       addons:
         apt:
+          sources:
+          - george-edison55-precise-backports
           packages:
           - swig
           - python-dev
@@ -13,6 +15,7 @@ matrix:
           - guile-2.0-dev
           - octave3.2-headers
           - cmake
+          - cmake-data
           - g++-mingw-w64-i686
           - gcc-mingw-w64-i686
           - binutils-mingw-w64-i686
index 97a152fa857b0bd134aa66816e76bfee356ca3de..4996bb3de0bc917848b6647a5351b86460dad4be 100644 (file)
@@ -1,18 +1,18 @@
 #==============================================================================\r
 # NLOPT CMake file\r
-# \r
-# NLopt is a free/open-source library for nonlinear optimization, providing \r
-# a common interface for a number of different free optimization routines \r
-# available online as well as original implementations of various other \r
+#\r
+# NLopt is a free/open-source library for nonlinear optimization, providing\r
+# a common interface for a number of different free optimization routines\r
+# available online as well as original implementations of various other\r
 # algorithms\r
-# WEBSITE: http://ab-initio.mit.edu/wiki/index.php/NLopt \r
+# WEBSITE: http://ab-initio.mit.edu/wiki/index.php/NLopt\r
 # AUTHOR: Steven G. Johnson\r
 #\r
 # This CMakeLists.txt file was created to compile NLOPT with the CMAKE utility.\r
 # Benoit Scherrer, 2010 CRL, Harvard Medical School\r
-# Copyright (c) 2008-2009 Children's Hospital Boston \r
+# Copyright (c) 2008-2009 Children's Hospital Boston\r
 #==============================================================================\r
-cmake_minimum_required (VERSION 2.8.5)\r
+cmake_minimum_required (VERSION 3.0)\r
 \r
 if (NOT DEFINED CMAKE_BUILD_TYPE)\r
   set (CMAKE_BUILD_TYPE Release CACHE STRING "Build type")\r
@@ -167,42 +167,17 @@ if (UNIX OR MINGW)
   install (FILES ${CMAKE_CURRENT_BINARY_DIR}/nlopt.pc DESTINATION ${RELATIVE_INSTALL_LIB_DIR}/pkgconfig)\r
 endif ()\r
 \r
-#==============================================================================\r
-# INCLUDE DIRECTORIES\r
-#==============================================================================\r
-set (${INCLUDE_DIRECTORIES} "")\r
-include_directories (\r
-  ${PROJECT_BINARY_DIR}/api\r
-  ${PROJECT_BINARY_DIR}\r
-  stogo\r
-  util\r
-  direct\r
-  cdirect\r
-  praxis\r
-  luksan\r
-  crs\r
-  mlsl\r
-  mma\r
-  cobyla\r
-  newuoa\r
-  neldermead\r
-  auglag\r
-  bobyqa\r
-  isres\r
-  slsqp\r
-  esch\r
-  api)\r
-\r
-\r
 #==============================================================================\r
 # nlopt LIBRARY TARGET (SHARED OR STATIC)\r
 #==============================================================================\r
 \r
-set (NLOPT_HEADERS \r
-  api/nlopt.h ${PROJECT_BINARY_DIR}/api/nlopt.hpp ${PROJECT_BINARY_DIR}/api/nlopt.f\r
+configure_file (api/nlopt.h ${PROJECT_BINARY_DIR}/api/nlopt.h COPYONLY)\r
+\r
+set (NLOPT_HEADERS\r
+  ${PROJECT_BINARY_DIR}/api/nlopt.h ${PROJECT_BINARY_DIR}/api/nlopt.hpp ${PROJECT_BINARY_DIR}/api/nlopt.f\r
 )\r
 \r
-set (NLOPT_SOURCES   \r
+set (NLOPT_SOURCES\r
   direct/DIRect.c direct/direct_wrap.c direct/DIRserial.c direct/DIRsubrout.c direct/direct-internal.h direct/direct.h\r
   cdirect/cdirect.c cdirect/hybrid.c cdirect/cdirect.h\r
   praxis/praxis.c praxis/praxis.h\r
@@ -212,7 +187,7 @@ set (NLOPT_SOURCES
   mma/mma.c mma/mma.h mma/ccsa_quadratic.c\r
   cobyla/cobyla.c cobyla/cobyla.h\r
   newuoa/newuoa.c newuoa/newuoa.h\r
-  neldermead/nldrmd.c neldermead/neldermead.h neldermead/sbplx.c \r
+  neldermead/nldrmd.c neldermead/neldermead.h neldermead/sbplx.c\r
   auglag/auglag.c auglag/auglag.h\r
   bobyqa/bobyqa.c bobyqa/bobyqa.h\r
   isres/isres.c isres/isres.h\r
@@ -226,12 +201,6 @@ 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)\r
 endif ()\r
 \r
-\r
-if (BUILD_SHARED_LIBS)\r
-  add_definitions (-DNLOPT_DLL)\r
-  add_definitions (-DNLOPT_DLL_EXPORT)\r
-endif ()\r
-\r
 install (FILES ${NLOPT_HEADERS} DESTINATION ${INSTALL_INCLUDE_DIR})\r
 \r
 set (nlopt_lib nlopt${NLOPT_SUFFIX})\r
@@ -241,6 +210,39 @@ target_link_libraries (${nlopt_lib} ${M_LIBRARY})
 set_target_properties (${nlopt_lib} PROPERTIES SOVERSION 0)\r
 set_target_properties (${nlopt_lib} PROPERTIES VERSION 0.9.0)\r
 \r
+#==============================================================================\r
+# INCLUDE DIRECTORIES\r
+#==============================================================================\r
+target_include_directories (${nlopt_lib} PRIVATE\r
+  ${PROJECT_BINARY_DIR}/api\r
+  ${PROJECT_BINARY_DIR}\r
+  stogo\r
+  util\r
+  direct\r
+  cdirect\r
+  praxis\r
+  luksan\r
+  crs\r
+  mlsl\r
+  mma\r
+  cobyla\r
+  newuoa\r
+  neldermead\r
+  auglag\r
+  bobyqa\r
+  isres\r
+  slsqp\r
+  esch\r
+  api)\r
+\r
+get_target_property (NLOPT_PRIVATE_INCLUDE_DIRS ${nlopt_lib} INCLUDE_DIRECTORIES)\r
+target_include_directories (${nlopt_lib} INTERFACE "$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/api>")\r
+\r
+if (BUILD_SHARED_LIBS)\r
+  target_compile_definitions (${nlopt_lib} INTERFACE -DNLOPT_DLL)\r
+  target_compile_definitions (${nlopt_lib} INTERFACE -DNLOPT_DLL_EXPORT)\r
+endif ()\r
+\r
 # pass -fPIC in case swig module is built with static library\r
 if (NOT BUILD_SHARED_LIBS)\r
   check_c_compiler_flag (-fPIC HAS_FPIC)\r
index d51ea0362d5e3016bfbe1c23688c6e58306b80e0..71c6f78e350440875b6fcc98255378042e7a2a33 100644 (file)
@@ -28,9 +28,11 @@ if (NUMPY_FOUND AND PYTHONLIBS_FOUND AND (SWIG_FOUND OR (EXISTS ${CMAKE_CURRENT_
     set_source_files_properties (nlopt.i PROPERTIES CPLUSPLUS ON)
     set (SWIG_MODULE_nlopt_EXTRA_DEPS nlopt-python.i numpy.i)
 
+    include_directories (${NLOPT_PRIVATE_INCLUDE_DIRS})
     swig_add_module (nlopt python nlopt.i)
     swig_link_libraries (nlopt ${nlopt_lib})
     swig_link_libraries (nlopt ${PYTHON_LIBRARIES})
+    target_include_directories (${SWIG_MODULE_nlopt_REAL_NAME} PRIVATE ${NLOPT_PRIVATE_INCLUDE_DIRS})
   endif ()
 
   install (FILES ${CMAKE_CURRENT_BINARY_DIR}/nlopt.py DESTINATION ${INSTALL_PYTHON_DIR})
index c1990fddecfd5e57027916542e02545d1705ba08..e17d12763db6dc3a14ba49f0f8f603596681e9da 100644 (file)
@@ -3,6 +3,7 @@ add_custom_target (tests)
 # have to add timer.c and mt19937ar.c as symbols are declared extern
 add_executable (testopt testfuncs.c testfuncs.h testopt.cpp ${PROJECT_SOURCE_DIR}/util/timer.c ${PROJECT_SOURCE_DIR}/util/mt19937ar.c)
 target_link_libraries (testopt ${nlopt_lib})
+target_include_directories (testopt PRIVATE ${NLOPT_PRIVATE_INCLUDE_DIRS})
 add_dependencies (tests testopt)
 
 foreach (algo_index RANGE 29)# 42
@@ -46,4 +47,4 @@ if (GUILE_FOUND AND ((SWIG_FOUND AND SWIG_VERSION VERSION_GREATER 2.0.9) OR (EXI
     )
   add_test (NAME test_guile COMMAND ${GUILE_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/t_guile.scm)
   set_tests_properties (test_guile PROPERTIES ENVIRONMENT "${GUILECHECK_ENVIRONMENT}")
-endif ()
\ No newline at end of file
+endif ()