Source

BayesOpt / CMakeLists.txt

Diff from to

CMakeLists.txt

+# -------------------------------------------------------------------------
+#    This file is part of BayesOpt, an efficient C++ library for 
+#    Bayesian optimization.
+#
+#    Copyright (C) 2011-2013 Ruben Martinez-Cantin <rmcantin@unizar.es>
+# 
+#    BayesOpt is free software: you can redistribute it and/or modify it 
+#    under the terms of the GNU General Public License as published by
+#    the Free Software Foundation, either version 3 of the License, or
+#    (at your option) any later version.
+#
+#    BayesOpt is distributed in the hope that it will be useful, but 
+#    WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with BayesOpt.  If not, see <http://www.gnu.org/licenses/>.
+# ------------------------------------------------------------------------
+
 PROJECT(BayesOpt CXX)
 CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
 
 
 set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} /opt/local/lib /opt/local/Library)
 set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} /opt/local/include
-/opt/local/Library)
+                                             /opt/local/Library)
 set(CMAKE_PROGRAM_PATH ${CMAKE_PROGRAM_PATH} /opt/local/bin/ /opt/local/Library)
 
 
 
 if(BAYESOPT_PYTHON_INTERFACE)
   INCLUDE(PythonMagic)
-  SET(PYTHON_LIB  ${PYTHON_LIBRARIES} )
   INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})
   SET(BAYESOPT_BUILD_SHARED ON CACHE BOOL "Build shared libraries?" FORCE)
 ELSE()
 endif()
 
 FIND_LIBRARY(NLOPT nlopt)
-
 IF(NLOPT MATCHES NLOPT-NOTFOUND)
   SET(NLOPT_BUILD ON CACHE BOOL "Build included version of NLOPT?")
 ELSE(NLOPT MATCHES NLOPT-NOTFOUND)
 
 INCLUDE(UseDoxygen)
 
-
 IF(BAYESOPT_BUILD_SOBOL)
   ADD_DEFINITIONS(-DUSE_SOBOL)	
   SET(SOBOL_SRC
   ./wrappers/bayesoptwpr.cpp
   )
 
-IF(BAYESOPT_PYTHON_INTERFACE)
-  SET(PYTHON_SRC  ./python/bayesopt.cpp)
-ELSE(BAYESOPT_PYTHON_INTERFACE)
-  SET(PYTHON_SRC)
-ENDIF(BAYESOPT_PYTHON_INTERFACE)
-
 
 INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/include 
                      ${CMAKE_SOURCE_DIR}/wrappers
 
 LINK_DIRECTORIES( ${CMAKE_SOURCE_DIR}/lib )
 
+IF(NLOPT_BUILD)
+  ADD_SUBDIRECTORY(nlopt)
+  include_directories(${CMAKE_SOURCE_DIR}/nlopt/api)
+  SET(EXT_LIBS nlopt)
+ELSE(NLOPT_BUILD)
+  SET(EXT_LIBS ${NLOPT})
+ENDIF(NLOPT_BUILD)
+
 
 IF(BAYESOPT_BUILD_SHARED)
   ADD_LIBRARY(bayesopt SHARED ${BAYESOPT_SRCS}   
-    ${WRAPPPERS_SRC} ${UTILS_SRC} ${PYTHON_SRC} )
+    ${WRAPPPERS_SRC} ${UTILS_SRC} )
+
+  IF(BAYESOPT_PYTHON_INTERFACE)
+    ADD_LIBRARY(esopt MODULE ${BAYESOPT_SRCS}   
+      ${WRAPPPERS_SRC} ${UTILS_SRC} ./python/bayesopt.cpp)
+    TARGET_LINK_LIBRARIES(esopt
+      ${EXT_LIBS} ${PYTHON_LIBRARIES} )
+  ENDIF(BAYESOPT_PYTHON_INTERFACE)
+
   IF(WIN32)
     ADD_DEFINITIONS(-DBAYESOPT_DLL)	
     # In new versions of CMAKE they use a different system and the
     # symbol is not defined
     ADD_DEFINITIONS(-Dbayesopt_EXPORT )
   ELSE()
-    SET_TARGET_PROPERTIES(bayesopt PROPERTIES PREFIX "" SUFFIX ".so")
+    IF(BAYESOPT_PYTHON_INTERFACE)
+      # Kind of a hack but it works
+      SET_TARGET_PROPERTIES(esopt PROPERTIES PREFIX "bay" SUFFIX ".so")
+    ENDIF(BAYESOPT_PYTHON_INTERFACE)
   ENDIF()
 ELSE()
   ADD_LIBRARY(bayesopt STATIC ${BAYESOPT_SRCS}   
-    ${WRAPPPERS_SRC} ${UTILS_SRC} ${PYTHON_SRC} )
+    ${WRAPPPERS_SRC} ${UTILS_SRC} )
 ENDIF()
 
+IF(NLOPT_BUILD)
+  add_dependencies(bayesopt nlopt)
+  IF(BAYESOPT_PYTHON_INTERFACE)
+    add_dependencies(esopt nlopt)
+  ENDIF(BAYESOPT_PYTHON_INTERFACE)
+ENDIF(NLOPT_BUILD)
+
+
 IF((BAYESOPT_BUILD_SHARED OR BAYESOPT_MATLAB_COMPATIBLE) AND NOT WIN32)
   SET_TARGET_PROPERTIES(bayesopt PROPERTIES COMPILE_FLAGS "-fPIC")
 ENDIF()
   
-
-IF(NLOPT_BUILD)
-  ADD_SUBDIRECTORY(nlopt)
-  include_directories(${CMAKE_SOURCE_DIR}/nlopt/api)
-  add_dependencies(bayesopt nlopt)
-  SET(EXT_LIBS nlopt)
-ELSE(NLOPT_BUILD)
-  SET(EXT_LIBS ${NLOPT})
-ENDIF(NLOPT_BUILD)
-
-TARGET_LINK_LIBRARIES(bayesopt
-  ${EXT_LIBS} ${PYTHON_LIB} )
-
+TARGET_LINK_LIBRARIES(bayesopt ${EXT_LIBS})
 
 IF(BAYESOPT_BUILD_EXAMPLES)
   ADD_SUBDIRECTORY(examples)
   LIBRARY DESTINATION lib
   ARCHIVE DESTINATION lib
 )
+
+IF(BAYESOPT_PYTHON_INTERFACE)
+  INSTALL(
+    TARGETS esopt
+    LIBRARY DESTINATION lib
+    ARCHIVE DESTINATION lib
+  )
+ENDIF(BAYESOPT_PYTHON_INTERFACE)