Skip to content

Commit

Permalink
#191 windows port
Browse files Browse the repository at this point in the history
Signed-off-by: Frédéric Vallée <[email protected]>
  • Loading branch information
Frédéric Vallée authored and gautierbureau committed Apr 6, 2023
1 parent f72d518 commit 8dd0cb2
Show file tree
Hide file tree
Showing 34 changed files with 1,037 additions and 224 deletions.
74 changes: 18 additions & 56 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,26 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${DYNAWO_ALGORITHMS_CMAKE_MODULE_PATH
option(BUILD_TESTS "Choose to build unit tests")
option(BUILD_TESTS_COVERAGE "Choose to build tests coverage")

set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel (CMake defaults)")

# Project dynawo-algorithms
project(dynawo-algorithms)
set(DYNAWO_ALGORITHMS_VERSION_MAJOR 1)
set(DYNAWO_ALGORITHMS_VERSION_MINOR 5)
set(DYNAWO_ALGORITHMS_VERSION_PATCH 0)
set(DYNAWO_ALGORITHMS_VERSION_STRING ${DYNAWO_ALGORITHMS_VERSION_MAJOR}.${DYNAWO_ALGORITHMS_VERSION_MINOR}.${DYNAWO_ALGORITHMS_VERSION_PATCH})

set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) # export all symbols from dll on Windows
set(CMAKE_ENABLE_EXPORTS ON) # export all symbols from exe on Windows
set(CMAKE_POSITION_INDEPENDENT_CODE ON) # set -fPIC on Linux

# Set repertory name
set(BINDIR_NAME bin)
set(SHAREDIR_NAME share)
set(INCLUDEDIR_NAME include)
set(LIBDIR_NAME lib)
set(DOCDIR_NAME doxygen)

get_filename_component(libdir ${CMAKE_INSTALL_PREFIX}/${LIBDIR_NAME} ABSOLUTE)

get_filename_component(DYNAWO_HOME ${DYNAWO_HOME} ABSOLUTE)
get_filename_component(DYNAWO_ALGORITHMS_HOME ${DYNAWO_ALGORITHMS_HOME} ABSOLUTE)
get_filename_component(DYNAWO_ALGORITHMS_THIRD_PARTY_DIR ${DYNAWO_ALGORITHMS_THIRD_PARTY_DIR} ABSOLUTE)
Expand All @@ -45,10 +49,14 @@ list(APPEND CMAKE_PREFIX_PATH "${DYNAWO_HOME}/share/cmake")
list(APPEND CMAKE_PREFIX_PATH "${DYNAWO_HOME}/share")
list(APPEND CMAKE_PREFIX_PATH "${DYNAWO_HOME}")

set(FORCE_CXX11_ABI OFF CACHE BOOL "Choose either ON or OFF.")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
if(FORCE_CXX11_ABI)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_USE_CXX11_ABI=1")
if(MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS -D_WIN32_WINNT=0x0601)
else()
set(FORCE_CXX11_ABI OFF CACHE BOOL "Choose either ON or OFF.")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
if(FORCE_CXX11_ABI)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_USE_CXX11_ABI=1")
endif()
endif()

# Add specific options for compiler
Expand Down Expand Up @@ -116,6 +124,10 @@ else()
# Use Boost_NO_BOOST_CMAKE to ensure that find_package uses MODULE mode and takes Boost_NO_SYSTEM_PATHS into account, instead of CONFIG mode
set(Boost_NO_BOOST_CMAKE ON)
endif()

set(BUILD_SHARED_LIBS ON)
set(Boost_USE_STATIC_RUNTIME False)
add_definitions(-DBOOST_ALL_DYN_LINK)
# Tell BOOST to disable auto linking
add_definitions(-DBOOST_ALL_NO_LIB)

Expand Down Expand Up @@ -194,43 +206,6 @@ if(BUILD_TESTS)
include(UnitTest)
endif()

