From f24a49246c5b0998fb8c94492f2c8fd16a1b9baa Mon Sep 17 00:00:00 2001 From: Julien Schueller Date: Fri, 25 Oct 2024 19:30:28 +0200 Subject: [PATCH] CMake: Add SWIG_COMPILE_FLAGS --- .github/workflows/build.yml | 2 +- src/swig/CMakeLists.txt | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fe8ea2bf..ba911bd2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,7 +11,7 @@ jobs: pip install mkdocs python-markdown-math --user PATH=$PATH:~/.local/bin mkdocs build mkdir build && pushd build - cmake -DCMAKE_INSTALL_PREFIX=~/.local -DNLOPT_FORTRAN=ON -DCMAKE_C_FLAGS='-std=c89 -pedantic -D_POSIX_C_SOURCE=200809L -Wall -Wextra' -DCMAKE_CXX_FLAGS='-Wall -Wextra' .. + cmake -DCMAKE_INSTALL_PREFIX=~/.local -DNLOPT_FORTRAN=ON -DCMAKE_C_FLAGS='-std=c89 -pedantic -D_POSIX_C_SOURCE=200809L -Wall -Wextra' -DCMAKE_CXX_FLAGS='-Wall -Wextra' -DSWIG_COMPILE_FLAGS="-Wno-unused-parameter -Wno-missing-field-initializers" .. make install -j2 && ctest -j2 --output-on-failure rm -rf * ~/.local cmake -DCMAKE_INSTALL_PREFIX=~/.local -DNLOPT_PYTHON=OFF -DNLOPT_OCTAVE=OFF -DNLOPT_GUILE=OFF -DNLOPT_FORTRAN=ON -DCMAKE_TOOLCHAIN_FILE=$PWD/../cmake/toolchain-x86_64-w64-mingw32.cmake .. diff --git a/src/swig/CMakeLists.txt b/src/swig/CMakeLists.txt index 7ea352ac..5e26b613 100644 --- a/src/swig/CMakeLists.txt +++ b/src/swig/CMakeLists.txt @@ -4,6 +4,9 @@ if (POLICY CMP0078) endif () include (UseSWIG) +# allows one set C++ flags for swig wrappers +set (SWIG_COMPILE_FLAGS "" CACHE STRING "C++ compiler flags used for wrapper code") + if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/nlopt-enum-renames.i) file (WRITE ${CMAKE_CURRENT_BINARY_DIR}/nlopt-enum-renames.i "// AUTOMATICALLY GENERATED -- DO NOT EDIT\n") file (STRINGS ${PROJECT_SOURCE_DIR}/src/api/nlopt.h NLOPT_H_LINES REGEX " NLOPT_[A-Z0-9_]+") @@ -35,6 +38,7 @@ if (NUMPY_FOUND AND Python_FOUND) endif () set_target_properties (nlopt_python PROPERTIES OUTPUT_NAME nlopt) + set_target_properties (nlopt_python PROPERTIES COMPILE_FLAGS "${SWIG_COMPILE_FLAGS}") install (FILES ${CMAKE_CURRENT_BINARY_DIR}/nlopt.py DESTINATION ${INSTALL_PYTHON_DIR}) install (TARGETS nlopt_python DESTINATION ${INSTALL_PYTHON_DIR}) @@ -57,6 +61,7 @@ if (GUILE_FOUND) swig_link_libraries (nlopt_guile ${nlopt_lib}) target_link_libraries (nlopt_guile ${GUILE_LIBRARIES}) + set_target_properties (nlopt_guile PROPERTIES COMPILE_FLAGS "${SWIG_COMPILE_FLAGS}") file (RELATIVE_PATH _REL_GUILE_SITE_PATH ${GUILE_ROOT_DIR} ${GUILE_SITE_DIR}) set (GUILE_SITE_PATH ${_REL_GUILE_SITE_PATH})