forked from modelica/ModelicaStandardLibrary
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refs modelica#4093 Add CMake configuration to build external libs
- Loading branch information
Showing
7 changed files
with
372 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
cmake_minimum_required(VERSION 3.15) | ||
|
||
if(POLICY CMP0091) | ||
cmake_policy(SET CMP0091 NEW) | ||
if(WIN32) | ||
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>") | ||
endif() | ||
endif() | ||
|
||
project(Modelica_Standard_Library_Tables C) | ||
|
||
include(Modelica_platform.cmake) | ||
include(Modelica_utilities.cmake) | ||
|
||
set(MODELICA_RESOURCES_DIR "${PROJECT_SOURCE_DIR}/../..") | ||
get_filename_component(ABSOLUTE_MODELICA_RESOURCES_DIR "${MODELICA_RESOURCES_DIR}" ABSOLUTE) | ||
set(CMAKE_INSTALL_PREFIX "${ABSOLUTE_MODELICA_RESOURCES_DIR}" CACHE PATH "Library installation prefix path (don't change)" FORCE) | ||
|
||
get_modelica_platform_name_with_compiler_version(MODELICA_PLATFORM_NAME) | ||
set(CMAKE_INSTALL_LIBDIR "${CMAKE_INSTALL_PREFIX}/Library/${MODELICA_PLATFORM_NAME}" CACHE PATH "Library installation path (don't change)" FORCE) | ||
|
||
include(compiler_options.cmake) | ||
include(options.cmake) | ||
include(test.cmake) | ||
include(src.cmake) |
77 changes: 77 additions & 0 deletions
77
Modelica/Resources/BuildProjects/CMake/Modelica_platform.cmake
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# Determines the Modelica platform name of the current platform | ||
function(get_modelica_platform_name var) | ||
set(IS_64BIT_BUILD false) | ||
if(CMAKE_SIZEOF_VOID_P EQUAL 8) | ||
set(IS_64BIT_BUILD true) | ||
endif() | ||
if(APPLE) | ||
list(LENGTH CMAKE_OSX_ARCHITECTURES NUMBER_OF_OSX_ARCHITECTURES) | ||
if (NUMBER_OF_OSX_ARCHITECTURES EQUAL 0) | ||
if (CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64") | ||
set(PLATFORM_PATH_SUFFIX "darwin64") | ||
elseif (CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "arm64") | ||
set(PLATFORM_PATH_SUFFIX "aarch64-darwin") | ||
else() | ||
message(FATAL_ERROR "Unknown macOS architecture CMAKE_HOST_SYSTEM_PROCESSOR=${CMAKE_HOST_SYSTEM_PROCESSOR}.") | ||
endif() | ||
elseif(NUMBER_OF_OSX_ARCHITECTURES EQUAL 1) | ||
if (CMAKE_OSX_ARCHITECTURES STREQUAL "x86_64") | ||
set(PLATFORM_PATH_SUFFIX "darwin64") | ||
elseif (CMAKE_OSX_ARCHITECTURES STREQUAL "arm64") | ||
set(PLATFORM_PATH_SUFFIX "aarch64-darwin") | ||
else() | ||
message(FATAL_ERROR "Unknown macOS architecture CMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}.") | ||
endif() | ||
else() | ||
message(FATAL_ERROR "Universal builds not supported CMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}.") | ||
endif() | ||
elseif(UNIX) | ||
if(IS_64BIT_BUILD) | ||
set(PLATFORM_PATH_SUFFIX "linux64") | ||
else() | ||
set(PLATFORM_PATH_SUFFIX "linux32") | ||
endif() | ||
elseif(MSVC OR MINGW) | ||
if(IS_64BIT_BUILD) | ||
set(PLATFORM_PATH_SUFFIX "win64") | ||
else() | ||
set(PLATFORM_PATH_SUFFIX "win32") | ||
endif() | ||
else() | ||
message(FATAL_ERROR "Unsupported compiler environment") | ||
endif() | ||
|
||
message(STATUS "Building for Modelica platform ${PLATFORM_PATH_SUFFIX}") | ||
|
||
set(${var} ${PLATFORM_PATH_SUFFIX} PARENT_SCOPE) | ||
endfunction() | ||
|
||
# Determines the Modelica platform name of the current platform, including VS version | ||
function(get_modelica_platform_name_with_compiler_version var) | ||
|
||
get_modelica_platform_name(PLATFORM_PATH_SUFFIX) | ||
|
||
if(WIN32) | ||
if(MSVC_VERSION EQUAL 1400) | ||
set(PLATFORM_PATH_SUFFIX "${PLATFORM_PATH_SUFFIX}/vs2005") | ||
elseif(MSVC_VERSION EQUAL 1500) | ||
set(PLATFORM_PATH_SUFFIX "${PLATFORM_PATH_SUFFIX}/vs2008") | ||
elseif(MSVC_VERSION EQUAL 1600) | ||
set(PLATFORM_PATH_SUFFIX "${PLATFORM_PATH_SUFFIX}/vs2010") | ||
elseif(MSVC_VERSION EQUAL 1700) | ||
set(PLATFORM_PATH_SUFFIX "${PLATFORM_PATH_SUFFIX}/vs2012") | ||
elseif(MSVC_VERSION EQUAL 1800) | ||
set(PLATFORM_PATH_SUFFIX "${PLATFORM_PATH_SUFFIX}/vs2013") | ||
elseif(MSVC_VERSION EQUAL 1900) | ||
set(PLATFORM_PATH_SUFFIX "${PLATFORM_PATH_SUFFIX}/vs2015") | ||
elseif(MSVC_VERSION GREATER_EQUAL 1910 AND MSVC_VERSION LESS 1920) | ||
set(PLATFORM_PATH_SUFFIX "${PLATFORM_PATH_SUFFIX}/vs2017") | ||
elseif(MSVC_VERSION GREATER_EQUAL 1920 AND MSVC_VERSION LESS 1930) | ||
set(PLATFORM_PATH_SUFFIX "${PLATFORM_PATH_SUFFIX}/vs2019") | ||
elseif(MSVC_VERSION GREATER_EQUAL 1930 AND MSVC_VERSION LESS 1940) | ||
set(PLATFORM_PATH_SUFFIX "${PLATFORM_PATH_SUFFIX}/vs2022") | ||
endif() | ||
endif() | ||
|
||
set(${var} ${PLATFORM_PATH_SUFFIX} PARENT_SCOPE) | ||
endfunction() |
16 changes: 16 additions & 0 deletions
16
Modelica/Resources/BuildProjects/CMake/Modelica_utilities.cmake
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
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.") | ||
endif() | ||
endif() |
35 changes: 35 additions & 0 deletions
35
Modelica/Resources/BuildProjects/CMake/compiler_options.cmake
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
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) | ||
check_include_file("io.h" HAVE_IO_H) | ||
check_include_file("locale.h" HAVE_LOCALE_H) | ||
check_include_file("pthread.h" HAVE_PTHREAD_H) | ||
check_include_file("stdarg.h" HAVE_STDARG_H) | ||
check_include_file("time.h" HAVE_TIME_H) | ||
check_include_file("unistd.h" HAVE_UNISTD_H) | ||
check_include_file("winapifamily.h" HAVE_WINAPIFAMILY_H) | ||
|
||
include(CheckCSourceCompiles) | ||
check_c_source_compiles( | ||
" | ||
#include <stdlib.h> | ||
static void f(void) __attribute__ ((visibility(\"hidden\"))); | ||
int main(void) {return 0;} | ||
" | ||
HAVE_ATTRIBUTE_VISIBILITY_HIDDEN | ||
) | ||
if (HAVE_UNISTD_H) | ||
check_c_source_compiles( | ||
" | ||
#include <unistd.h> | ||
int main(void) {getpid(); return 0;} | ||
" | ||
HAVE_GETPID | ||
) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Option to trace time events | ||
option(MODELICA_DEBUG_TIME_EVENTS "Trace time events of CombiTimeTable" OFF) | ||
|
||
# Option to share table arrays | ||
option(MODELICA_SHARE_TABLE_DATA "Store shared table arrays (read from file) in a global hash table" ON) | ||
|
||
# Option to deep-copy table arrays | ||
option(MODELICA_COPY_TABLE_DATA "Deep-copy table arrays (passed as array)" ON) | ||
|
||
# Option to add a dummy function "usertab" | ||
option(MODELICA_DUMMY_FUNCTION_USERTAB "Add a dummy usertab function" OFF) | ||
|
||
# Option to build zlib from sources | ||
option(MODELICA_BUILD_ZLIB "Build zlib from sources in this project, otherwise provide ZLIB_INCLUDE_DIR" ON) | ||
|
||
# Option whether to install ModelicaExternalC | ||
option(MODELICA_INSTALL_EXTC "Install ModelicaExternalC library" OFF) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
if(NOT HAVE_LOCALE_H) | ||
add_definitions(-DNO_LOCALE) | ||
endif() | ||
if(NOT HAVE_PTHREAD_H AND NOT WIN32) | ||
add_definitions(-DNO_MUTEX) | ||
endif() | ||
if(HAVE_STDARG_H) | ||
add_definitions(-DHAVE_STDARG_H) | ||
endif() | ||
if(HAVE_UNISTD_H) | ||
add_definitions(-DHAVE_UNISTD_H) | ||
endif() | ||
if(NOT HAVE_DIRENT_H AND NOT WIN32) | ||
add_definitions(-DNO_FILE_SYSTEM) | ||
endif() | ||
if(NOT HAVE_TIME_H) | ||
add_definitions(-DNO_TIME) | ||
endif() | ||
if(HAVE_UNISTD_H AND NOT HAVE_GETPID) | ||
add_definitions(-DNO_PID) | ||
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} -Wno-attributes -fno-delete-null-pointer-checks") | ||
elseif(MSVC) | ||
add_definitions(-D_CRT_SECURE_NO_WARNINGS /W3) | ||
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.") | ||
endif() | ||
endif() | ||
|
||
set(EXTC_SOURCES | ||
"${MODELICA_RESOURCES_DIR}/C-Sources/ModelicaFFT.c" | ||
"${MODELICA_RESOURCES_DIR}/C-Sources/ModelicaFFT.h" | ||
"${MODELICA_RESOURCES_DIR}/C-Sources/ModelicaInternal.c" | ||
"${MODELICA_RESOURCES_DIR}/C-Sources/ModelicaInternal.h" | ||
"${MODELICA_RESOURCES_DIR}/C-Sources/ModelicaRandom.c" | ||
"${MODELICA_RESOURCES_DIR}/C-Sources/ModelicaRandom.h" | ||
"${MODELICA_RESOURCES_DIR}/C-Sources/ModelicaStrings.c" | ||
"${MODELICA_RESOURCES_DIR}/C-Sources/ModelicaStrings.h" | ||
"${MODELICA_RESOURCES_DIR}/C-Sources/gconstructor.h" | ||
"${MODELICA_RESOURCES_DIR}/C-Sources/stdint_msvc.h" | ||
"${MODELICA_RESOURCES_DIR}/C-Sources/stdint_wrap.h" | ||
"${MODELICA_RESOURCES_DIR}/C-Sources/uthash.h" | ||
"${MODELICA_RESOURCES_DIR}/C-Sources/win32_dirent.c" | ||
"${MODELICA_RESOURCES_DIR}/C-Sources/win32_dirent.h" | ||
"${MODELICA_UTILITIES_INCLUDE_DIR}/ModelicaUtilities.h" | ||
) | ||
|
||
set(TABLES_SOURCES | ||
"${MODELICA_RESOURCES_DIR}/C-Sources/ModelicaStandardTables.c" | ||
"${MODELICA_RESOURCES_DIR}/C-Sources/ModelicaStandardTables.h" | ||
"${MODELICA_RESOURCES_DIR}/C-Sources/ModelicaStandardTablesUsertab.c" | ||
"${MODELICA_RESOURCES_DIR}/C-Sources/ModelicaMatIO.h" | ||
"${MODELICA_RESOURCES_DIR}/C-Sources/gconstructor.h" | ||
"${MODELICA_RESOURCES_DIR}/C-Sources/stdint_msvc.h" | ||
"${MODELICA_RESOURCES_DIR}/C-Sources/stdint_wrap.h" | ||
"${MODELICA_RESOURCES_DIR}/C-Sources/uthash.h" | ||
"${MODELICA_UTILITIES_INCLUDE_DIR}/ModelicaUtilities.h" | ||
) | ||
|
||
set(MATIO_SOURCES | ||
"${MODELICA_RESOURCES_DIR}/C-Sources/ModelicaMatIO.c" | ||
"${MODELICA_RESOURCES_DIR}/C-Sources/ModelicaMatIO.h" | ||
"${MODELICA_RESOURCES_DIR}/C-Sources/read_data_impl.h" | ||
"${MODELICA_RESOURCES_DIR}/C-Sources/safe-math.h" | ||
"${MODELICA_RESOURCES_DIR}/C-Sources/snprintf.c" | ||
"${MODELICA_RESOURCES_DIR}/C-Sources/stdint_msvc.h" | ||
"${ZLIB_INCLUDE_DIR}/zlib.h" | ||
"${MODELICA_UTILITIES_INCLUDE_DIR}/ModelicaUtilities.h" | ||
) | ||
|
||
set(IO_SOURCES | ||
"${MODELICA_RESOURCES_DIR}/C-Sources/ModelicaIO.c" | ||
"${MODELICA_RESOURCES_DIR}/C-Sources/ModelicaIO.h" | ||
"${MODELICA_RESOURCES_DIR}/C-Sources/ModelicaMatIO.h" | ||
"${MODELICA_UTILITIES_INCLUDE_DIR}/ModelicaUtilities.h" | ||
) | ||
|
||
if(MODELICA_BUILD_ZLIB) | ||
file(GLOB ZLIB_SOURCES | ||
"${MODELICA_RESOURCES_DIR}/C-Sources/zlib/*.c" | ||
"${MODELICA_RESOURCES_DIR}/C-Sources/zlib/*.h" | ||
) | ||
endif() | ||
|
||
add_library(ModelicaExternalC STATIC ${EXTC_SOURCES}) | ||
add_library(ModelicaStandardTables STATIC ${TABLES_SOURCES}) | ||
add_library(ModelicaMatIO STATIC ${MATIO_SOURCES}) | ||
add_library(ModelicaIO STATIC ${IO_SOURCES}) | ||
|
||
if(MODELICA_BUILD_ZLIB) | ||
add_library(zlib STATIC ${ZLIB_SOURCES}) | ||
endif() | ||
|
||
if(MODELICA_DEBUG_TIME_EVENTS) | ||
target_compile_definitions(ModelicaStandardTables PRIVATE -DDEBUG_TIME_EVENTS=1) | ||
endif() | ||
if(MODELICA_SHARE_TABLE_DATA) | ||
target_compile_definitions(ModelicaStandardTables PRIVATE -DTABLE_SHARE=1) | ||
endif() | ||
if(NOT MODELICA_COPY_TABLE_DATA) | ||
target_compile_definitions(ModelicaStandardTables PRIVATE -DNO_TABLE_COPY=1) | ||
endif() | ||
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) AND NOT CYGWIN) | ||
target_compile_definitions(zlib PRIVATE -DWINAPI_FAMILY=100) | ||
endif() | ||
target_compile_definitions(ModelicaMatIO PRIVATE -DHAVE_ZLIB=1) | ||
if(MSVC) | ||
target_compile_options(ModelicaMatIO PRIVATE /wd4267) | ||
endif() | ||
|
||
install( | ||
TARGETS ModelicaStandardTables ModelicaMatIO ModelicaIO | ||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
) | ||
|
||
if(MODELICA_BUILD_ZLIB) | ||
install( | ||
TARGETS zlib | ||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
) | ||
endif() | ||
|
||
if(MODELICA_INSTALL_EXTC) | ||
install( | ||
TARGETS ModelicaExternalC | ||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
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) | ||
if(MODELICA_BUILD_ZLIB) | ||
target_link_libraries(Test${TEST} zlib) | ||
else() | ||
target_link_libraries(Test${TEST} z) | ||
endif() | ||
if(UNIX) | ||
target_link_libraries(Test${TEST} m) | ||
endif() | ||
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() |