Skip to content

Commit 22018b4

Browse files
adrimouritsharmenwierengaAabhasSrivastava
authored
All/feature/unst 9548 cpp setup for csumo_precice (#546)
* Set up first c++ project for csumo_precice * Changes in cmake to build cmake_precice * Add csumo_precice to tools_configuration * UNST-9548: Added: show up in Visual Studio * Add install rule for csumo_precice * UNST-9548: binary list: added: csumo_precice --------- Co-authored-by: Harmen Wierenga <harmen.wierenga@deltares.nl> Co-authored-by: Aabhas Srivastava <srivastava.aabhas@deltares.nl>
1 parent c0db091 commit 22018b4

File tree

11 files changed

+200
-0
lines changed

11 files changed

+200
-0
lines changed

ci/python/ci_tools/dimrset_delivery/all-testbench-binaries.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,10 @@
196196
"file": "bin\\d_hydro.exe",
197197
"issuedTo": "Stichting Deltares"
198198
},
199+
{
200+
"file": "bin\\csumo_precice.exe",
201+
"issuedTo": "Stichting Deltares"
202+
},
199203
{
200204
"file": "bin\\datsel.exe",
201205
"issuedTo": "Stichting Deltares"

ci/python/ci_tools/dimrset_delivery/fm-suite-binaries.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
"file": "bin\\dflowfm-cli.exe",
2525
"issuedTo": "Stichting Deltares"
2626
},
27+
{
28+
"file": "bin\\csumo_precice.exe",
29+
"issuedTo": "Stichting Deltares"
30+
},
2731
{
2832
"file": "bin\\dfmoutput.exe",
2933
"issuedTo": "Stichting Deltares"

src/cmake/configurations/miscellaneous/tools_configuration.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ if (NOT TARGET csumo_nfio)
7070
add_subdirectory(${checkout_src_root}/${csumo_nfio_module} csumo_nfio)
7171
endif()
7272

73+
# csumo_precice
74+
if (NOT TARGET csumo_precice)
75+
add_subdirectory(${checkout_src_root}/${csumo_precice_module} csumo_precice)
76+
endif()
77+
7378
# Third party
7479
# FLAP
7580
if(NOT TARGET FLAP)

src/cmake/configurations/miscellaneous/tools_delft3dfm_configuration.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,10 @@ if(NOT TARGET csumo_nfio)
3232
add_subdirectory(${checkout_src_root}/${csumo_nfio_module} csumo_nfio)
3333
endif()
3434

35+
# csumo_precice
36+
if(NOT TARGET csumo_precice)
37+
add_subdirectory(${checkout_src_root}/${csumo_precice_module} csumo_precice)
38+
endif()
39+
3540
# D-Waq tools
3641
include(${CMAKE_CURRENT_SOURCE_DIR}/configurations/components/dwaq/dwaq_tools.cmake)

src/cmake/modules/tools_gpl.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,6 @@ set(cosumo_bmi_module "${tools_gpl_path}/cosumo_bmi")
6666

6767
# csumo_nfio
6868
set(csumo_nfio_module "${tools_gpl_path}/csumo_nfio")
69+
70+
# csumo_precice
71+
set(csumo_precice_module "${tools_gpl_path}/csumo_precice")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build/**
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
cmake_minimum_required(VERSION 3.30)
2+
3+
set(CMAKE_CXX_STANDARD 23)
4+
set(CMAKE_CXX_EXTENSIONS OFF)
5+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
6+
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
7+
8+
project(
9+
csumo_precice
10+
VERSION 0.0.1
11+
DESCRIPTION "CSUMO wrapper for coupling through preCICE"
12+
LANGUAGES CXX
13+
)
14+
15+
include(cmake/PreventInSourceBuilds.cmake)
16+
include(cmake/CompilerWarnings.cmake)
17+
18+
add_subdirectory(src)
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# from here:
2+
#
3+
# https://github.com/lefticus/cppbestpractices/blob/master/02-Use_the_Tools_Available.md
4+
5+
function(
6+
set_compiler_warnings
7+
target_name
8+
MSVC_WARNINGS
9+
CLANG_WARNINGS
10+
INTEL_WARNINGS)
11+
if("${MSVC_WARNINGS}" STREQUAL "")
12+
set(MSVC_WARNINGS
13+
/W4 # Baseline reasonable warnings
14+
/w14242 # 'identifier': conversion from 'type1' to 'type2', possible loss of data
15+
/w14254 # 'operator': conversion from 'type1:field_bits' to 'type2:field_bits', possible loss of data
16+
/w14263 # 'function': member function does not override any base class virtual member function
17+
/w14265 # 'classname': class has virtual functions, but destructor is not virtual instances of this class may not
18+
# be destructed correctly
19+
/w14287 # 'operator': unsigned/negative constant mismatch
20+
/we4289 # nonstandard extension used: 'variable': loop control variable declared in the for-loop is used outside
21+
# the for-loop scope
22+
/w14296 # 'operator': expression is always 'boolean_value'
23+
/w14311 # 'variable': pointer truncation from 'type1' to 'type2'
24+
/w14545 # expression before comma evaluates to a function which is missing an argument list
25+
/w14546 # function call before comma missing argument list
26+
/w14547 # 'operator': operator before comma has no effect; expected operator with side-effect
27+
/w14549 # 'operator': operator before comma has no effect; did you intend 'operator'?
28+
/w14555 # expression has no effect; expected expression with side- effect
29+
/w14619 # pragma warning: there is no warning number 'number'
30+
/w14640 # Enable warning on thread un-safe static member initialization
31+
/w14826 # Conversion from 'type1' to 'type2' is sign-extended. This may cause unexpected runtime behavior.
32+
/w14905 # wide string literal cast to 'LPSTR'
33+
/w14906 # string literal cast to 'LPWSTR'
34+
/w14928 # illegal copy-initialization; more than one user-defined conversion has been implicitly applied
35+
/permissive- # standards conformance mode for MSVC compiler.
36+
/WX # Treat warnings as errors
37+
)
38+
endif()
39+
40+
if("${CLANG_WARNINGS}" STREQUAL "")
41+
set(CLANG_WARNINGS
42+
-Wall
43+
-Wextra # reasonable and standard
44+
-Wshadow # warn the user if a variable declaration shadows one from a parent context
45+
-Wnon-virtual-dtor # warn the user if a class with virtual functions has a non-virtual destructor. This helps
46+
# catch hard to track down memory errors
47+
-Wold-style-cast # warn for c-style casts
48+
-Wcast-align # warn for potential performance problem casts
49+
-Wunused # warn on anything being unused
50+
-Woverloaded-virtual # warn if you overload (not override) a virtual function
51+
-Wpedantic # warn if non-standard C++ is used
52+
-Wconversion # warn on type conversions that may lose data
53+
-Wsign-conversion # warn on sign conversions
54+
-Wnull-dereference # warn if a null dereference is detected
55+
-Wdouble-promotion # warn if float is implicit promoted to double
56+
-Wformat=2 # warn on security issues around functions that format output (ie printf)
57+
-Wimplicit-fallthrough # warn on statements that fallthrough without an explicit annotation
58+
-Werror # treat warnings as errors
59+
)
60+
endif()
61+
62+
if("${GCC_WARNINGS}" STREQUAL "")
63+
set(GCC_WARNINGS
64+
${CLANG_WARNINGS}
65+
-Wmisleading-indentation # warn if indentation implies blocks where blocks do not exist
66+
-Wduplicated-cond # warn if if / else chain has duplicated conditions
67+
-Wduplicated-branches # warn if if / else branches have duplicated code
68+
-Wlogical-op # warn about logical operations being used where bitwise were probably wanted
69+
-Wuseless-cast # warn if you perform a cast to the same type
70+
-Wsuggest-override # warn if an overridden member function is not marked 'override' or 'final'
71+
)
72+
endif()
73+
74+
if("${INTEL_WARNINGS}" STREQUAL "")
75+
if(WIN32)
76+
set(INTEL_WARNINGS
77+
/Wall
78+
/Wshadow # warn when a variable declaration hides a previous declaration
79+
/Wunused-variable # warn if a local or non-constant static variable is unused
80+
/Wunused-function # warn if a declared function is not used
81+
/Wformat # whether argument checking is enabled for calls to printf, scanf, and so forth
82+
/Werror-all # Treat all warnings as errors
83+
)
84+
else()
85+
set(INTEL_WARNINGS
86+
-Wall
87+
-Wshadow # warn when a variable declaration hides a previous declaration
88+
-Wunused-variable # warn if a local or non-constant static variable is unused
89+
-Wunused-function # warn if a declared function is not used
90+
-Woverloaded-virtual # warn if you overload (not override) a virtual function
91+
-Wformat # whether argument checking is enabled for calls to printf, scanf, and so forth
92+
-Werror-all # Treat all warnings as errors
93+
)
94+
endif()
95+
endif()
96+
97+
if(MSVC)
98+
set(PROJECT_WARNINGS_CXX ${MSVC_WARNINGS})
99+
elseif(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
100+
set(PROJECT_WARNINGS_CXX ${CLANG_WARNINGS})
101+
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
102+
set(PROJECT_WARNINGS_CXX ${GCC_WARNINGS})
103+
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM")
104+
set(PROJECT_WARNINGS_CXX ${INTEL_WARNINGS})
105+
else()
106+
message(AUTHOR_WARNING "No compiler warnings set for CXX compiler: '${CMAKE_CXX_COMPILER_ID}'")
107+
endif()
108+
109+
target_compile_options(
110+
${target_name}
111+
INTERFACE
112+
$<$<COMPILE_LANGUAGE:CXX>:${PROJECT_WARNINGS_CXX}>
113+
)
114+
endfunction()
115+
116+
add_library(compiler_warnings_settings INTERFACE)
117+
set_compiler_warnings(
118+
compiler_warnings_settings
119+
""
120+
""
121+
""
122+
)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#
2+
# This function will prevent in-source builds
3+
#
4+
function(myproject_assure_out_of_source_builds)
5+
# make sure the user doesn't play dirty with symlinks
6+
file(REAL_PATH "${CMAKE_SOURCE_DIR}" srcdir)
7+
file(REAL_PATH "${CMAKE_BINARY_DIR}" bindir)
8+
9+
# disallow in-source builds
10+
if("${srcdir}" STREQUAL "${bindir}")
11+
message("######################################################")
12+
message("Warning: in-source builds are disabled")
13+
message("Please create a separate build directory and run cmake from there")
14+
message("######################################################")
15+
message(FATAL_ERROR "Quitting configuration")
16+
endif()
17+
endfunction()
18+
19+
myproject_assure_out_of_source_builds()
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
set(source_files main.cpp)
2+
3+
add_executable(csumo_precice ${source_files})
4+
target_link_libraries(csumo_precice PRIVATE compiler_warnings_settings)
5+
target_include_directories(csumo_precice PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../include)
6+
7+
# Define how the files should be structured within Visual Studio
8+
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${source_files})
9+
set_target_properties (csumo_precice PROPERTIES FOLDER tools_gpl/csumo_precice)
10+
11+
install(TARGETS csumo_precice
12+
RUNTIME DESTINATION bin
13+
)

0 commit comments

Comments
 (0)