Skip to content

Commit

Permalink
Corrections after review of handle of static/shared compilation.
Browse files Browse the repository at this point in the history
Signed-off-by: Gautier Bureau <gautier.bureau@gmail.com>
  • Loading branch information
gautierbureau committed Apr 7, 2021
1 parent acc3995 commit 7a7da82
Show file tree
Hide file tree
Showing 19 changed files with 223 additions and 99 deletions.
41 changes: 14 additions & 27 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
# 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")
if(POLICY CMP0091)
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()
endif ()
endif ()

project(powsybl-iidm4cpp)

Expand All @@ -31,23 +32,18 @@ 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_SHARED_EXTENSIONS "Enable/disable build of shared extensions." ON)
option(BUILD_STATIC_LIBS "Enable/disable build of static libraries." ON)
option(BUILD_STATIC_EXTENSIONS "Enable/disable build of static extensions." ON)
option(MSVC_STATIC_RUNTIME_LIBRARY "Enable/disable static runtime on Windows." OFF)
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)
set(BOOST_STATIC_LIBS OFF)
message(WARNING "BOOST_STATIC_LIBS disabled if you want to build shared libraries. Use this option with BUILD_SHARED_LIBS=OFF")
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 ()

if (BUILD_TESTS AND NOT BUILD_SHARED_LIBS)
message(FATAL_ERROR "BUILD_TESTS is ON but BUILD_SHARED_LIBS is OFF, you should turn ON BUILD_SHARED_LIBS or turn off BUILD_TESTS.")
endif ()

if (BUILD_STATIC_EXTENSIONS AND NOT BUILD_STATIC_LIBS)
message(FATAL_ERROR "BUILD_STATIC_EXTENSIONS is ON but BUILD_STATIC_LIBS is OFF, you should turn ON BUILD_STATIC_LIBS or turn off BUILD_STATIC_EXTENSIONS.")
if (BUILD_STATIC_LIBS AND NOT BUILD_SHARED_LIBS)
set(TARGET_POSTFIX "-static")
endif ()

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
Expand All @@ -72,17 +68,8 @@ elseif (MSVC)
endif ()
endif ()

