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

Improve C and CPP API target structure #741

Merged
merged 4 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
21 changes: 7 additions & 14 deletions power_grid_model_c/power_grid_model_c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,21 @@ target_include_directories(power_grid_model_c PUBLIC
$<INSTALL_INTERFACE:include>
)

set(PGM_PUBLIC_HEADERS
"${CMAKE_CURRENT_SOURCE_DIR}/include/power_grid_model_c/basics.h"
"${CMAKE_CURRENT_SOURCE_DIR}/include/power_grid_model_c/buffer.h"
"${CMAKE_CURRENT_SOURCE_DIR}/include/power_grid_model_c/handle.h"
"${CMAKE_CURRENT_SOURCE_DIR}/include/power_grid_model_c/meta_data.h"
"${CMAKE_CURRENT_SOURCE_DIR}/include/power_grid_model_c/model.h"
"${CMAKE_CURRENT_SOURCE_DIR}/include/power_grid_model_c/options.h"
"${CMAKE_CURRENT_SOURCE_DIR}/include/power_grid_model_c/dataset_definitions.h"
"${CMAKE_CURRENT_SOURCE_DIR}/include/power_grid_model_c/serialization.h"
"${CMAKE_CURRENT_SOURCE_DIR}/include/power_grid_model_c/dataset.h"
"${CMAKE_CURRENT_SOURCE_DIR}/include/power_grid_model_c.h"
file(
GLOB_RECURSE
pgm_c_public_headers
"${CMAKE_CURRENT_SOURCE_DIR}/include/*.h"
)

target_link_libraries(power_grid_model_c
PRIVATE power_grid_model
)

target_sources(power_grid_model_c PUBLIC
FILE_SET pgm_public_headers
FILE_SET pgm_c_public_headers
TYPE HEADERS
BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/include/"
FILES "${PGM_PUBLIC_HEADERS}"
FILES "${pgm_c_public_headers}"
)

set_target_properties(power_grid_model_c PROPERTIES
Expand All @@ -53,5 +46,5 @@ set_target_properties(power_grid_model_c PROPERTIES
install(TARGETS power_grid_model_c
EXPORT power_grid_modelTargets
COMPONENT power_grid_model
FILE_SET pgm_public_headers
FILE_SET pgm_c_public_headers
)
29 changes: 24 additions & 5 deletions power_grid_model_c/power_grid_model_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,31 @@ target_include_directories(power_grid_model_cpp INTERFACE
$<INSTALL_INTERFACE:include>
)

file(
GLOB_RECURSE
pgm_cpp_public_headers
"${CMAKE_CURRENT_SOURCE_DIR}/include/*.hpp"
)

target_link_libraries(power_grid_model_cpp
INTERFACE power_grid_model_c
)
mgovers marked this conversation as resolved.
Show resolved Hide resolved

target_sources(power_grid_model_cpp PUBLIC
FILE_SET pgm_cpp_public_headers
TYPE HEADERS
BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/include/"
FILES "${pgm_cpp_public_headers}"
)

set_target_properties(power_grid_model_cpp PROPERTIES
VERSION ${PGM_VERSION}
SOVERSION ${PGM_VERSION}
)


install(TARGETS power_grid_model_cpp
EXPORT power_grid_modelTargets
COMPONENT power_grid_model
)

install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/
DESTINATION include
FILES_MATCHING PATTERN "*.hpp"
FILE_SET pgm_cpp_public_headers
)
6 changes: 6 additions & 0 deletions tests/native_api_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,10 @@ target_link_libraries(power_grid_model_api_tests
doctest::doctest
)

# TODO: remove this when the API becomes stable
target_compile_definitions(power_grid_model_api_tests
PRIVATE
PGM_ENABLE_EXPERIMENTAL
)

doctest_discover_tests(power_grid_model_api_tests)
2 changes: 0 additions & 2 deletions tests/native_api_tests/test_api_meta_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
//
// SPDX-License-Identifier: MPL-2.0

#define PGM_ENABLE_EXPERIMENTAL

#include "power_grid_model_cpp.hpp"

#include <doctest/doctest.h>
Expand Down
2 changes: 0 additions & 2 deletions tests/native_api_tests/test_api_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
//
// SPDX-License-Identifier: MPL-2.0

#define PGM_ENABLE_EXPERIMENTAL

#include "power_grid_model_cpp.hpp"

#include <power_grid_model_c/dataset_definitions.h>
Expand Down
2 changes: 0 additions & 2 deletions tests/native_api_tests/test_api_serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
//
// SPDX-License-Identifier: MPL-2.0

#define PGM_ENABLE_EXPERIMENTAL

#include "power_grid_model_cpp.hpp"

#include <power_grid_model_c/dataset_definitions.h>
Expand Down
4 changes: 4 additions & 0 deletions tests/package_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ set(PROJECT_SOURCES
# Link against shared power_grid_model object installed by main project
add_executable(power_grid_model_package_test ${PROJECT_SOURCES})
target_link_libraries(power_grid_model_package_test PRIVATE power_grid_model::power_grid_model_c)
target_link_libraries(power_grid_model_package_test PRIVATE power_grid_model::power_grid_model_cpp)
set_target_properties(power_grid_model_package_test PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE)

# TODO: remove this when the API becomes stable
target_compile_definitions(power_grid_model_package_test PRIVATE PGM_ENABLE_EXPERIMENTAL)

install(TARGETS power_grid_model_package_test)
install(IMPORTED_RUNTIME_ARTIFACTS power_grid_model::power_grid_model_c)
13 changes: 9 additions & 4 deletions tests/package_tests/test_c_api_package.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// SPDX-License-Identifier: MPL-2.0

#include "power_grid_model_c.h"
#include "power_grid_model_cpp.hpp"

#include <iostream>
#include <memory>
Expand All @@ -17,8 +18,12 @@ using HandlePtr = std::unique_ptr<PGM_Handle, DeleterFunctor<&PGM_destroy_handle
} // namespace

auto main() -> int {
// get handle
HandlePtr const unique_handle{PGM_create_handle()};
std::cout << (unique_handle ? "Handle created: API is available.\n" : "No handle could be created.\n");
return unique_handle ? 0 : 1;
// get handle from C-API
HandlePtr const c_handle{PGM_create_handle()};
std::cout << (c_handle ? "Handle created: C-API is available.\n" : "No handle could be created.\n");
// get handle from C++ API
power_grid_model_cpp::Handle const cpp_handle{};
std::cout << (cpp_handle.get() ? "Handle created: C++ API is available.\n" : "No handle could be created.\n");
int return_code = (c_handle != nullptr) && (cpp_handle.get() != nullptr) ? 0 : 1;
return return_code;
}
Loading