]> granicus.if.org Git - check/blob - src/CMakeLists.txt
f5e4af9eefec680fa8dab225a0dfe1aada5aae36
[check] / src / CMakeLists.txt
1 #
2 # Check: a unit test framework for C
3 # Copyright (C) 2011 Mateusz Loskot
4 # Copyright (C) 2001, 2002 Arien Malec
5 #
6 # This library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License, or (at your option) any later version.
10 #
11 # This library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 # Lesser General Public License for more details.
15 #
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with this library; if not, write to the
18 # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 # Boston, MA 02111-1307, USA.
20 #
21
22 set(SOURCES
23   check.c
24   check_error.c
25   check_list.c
26   check_log.c
27   check_msg.c
28   check_pack.c
29   check_print.c
30   check_run.c
31   check_str.c)
32
33 set(HEADERS
34   ${CONFIG_HEADER}
35   ${CMAKE_CURRENT_BINARY_DIR}/check.h
36   check.h.in
37   check_error.h
38   check_impl.h
39   check_list.h
40   check_log.h
41   check_msg.h
42   check_pack.h
43   check_print.h
44   check_str.h)
45
46 configure_file(check.h.in check.h @ONLY)
47
48 add_library(check STATIC ${SOURCES} ${HEADERS})
49
50 # We would like to create an OBJECT library but currently they are
51 # too unreliable and cumbersome,
52 # especially with target_link_libraries and install(EXPORT...
53 # https://stackoverflow.com/questions/38832528/transitive-target-include-directories-on-object-libraries
54 # So we instead do the work twice.
55 add_library(checkShared SHARED ${SOURCES} ${HEADERS})
56
57 # Add parts of libcompat as required
58 target_sources(check PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/fpclassify.c)
59 target_sources(checkShared PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/fpclassify.c)
60
61 if (NOT HAVE_LIBRT)
62   target_sources(check PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/clock_gettime.c)
63   target_sources(check PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/timer_create.c)
64   target_sources(check PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/timer_delete.c)
65   target_sources(check PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/timer_settime.c)
66   target_sources(checkShared PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/clock_gettime.c)
67   target_sources(checkShared PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/timer_create.c)
68   target_sources(checkShared PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/timer_delete.c)
69   target_sources(checkShared PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/timer_settime.c)
70 endif(NOT HAVE_LIBRT)
71
72 if(NOT HAVE_GETLINE)
73   target_sources(check PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/getline.c)
74   target_sources(checkShared PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/getline.c)
75 endif(NOT HAVE_GETLINE)
76
77 if(NOT HAVE_GETTIMEOFDAY)
78   target_sources(check PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/gettimeofday.c)
79   target_sources(checkShared PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/gettimeofday.c)
80 endif(NOT HAVE_GETTIMEOFDAY)
81
82 if(NOT HAVE_DECL_LOCALTIME_R)
83   target_sources(check PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/localtime_r.c)
84   target_sources(checkShared PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/localtime_r.c)
85 endif(NOT HAVE_DECL_LOCALTIME_R)
86
87 if(NOT HAVE_MALLOC)
88   target_sources(check PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/malloc.c)
89   target_sources(checkShared PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/malloc.c)
90 endif(NOT HAVE_MALLOC)
91
92 if(NOT HAVE_REALLOC)
93   target_sources(check PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/realloc.c)
94   target_sources(checkShared PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/realloc.c)
95 endif(NOT HAVE_REALLOC)
96
97 if(NOT HAVE_SNPRINTF)
98   target_sources(check PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/snprintf.c)
99   target_sources(checkShared PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/snprintf.c)
100 endif(NOT HAVE_SNPRINTF)
101
102 if(NOT HAVE_DECL_STRDUP AND NOT HAVE__STRDUP)
103   target_sources(check PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/strdup.c)
104   target_sources(checkShared PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/snprintf.c)
105 endif(NOT HAVE_DECL_STRDUP AND NOT HAVE__STRDUP)
106
107 if(NOT HAVE_DECL_STRSIGNAL)
108   target_sources(check PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/strsignal.c)
109   target_sources(checkShared PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/strsignal.c)
110 endif(NOT HAVE_DECL_STRSIGNAL)
111
112 if(NOT HAVE_DECL_ALARM)
113   target_sources(check PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/alarm.c)
114   target_sources(checkShared PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/alarm.c)
115 endif(NOT HAVE_DECL_ALARM)
116
117 # Include libraries if available
118 if (HAVE_LIBM)
119   target_link_libraries(check PUBLIC m)
120   target_link_libraries(checkShared PUBLIC m)
121 endif (HAVE_LIBM)
122 if (HAVE_LIBRT)
123   target_link_libraries(check PUBLIC rt)
124   target_link_libraries(checkShared PUBLIC rt)
125 endif (HAVE_LIBRT)
126 if (HAVE_SUBUNIT)
127   target_link_libraries(check PUBLIC subunit)
128   target_link_libraries(checkShared PUBLIC subunit)
129 endif (HAVE_SUBUNIT)
130
131 if(MSVC)
132   target_compile_definitions(checkShared
133     PRIVATE "CK_DLL_EXP=_declspec(dllexport)"
134     INTERFACE "CK_DLL_EXP=_declspec(dllimport)"
135   )
136 endif (MSVC)
137
138 # More configuration for exporting
139
140 set(LIBRARY_OUTPUT_NAME "check")
141
142 set_target_properties(check PROPERTIES
143   OUTPUT_NAME ${LIBRARY_OUTPUT_NAME}
144   PUBLIC_HEADER ${CMAKE_CURRENT_BINARY_DIR}/check.h
145 )
146
147 if (MSVC)
148   # "On Windows you should probably give each library a different name,
149   # since there is a ".lib" file for both shared and static".
150   # https://stackoverflow.com/a/2152157/4716395
151   set(LIBRARY_OUTPUT_NAME "checkStatic")
152 endif (MSVC)
153 set_target_properties(checkShared PROPERTIES
154   OUTPUT_NAME ${LIBRARY_OUTPUT_NAME}
155   VERSION ${PROJECT_VERSION}
156   SOVERSION ${PROJECT_VERSION_MAJOR}
157   PUBLIC_HEADER ${CMAKE_CURRENT_BINARY_DIR}/check.h
158 )
159 target_include_directories(check
160   PUBLIC
161     $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
162     $<INSTALL_INTERFACE:include>
163 )
164 target_include_directories(checkShared
165   PUBLIC
166     $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
167     $<INSTALL_INTERFACE:include>
168 )
169
170 include(GNUInstallDirs)
171 install(TARGETS check checkShared
172   EXPORT check-targets
173   ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
174   LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
175   RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
176   PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
177 )
178