if (BOOST_STATIC_LIBS)
set(Boost_USE_STATIC_LIBS ON)
if (MSVC_STATIC_RUNTIME_LIBRARY)
set(Boost_USE_STATIC_RUNTIME ON)
else ()
set(Boost_USE_STATIC_RUNTIME OFF)
endif ()
else ()
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_STATIC_RUNTIME OFF)
endif ()
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 ()
Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,9 @@ $> cmake .. -DCMAKE_INSTALL_PREFIX=<PREFIX> -DCMAKE_BUILD_TYPE=<BUILD_TYPE>
- 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_SHARED_EXTENSIONS: Build shared version of the extensions (Default is **ON**)
- BUILD_STATIC_LIBS: Build static version of library (Default is **ON**)
- BUILD_STATIC_EXTENSIONS: Build static version of the extensions (Default is **ON**)
- MSVC_STATIC_RUNTIME_LIBRARY: Use MSVC static runtime (Default is **OFF**)
- 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:
```
Expand Down
4 changes: 3 additions & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@
#

add_subdirectory(example1)
add_subdirectory(example3)
if (BUILD_STATIC_LIBS)
add_subdirectory(example3)
endif ()
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})
17 changes: 7 additions & 10 deletions extensions/entsoe/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ set(UNIT_TEST_SOURCES
test/XnodeTest.cpp
)

if (BUILD_SHARED_EXTENSIONS)
if (BUILD_SHARED_LIBS)
# Shared library
add_library(${EXT_NAME} SHARED ${EXT_SOURCES})
set_target_properties(${EXT_NAME} PROPERTIES SOVERSION ${IIDM_SOVERSION} VERSION ${IIDM_VERSION} OUTPUT_NAME iidm-${EXT_NAME})
Expand All @@ -38,12 +38,7 @@ if (BUILD_SHARED_EXTENSIONS)
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)
if (BUILD_STATIC_LIBS AND NOT BUILD_SHARED_LIBS)
target_link_libraries(${EXT_NAME} PUBLIC iidm-static)
else ()
target_link_libraries(${EXT_NAME} PUBLIC iidm)
endif ()

target_link_libraries(${EXT_NAME} PUBLIC iidm)

# Installation
install(TARGETS ${EXT_NAME}
Expand All @@ -54,7 +49,7 @@ if (BUILD_SHARED_EXTENSIONS)
)
endif ()

if (BUILD_STATIC_EXTENSIONS)
if (BUILD_STATIC_LIBS)
# Static library
add_library(${EXT_NAME}-static STATIC ${EXT_SOURCES})
set_target_properties(${EXT_NAME}-static PROPERTIES OUTPUT_NAME iidm-${EXT_NAME})
Expand All @@ -78,8 +73,10 @@ endif ()
if (BUILD_TESTS)
# Unit tests
add_executable(unit-tests-${EXT_NAME} ${UNIT_TEST_SOURCES})
target_compile_definitions(unit-tests-${EXT_NAME} PRIVATE BOOST_TEST_DYN_LINK)
target_link_libraries(unit-tests-${EXT_NAME} PRIVATE ${EXT_NAME} iidm-tests)
if (BUILD_SHARED_LIBS)
target_compile_definitions(unit-tests-${EXT_NAME} PRIVATE BOOST_TEST_DYN_LINK)
endif ()
target_link_libraries(unit-tests-${EXT_NAME} PRIVATE ${EXT_NAME}${TARGET_POSTFIX} iidm-tests${TARGET_POSTFIX})

add_test(NAME ${EXT_NAME} COMMAND unit-tests-${EXT_NAME} -- --resources=${CMAKE_CURRENT_SOURCE_DIR}/resources)
endif()
Expand Down
33 changes: 32 additions & 1 deletion extensions/entsoe/test/entsoe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,45 @@
#define BOOST_TEST_MODULE entsoe
#include <boost/test/unit_test.hpp>

#include <powsybl/iidm/ExtensionProviders.hpp>
#include <powsybl/iidm/converter/xml/ExtensionXmlSerializer.hpp>
#include <powsybl/iidm/extensions/entsoe/EntsoeAreaXmlSerializer.hpp>
#include <powsybl/iidm/extensions/entsoe/MergedXnodeXmlSerializer.hpp>
#include <powsybl/iidm/extensions/entsoe/XnodeXmlSerializer.hpp>
#include <powsybl/test/ExtensionFixture.hpp>
#include <powsybl/test/XmlFixture.hpp>

namespace xml = powsybl::iidm::converter::xml;
namespace ext = powsybl::iidm::extensions::entsoe;

namespace powsybl {

namespace test {

BOOST_TEST_GLOBAL_FIXTURE(ExtensionFixture);
class ExtensionFixtureEnstsoe : public ResourceFixture {
public:
ExtensionFixtureEnstsoe();

ExtensionFixtureEnstsoe(const ExtensionFixtureEnstsoe&) = default;

ExtensionFixtureEnstsoe(ExtensionFixtureEnstsoe&&) = default;

~ExtensionFixtureEnstsoe() = default;

ExtensionFixtureEnstsoe& operator=(const ExtensionFixtureEnstsoe&) = default;

ExtensionFixtureEnstsoe& operator=(ExtensionFixtureEnstsoe&&) = default;
};

ExtensionFixtureEnstsoe::ExtensionFixtureEnstsoe() {
for (auto& extension : powsybl::iidm::extensions::entsoe::create())
auto& extProvider = powsybl::iidm::ExtensionProviders<xml::ExtensionXmlSerializer>::getInstance();
extProvider.registerExtension(stdcxx::make_unique<ext::EntsoeAreaXmlSerializer>());
extProvider.registerExtension(stdcxx::make_unique<ext::MergedXnodeXmlSerializer>());
extProvider.registerExtension(stdcxx::make_unique<ext::XnodeXmlSerializer>());
}

BOOST_TEST_GLOBAL_FIXTURE(ExtensionFixtureEnstsoe);
BOOST_TEST_GLOBAL_FIXTURE(XmlFixture);

} // namespace test
Expand Down
16 changes: 7 additions & 9 deletions extensions/iidm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ set(UNIT_TEST_SOURCES
test/VoltagePerReactivePowerControlTest.cpp
)

if (BUILD_SHARED_EXTENSIONS)
if (BUILD_SHARED_LIBS)
# Shared library
add_library(${EXT_NAME} SHARED ${EXT_SOURCES})
set_target_properties(${EXT_NAME} PROPERTIES SOVERSION ${IIDM_SOVERSION} VERSION ${IIDM_VERSION} OUTPUT_NAME iidm-${EXT_NAME})
Expand All @@ -45,11 +45,7 @@ if (BUILD_SHARED_EXTENSIONS)
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)
if (BUILD_STATIC_LIBS AND NOT BUILD_SHARED_LIBS)
target_link_libraries(${EXT_NAME} PUBLIC iidm-static)
else ()
target_link_libraries(${EXT_NAME} PUBLIC iidm)
endif ()
target_link_libraries(${EXT_NAME} PUBLIC iidm)

# Installation
install(TARGETS ${EXT_NAME}
Expand All @@ -60,7 +56,7 @@ if (BUILD_SHARED_EXTENSIONS)
)
endif ()

if (BUILD_STATIC_EXTENSIONS)
if (BUILD_STATIC_LIBS)
# Static library
add_library(${EXT_NAME}-static STATIC ${EXT_SOURCES})
set_target_properties(${EXT_NAME}-static PROPERTIES OUTPUT_NAME iidm-${EXT_NAME})
Expand All @@ -84,8 +80,10 @@ endif ()
if (BUILD_TESTS)
# Unit tests
add_executable(unit-tests-${EXT_NAME} ${UNIT_TEST_SOURCES})
target_compile_definitions(unit-tests-${EXT_NAME} PRIVATE BOOST_TEST_DYN_LINK)
target_link_libraries(unit-tests-${EXT_NAME} PRIVATE ${EXT_NAME} iidm-tests)
if (BUILD_SHARED_LIBS)
target_compile_definitions(unit-tests-${EXT_NAME} PRIVATE BOOST_TEST_DYN_LINK)
endif ()
target_link_libraries(unit-tests-${EXT_NAME} PRIVATE ${EXT_NAME}${TARGET_POSTFIX} iidm-tests${TARGET_POSTFIX})

add_test(NAME ${EXT_NAME} COMMAND unit-tests-${EXT_NAME} -- --resources=${CMAKE_CURRENT_SOURCE_DIR}/resources)
endif()
Expand Down
36 changes: 35 additions & 1 deletion extensions/iidm/test/iidm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,48 @@
#define BOOST_TEST_MODULE iidm
#include <boost/test/unit_test.hpp>

#include <powsybl/iidm/ExtensionProviders.hpp>
#include <powsybl/iidm/converter/xml/ExtensionXmlSerializer.hpp>
#include <powsybl/iidm/extensions/iidm/ActivePowerControlXmlSerializer.hpp>
#include <powsybl/iidm/extensions/iidm/CoordinatedReactiveControlXmlSerializer.hpp>
#include <powsybl/iidm/extensions/iidm/ThreeWindingsTransformerPhaseAngleClockXmlSerializer.hpp>
#include <powsybl/iidm/extensions/iidm/TwoWindingsTransformerPhaseAngleClockXmlSerializer.hpp>
#include <powsybl/iidm/extensions/iidm/VoltagePerReactivePowerControlXmlSerializer.hpp>
#include <powsybl/test/ExtensionFixture.hpp>
#include <powsybl/test/XmlFixture.hpp>

namespace xml = powsybl::iidm::converter::xml;
namespace ext = powsybl::iidm::extensions::iidm;

namespace powsybl {

namespace test {

BOOST_TEST_GLOBAL_FIXTURE(ExtensionFixture);
class ExtensionFixtureIidm : public ResourceFixture {
public:
ExtensionFixtureIidm();

ExtensionFixtureIidm(const ExtensionFixtureIidm&) = default;

ExtensionFixtureIidm(ExtensionFixtureIidm&&) = default;

~ExtensionFixtureIidm() = default;

ExtensionFixtureIidm& operator=(const ExtensionFixtureIidm&) = default;

ExtensionFixtureIidm& operator=(ExtensionFixtureIidm&&) = default;
};

ExtensionFixtureIidm::ExtensionFixtureIidm() {
auto& extProvider = powsybl::iidm::ExtensionProviders<xml::ExtensionXmlSerializer>::getInstance();
extProvider.registerExtension(stdcxx::make_unique<ext::ActivePowerControlXmlSerializer>());
extProvider.registerExtension(stdcxx::make_unique<ext::CoordinatedReactiveControlXmlSerializer>());
extProvider.registerExtension(stdcxx::make_unique<ext::ThreeWindingsTransformerPhaseAngleClockXmlSerializer>());
extProvider.registerExtension(stdcxx::make_unique<ext::TwoWindingsTransformerPhaseAngleClockXmlSerializer>());
extProvider.registerExtension(stdcxx::make_unique<ext::VoltagePerReactivePowerControlXmlSerializer>());
}

BOOST_TEST_GLOBAL_FIXTURE(ExtensionFixtureIidm);
BOOST_TEST_GLOBAL_FIXTURE(XmlFixture);

} // namespace test
Expand Down
16 changes: 7 additions & 9 deletions extensions/sld/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ set(UNIT_TEST_SOURCES
test/sld.cpp
)

if (BUILD_SHARED_EXTENSIONS)
if (BUILD_SHARED_LIBS)
# Shared library
add_library(${EXT_NAME} SHARED ${EXT_SOURCES})
set_target_properties(${EXT_NAME} PROPERTIES SOVERSION ${IIDM_SOVERSION} VERSION ${IIDM_VERSION} OUTPUT_NAME iidm-${EXT_NAME})
Expand All @@ -33,11 +33,7 @@ if (BUILD_SHARED_EXTENSIONS)
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)
if (BUILD_STATIC_LIBS AND NOT BUILD_SHARED_LIBS)
target_link_libraries(${EXT_NAME} PUBLIC iidm-static)
else ()
target_link_libraries(${EXT_NAME} PUBLIC iidm)
endif ()
target_link_libraries(${EXT_NAME} PUBLIC iidm)

# Installation
install(TARGETS ${EXT_NAME}
Expand All @@ -48,7 +44,7 @@ if (BUILD_SHARED_EXTENSIONS)
)
endif ()

if (BUILD_STATIC_EXTENSIONS)
if (BUILD_STATIC_LIBS)
# Static library
add_library(${EXT_NAME}-static STATIC ${EXT_SOURCES})
set_target_properties(${EXT_NAME}-static PROPERTIES OUTPUT_NAME iidm-${EXT_NAME})
Expand All @@ -72,8 +68,10 @@ endif ()
if (BUILD_TESTS)
# Unit tests
add_executable(unit-tests-${EXT_NAME} ${UNIT_TEST_SOURCES})
target_compile_definitions(unit-tests-${EXT_NAME} PRIVATE BOOST_TEST_DYN_LINK)
target_link_libraries(unit-tests-${EXT_NAME} PRIVATE ${EXT_NAME} iidm-tests)
if (BUILD_SHARED_LIBS)
target_compile_definitions(unit-tests-${EXT_NAME} PRIVATE BOOST_TEST_DYN_LINK)
endif ()
target_link_libraries(unit-tests-${EXT_NAME} PRIVATE ${EXT_NAME}${TARGET_POSTFIX} iidm-tests${TARGET_POSTFIX})

add_test(NAME ${EXT_NAME} COMMAND unit-tests-${EXT_NAME} -- --resources=${CMAKE_CURRENT_SOURCE_DIR}/resources)
endif()
Expand Down
29 changes: 28 additions & 1 deletion extensions/sld/test/sld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,41 @@
#define BOOST_TEST_MODULE sld
#include <boost/test/unit_test.hpp>

#include <powsybl/iidm/ExtensionProviders.hpp>
#include <powsybl/iidm/extensions/sld/BusbarSectionPositionXmlSerializer.hpp>
#include <powsybl/iidm/extensions/sld/ConnectablePositionXmlSerializer.hpp>
#include <powsybl/test/ExtensionFixture.hpp>
#include <powsybl/test/XmlFixture.hpp>

namespace xml = powsybl::iidm::converter::xml;
namespace ext = powsybl::iidm::extensions::sld;

namespace powsybl {

namespace test {

BOOST_TEST_GLOBAL_FIXTURE(ExtensionFixture);
class ExtensionFixtureSld : public ResourceFixture {
public:
ExtensionFixtureSld();

ExtensionFixtureSld(const ExtensionFixtureSld&) = default;

ExtensionFixtureSld(ExtensionFixtureSld&&) = default;

~ExtensionFixtureSld() = default;

ExtensionFixtureSld& operator=(const ExtensionFixtureSld&) = default;

ExtensionFixtureSld& operator=(ExtensionFixtureSld&&) = default;
};

ExtensionFixtureSld::ExtensionFixtureSld() {
auto& extProvider = powsybl::iidm::ExtensionProviders<xml::ExtensionXmlSerializer>::getInstance();
extProvider.registerExtension(stdcxx::make_unique<ext::BusbarSectionPositionXmlSerializer>());
extProvider.registerExtension(stdcxx::make_unique<ext::ConnectablePositionXmlSerializer>());
}

BOOST_TEST_GLOBAL_FIXTURE(ExtensionFixtureSld);
BOOST_TEST_GLOBAL_FIXTURE(XmlFixture);

} // namespace test
Expand Down
6 changes: 4 additions & 2 deletions test/iidm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ set(UNIT_TEST_SOURCES
)

add_executable(unit-tests-iidm ${UNIT_TEST_SOURCES})
target_compile_definitions(unit-tests-iidm PRIVATE BOOST_TEST_DYN_LINK)
target_link_libraries(unit-tests-iidm PRIVATE iidm-tests)
if (BUILD_SHARED_LIBS)
target_compile_definitions(unit-tests-iidm PRIVATE BOOST_TEST_DYN_LINK)
endif ()
target_link_libraries(unit-tests-iidm PRIVATE iidm-tests${TARGET_POSTFIX})

add_test(NAME iidm COMMAND unit-tests-iidm -- --resources=${CMAKE_SOURCE_DIR}/test/resources)

Expand Down
Loading

0 comments on commit 7a7da82

Please sign in to comment.