Skip to content

Commit

Permalink
refs modelica#4093 Also add support for unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
beutlich committed Jan 29, 2024
1 parent 75efa2c commit d78e36f
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 8 deletions.
1 change: 1 addition & 0 deletions Modelica/Resources/BuildProjects/CMake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ set(CMAKE_INSTALL_LIBDIR "${CMAKE_INSTALL_PREFIX}/Library/${MODELICA_PLATFORM_NA

include(compiler_options.cmake)
include(options.cmake)
include(test.cmake)
include(src.cmake)
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
if(DEFINED MODELICA_UTILITIES_INCLUDE_DIR)
if(NOT MODELICA_UTILITIES_INCLUDE_DIR STREQUAL "")
file(TO_CMAKE_PATH ${MODELICA_UTILITIES_INCLUDE_DIR} MODELICA_UTILITIES_INCLUDE_DIR)
include_directories(${MODELICA_UTILITIES_INCLUDE_DIR})
else()
message(FATAL_ERROR "MODELICA_UTILITIES_INCLUDE_DIR is an empty string.")
endif()
else()
set(MODELICA_UTILITIES_INCLUDE_DIR "" CACHE PATH "Include directory of the (tool-vendor specific) ModelicaUtilities.h header file")
if(NOT MODELICA_UTILITIES_INCLUDE_DIR STREQUAL "")
file(TO_CMAKE_PATH ${MODELICA_UTILITIES_INCLUDE_DIR} MODELICA_UTILITIES_INCLUDE_DIR)
include_directories(${MODELICA_UTILITIES_INCLUDE_DIR})
else()
message(FATAL_ERROR "MODELICA_UTILITIES_INCLUDE_DIR is an empty string.")
Expand Down
4 changes: 4 additions & 0 deletions Modelica/Resources/BuildProjects/CMake/compiler_options.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
include(CheckSymbolExists)
check_symbol_exists(memcpy "string.h" HAVE_MEMCPY)
check_symbol_exists(fseeko "stdio.h" HAVE_FSEEKO)
check_symbol_exists(ftello "stdio.h" HAVE_FTELLO)
check_symbol_exists(fseeko64 "stdio.h" HAVE_FSEEKO64)
check_symbol_exists(ftello64 "stdio.h" HAVE_FTELLO64)

include(CheckIncludeFile)
check_include_file("dirent.h" HAVE_DIRENT_H)
Expand Down
31 changes: 23 additions & 8 deletions Modelica/Resources/BuildProjects/CMake/src.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ endif()
if(HAVE_MEMCPY)
add_definitions(-DHAVE_MEMCPY)
endif()
if(HAVE_FSEEKO)
add_definitions(-DHAVE_FSEEKO)
endif()
if(HAVE_FTELLO)
add_definitions(-DHAVE_FTELLO)
endif()
if(HAVE_FSEEKO64)
add_definitions(-DHAVE_FSEEKO64)
endif()
if(HAVE_FTELLO64)
add_definitions(-DHAVE_FTELLO64)
endif()

if(UNIX)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -Wno-attributes -fno-delete-null-pointer-checks")
Expand All @@ -31,16 +43,19 @@ endif()

if(MODELICA_BUILD_ZLIB)
set(ZLIB_INCLUDE_DIR "${MODELICA_RESOURCES_DIR}/C-Sources/zlib")
file(TO_CMAKE_PATH ${ZLIB_INCLUDE_DIR} ZLIB_INCLUDE_DIR)
include_directories(${ZLIB_INCLUDE_DIR})
elseif(DEFINED ZLIB_INCLUDE_DIR)
if(NOT ZLIB_INCLUDE_DIR STREQUAL "")
file(TO_CMAKE_PATH ${ZLIB_INCLUDE_DIR} ZLIB_INCLUDE_DIR)
include_directories(${ZLIB_INCLUDE_DIR})
else()
message(FATAL_ERROR "ZLIB_INCLUDE_DIR is an empty string.")
endif()
else()
set(ZLIB_INCLUDE_DIR "" CACHE PATH "Include directory of the zlib.h header file")
if(NOT ZLIB_INCLUDE_DIR STREQUAL "")
file(TO_CMAKE_PATH ${ZLIB_INCLUDE_DIR} ZLIB_INCLUDE_DIR)
include_directories(${ZLIB_INCLUDE_DIR})
else()
message(FATAL_ERROR "ZLIB_INCLUDE_DIR is an empty string.")
Expand Down Expand Up @@ -112,23 +127,23 @@ if(MODELICA_BUILD_ZLIB)
endif()

if(MODELICA_DEBUG_TIME_EVENTS)
target_compile_definitions(ModelicaStandardTables PUBLIC -DDEBUG_TIME_EVENTS=1)
target_compile_definitions(ModelicaStandardTables PRIVATE -DDEBUG_TIME_EVENTS=1)
endif()
if(MODELICA_SHARE_TABLE_DATA)
target_compile_definitions(ModelicaStandardTables PUBLIC -DTABLE_SHARE=1)
target_compile_definitions(ModelicaStandardTables PRIVATE -DTABLE_SHARE=1)
endif()
if(NOT MODELICA_COPY_TABLE_DATA)
target_compile_definitions(ModelicaStandardTables PUBLIC -DNO_TABLE_COPY=1)
target_compile_definitions(ModelicaStandardTables PRIVATE -DNO_TABLE_COPY=1)
endif()
if(MODELICA_DUMMY_FUNCTION_USERTAB)
target_compile_definitions(ModelicaStandardTables PUBLIC -DDUMMY_FUNCTION_USERTAB=1)
if(MODELICA_DUMMY_FUNCTION_USERTAB OR BUILD_TESTING)
target_compile_definitions(ModelicaStandardTables PRIVATE -DDUMMY_FUNCTION_USERTAB=1)
endif()
if(MODELICA_BUILD_ZLIB AND (HAVE_WINAPIFAMILY_H OR HAVE_IO_H))
target_compile_definitions(zlib PUBLIC -DWINAPI_FAMILY=100)
target_compile_definitions(zlib PRIVATE -DWINAPI_FAMILY=100)
endif()
target_compile_definitions(ModelicaMatIO PUBLIC -DHAVE_ZLIB=1)
target_compile_definitions(ModelicaMatIO PRIVATE -DHAVE_ZLIB=1)
if(MSVC)
target_compile_options(ModelicaMatIO PUBLIC /wd4267)
target_compile_options(ModelicaMatIO PRIVATE /wd4267)
endif()

install(
Expand Down
28 changes: 28 additions & 0 deletions Modelica/Resources/BuildProjects/CMake/test.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
include(CTest)

if(BUILD_TESTING)
set(MODELICA_TEST_SOURCE_DIR "${PROJECT_SOURCE_DIR}/../../../../.CI/Test")
get_filename_component(ABSOLUTE_MODELICA_TEST_SOURCE_DIR "${MODELICA_TEST_SOURCE_DIR}" ABSOLUTE)
if(EXISTS "${ABSOLUTE_MODELICA_TEST_SOURCE_DIR}")
set(MODELICA_TESTS
FileSystem
ModelicaStrings
Streams
Tables
TablesFromCsvFile
TablesFromMatFile
TablesFromTxtFile
TablesNoUsertab
)
foreach(TEST ${MODELICA_TESTS})
add_executable(Test${TEST} "${ABSOLUTE_MODELICA_TEST_SOURCE_DIR}/${TEST}.c")
target_link_libraries(Test${TEST} ModelicaExternalC ModelicaStandardTables ModelicaIO ModelicaMatIO zlib)
add_test(NAME Test${TEST} COMMAND Test${TEST} WORKING_DIRECTORY "${ABSOLUTE_MODELICA_TEST_SOURCE_DIR}")
endforeach()
else()
message(WARNING
" Testsuite not found in \"${ABSOLUTE_MODELICA_TEST_SOURCE_DIR}\"."
" Set BUILD_TESTING to OFF to silence this warning."
)
endif()
endif()

0 comments on commit d78e36f

Please sign in to comment.