Skip to content

Commit

Permalink
Maintenance / Minor changes (JSBSim-Team#1031)
Browse files Browse the repository at this point in the history
* Group `WIN32` conditions in `python/CMakeLists.txt`.

* Avoid duplicating source files in the Python source dir.

* Make the compiler stop complaining about hidden overloaded methods.

* Make the compiler stop complaining about missing `override` keywords.

* Replace calls to `sprintf` by `snprintf` which is safer.
  • Loading branch information
bcoconni authored Feb 5, 2024
1 parent 6f0c4d8 commit 853480d
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 46 deletions.
39 changes: 21 additions & 18 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ set(JSBSIM_PYX ${CMAKE_CURRENT_BINARY_DIR}/_jsbsim.pyx)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/jsbsim.pyx.in ${JSBSIM_PYX})
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/jsbsim.pxd ${CMAKE_CURRENT_BINARY_DIR}/_jsbsim.pxd COPYONLY)
set_source_files_properties(${JSBSIM_PYX} PROPERTIES CYTHON_IS_CXX TRUE
INCLUDE_DIRECTORIES ${PROJECT_SOURCE_DIR}/src)
INCLUDE_DIRECTORIES ${PROJECT_SOURCE_DIR}/src)

# Autogenerate the Python module doc strings from Doxygen docs
if(DOXYGEN_FOUND AND BUILD_DOCS)
Expand Down Expand Up @@ -79,11 +79,12 @@ foreach(OBJECT ${libJSBSim_SOURCE_FILES})
if(${OBJECT} MATCHES "TARGET_OBJECTS:([^ >]+)")
get_target_property(TARGET_SOURCE_FILES ${CMAKE_MATCH_1} SOURCES)
get_target_property(TARGET_SOURCE_DIRECTORY ${CMAKE_MATCH_1} TARGET_DIRECTORY)
file(RELATIVE_PATH TARGET_PATH ${PROJECT_SOURCE_DIR} ${TARGET_SOURCE_DIRECTORY})
file(RELATIVE_PATH TARGET_RELATIVE_PATH ${PROJECT_SOURCE_DIR} ${TARGET_SOURCE_DIRECTORY})
set(TARGET_PATH ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_RELATIVE_PATH})
file(MAKE_DIRECTORY ${TARGET_PATH})
foreach(_FILE ${TARGET_SOURCE_FILES})
configure_file(${TARGET_SOURCE_DIRECTORY}/${_FILE} ${TARGET_PATH}/${_FILE} COPYONLY)
list(APPEND SOURCE_FILES ${TARGET_PATH}/${_FILE})
list(APPEND SOURCE_FILES ${TARGET_RELATIVE_PATH}/${_FILE})
endforeach()
else()
configure_file(${libJSBSim_DIRECTORY}/${OBJECT} ${libJSBSim_PATH}/${OBJECT} COPYONLY)
Expand All @@ -109,24 +110,26 @@ target_include_directories(_jsbsim PRIVATE ${PROJECT_SOURCE_DIR}/src)
target_link_libraries(_jsbsim PRIVATE libJSBSim)
set_target_properties(_jsbsim PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${JSBSIM_TEST_PACKAGE_DIR})

# Output directories for MSVC
set_target_properties(_jsbsim PROPERTIES LIBRARY_OUTPUT_DIRECTORY_DEBUG ${JSBSIM_TEST_PACKAGE_DIR})
set_target_properties(_jsbsim PROPERTIES LIBRARY_OUTPUT_DIRECTORY_RELEASE ${JSBSIM_TEST_PACKAGE_DIR})
set_target_properties(_jsbsim PROPERTIES LIBRARY_OUTPUT_DIRECTORY_MINSIZEREL ${JSBSIM_TEST_PACKAGE_DIR})
set_target_properties(_jsbsim PROPERTIES LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO ${JSBSIM_TEST_PACKAGE_DIR})
if(WIN32)
# Output directories for MSVC
set_target_properties(_jsbsim PROPERTIES LIBRARY_OUTPUT_DIRECTORY_DEBUG ${JSBSIM_TEST_PACKAGE_DIR})
set_target_properties(_jsbsim PROPERTIES LIBRARY_OUTPUT_DIRECTORY_RELEASE ${JSBSIM_TEST_PACKAGE_DIR})
set_target_properties(_jsbsim PROPERTIES LIBRARY_OUTPUT_DIRECTORY_MINSIZEREL ${JSBSIM_TEST_PACKAGE_DIR})
set_target_properties(_jsbsim PROPERTIES LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO ${JSBSIM_TEST_PACKAGE_DIR})