if(BUILD_TESTS OR BUILD_TESTS_COVERAGE)
find_package(GTest REQUIRED)

if(NOT TARGET GTest::gtest AND TARGET GTest::GTest)
add_library(GTest::gtest UNKNOWN IMPORTED)
if(EXISTS "${GTEST_LIBRARY_DEBUG}")
set_target_properties(GTest::gtest PROPERTIES
IMPORTED_LOCATION "${GTEST_LIBRARY_DEBUG}")
elseif(EXISTS "${GTEST_LIBRARY}")
set_target_properties(GTest::gtest PROPERTIES
IMPORTED_LOCATION "${GTEST_LIBRARY}")
endif()
endif()
if(NOT TARGET GTest::gtest_main AND TARGET GTest::Main)
add_library(GTest::gtest_main UNKNOWN IMPORTED)
if(EXISTS "${GTEST_MAIN_LIBRARY_DEBUG}")
set_target_properties(GTest::gtest_main PROPERTIES
IMPORTED_LOCATION "${GTEST_MAIN_LIBRARY_DEBUG}")
elseif(EXISTS "${GTEST_MAIN_LIBRARY}")
set_target_properties(GTest::gtest_main PROPERTIES
IMPORTED_LOCATION "${GTEST_MAIN_LIBRARY}")
endif()
endif()
find_package(GMock REQUIRED)

add_library(dynawo_algorithms_Test INTERFACE)
target_link_libraries(dynawo_algorithms_Test
INTERFACE
Dynawo::dynawo_Common
dynawo_algorithms_Test_utils
GTest::gmock_main
GTest::gtest_main
Boost::iostreams
Boost::filesystem
)
endif()

set(CMAKE_SKIP_RPATH TRUE)

install(EXPORT dynawo_algorithms-targets
Expand All @@ -252,19 +227,6 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/dynawoalgorithms-config-version.cmake

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/sources/config_algorithms.h.in ${CMAKE_CURRENT_SOURCE_DIR}/sources/config_algorithms.h @ONLY)

if(MSVC)
set(runtime_PATH "PATH=${DYNAWO_HOME}/bin;${DYNAWO_HOME}/OpenModelica/bin;${libdir};$ENV{PATH}")
if(BUILD_TESTS OR BUILD_TESTS_COVERAGE)
set(runtime_tests_PATH "PATH=${GTEST_ROOT}/bin;${DYNAWO_HOME}/bin;${DYNAWO_HOME}/OpenModelica/bin;${libdir};$ENV{PATH}")
endif()
else() # Linux
set(runtime_LD_LIBRARY_PATH "LD_LIBRARY_PATH=\"${DYNAWO_HOME}/lib:${libdir}:$ENV{LD_LIBRARY_PATH}\"")
set(runtime_PATH "PATH=\"${DYNAWO_HOME}/OpenModelica/bin:$ENV{PATH}\"")
if(BUILD_TESTS OR BUILD_TESTS_COVERAGE)
set(runtime_tests_PATH "LD_LIBRARY_PATH=${GTEST_ROOT}/lib:${DYNAWO_HOME}/lib:${libdir}:$ENV{LD_LIBRARY_PATH}")
endif()
endif()

include(cpplint/cpplint.cmake)

add_subdirectory(sources)
Expand Down
113 changes: 109 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ It provides the following possibilities:
Dyna&omega;o-algorithms is an open-source project and as such, questions, discussions, feedbacks and more generally any form of contribution are very welcome and greatly appreciated!

