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

Add options to handle static and static runtime builds. #299

Draft
wants to merge 32 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
e621f84
Add substation in error message (#237)
sebalaig Dec 18, 2020
3755724
Make sure xml serializer is not null when writing extensions (#239)
sebalaig Dec 21, 2020
7ffef53
Invalidate cache after an element is removed from NodeBreakerVoltageL…
sebalaig Jan 22, 2021
1ecaa31
Update current version to 1.4.0 (#252)
sebalaig Jan 22, 2021
7ec5fe4
[IIDM v1.4] Add ThreeWindingsTransformer::getLegs()
sebalaig Jan 25, 2021
3a08d4e
[IIDM v1.4] Aliases by type (#243) (#255)
sebalaig Feb 2, 2021
f37484e
[IIDM v1.4] Add Extendable::getExtensionByName (#210) (#259)
sebalaig Feb 2, 2021
9b928fa
[IIDM v1.4] Allow overwriting an existing variant (#209) (#263)
sebalaig Feb 2, 2021
f99900c
Remove unreached cmake code because required cmake version is 3.12 or…
sebalaig Feb 3, 2021
538022a
[IIDM v1.4.1] Usage of stdcxx::optional (#267)
sebalaig Feb 3, 2021
5cafded
[IIDM v1.4.1] Removal of parameters on defaulted/deleted special func…
sebalaig Feb 3, 2021
8781b72
Call to direct parent's read method from xml parsers (#226) (#269)
sebalaig Feb 3, 2021
d749cf1
[IIDM v1.4.1] Rename stdcxx::reference_wrapper into stdcxx::Reference…
sebalaig Feb 8, 2021
3ccb3a2
Refactor powsybl::iidm::util (#222) (#270)
sebalaig Feb 8, 2021
2dea989
Refactoring XML read/write of a Network API (#273)
sebalaig Feb 12, 2021
f10cb4f
Add option to disable unit tests build (#184) (#274)
sebalaig Feb 12, 2021
1667068
Pass unique_ptr as parameters by rvalue to functions (#234) (#275)
sebalaig Feb 24, 2021
b0aa032
Fix CI (boost not avaible on github actions) (#278)
sebalaig Feb 26, 2021
1eeccab
[IIDM v1.4] Add SimpleAnonymizer (#71) (#271)
sebalaig Feb 26, 2021
b7f6932
[IIDM v1.4] Add AbstractTerminalTopologyVisitor (#240) (#272)
sebalaig Mar 1, 2021
bdc6968
fix node/breaker voltage level connect/disconnect for internal connec…
zamarrenolm Mar 1, 2021
5a7aa5b
Fix CI: invoke apt-get update before installing boost (#287)
sebalaig Mar 8, 2021
a34a16a
[IIDM v1.4] Add ThreadLocalMultipleVariantContext (#183) (#277)
sebalaig Mar 15, 2021
fb284d6
Add four substations node breaker factory (#276) (#286)
sebalaig Mar 15, 2021
01f6b3c
Cosmetic: fix methods order (#289)
sebalaig Mar 15, 2021
1247341
Iso APIs: backport missing methods (#284)
sebalaig Mar 17, 2021
9df3438
Add option to disable tools build.
gautierbureau Mar 18, 2021
c50b0aa
Add Substation::remove() (#283)
sebalaig Mar 19, 2021
a65cddc
Link extensions static libraries with iidm-static
Mar 22, 2021
d84e4a4
Make registerExtension public (#303)
Mar 25, 2021
acc3995
Add options to handle static and static runtime builds.
gautierbureau Mar 18, 2021
3b81bdc
Corrections after review of handle of static/shared compilation.
gautierbureau Apr 7, 2021
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
34 changes: 26 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ jobs:
name: Linux
runs-on: ubuntu-latest
steps:
- name: Install Boost
run: |
sudo apt-get update -y
sudo apt-get install -y libboost-all-dev

- name: Checkout sources
uses: actions/checkout@v1

Expand All @@ -19,7 +24,6 @@ jobs:
cmake -S $GITHUB_WORKSPACE -B $GITHUB_WORKSPACE/build-linux
-DCMAKE_BUILD_TYPE=Release
-DBUILD_EXAMPLES=ON
-DCMAKE_PREFIX_PATH=$BOOST_ROOT_1_72_0

- name: Build
run: cmake --build $GITHUB_WORKSPACE/build-linux --parallel 3
Expand All @@ -33,7 +37,7 @@ jobs:
name: MacOS
runs-on: macos-latest
steps:
- name: Pre-requisites
- name: Install Boost
run: brew install boost

- name: Checkout sources
Expand All @@ -51,21 +55,32 @@ jobs:
CTEST_OUTPUT_ON_FAILURE: 1

windows:
env:
BOOST_ROOT: C:\thirdparties\boost-1.72.0
BOOST_URL: https://sourceforge.net/projects/boost/files/boost-binaries/1.72.0/boost_1_72_0-msvc-14.2-64.exe/download
LIBXML2_ROOT: C:\thirdparties\libxml2-2.9.10
LIBXML2_URL: https://github.com/GNOME/libxml2/archive/v2.9.10.zip
name: Windows
runs-on: windows-latest
steps:
- name: Pre-requisites
- name: Install LibXml2
shell: cmd
run: |
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
choco install wget --no-progress
wget -nv https://github.com/GNOME/libxml2/archive/v2.9.10.zip
wget -nv %LIBXML2_URL%
7z x v2.9.10.zip
cd libxml2-2.9.10/win32
cscript configure.js compiler=msvc prefix=C:\thirdparties\libxml2-2.9.10 iconv=no
cscript configure.js compiler=msvc prefix=%LIBXML2_ROOT% iconv=no
nmake -f Makefile.msvc
nmake -f Makefile.msvc install

- name: Install Boost
shell: cmd
run: |
wget -nv -O boost-installer.exe %BOOST_URL%
boost-installer.exe /dir=%BOOST_ROOT% /sp- /verysilent /suppressmsgboxes /norestart

- name: Checkout sources
uses: actions/checkout@v1

Expand All @@ -74,7 +89,6 @@ jobs:
run: >
cmake -S %GITHUB_WORKSPACE% -B %GITHUB_WORKSPACE%\build-windows
-DBUILD_EXAMPLES=ON
-DCMAKE_PREFIX_PATH=%BOOST_ROOT_1_72_0%;C:\thirdparties\libxml2-2.9.10

- name: Build
shell: cmd
Expand All @@ -85,7 +99,7 @@ jobs:
- name: Tests
shell: cmd
run: |
set PATH=%PATH%;C:\thirdparties\libxml2-2.9.10\bin;%BOOST_ROOT_1_72_0%\lib;%GITHUB_WORKSPACE%\build-windows\src\Release;%GITHUB_WORKSPACE%\build-windows\src\test\Release
set PATH=%PATH%;%LIBXML2_ROOT%\bin;%BOOST_ROOT%\lib64-msvc-14.2;%GITHUB_WORKSPACE%\build-windows\src\Release;%GITHUB_WORKSPACE%\build-windows\src\test\Release
cmake --build %GITHUB_WORKSPACE%\build-windows --target RUN_TESTS --config Release --verbose
env:
CTEST_OUTPUT_ON_FAILURE: 1
Expand Down Expand Up @@ -118,6 +132,11 @@ jobs:
env:
SONAR_SCANNER_VERSION: 3.3.0.1492

- name: Install Boost
run: |
sudo apt-get update -y
sudo apt-get install -y libboost-all-dev

- name: Checkout sources
uses: actions/checkout@v1

Expand All @@ -127,7 +146,6 @@ jobs:
-DCMAKE_BUILD_TYPE=Debug
-DCODE_COVERAGE=TRUE
-DBUILD_EXAMPLES=ON
-DCMAKE_PREFIX_PATH=$BOOST_ROOT_1_72_0

- name: Build
run: >
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/clang-tidy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ jobs:
name: clang-tidy
runs-on: ubuntu-latest
steps:
- name: Install Boost
run: |
sudo apt-get update -y
sudo apt-get install -y libboost-all-dev

- name: Install clang-tidy
run: |
sudo apt-get install -y clang-tidy-9
Expand All @@ -22,6 +27,7 @@ jobs:
cmake -S $GITHUB_WORKSPACE -B $GITHUB_WORKSPACE/build
-DCMAKE_BUILD_TYPE=Debug
-DCMAKE_PREFIX_PATH=$BOOST_ROOT_1_72_0
-DBUILD_EXAMPLES=ON
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON

- name: Clang Tidy
Expand Down
68 changes: 56 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@
# 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/.
#
cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
cmake_minimum_required(VERSION 3.15 FATAL_ERROR)

if (${CMAKE_VERSION} VERSION_GREATER "3.15.0")
# Policy to activate a way to choose MSVC runtime. https://cmake.org/cmake/help/v3.15/policy/CMP0091.html
if (POLICY CMP0091)
cmake_policy(SET CMP0091 NEW)
endif ()
endif ()

project(powsybl-iidm4cpp)

set(IIDM_VERSION_MAJOR 1)
set(IIDM_VERSION_MINOR 3)
set(IIDM_VERSION_MINOR 4)
set(IIDM_VERSION_PATCH 0)
set(IIDM_VERSION ${IIDM_VERSION_MAJOR}.${IIDM_VERSION_MINOR}.${IIDM_VERSION_PATCH})
set(IIDM_SOVERSION ${IIDM_VERSION_MAJOR})
Expand All @@ -22,27 +29,54 @@ set(INSTALL_DOC_DIR share CACHE PATH "Installation directory for doxygen files")

option(BUILD_DOXYGEN "Enable/Disable the generation of the Doxygen." OFF)
option(BUILD_EXAMPLES "Enable/Disable the compilation of the examples." OFF)
option(BUILD_TESTS "Enable/Disable the compilation of unit tests." ON)
option(BUILD_TOOLS "Enable/Disable the compilation of tools." ON)
option(BUILD_SHARED_LIBS "Enable/disable build of shared libraries." ON)
option(BUILD_STATIC_LIBS "Enable/disable build of static libraries." ON)
option(BOOST_STATIC_LIBS "Use static version of boost libraries." OFF)
option(MSVC_STATIC_RUNTIME_LIBRARY "Enable/disable static runtime on Windows." OFF)

# Handle options compatibility
if (BOOST_STATIC_LIBS AND BUILD_SHARED_LIBS)
message(FATAL_ERROR "BOOST_STATIC_LIBS and BUILD_SHARED_LIBS are ON and should not be used together.
BOOST_STATIC_LIBS should only be used with BUILD_STATIC_LIBS=ON and BUILD_SHARED_LIBS=OFF.")
endif ()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would raise an error in that case instead of making an arbitrary choice.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


if (BUILD_STATIC_LIBS AND NOT BUILD_SHARED_LIBS)
set(TARGET_POSTFIX "-static")
endif ()

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

if (${CMAKE_VERSION} VERSION_LESS "3.1.0")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++11")
else ()
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
endif ()
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -pedantic -Wswitch-enum")
# set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_GLIBCXX_DEBUG")
# set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -D_GLIBCXX_DEBUG")
elseif (MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4244 /wd4250 /wd4251 /wd4267 /wd4275")
if (NOT BUILD_SHARED_LIBS AND BUILD_STATIC_LIBS)
if (MSVC_STATIC_RUNTIME_LIBRARY)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This variable has been added in cmake v3.15 (https://cmake.org/cmake/help/git-stage/variable/CMAKE_MSVC_RUNTIME_LIBRARY.html). Is there an equivalent for older version?

endif ()
else()
if (MSVC_STATIC_RUNTIME_LIBRARY)
message(WARNING "MSVC_STATIC_RUNTIME_LIBRARY should be used with BUILD_SHARED_LIBS=OFF and BUILD_STATIC_LIBS=ON.")
endif ()
endif ()
endif ()

set(Boost_USE_STATIC_LIBS OFF)
find_package(Boost 1.65 REQUIRED COMPONENTS date_time filesystem program_options system unit_test_framework)
set(Boost_USE_STATIC_LIBS ${BOOST_STATIC_LIBS})
set(Boost_USE_STATIC_RUNTIME ${MSVC_STATIC_RUNTIME_LIBRARY})
if (BUILD_TESTS)
find_package(Boost 1.65 REQUIRED COMPONENTS date_time filesystem program_options system unit_test_framework)
else ()
find_package(Boost 1.65 REQUIRED COMPONENTS date_time filesystem program_options system)
endif()
find_package(LibXml2 REQUIRED)
find_package(Threads REQUIRED)

if (WIN32)
# On windows, also force prefix to avoid conflict between import file (for shared compilation) and static file
Expand All @@ -55,6 +89,9 @@ enable_testing()

set(CODE_COVERAGE FALSE CACHE BOOL "Enable code coverage")
if (CODE_COVERAGE)
# if code-coverage is ON, force tests build
set(BUILD_TESTS ON)

include(CodeCoverage)
code_coverage(NAME code-coverage
OUTPUT_DIR coverage
Expand All @@ -67,9 +104,16 @@ if (BUILD_DOXYGEN)
endif ()

add_subdirectory(src)
add_subdirectory(test)
add_subdirectory(extensions)
add_subdirectory(tools)

if (BUILD_TOOLS)
add_subdirectory(tools)
endif ()

if (BUILD_TESTS)
add_subdirectory(test)
endif ()

if (BUILD_EXAMPLES)
add_subdirectory(examples)
endif ()
Expand Down
29 changes: 22 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- [Build from sources](#build-from-sources)
- [Build the examples](#build-the-examples)
- [Generate the documentation](#generate-the-documentation)
- [Disable unit tests generation](#disable-tests-generation)
- [Link with powsybl-iidm4cpp](#link-with-powsybl-iidm4cpp)
- [Contributing](#contributing)

Expand All @@ -33,7 +34,7 @@ To build powsybl-iidm4cpp, you need:
### Ubuntu 20.04
```
$> apt install -y cmake g++ git libboost-all-dev libxml2-dev make
```
```

### Ubuntu 18.04
```
Expand Down Expand Up @@ -145,11 +146,17 @@ $> cmake .. -DCMAKE_INSTALL_PREFIX=<PREFIX> -DCMAKE_BUILD_TYPE=<BUILD_TYPE>
**Available options:**
- BUILD_DOXYGEN: Generate the API documentation using doxygen (Default is **OFF**)
- BUILD_EXAMPLES: Build the examples (Default is **OFF**)
- BUILD_TESTS: Generate unit tests (Default is **ON**)
- BUILD_TOOLS: Build the tools (Default is **ON**)
- BUILD_SHARED_LIBS: Build shared version of the library (Default is **ON**)
- BUILD_STATIC_LIBS: Build static version of library (Default is **ON**)
- BOOST_STATIC_LIBS: Use static version of Boost libraries (Default is **OFF**)
- MSVC_STATIC_RUNTIME_LIBRARY: Use MSVC static runtime (Default is **OFF**)

**Note:** If you want to use custom version of **Boost** or **LibXML**, you would have to help `cmake` to find the required packages, using the `-DCMAKE_PREFIX_PATH` options:
```
$> cmake .. -DCMAKE_INSTALL_PREFIX=<PREFIX> -DCMAKE_PREFIX_PATH=<BOOST_PREFIX>;<LIBXML2_PREFIX>
```
```

3. Build the sources
```
Expand All @@ -172,9 +179,9 @@ To build the examples, you have to pass the `-DBUILD_EXAMPLES=ON` flag to the co
```
$> cmake .. -DCMAKE_INSTALL_PREFIX=<PREFIX> -DCMAKE_BUILD_TYPE=<BUILD_TYPE> -DBUILD_EXAMPLES=ON
$> cmake --build .
```
```

Click [here](examples/README.md) to see the list of available examples.
Click [here](examples/README.md) to see the list of available examples.

### Generate the documentation
This project uses [doxygen](http://www.doxygen.nl/) to generate code documentation. To generate the API documentation using doxygen, add `-DBUILD_DOXYGEN=ON` flag to the configure command line. This will create a new `doxygen` target.
Expand All @@ -184,20 +191,28 @@ $> cmake --build . --target doxygen
```
The HTML documentation is available in `<BUILD_DIR>/doc/html/index.html`.

### Disable unit tests generation
Unit tests generation may be disabled to increase compilation time. When disabled, `Boost::unit_test_framework` is not necessary to build successfully.
To disable tests generation, add `-DBUILD_TESTS=OFF` flag to the configure command line.
```
$> cmake .. -DCMAKE_INSTALL_PREFIX=<PREFIX> -DCMAKE_BUILD_TYPE=<BUILD_TYPE> -DBUILD_TESTS=OFF
$> cmake --build .
```

## Link with powsybl-iidm4cpp
We provide cmake script files that make it easy to use `powsybl-iidm4cpp` in a CMake project, that are installed in the `<PREFIX>/LibIIDM/cmake` folder.

To use the library in your project, add the `find_package` instruction to your `CMakeLists.txt` file:
```
find_package(LibIIDM REQUIRED)
```
```

Then configure your project passing the `-DCMAKE_PREFIX_PATH=<IIDM4CPP_PREFIX>` option to the cmake command:
```
$> cmake ... -DCMAKE_PREFIX_PATH=<IIDM4CPP_PREFIX>
```

A complete example is available [here](examples/example2).
A complete example is available [here](examples/example2).

## Contributing

Expand All @@ -215,4 +230,4 @@ $> cmake --build .
$> cmake --build . --target test
$> cmake --build . --target code-coverage
```
The HTML report is available in `<BUILD_DIR>/coverage/index.html`.
The HTML report is available in `<BUILD_DIR>/coverage/index.html`.
3 changes: 3 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@
#

add_subdirectory(example1)
if (BUILD_STATIC_LIBS)
add_subdirectory(example3)
endif ()
1 change: 1 addition & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
## Basic examples
- [Example 1](example1/README.md): Read and write an XIIDM file
- [Example 2](example2/README.md): Use iidm4cpp in a CMake project
- [Example 3](example3/README.md): Use XIIDM extensions

## Advanced examples
2 changes: 1 addition & 1 deletion examples/example1/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
#

add_executable(example1 example1.cpp)
target_link_libraries(example1 PRIVATE iidm)
target_link_libraries(example1 PRIVATE iidm${TARGET_POSTFIX})
6 changes: 2 additions & 4 deletions examples/example1/example1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@ int main(int argc, char** argv) {
try {
xmlInitParser();

std::ifstream inputStream(argv[1]);
powsybl::iidm::Network network = powsybl::iidm::Network::readXml(inputStream);
powsybl::iidm::Network network = powsybl::iidm::Network::readXml(argv[1]);

std::ofstream outputStream(argv[2]);
powsybl::iidm::Network::writeXml(outputStream, network);
powsybl::iidm::Network::writeXml(argv[2], network);

xmlCleanupParser();

Expand Down
2 changes: 1 addition & 1 deletion examples/example2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
project(my-project)

# Find the required dependencies: Boost, LibXML2 and IIDM and import the targets
find_package(Boost 1.56 REQUIRED COMPONENTS date_time filesystem program_options system unit_test_framework)
find_package(Boost 1.65 REQUIRED COMPONENTS date_time filesystem program_options system unit_test_framework)
find_package(LibXml2 REQUIRED)
find_package(LibIIDM REQUIRED)

Expand Down
2 changes: 1 addition & 1 deletion examples/example2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
project(my-project)

# Find the required dependencies: Boost, LibXML2 and IIDM and import the targets
find_package(Boost 1.56 REQUIRED COMPONENTS date_time filesystem program_options system unit_test_framework)
find_package(Boost 1.65 REQUIRED COMPONENTS date_time filesystem program_options system unit_test_framework)
find_package(LibXml2 REQUIRED)
find_package(LibIIDM REQUIRED)

Expand Down
9 changes: 9 additions & 0 deletions examples/example3/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#
# Copyright (c) 2021, RTE (http://www.rte-france.com)
# This Source Code Form is subject to 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/.
#

add_executable(example3 example3.cpp)
target_link_libraries(example3 PRIVATE iidm-static ext-iidm-static)
Loading