-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
154 lines (111 loc) · 5.28 KB
/
Copy pathCMakeLists.txt
File metadata and controls
154 lines (111 loc) · 5.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
cmake_minimum_required(VERSION 3.15)
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/VERSION.txt")
file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/VERSION.txt" VersionString NEWLINE_CONSUME)
string(STRIP "${VersionString}" VersionString)
set(LIBSBMLJS_DOTTED_VERSION ${VersionString})
string(REPLACE "." ";" VersionString "${VersionString}" )
string(REPLACE "-" ";" VersionString "${VersionString}" )
list(LENGTH VersionString versionLength)
list(GET VersionString 0 LIBSBMLJS_VERSION_MAJOR )
list(GET VersionString 1 LIBSBMLJS_VERSION_MINOR )
list(GET VersionString 2 LIBSBMLJS_VERSION_PATCH )
if(${versionLength} GREATER 3)
list(GET VersionString 3 LIBSBMLJS_VERSION_RELEASE )
endif()
endif()
# version number needs to be calculated correctly
MATH(EXPR LIBSBMLJS_VERSION_NUMERIC "${LIBSBMLJS_VERSION_MAJOR} * 10000 + ${LIBSBMLJS_VERSION_MINOR} * 100 + ${LIBSBMLJS_VERSION_PATCH}" )
project(LIBSBMLjs LANGUAGES CXX VERSION ${LIBSBMLJS_DOTTED_VERSION})
enable_testing()
set(CMAKE_CXX_STANDARD 17)
# Specify directory with dependencies
set(LIBSBMLJS_DEPENDENCY_DIR "dependencies" CACHE PATH "Directory with dependencies")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${LIBSBMLJS_DEPENDENCY_DIR}/share/LIBSBML/CMakeModules")
find_package(LIBSBML REQUIRED)
# Add library target
if (EMSCRIPTEN)
option(LIBSBMLJS_SINGLE_FILE "Build single js (on) or js + wasm (if off)" OFF)
set (LIBSBMLJS_ENVIRONMENT "node" CACHE STRING "Environment for which to build one of: web, node")
set (EXPORTED_FUNCTIONS "ccall,cwrap")
set (PRELOAD_FILE)
set (DATA_FILE)
#add_executable(LIBSBMLjs src/LIBSBMLjs.cpp src/LIBSBMLjs.h src/)
#target_link_libraries(LIBSBMLjs PUBLIC embind)
add_executable(sbml_utils src/sbml_utils.cpp src/)
target_link_libraries(sbml_utils PUBLIC embind)
set(CMAKE_EXECUTABLE_SUFFIX ".js")
set(LIBSBMLJS_OPT_FLAGS "-Os -sNO_DISABLE_EXCEPTION_CATCHING -fexceptions")
# set(LIBSBMLJS_OPT_FLAGS "-O3 -g -sASSERTIONS=2 -sNO_DISABLE_EXCEPTION_CATCHING -fexceptions")
set (WASM_FILE)
if (LIBSBMLJS_SINGLE_FILE)
set (SINGLE_FILE "-sSINGLE_FILE=1 ")
else()
set (WASM_FILE ${CMAKE_CURRENT_BINARY_DIR}/sbml_utils.wasm)
set (SINGLE_FILE "-sSINGLE_FILE=0 ")
endif()
set_target_properties(sbml_utils PROPERTIES COMPILE_FLAGS "${LIBSBMLJS_OPT_FLAGS}")
set_target_properties(sbml_utils PROPERTIES LINK_FLAGS "${LIBSBMLJS_OPT_FLAGS} -s ALLOW_MEMORY_GROWTH=1 -sENVIRONMENT=${LIBSBMLJS_ENVIRONMENT} ${SINGLE_FILE} -sEXPORT_ES6=0 -s WASM=1 -s MODULARIZE -s 'EXPORT_NAME=createCpsModule' --no-entry ${PRELOAD_FILE} -sEXPORTED_RUNTIME_METHODS=${EXPORTED_FUNCTIONS}")
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/sbml_utils.js
#${CMAKE_CURRENT_SOURCE_DIR}/js/LIBSBML.js
#${CMAKE_CURRENT_SOURCE_DIR}/js/LIBSBML.d.ts
${DATA_FILE}
${WASM_FILE}
DESTINATION ${CMAKE_INSTALL_PREFIX}
)
else()
#add_library(LIBSBMLjs src/LIBSBMLjs.cpp src/LIBSBMLjs.h src/)
endif()
# Add include directory from dependencies
target_include_directories(sbml_utils PRIVATE ${CMAKE_SOURCE_DIR}/src)
# Link dependencies
target_link_libraries(sbml_utils PUBLIC ${LIBSBML_LIBRARY})
if (NOT EMSCRIPTEN)
# compile a test executable
Include(FetchContent)
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.4.0 # or a later release
)
FetchContent_MakeAvailable(Catch2)
# These tests can use the Catch2-provided main
add_executable(LIBSBMLjs_test test/LIBSBMLjs_test.cpp)
target_include_directories(LIBSBMLjs_test PUBLIC ${LIBSBML_DEPENDENCY_DIR}/include)
target_include_directories(LIBSBMLjs_test PRIVATE ${CMAKE_SOURCE_DIR}/src)
target_link_libraries(LIBSBMLjs_test PRIVATE Catch2::Catch2WithMain LIBSBMLjs)
if (APPLE)
target_link_libraries(LIBSBMLjs_test PRIVATE "-framework CoreFoundation -framework Accelerate")
endif()
add_test(NAME LIBSBMLjs_test_run COMMAND LIBSBMLjs_test)
set_tests_properties(LIBSBMLjs_test_run PROPERTIES
ENVIRONMENT "srcdir=${CMAKE_CURRENT_SOURCE_DIR}/test"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
endif()
message(STATUS "
----------------------------------------------------------------------
LIBSBMLJS version ${LIBSBMLJS_DOTTED_VERSION}
----------------------------------------------------------------------
More information and the latest version are available online at
https://sbml.org
Please report problems using the issue tracker at
https://github.com/fbergmann/libsbml-utils.js/issues
Configured on host '${HOSTNAME}'
host type = ${CMAKE_SYSTEM_NAME}
host operating system = ${CMAKE_SYSTEM_NAME} ${CMAKE_SYSTEM_VERSION}
host CPU architecture = ${CMAKE_SYSTEM_PROCESSOR}
General build flags:
CC = ${CMAKE_C_COMPILER}
CXX = ${CMAKE_CXX_COMPILER}
CPPFLAGS = ${BUILD_DEFINITIONS}
CFLAGS = ${CMAKE_C_FLAGS}
CXXFLAGS = ${CMAKE_CXX_FLAGS}
LDFLAGS = ${CMAKE_EXE_LINKER_FLAGS}
Dependencies directory = ${LIBSBMLJS_DEPENDENCY_DIR}
LibSBML = ${LIBSBML_VERSION}
Other libSBML configuration settings:
Installation $prefix = ${CMAKE_INSTALL_PREFIX}
")