-
Notifications
You must be signed in to change notification settings - Fork 0
/
targets.cmake
143 lines (126 loc) · 5.44 KB
/
targets.cmake
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
# Dynamic library / shared object
add_library(gdxcclib64 SHARED ${gdx-core} generated/gdxcclib.cpp)
if (UNIX)
target_compile_options(gdxcclib64 PRIVATE -fvisibility=hidden)
endif ()
target_include_directories(gdxcclib64 PRIVATE ${inc-dirs})
if (APPLE)
set(cclib-link-options "-Bdynamic")
elseif (UNIX) # Linux
set(cclib-link-options "-Bdynamic -Wl,-Bsymbolic")
else () # Windows
set(cclib-link-options "")
endif ()
target_link_libraries(gdxcclib64 ${mylibs} ${cclib-link-options})
set_property(TARGET gdxcclib64 PROPERTY POSITION_INDEPENDENT_CODE ON)
# Check compilation of unused infrastructure units
set(BASE_ALL OFF CACHE BOOL "Check compilation of unused infrastructure units")
if(BASE_ALL)
add_library(base-units-all STATIC ${base-units-all})
target_include_directories(base-units-all PRIVATE ${inc-dirs})
endif()
# Static library
add_library(gdx-static STATIC ${gdx-core})
target_include_directories(gdx-static PRIVATE ${inc-dirs})
set_property(TARGET gdx-static PROPERTY POSITION_INDEPENDENT_CODE ON)
set(NO_TESTS OFF CACHE BOOL "Skip building unit tests")
if(NOT NO_TESTS)
# Unit test suite (against statically compiled GDX)
add_executable(gdxtest ${test-deps} ${tests})
target_include_directories(gdxtest PRIVATE ${inc-dirs})
target_link_libraries(gdxtest gdx-static ${mylibs})
# Unit test suite (against GDX dynamic library)
add_executable(gdxwraptest src/tests/doctestmain.cpp src/tests/gdxtests.cpp generated/gdxcc.c)
target_link_libraries(gdxwraptest ${mylibs})
target_include_directories(gdxwraptest PRIVATE src generated)
target_compile_options(gdxwraptest PRIVATE -DGXFILE_CPPWRAP -DGC_NO_MUTEX)
endif()
# Quickly run "include what you use" (https://include-what-you-use.org/) over project
#[[find_program(iwyu_path NAMES include-what-you-use iwyu REQUIRED)
set_property(TARGET gdxcclib64 PROPERTY CXX_INCLUDE_WHAT_YOU_USE ${iwyu_path})
set_property(TARGET gdxtest PROPERTY CXX_INCLUDE_WHAT_YOU_USE ${iwyu_path})]]
set(NO_EXAMPLES OFF CACHE BOOL "Skip building example programs/executables")
if(NOT NO_EXAMPLES)
# Standalone GDX example program 1
add_executable(xp_example1 ${gdx-core} src/examples/xp_example1.cpp)
target_include_directories(xp_example1 PRIVATE ${inc-dirs})
target_link_libraries(xp_example1 ${mylibs})
# Standalone GDX example program 2
add_executable(xp_example2 ${gdx-core} src/examples/xp_example2.cpp generated/optcc.c)
target_include_directories(xp_example2 PRIVATE ${inc-dirs})
target_link_libraries(xp_example2 ${mylibs})
# Standalone GDX example program 3 (associative "supply.demand" str -> double (level))
add_executable(xp_associative ${gdx-core} src/examples/xp_associative.cpp)
target_include_directories(xp_associative PRIVATE ${inc-dirs})
target_link_libraries(xp_associative ${mylibs})
# Standalone GDX example program 4 (associative {supply,demand} vector -> double (level))
add_executable(xp_associative_vec ${gdx-core} src/examples/xp_associative_vec.cpp)
target_include_directories(xp_associative_vec PRIVATE ${inc-dirs})
target_link_libraries(xp_associative_vec ${mylibs})
# Standalone GDX example program 5 (data write)
# Needs path to GAMS distribution in environment variable GAMSDIR
# (either directly or as first entry of semicolon separated list)
if (DEFINED ENV{GAMSDIR})
set(ENTRIES $ENV{GAMSDIR})
string(FIND "${ENTRIES}" ";" index)
if (index GREATER -1) # contains multiple semicolon separated entries
string(REPLACE ";" "\n" ENTRIES "${ENTRIES}")
string(REGEX MATCH "^([^\n]*)" FIRST_ENTRY "${ENTRIES}")
string(REPLACE "\\" "/" FIRST_ENTRY "${FIRST_ENTRY}")
set(cur-apifiles-path ${FIRST_ENTRY})
else () # just one entry
set(cur-apifiles-path ${ENTRIES})
endif ()
string(APPEND cur-apifiles-path "/apifiles/C/api/")
if (EXISTS ${cur-apifiles-path}gmdcc.c)
message(STATUS "Found expert-level API sources and headers in ${cur-apifiles-path}")
add_executable(xp_dataWrite ${gdx-core} src/examples/xp_dataWrite.cpp ${cur-apifiles-path}gmdcc.c)
target_include_directories(xp_dataWrite PRIVATE ${inc-dirs} ${cur-apifiles-path})
target_link_libraries(xp_dataWrite ${mylibs})
if (UNIX)
target_compile_options(xp_dataWrite PRIVATE -DGC_NO_MUTEX)
endif ()
endif ()
endif ()
endif()
set(NO_TOOLS OFF CACHE BOOL "Skip building GDX tools")
if(NOT NO_TOOLS)
# Library for gdxdump, gdxdiff and gdxmerge
add_library(gdxtools-library
generated/gdxcc.h
generated/gdxcc.c
src/tools/library/common.h
src/tools/library/common.cpp
src/tools/library/short_string.h
src/tools/library/short_string.cpp
src/tools/library/cmdpar.h
src/tools/library/cmdpar.cpp
${base-units-all}
)
target_include_directories(gdxtools-library PRIVATE ${inc-dirs})
target_link_libraries(gdxtools-library gdx-static)
if (UNIX)
target_link_libraries(gdxtools-library ${CMAKE_DL_LIBS})
endif ()
# gdxdump
add_executable(gdxdump
src/tools/gdxdump/gdxdump.h
src/tools/gdxdump/gdxdump.cpp
)
target_include_directories(gdxdump PRIVATE ${inc-dirs})
target_link_libraries(gdxdump gdxtools-library)
# gdxdiff
add_executable(gdxdiff
src/tools/gdxdiff/gdxdiff.h
src/tools/gdxdiff/gdxdiff.cpp
)
target_include_directories(gdxdiff PRIVATE ${inc-dirs})
target_link_libraries(gdxdiff gdxtools-library)
# gdxmerge
add_executable(gdxmerge
src/tools/gdxmerge/gdxmerge.h
src/tools/gdxmerge/gdxmerge.cpp
)
target_include_directories(gdxmerge PRIVATE ${inc-dirs})
target_link_libraries(gdxmerge gdxtools-library)
endif(NOT NO_TOOLS)