# Windows needs the DLL to be copied locally for unit tests to run.
if(BUILD_SHARED_LIBS)
add_custom_command(OUTPUT ${JSBSIM_TEST_PACKAGE_DIR}/JSBSim.dll
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:libJSBSim>
${JSBSIM_TEST_PACKAGE_DIR})
add_custom_target(CopyJSBSimDLL ALL DEPENDS ${JSBSIM_TEST_PACKAGE_DIR}/JSBSim.dll)
add_dependencies(CopyJSBSimDLL libJSBSim)
endif(BUILD_SHARED_LIBS)
endif(WIN32)

add_subdirectory(fpectl)

# Windows needs the DLL to be copied locally for unit tests to run.
if(WIN32 AND BUILD_SHARED_LIBS)
add_custom_command(OUTPUT ${JSBSIM_TEST_PACKAGE_DIR}/JSBSim.dll
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:libJSBSim>
${JSBSIM_TEST_PACKAGE_DIR})
add_custom_target(CopyJSBSimDLL ALL DEPENDS ${JSBSIM_TEST_PACKAGE_DIR}/JSBSim.dll)
add_dependencies(CopyJSBSimDLL libJSBSim)
endif(WIN32 AND BUILD_SHARED_LIBS)

# Install the JSBSim Python module
if (INSTALL_JSBSIM_PYTHON_MODULE)
execute_process(COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/findInstallDir.py OUTPUT_VARIABLE PYTHON_INSTALL_DIR)
Expand Down
4 changes: 2 additions & 2 deletions src/input_output/FGOutputType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ bool FGOutputType::InitModel(void)

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

bool FGOutputType::Run(void)
bool FGOutputType::Run(bool Holding)
{
if (FGModel::Run(false)) return true;
if (FGModel::Run(Holding)) return true;
if (!enabled) return true;

RunPreFunctions();
Expand Down
10 changes: 6 additions & 4 deletions src/input_output/FGOutputType.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,14 @@ class FGOutputType : public FGModel
bool InitModel(void) override;

/** Executes the output directives (implement the FGModel interface).
This method checks that the current time step matches the output
rate and calls the registered "pre" functions, the output
generation and finally the "post" functions.
This method checks that the current time step matches the output rate and
calls the registered "pre" functions, the output generation and finally
the "post" functions.
@param Holding if true, the executive has been directed to hold the sim
from advancing time.
@result false if no error.
*/
bool Run(void);
bool Run(bool Holding) override;

/** Generate the output. This is a pure method so it must be implemented by
the classes that inherits from FGOutputType. The Print name may not be
Expand Down
7 changes: 5 additions & 2 deletions src/math/FGTemplateFunc.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,11 @@ class FGTemplateFunc : public FGFunction
}

private:
/** FGTemplateFunc must not be bound to the property manager. The bind method
is therefore made private and overloaded as a no-op */
/* Direct calls to FGFunction::GetValue are meaningless from the public interface.
The method is therefore made private. */
using FGFunction::GetValue;
/* FGTemplateFunc must not be bound to the property manager. The bind method
is therefore made private and overloaded as a no-op */
void bind(Element*, const std::string&) override {}
FGPropertyValue_ptr var;
};
Expand Down
2 changes: 1 addition & 1 deletion src/models/FGOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ bool FGOutput::Run(bool Holding)
if (!enabled) return true;

for (auto output: OutputTypes)
output->Run();
output->Run(Holding);

return false;
}
Expand Down
24 changes: 12 additions & 12 deletions src/simgear/props/props.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ find_node (SGPropertyNode * current,
using namespace boost;
typedef split_iterator<typename range_result_iterator<Range>::type>
PathSplitIterator;

PathSplitIterator itr
= make_split_iterator(path, first_finder("/", is_equal()));
if (*path.begin() == '/')
Expand Down Expand Up @@ -878,7 +878,7 @@ SGPropertyNode::SGPropertyNode (const SGPropertyNode &node)
}
switch (_type) {
case props::BOOL:
set_bool(node.get_bool());
set_bool(node.get_bool());
break;
case props::INT:
set_int(node.get_int());
Expand Down Expand Up @@ -1305,7 +1305,7 @@ SGPropertyNode::getType () const
}