For further informations about contributing guidelines, please refers to the [contributing documentation](https://github.com/dynawo/.github/blob/master/CONTRIBUTING.md).

## Dyna&omega;o algorithms Distribution

You can download a pre-built Dyna&omega;o-algorithms release to start testing it. Pre-built releases are available for **Linux**:
You can download a pre-built Dyna&omega;o-algorithms release to start testing it. Pre-built releases are available for **Linux** and **Windows**:
- [Linux](https://github.com/dynawo/dynawo-algorithms/releases/download/v1.4.0/DynawoAlgorithms_Linux_v1.4.0.zip)
- Windows  *Coming soon*

### Linux Requirements for Distribution

Expand All @@ -48,6 +50,14 @@ $> apt install -y unzip curl
$> dnf install -y unzip curl
```

### Windows Requirements for Distribution

- Runtime to be installed as administrator [Microsoft MPI v10.1.2](https://www.microsoft.com/en-us/download/details.aspx?id=100593)

``` batch
> msmpisetup
```

### Using a distribution

#### Linux
Expand All @@ -64,7 +74,18 @@ $> ./dynawo-algorithms.sh SA --input fic_MULTIPLE.xml --output testSA.zip --dire
$> ./dynawo-algorithms.sh MC --input fic_MULTIPLE.xml --output testMC.zip --directory examples/MC
```

## Building Dyna&omega;o-algorithms
#### Windows

Download the zip of the distribution and unzip it somewhere. Then open either `Command Prompt` or `x64 Native Tools Command Prompt for VS2019` and use cd to go into the directory you previously unzipped. You should see a dynawo-algorithms.cmd file at the top of the folder. You can then launch:

``` batch
> dynawo-algorithms help
> dynawo-algorithms CS --input examples/CS/IEEE14.jobs
> dynawo-algorithms SA --input fic_MULTIPLE.xml --output testSA.zip --directory examples/SA
> dynawo-algorithms MC --input fic_MULTIPLE.xml --output testMC.zip --directory examples/MC
```

## Build Dyna&omega;o-algorithms on Linux

### Optional requirements

Expand Down Expand Up @@ -151,6 +172,87 @@ To deploy Dyna&omega;o-algorithms, launch the following command after build:
$> ./myEnvDynawoAlgorithms.sh deploy
```

## Build and use Dyna&omega;o-algorithms on Windows

### Requirements

- SDK to be installed as administrator [Microsoft MPI v10.1.2](https://www.microsoft.com/en-us/download/details.aspx?id=100593)

``` batch
> msmpisdk.msi
```

### Build

Open `x64 Native Tools Command Prompt for VS2019` and run the following commands (don't forget to adjust the path to the Dyna&omega;o deploy folder in the DYNAWO_HOME define):

``` batch
> git config --global core.eol lf
> git config --global core.autocrlf input
> md dynawo-project
> cd dynawo-project
> git clone https://github.com/dynawo/dynawo-algorithms.git
> cd dynawo-algorithms
> cmake -S . -B b -DCMAKE_INSTALL_PREFIX=../da-i -DDYNAWO_ALGORITHMS_HOME=. -DDYNAWO_HOME=../dynawo/deploy/dynawo -DDYNAWO_ALGORITHMS_THIRD_PARTY_DIR=. -G "NMake Makefiles"
> cmake --build b --target install
```

**Warning** We try to limit as far as possible the name of the build and install folders (for example da-i instead of dynawo-algorithms-install) because of Windows limitation of length of path for folders. We know it causes problems and the only solution is to install Dyna&omega;o-algorithms in a shorter length directory path.

**Warning** Only the build directory (b) can be located in the `dynawo-algorithms` folder, the install (da-i) folder should be located outside to avoid problems with CMake.

### Command utility

A command file `dynawo-algorithms.cmd` (similar to myEnvDynawoAlgorithms.sh or dynawo-algorithms.sh) is available:
* from build environment: use `util\windows\dynawo-algorithms`
* from installation or deploy or distribution folder: use `dynawo-algorithms`

```
usage: dynawo-algorithms [VERBOSE] [DEBUG] [HELP | <command>]
HELP command displays this message.
Add VERBOSE option to echo environment variables used.
All commands are run in Release mode by default. Add DEBUG option to turn in Debug mode.
These are commands used by end-user:
CS|SA|MC [<simulation_options>] Launch dynawoAlgorithms simulation (see simulation_options below)
[SHOW] nrt Launch dynawoAlgorithms Non Regressions Tests (option SHOW uses DYNAWO_BROWSER to show results)
version Print dynawoAlgorithms version
where <simulation_options> are:
--simulationType arg Set the simulation type to launch : MC (Margin
calculation), SA (systematic analysis) or CS (compute
simulation)
--input arg Set the input file of the simulation (*.zip or *.xml)
--output arg Set the output file of the simulation (*.zip or *.xml)
--directory arg Set the working directory of the simulation
--variation arg Specify a specific load increase variation to launch
These are commands used by developer only:
build [<install_dir>] Build dynawoAlgorithms
[SHOW] tests [<unit_test>] Build and run unit tests or a specific unit test (option SHOW lists available unit tests)
clean Clean build directory
deploy [<deploy_dir>] Deploy the current version of dynawoAlgorithms binaries/libraries/includes
to be used as a release by an another project
distrib [<distrib_dir>] Create distribution of dynawoAlgorithms
distrib-headers [<distrib_dir>] Create distribution of dynawoAlgorithms with headers
distrib-omc [<distrib_dir>] Create distribution of dynawoAlgorithms with OpenModelica
```

Not all options are available depending on whether the utility is run from the build environment or the installation/deployment/distribution folder.

The utility tries to guess some environment variables from context and set other to default values (please set it to another value if not correct):
```
DYNAWO_HOME=<found_in_distribution_or_in_a_known_place_for_deployment>
DYNAWO_ALGORITHMS_HOME=<found_in_a_known_place_for_building_environment>
DYNAWO_ALGORITHMS_LOCALE=en
DYNAWO_USE_XSD_VALIDATION=false
DYNAWO_PYTHON_COMMAND=python
DYNAWO_BROWSER=<read_from_registry_with_default_to_iexplore>
DYNAWO_NB_PROCESSORS_USED=2
```
Then the utility automatically sets all other environment variables based on the commandline, above variables and context.

## Tests

To launch Dyna&omega;o-algorithms unit tests, launch the following command:
Expand Down Expand Up @@ -209,8 +311,11 @@ A. Guironnet, M. Saugier, S. Petitrenaud, F. Xavier, and P. Panciatici, “Towar
Dyna&omega;o-algorithms is licensed under the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, you can obtain one at http://mozilla.org/MPL/2.0. You can also see the [LICENSE](LICENSE.txt) file for more information.

Dyna&omega;o-algorithms is using some external libraries to run simulations:
* [gperftools](https://github.com/gperftools/gperftools), a collection of a high-performance multi-threaded malloc implementations distributed under the BSD license. Dyna&omega;o-algorithms is currently using the version 2.6.1.
* [MPICH](https://www.mpich.org/), an implementation of the Message Passing Interface (MPI) standard distributed under a BSD-like license. Dyna&omega;o-algorithms currently using the version 3.4.2.
* on Linux:
* [gperftools](https://github.com/gperftools/gperftools), a collection of a high-performance multi-threaded malloc implementations distributed under the BSD license. Dyna&omega;o-algorithms is currently using the version 2.6.1.
* [MPICH](https://www.mpich.org/), an implementation of the Message Passing Interface (MPI) standard distributed under a BSD-like license. Dyna&omega;o-algorithms currently using the version 3.4.2.
* on Windows:
* [MSMPI](https://learn.microsoft.com/en-us/message-passing-interface/microsoft-mpi?redirectedfrom=MSDN), a Microsoft implementation of the Message Passing Interface standard distributed under a MIT license. Dyna&omega;o-algorithms currently using the version 10.1.2.

## Maintainers

Expand Down
12 changes: 6 additions & 6 deletions cmake/FindGMock.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ if(NOT GMOCK_HOME AND NOT $ENV{GMOCK_ROOT} STREQUAL "")
set(GMOCK_HOME $ENV{GMOCK_ROOT})
endif()

find_path(GMOCK_INCLUDE_DIR NAME gmock/gmock.h gtest/gtest.h HINTS $ENV{GMOCK_HOME}/include ${GMOCK_HOME}/include)
find_library(GMOCK_LIBRARY NAME gmock libgmock gtest libgtest HINTS ENV{GMOCK_HOME} ${GMOCK_HOME} PATH_SUFFIXES lib lib${CMAKE_LIBRARY_ARCHITECTURE} )
find_path(GMOCK_INCLUDE_DIR NAME gmock/gmock.h gtest/gtest.h HINTS ENV GMOCK_HOME ${GMOCK_HOME} PATH_SUFFIXES include)
find_library(GMOCK_LIBRARY NAME gmock libgmock gtest libgtest HINTS ENV GMOCK_HOME ${GMOCK_HOME} PATH_SUFFIXES lib lib${CMAKE_LIBRARY_ARCHITECTURE} )
find_library(GMOCK_MAIN_LIBRARY NAME gmock_main liggmock_main gtest_main libgtest_main
HINTS ENV{GMOCK_HOME} ${GMOCK_HOME} PATH_SUFFIXES lib lib${CMAKE_LIBRARY_ARCHITECTURE} )
find_library(GMOCK_LIBRARY_DEBUG NAME gmockd libgmockd gtestd libgtestd HINTS ENV{GMOCK_HOME} ${GMOCK_HOME} PATH_SUFFIXES lib lib${CMAKE_LIBRARY_ARCHITECTURE} )
HINTS ENV GMOCK_HOME ${GMOCK_HOME} PATH_SUFFIXES lib lib${CMAKE_LIBRARY_ARCHITECTURE} )
find_library(GMOCK_LIBRARY_DEBUG NAME gmockd libgmockd gtestd libgtestd HINTS ENV GMOCK_HOME ${GMOCK_HOME} PATH_SUFFIXES lib lib${CMAKE_LIBRARY_ARCHITECTURE} )
find_library(GMOCK_MAIN_LIBRARY_DEBUG NAME gmock_maind liggmock_maind gtest_maind libgtest_main
HINTS ENV{GMOCK_HOME} ${GMOCK_HOME} PATH_SUFFIXES lib lib${CMAKE_LIBRARY_ARCHITECTURE} )
HINTS ENV GMOCK_HOME ${GMOCK_HOME} PATH_SUFFIXES lib lib${CMAKE_LIBRARY_ARCHITECTURE} )

mark_as_advanced(GMOCK_INCLUDE_DIR GMOCK_LIBRARY GMOCK_MAIN_LIBRARY)

# Handle the QUIETLY and REQUIRED arguments and set GMOCK_FOUND
# to TRUE if all listed variables are TRUE.
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(GMock DEFAULT_MSG GMOCK_INCLUDE_DIR GMOCK_LIBRARY GMOCK_MAIN_LIBRARY)
find_package_handle_standard_args(GMock DEFAULT_MSG GMOCK_LIBRARY GMOCK_INCLUDE_DIR GMOCK_MAIN_LIBRARY)

if(GMOCK_FOUND)
set(GMOCK_INCLUDE_DIRS ${GMOCK_INCLUDE_DIR})
Expand Down
8 changes: 0 additions & 8 deletions cmake/UnitTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,6 @@ if (NOT (CMAKE_BUILD_TYPE STREQUAL "Debug" OR BUILD_TESTS))
message(WARNING "Unit tests should be launched with debug or tests configuration")
endif()

if(MSVC)
add_definitions(-D_DEBUG_)
add_definitions(-DGTEST_LINKED_AS_SHARED_LIBRARY)
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 -D_DEBUG_")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0")
endif()

function(add_test test-target)
add_dependencies(tests ${test-target})
endfunction()
Expand Down
2 changes: 1 addition & 1 deletion documentation/clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# license. All rights reserved.

folders=(introduction installation configuringDynawoAlgorithms advancedDoc
licenses/dynawo licenses/dynawo-algorithms licenses/dynawo-algorithms-documentation licenses/gperftools licenses/mpich licenses/cpplint)
licenses/dynawo licenses/dynawo-algorithms licenses/dynawo-algorithms-documentation licenses/gperftools licenses/mpich licenses/msmpi licenses/cpplint)

for folder in ${folders[*]}; do
if [ -d "$folder" ]; then
Expand Down
2 changes: 1 addition & 1 deletion documentation/compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# license. All rights reserved.

folders=(introduction installation configuringDynawoAlgorithms advancedDoc
licenses/dynawo licenses/dynawo-algorithms licenses/dynawo-algorithms-documentation licenses/gperftools licenses/mpich licenses/cpplint)
licenses/dynawo licenses/dynawo-algorithms licenses/dynawo-algorithms-documentation licenses/gperftools licenses/mpich licenses/msmpi licenses/cpplint)
pdflatex_options="-halt-on-error -interaction=nonstopmode"

for folder in ${folders[*]}; do
Expand Down
4 changes: 2 additions & 2 deletions documentation/dynawo_algorithms_documentation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ done

echo "\begin{appendices}" >> dynawoAlgorithmsDocumentation/$output_file

licenses_folders=(licenses/dynawo licenses/dynawo-algorithms licenses/dynawo-algorithms-documentation licenses/gperftools licenses/mpich licenses/cpplint)
licenses_folders=(licenses/dynawo licenses/dynawo-algorithms licenses/dynawo-algorithms-documentation licenses/gperftools licenses/mpich licenses/msmpi licenses/cpplint)

# Latex compile
for folder in ${licenses_folders[*]}; do
Expand All @@ -69,7 +69,7 @@ for folder in ${licenses_folders[*]}; do
done
done

license_name=('\Dynawo' '\Dynawo-algorithms' '\Dynawo-algorithms documentation' 'gperftools' 'mpich' 'cpplint')
license_name=('\Dynawo' '\Dynawo-algorithms' '\Dynawo-algorithms documentation' 'gperftools' 'mpich' 'msmpi' 'cpplint')

i=0
j=1
Expand Down
8 changes: 7 additions & 1 deletion documentation/installation/installation.tex
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ \section{Building requirements}

\section{Third parties}

To run a simulation, \Dynawo-algorithms uses several external libraries that are downloaded and compiled during the building process:
To run a simulation on Linux, \Dynawo-algorithms uses several external libraries that are downloaded and compiled during the building process:
\begin{itemize}
\item \href{https://github.com/gperftools/gperftools} {\underline{gperftools}}, a collection of a high-performance multi-threaded
malloc implementations distributed under the BSD license. \Dynawo-algorithms is currently using the version 2.6.1.
Expand All @@ -127,6 +127,12 @@ \section{Third parties}
\Dynawo-algorithms is currently using the version 3.4.2.
\end{itemize}

To run a simulation on Windows, \Dynawo-algorithms uses an external librarie that has to be installed before the building process:
\begin{itemize}
\item \href{https://learn.microsoft.com/en-us/message-passing-interface/microsoft-mpi?redirectedfrom=MSDN}{\underline{MSMPI}}, a Microsoft implementation of the Message Passing Interface standard distributed under a MIT license.
\Dynawo-algorithms is currently using the version 10.1.2.
\end{itemize}

In addition to these libraries needed for the simulation process, \Dynawo-algorithms downloads the code for one other library:
\begin{itemize}
\item \href{https://github.com/google/styleguide/tree/gh-pages/cpplint}{\underline{cpplint}},
Expand Down
Loading

0 comments on commit 8dd0cb2

Please sign in to comment.