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

Windows support #247

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Conversation

tsadakane
Copy link

@tsadakane tsadakane commented Jan 7, 2025

Please forgive me for opening a similar PR even though @chobby has opened PR #246 for Issue #245.

This PR includes

  • commit e68e82c
  • More CMake options
  • Possible to build tests and examples

You can build and test by the following steps:

  1. make a working dir.
root
 +-- libcmaes  <= your workspace.
 +-- tools
        +-- build_libcmaes.sh 

"build_libcmaes.sh" is...

#!/bin/bash
# Choose one triplet from the three 
# triplet="x64-windows"
# triplet="x64-windows-static"
triplet="x64-windows-static-md"

build_type="Release"

pushd ..

if [ ! -d "vcpkg" ]; then
    git clone https://github.com/microsoft/vcpkg.git vcpkg
    pushd vcpkg
    ./bootstrap-vcpkg.sh -disableMetrics
    popd
fi

pushd vcpkg
./vcpkg.exe install eigen3:${triplet} 
./vcpkg.exe install gflags:${triplet}
./vcpkg.exe install glog:${triplet} 
popd

if [ ${triplet} = "x64-windows-static-md" ]; then
    MAKE_DYNAMIC_LIB="OFF"
    CRT_DYNAMIC="ON"
elif [ ${triplet} = "x64-windows-static" ]; then
    MAKE_DYNAMIC_LIB="OFF"
    CRT_DYNAMIC="OFF"
elif [ ${triplet} = "x64-windows" ]; then
    MAKE_DYNAMIC_LIB="ON"
    CRT_DYNAMIC="ON"
else
    triplet="x64-windows"
    MAKE_DYNAMIC_LIB="ON"
    CRT_DYNAMIC="ON"
fi

echo "MAKE_DYNAMIC_LIB=${MAKE_DYNAMIC_LIB}"
echo "CRT_DYNAMIC=${CRT_DYNAMIC}"

if [ ! -d "build" ]; then
    mkdir build
fi
if [ ! -d "installed/libcmaes" ]; then
    mkdir -p installed/libcmaes
fi

# Current directory
CURRENT=$(cd $(dirname $0); pwd)

# Configure
cd build
cmake ${CURRENT}/libcmaes \
    -DCMAKE_BUILD_TYPE=${build_type} \
    -DCMAKE_INSTALL_PREFIX=${CURRENT}/installed/libcmaes \
    -DLIBCMAES_BUILD_EXAMPLES=ON \
    -DLIBCMAES_BUILD_PYTHON=OFF \
    -DLIBCMAES_BUILD_SHARED_LIBS=${MAKE_DYNAMIC_LIB} \
    -DLIBCMAES_BUILD_TESTS=ON \
    -DLIBCMAES_CRT_DYNAMIC=${CRT_DYNAMIC} \
    -DLIBCMAES_ENABLE_SURROG=ON \
    -DLIBCMAES_USE_GFLAGS=ON \
    -DLIBCMAES_USE_GLOG=ON \
    -DLIBCMAES_USE_OPENMP=ON \
    -DEigen3_DIR=${CURRENT}/vcpkg/installed/${triplet}/share/eigen3 \
    -Dgflags_DIR=${CURRENT}/vcpkg/installed/${triplet}/share/gflags \
    -Dglog_DIR=${CURRENT}/vcpkg/installed/${triplet}/share/glog \
    -G "Visual Studio 17 2022" -A x64

# Build and install
cmake --build . --config ${build_type}
cmake --install . --config ${build_type}

# Run tests
if [ $MAKE_DYNAMIC_LIB = "ON" ]; then
    # Copy glolg.dll, gflags.dll, cmaes.dll to tests/Release
    cp ${CURRENT}/vcpkg/installed/${triplet}/bin/glog.dll ${CURRENT}/build/tests/${build_type}
    cp ${CURRENT}/vcpkg/installed/${triplet}/bin/gflags.dll ${CURRENT}/build/tests/${build_type}
    cp ${CURRENT}/build/src/Release/cmaes.dll ${CURRENT}/build/tests/${build_type}
fi
cd tests/${build_type}
./test-functions.exe --all

popd
  1. Select one of the triplets in build_libcmaes.sh
  2. Run build_libcmaes.sh
    • test-functions --all will run at the end.

takuto-NA and others added 6 commits December 4, 2024 19:45
* Add options to use glog and gflags
   *  glog_DIR and gflags_DIR are required to set the directories containing CMake configuration files.
* Add CMake options to build dynamic/static libraries
   * Dynamic library (DLL) with dynamically linked CRT
   * Static library with dynamically linked CRT
   * Static library with statically linked CRT
* Removed additional modification from the original master.
* Changed `contour` class to template class
   * To avoid the following error when compiling with MSVC :
   ```
   3>cmaes.lib(errstats.obj) : error LNK2005: "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl libcmaes::operator<<(class std::basic_ostream<char,struct std::char_traits<char> > &,class libcmaes::contour const &)" (??6libcmaes@@YAAEAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AEAV12@AEBVcontour@0@@z) already defined in test-functions.obj
   3>.\build\tests\Release\test-functions.exe : fatal error LNK1169: one or more multiply defined symbols found
   3>Done building project "test-functions.vcxproj" -- FAILED.
   ```
   * `contour` is now `contour_<0>`. No need to change the existing code.
* `M_PI` etc. are not defined by default in MSVC.
* The `_USE_MATH_DEFINES` macro is required to define them.
@tsadakane
Copy link
Author

I found that LIBCMAES_USE_GLOG option does not work as expected. I'm working on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants