Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experimental support for statically linked NOMAD #126

Closed
Closed
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
e807cff
Experimental support for statically linked NOMAD
jan-provaznik Jan 11, 2023
47e5555
Fixed CMakeFiles for C interface.
jan-provaznik Jan 11, 2023
6eb7d45
Fixed CMakeFilesLibs and setup_PyNomadStatic.
jan-provaznik Jan 11, 2023
305f7eb
Separated STATIC.
jan-provaznik Jan 12, 2023
44eaab5
Fixed up PyNomad interface
jan-provaznik Jan 12, 2023
1dd1c5e
Fixed problems with MSVC. Static build now optional.
jan-provaznik Jan 12, 2023
aca72af
Merged static libraries into nomadStatic.
jan-provaznik Jan 12, 2023
e66690a
Make PyNomad build work without installing first.
ctribes Jan 20, 2023
3b62d9c
Static build by default.
jan-provaznik Jan 21, 2023
f204bea
Fixed MSVC missing exports in CInterface header.
jan-provaznik Jan 21, 2023
d505757
Cleaned up CMakeLists*, fixed leftover comments.
jan-provaznik Jan 23, 2023
6d3154b
Merge branch 'feature-buildPyNomad-without-install' into feature-expe…
ctribes Jan 25, 2023
7510b5c
Make PyNomad build work without installing first.
ctribes Jan 25, 2023
7958771
Link against CInterface a shared nomad libraries.
jan-provaznik Jan 27, 2023
72ff71f
Merge branch 'feature-experimental-static' of https://github.com/jan-…
ctribes Feb 1, 2023
830e3f1
Updated PyNomad to work with MSVC.
jan-provaznik Feb 4, 2023
c4ccd8c
Introduced PyPi workflow.
jan-provaznik Feb 9, 2023
e542072
Introduced 'next' continuous integration workflow.
jan-provaznik Feb 11, 2023
7953441
Fixed incorrect PyNomad test.
jan-provaznik Feb 14, 2023
84c73d4
Test configuration moved to PyPi workflow.
jan-provaznik Feb 28, 2023
dbd6eb0
Renamed PyNomadStatic target to PyNomad.
jan-provaznik Feb 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/advanced/library/c_api/example1/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ set_target_properties(example1_c_api.exe PROPERTIES INSTALL_RPATH "${CMAKE_INSTA


if(OpenMP_CXX_FOUND)
target_link_libraries(example1_c_api.exe PUBLIC nomadAlgos nomadUtils nomadEval nomadCInterface OpenMP::OpenMP_CXX)
target_link_libraries(example1_c_api.exe PUBLIC nomadCInterface OpenMP::OpenMP_CXX)
else()
target_link_libraries(example1_c_api.exe PUBLIC nomadAlgos nomadUtils nomadEval nomadCInterface)
target_link_libraries(example1_c_api.exe PUBLIC nomadCInterface)
endif()
if (WIN32)
else()
Expand Down
4 changes: 2 additions & 2 deletions examples/advanced/library/c_api/example2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ set_target_properties(example2_c_api.exe PROPERTIES INSTALL_RPATH "${CMAKE_INSTA


if(OpenMP_CXX_FOUND)
target_link_libraries(example2_c_api.exe PUBLIC nomadAlgos nomadUtils nomadEval nomadCInterface OpenMP::OpenMP_CXX)
target_link_libraries(example2_c_api.exe PUBLIC nomadCInterface OpenMP::OpenMP_CXX)
else()
target_link_libraries(example2_c_api.exe PUBLIC nomadAlgos nomadUtils nomadEval nomadCInterface)
target_link_libraries(example2_c_api.exe PUBLIC nomadCInterface)
endif()
if (WIN32)
else()
Expand Down
50 changes: 13 additions & 37 deletions ext/sgtelib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,42 +103,18 @@ set(SGTELIB_MAIN_SOURCE src/sgtelib.cpp)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)

# build shared library sgtelib
add_library (sgtelib SHARED ${SGTELIB_SOURCES})
target_include_directories(sgtelib PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/sgtelib>
)

# export symbols on Windows
if (WIN32)
target_compile_definitions(sgtelib PRIVATE -DDLL_EXPORTS)
endif()

#add_executable (sgtelib_main ${SGTELIB_MAIN_SOURCE})
#set_target_properties(sgtelib_main PROPERTIES INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
#target_include_directories(sgtelib_main PUBLIC
# $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
# $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/sgtelib>
#)
#target_link_libraries(sgtelib_main PUBLIC sgtelib)

set_target_properties(sgtelib PROPERTIES
VERSION ${SGTELIB_VERSION}
SOVERSION ${SGTELIB_VERSION_MAJOR}.${SGTELIB_VERSION_MINOR})

# installing executables and libraries
install(TARGETS sgtelib
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/sgtelib
)

# install header files
install(FILES ${SGTELIB_HEADERS}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/sgtelib
)


# Build shared libraries (sgtelib)
include(./CMakeListsLibs.txt)

# Build static libraries (sgtelibStatic)
include(./CMakeListsLibsStatic.txt)

# Install header files
install(
FILES
${SGTELIB_HEADERS}
DESTINATION
${CMAKE_INSTALL_INCLUDEDIR}/sgtelib
)


52 changes: 52 additions & 0 deletions ext/sgtelib/CMakeListsLibs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Build the object first.
#
# It will be built only once, then linked twice to make the shared and the
jan-provaznik marked this conversation as resolved.
Show resolved Hide resolved
# static variant of the library.

add_library(
sgtelib
SHARED
${SGTELIB_SOURCES}
)

target_include_directories(
sgtelib
PUBLIC
$<BUILD_INTERFACE:
${CMAKE_CURRENT_SOURCE_DIR}/src
>
$<INSTALL_INTERFACE:
${CMAKE_INSTALL_INCLUDEDIR}/sgtelib
>
)

set_target_properties(
sgtelib
PROPERTIES
VERSION ${SGTELIB_VERSION}
SOVERSION ${SGTELIB_VERSION_MAJOR}.${SGTELIB_VERSION_MINOR}
OUTPUT_NAME sgtelib
)

if (WIN32)
target_compile_definitions(
sgtelib
PRIVATE
-DDLL_EXPORTS
)
endif()

# Install both variants of the library.
jan-provaznik marked this conversation as resolved.
Show resolved Hide resolved
#

install(
TARGETS
sgtelib
RUNTIME DESTINATION
${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION
${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION
${CMAKE_INSTALL_INCLUDEDIR}/sgtelib
)

50 changes: 50 additions & 0 deletions ext/sgtelib/CMakeListsLibsStatic.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Build the object first.
#
# It will be built only once, then linked twice to make the shared and the
jan-provaznik marked this conversation as resolved.
Show resolved Hide resolved
# static variant of the library.

add_library(
sgtelibStatic
STATIC
${SGTELIB_SOURCES}
)

target_include_directories(
sgtelibStatic
PUBLIC
$<BUILD_INTERFACE:
${CMAKE_CURRENT_SOURCE_DIR}/src
>
$<INSTALL_INTERFACE:
${CMAKE_INSTALL_INCLUDEDIR}/sgtelib
>
)

set_target_properties(
sgtelibStatic
PROPERTIES
VERSION ${SGTELIB_VERSION}
SOVERSION ${SGTELIB_VERSION_MAJOR}.${SGTELIB_VERSION_MINOR}
OUTPUT_NAME sgtelibStatic
)

if (WIN32)
target_compile_definitions(
sgtelibStatic
PRIVATE
-DNOMAD_STATIC_BUILD
)
endif()

# Install both variants of the library.
#

install(
TARGETS
sgtelibStatic
RUNTIME DESTINATION
${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION
${CMAKE_INSTALL_LIBDIR}
)

2 changes: 1 addition & 1 deletion ext/sgtelib/src/Defines.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#include <limits.h>

// CASE Visual Studio C++ compiler
#ifdef _MSC_VER
#if defined(_MSC_VER) && !defined(NOMAD_STATIC_BUILD)
#pragma warning(disable:4251)
#ifdef DLL_EXPORTS
#define DLL_API __declspec(dllexport)
Expand Down
102 changes: 78 additions & 24 deletions interfaces/CInterface/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,45 +1,99 @@
#
# Source and header
#

set(INTERFACE_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/NomadStdCInterface.cpp)
${CMAKE_CURRENT_SOURCE_DIR}/NomadStdCInterface.cpp)

set(INTERFACE_HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/NomadStdCInterface.h)

${CMAKE_CURRENT_SOURCE_DIR}/NomadStdCInterface.h)

#
# Build
#
add_library (nomadCInterface SHARED ${INTERFACE_SOURCES})
target_include_directories(nomadCInterface PUBLIC
$<BUILD_INTERFACE: ${CMAKE_BINARY_DIR}/interfaces/CInterface>
$<INSTALL_INTERFACE: ${CMAKE_INSTALL_INCLUDEDIR}>

if(WIN32)
# set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
endif()

add_library(
nomadCInterface
SHARED
${INTERFACE_SOURCES}
)

target_include_directories(
nomadCInterface
PUBLIC
$<BUILD_INTERFACE:
${CMAKE_BINARY_DIR}/interfaces/CInterface
>
$<INSTALL_INTERFACE:
${CMAKE_INSTALL_INCLUDEDIR}
>
)

target_link_libraries(
nomadCInterface
PRIVATE
nomadStatic
)

if (WIN32)
target_compile_definitions(nomadCInterface PRIVATE -DDLL_ALGO_EXPORTS)
target_compile_definitions(
nomadCInterface
PRIVATE
-DNOMAD_STATIC_BUILD
-DNOMAD_INTERFACE_C_DLL
)
endif()

target_link_libraries(nomadCInterface PUBLIC nomadAlgos nomadUtils nomadEval)
if(OpenMP_CXX_FOUND)
target_link_libraries(nomadCInterface PUBLIC OpenMP::OpenMP_CXX)
if (OpenMP_CXX_FOUND)
target_link_libraries(
nomadCInterface
PUBLIC
OpenMP::OpenMP_CXX
)
endif()
if (WIN32)
else()
target_link_libraries(nomadCInterface PRIVATE m)

if(NOT WIN32)
target_link_libraries(
nomadCInterface
PRIVATE
m
)
endif()

set_target_properties(nomadCInterface PROPERTIES INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
set_target_properties(
nomadCInterface
PROPERTIES
INSTALL_RPATH
"${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}"
VERSION
"${NOMAD_VERSION}"
SOVERSION
"${NOMAD_VERSION_MAJOR}.${NOMAD_VERSION_MINOR}"
)

#
# Install binary and header
# Install library and headers
#
install(TARGETS nomadCInterface
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/
)

install(FILES ${INTERFACE_HEADERS}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/interfaces/CInterface
)
install(
TARGETS
nomadCInterface
RUNTIME DESTINATION
${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION
${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION
${CMAKE_INSTALL_INCLUDEDIR}/
)

install(
FILES
${INTERFACE_HEADERS}
DESTINATION
${CMAKE_INSTALL_INCLUDEDIR}/interfaces/CInterface
)

27 changes: 18 additions & 9 deletions interfaces/CInterface/NomadStdCInterface.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
#ifndef _NOMADSTDCINTERFACE_H_
#define _NOMADSTDCINTERFACE_H_

#ifdef _MSC_VER
jan-provaznik marked this conversation as resolved.
Show resolved Hide resolved
#ifdef NOMAD_INTERFACE_C_DLL
#define DLL_EXPORT_API __declspec(dllexport)
#else
#define DLL_EXPORT_API __declspec(dllimport)
#endif
#else
#define DLL_EXPORT_API
#endif

#include "nomad_platform.hpp"
// strongly inspired by Ipopt C interface
Expand All @@ -22,31 +31,31 @@ extern "C"
// Blackbox functions types
typedef bool (*Callback_BB_single)(int, double *, int, double *, bool *, NomadUserDataPtr);

DLL_ALGO_API NomadProblem createNomadProblem(
DLL_EXPORT_API NomadProblem createNomadProblem(
Callback_BB_single bb_single, // black box function
int nb_inputs, // number of inputs
int nb_outputs // number of outputs
);

DLL_ALGO_API void freeNomadProblem(NomadProblem nomad_problem);
DLL_EXPORT_API void freeNomadProblem(NomadProblem nomad_problem);



// parameters settings
DLL_ALGO_API bool addNomadParam(NomadProblem nomad_problem, char *keyword_value_pair);
DLL_EXPORT_API bool addNomadParam(NomadProblem nomad_problem, char *keyword_value_pair);

DLL_ALGO_API bool addNomadValParam(NomadProblem nomad_problem, char *keyword, int value);
DLL_EXPORT_API bool addNomadValParam(NomadProblem nomad_problem, char *keyword, int value);

DLL_ALGO_API bool addNomadDoubleParam(NomadProblem nomad_problem, char *keyword, double value);
DLL_EXPORT_API bool addNomadDoubleParam(NomadProblem nomad_problem, char *keyword, double value);

DLL_ALGO_API bool addNomadBoolParam(NomadProblem nomad_problem, char *keyword, bool value);
DLL_EXPORT_API bool addNomadBoolParam(NomadProblem nomad_problem, char *keyword, bool value);

DLL_ALGO_API bool addNomadStringParam(NomadProblem nomad_problem, char *keyword, char *param_str);
DLL_EXPORT_API bool addNomadStringParam(NomadProblem nomad_problem, char *keyword, char *param_str);

DLL_ALGO_API bool addNomadArrayOfDoubleParam(NomadProblem nomad_problem, char *keyword, double *array_param);
DLL_EXPORT_API bool addNomadArrayOfDoubleParam(NomadProblem nomad_problem, char *keyword, double *array_param);

// For the moment, do not allow the warm start
DLL_ALGO_API bool solveNomadProblem(NomadProblem nomad_problem,
DLL_EXPORT_API bool solveNomadProblem(NomadProblem nomad_problem,
int nb_starting_points, // number of starting points
double *x0s, // starting points
bool *exists_feas_sol, // indicates if the algorithm finds a feasible solution
Expand Down
Loading