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

[BugFix] OpenFAST Registry on Windows #1618

Merged
merged 3 commits into from
Jun 9, 2023
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
2 changes: 2 additions & 0 deletions glue-codes/simulink/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ matlab_add_mex(
$<TARGET_FILE:icedynlib>
$<TARGET_FILE:icefloelib>
$<TARGET_FILE:ifwlib>
$<TARGET_FILE:maplib_fortran>
$<TARGET_FILE:maplib_c>
$<TARGET_FILE:maplib>
$<TARGET_FILE:moordynlib>
$<TARGET_FILE:orcaflexlib>
Expand Down
23 changes: 16 additions & 7 deletions modules/map/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,32 @@ endif()
file(GLOB MAP_CLIB_SOURCES src/*.c src/*.cc src/*/*.c src/*/*.cc)
file(GLOB MAP_C_HEADERS src/*.h src/*/*.h)

add_library(maplib
src/map.f90
src/MAP_Types.f90
add_library(maplib_fortran
src/MAP_Fortran_Types.f90
src/MAP_Types.f90
)
target_link_libraries(maplib_fortran nwtclibs)

add_library(maplib_c
${MAP_CLIB_SOURCES}
${MAP_C_HEADERS}
)
target_link_libraries(maplib nwtclibs)
target_include_directories(maplib PUBLIC
target_link_libraries(maplib_c nwtclibs)
target_include_directories(maplib_c PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/bstring>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/cminpack>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/lapack>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/simclist>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
)
set_target_properties(maplib PROPERTIES PUBLIC_HEADER src/MAP_Types.h)
set_target_properties(maplib_c PROPERTIES PUBLIC_HEADER src/MAP_Types.h)

add_library(maplib
src/map.f90
)
target_link_libraries(maplib maplib_fortran maplib_c)

install(TARGETS maplib
install(TARGETS maplib maplib_fortran maplib_c
EXPORT "${CMAKE_PROJECT_NAME}Libraries"
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
Expand Down
2 changes: 1 addition & 1 deletion modules/openfast-registry/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ add_executable(openfast_registry
src/registry.hpp
src/templates.hpp
)
set_property(TARGET openfast_registry PROPERTY CXX_STANDARD 17)
target_compile_features(openfast_registry PRIVATE cxx_std_11)

set_target_properties(openfast_registry PROPERTIES
RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/modules/openfast-registry
Expand Down
19 changes: 14 additions & 5 deletions modules/openfast-registry/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <fstream>
#include <filesystem>

#include "registry.hpp"
#include "templates.hpp"
Expand Down Expand Up @@ -113,6 +112,7 @@ int main(int argc, char *argv[])
bool is_template = arg.substr(1).compare("template") == 0;

output_template(module_name, module_nickname, output_force_template, is_template);
return EXIT_SUCCESS;
}
else if ((arg.compare("-h") == 0) || (arg.compare("/h") == 0))
{
Expand All @@ -124,9 +124,16 @@ int main(int argc, char *argv[])
// Set input file path
inp_file_path = arg;

// Add input file directory to list of directories to search
std::filesystem::path path(arg);
reg.include_dirs.push_back(path.parent_path());
// Replace backslashes with forward slashes in path
std::string path = std::regex_replace(arg, std::regex("\\\\"), "/");

// If path contains / remove everything after it
auto slash_index = path.find_last_of("/");
if (slash_index != std::string::npos)
path = path.substr(0, slash_index);

// Add input file directory to list of include directories
reg.include_dirs.push_back(path);
}
}

Expand Down Expand Up @@ -172,12 +179,14 @@ void output_template(std::string &module_name, std::string &module_nickname, boo
}

// Select file contents
auto contents = (is_template ? module_template : registry_template).substr(1);
auto contents = (is_template ? module_template : registry_template);

// Populate module name and module nickname
contents = std::regex_replace(contents, std::regex("ModuleName"), module_name);
contents = std::regex_replace(contents, std::regex("ModName"), module_nickname);

// Output contents to file
outfile << contents;

std::cerr << "Created " << (is_template ? "template" : "registry") << " file '" << fname << "'" << std::endl;
}
3 changes: 3 additions & 0 deletions modules/openfast-registry/src/registry.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#include <cstdlib>
#include <cctype>

#include "registry.hpp"

void Registry::gen_module_files(std::string const &out_dir)
Expand Down
3 changes: 1 addition & 2 deletions modules/openfast-registry/src/registry_gen_fortran.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <fstream>
#include <fstream>

#include "registry.hpp"
#include "templates.hpp"
Expand Down Expand Up @@ -75,7 +74,7 @@ void Registry::gen_fortran_module(const Module &mod, const std::string &out_dir)
}

// Write preamble
w << std::regex_replace(FAST_preamble.substr(1), std::regex("ModuleName"), mod.name);
w << std::regex_replace(FAST_preamble, std::regex("ModuleName"), mod.name);

// Output USE statements for non-root modules
for (auto const &mod : this->use_modules)
Expand Down
Loading