bool
bool
SGPropertyNode::getBoolValue () const
{
// Shortcut for common case
Expand Down Expand Up @@ -1338,7 +1338,7 @@ SGPropertyNode::getBoolValue () const
}
}

int
int
SGPropertyNode::getIntValue () const
{
// Shortcut for common case
Expand Down Expand Up @@ -1371,7 +1371,7 @@ SGPropertyNode::getIntValue () const
}
}

long
long
SGPropertyNode::getLongValue () const
{
// Shortcut for common case
Expand Down Expand Up @@ -1404,7 +1404,7 @@ SGPropertyNode::getLongValue () const
}
}

float
float
SGPropertyNode::getFloatValue () const
{
// Shortcut for common case
Expand Down Expand Up @@ -1437,7 +1437,7 @@ SGPropertyNode::getFloatValue () const
}
}

double
double
SGPropertyNode::getDoubleValue () const
{
// Shortcut for common case
Expand Down Expand Up @@ -1570,7 +1570,7 @@ SGPropertyNode::setIntValue (int value)
case props::STRING:
case props::UNSPECIFIED: {
char buf[128];
sprintf(buf, "%d", value);
snprintf(buf, 128, "%d", value);
result = set_string(buf);
break;
}
Expand Down Expand Up @@ -1621,7 +1621,7 @@ SGPropertyNode::setLongValue (long value)
case props::STRING:
case props::UNSPECIFIED: {
char buf[128];
sprintf(buf, "%ld", value);
snprintf(buf, 128, "%ld", value);
result = set_string(buf);
break;
}
Expand Down Expand Up @@ -1672,7 +1672,7 @@ SGPropertyNode::setFloatValue (float value)
case props::STRING:
case props::UNSPECIFIED: {
char buf[128];
sprintf(buf, "%f", value);
snprintf(buf, 128, "%f", value);
result = set_string(buf);
break;
}
Expand Down Expand Up @@ -1723,7 +1723,7 @@ SGPropertyNode::setDoubleValue (double value)
case props::STRING:
case props::UNSPECIFIED: {
char buf[128];
sprintf(buf, "%f", value);
snprintf(buf, 128, "%f", value);
result = set_string(buf);
break;
}
Expand Down Expand Up @@ -2558,7 +2558,7 @@ template<>
std::ostream& SGRawBase<SGVec4d>::printOn(std::ostream& stream) const
{
const SGVec4d vec
= static_cast<const SGRawValue<SGVec4d>*>(this)->getValue();
= static_cast<const SGRawValue<SGVec4d>*>(this)->getValue();
for (int i = 0; i < 4; ++i) {
stream << vec[i];
if (i < 3)
Expand Down
7 changes: 3 additions & 4 deletions utils/aeromatic++/Systems/Controls.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class YawDamper : public System
void set(const float cg_loc[3]) override {
_control->set(cg_loc);
}
std::string system();
std::string system() override;

std::string lift() override {
return _control->lift();
Expand Down Expand Up @@ -111,7 +111,7 @@ class FlyByWire : public System
void set(const float cg_loc[3]) override {
_control->set(cg_loc);
}
std::string system();
std::string system() override;

std::string lift() override {
return _control->lift();
Expand Down Expand Up @@ -146,7 +146,7 @@ class Controls : public System
void set(const float cg_loc[3]) override {
_control[_ctype]->set(cg_loc);
}
std::string comment();
std::string comment() override;
std::string fdm() override {
return _control[_ctype]->fdm();
}
Expand Down Expand Up @@ -205,4 +205,3 @@ class Controls : public System
} /* namespace Aeromatic */

#endif /* __CONTROLS_H */

5 changes: 2 additions & 3 deletions utils/aeromatic++/Systems/Propulsion.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ class Propulsion : public Engine
return _propulsion[_ptype]->_thruster->thruster();
}

void param_reset();
Param* param_next();
void param_reset() override;
Param* param_next() override;

char _engine_name[PARAM_MAX_STRING+1] = "";
public:
Expand Down Expand Up @@ -242,4 +242,3 @@ class Propulsion : public Engine
} // namespace Aeromatic

#endif /* __ENGINE_H */

0 comments on commit 853480d

Please sign in to comment.