tsort: replace with openbsd version
[unleashed.git] / contrib / libjeffpc / CMakeLists.txt
blob5229405eb0f763d7dd8554f2b072e74fb793733a
2 # Copyright (c) 2016 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
4 # Permission is hereby granted, free of charge, to any person obtaining a copy
5 # of this software and associated documentation files (the "Software"), to deal
6 # in the Software without restriction, including without limitation the rights
7 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 # copies of the Software, and to permit persons to whom the Software is
9 # furnished to do so, subject to the following conditions:
11 # The above copyright notice and this permission notice shall be included in
12 # all copies or substantial portions of the Software.
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 # SOFTWARE.
23 cmake_minimum_required(VERSION 2.8.12.2)
24 project(libjeffpc)
26 enable_testing()
28 add_definitions(
29         -D__EXTENSIONS__
30         -D_REENTRANT
31         -D_POSIX_C_SOURCE=200112L
32         -D_GNU_SOURCE
35 add_compile_options(
36         -Wall
37         -O2
38         -g
39         -std=gnu99
40         -fno-omit-frame-pointer
41         $<$<C_COMPILER_ID:gcc>:-fno-inline-small-functions>
42         $<$<C_COMPILER_ID:gcc>:-fno-inline-functions-called-once>
45 set(CMAKE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
47 include(cmake/config.cmake)
48 include(cmake/mapfile.cmake)
49 include(cmake/test.cmake)
50 include(cmake/paths.cmake)
52 # handle missing libumem
53 if(NOT UMEM_FOUND)
54         set(UMEM_LIBRARY "")
55         set(UMEM_INCLUDE_DIR fakeumem/include)
56         set(UMEM_EXTRA_SOURCE fakeumem/fakeumem.c)
57 else()
58         set(UMEM_EXTRA_SOURCE)
59 endif()
61 find_package(BISON)
62 find_package(FLEX)
64 include_directories(
65         include
66         ${UMEM_INCLUDE_DIR}
69 # include the current source dir but only for: #include "foo.h"
70 add_compile_options(
71         -iquote ${CMAKE_CURRENT_SOURCE_DIR}
74 BISON_TARGET(sexpr sexpr.y ${CMAKE_CURRENT_BINARY_DIR}/sexpr.tab.c
75         COMPILE_FLAGS "-p sexpr_reader_")
76 FLEX_TARGET(sexpr sexpr.l ${CMAKE_CURRENT_BINARY_DIR}/sexpr.lex.c
77         COMPILE_FLAGS "-P sexpr_reader_")
78 ADD_FLEX_BISON_DEPENDENCY(sexpr sexpr)
80 add_library(jeffpc SHARED
81         error.c
82         hexdump.c
83         init.c
84         io.c
85         padding.c
86         rand.c
87         sexpr.c
88         sexpr_eval.c
89         ${FLEX_sexpr_OUTPUTS} ${BISON_sexpr_OUTPUTS}
90         sock.c
91         str.c
92         synch.c
93         uuid.c
94         val.c
95         ${UMEM_EXTRA_SOURCE}
98 target_link_libraries(jeffpc
99         ${UMEM_LIBRARY}
100         pthread
101         uuid
104 target_apply_mapfile(jeffpc mapfile-vers)
106 install(TARGETS jeffpc DESTINATION ${CMAKE_INSTALL_LIBDIR}
107         PERMISSIONS OWNER_WRITE OWNER_READ GROUP_READ WORLD_READ)
108 install(FILES   include/jeffpc/atomic.h
109                 include/jeffpc/error.h
110                 include/jeffpc/hexdump.h
111                 include/jeffpc/int.h
112                 include/jeffpc/io.h
113                 include/jeffpc/jeffpc.h
114                 include/jeffpc/padding.h
115                 include/jeffpc/rand.h
116                 include/jeffpc/refcnt.h
117                 include/jeffpc/sexpr.h
118                 include/jeffpc/sock.h
119                 include/jeffpc/str.h
120                 include/jeffpc/synch.h
121                 include/jeffpc/thread.h
122                 include/jeffpc/time.h
123                 include/jeffpc/types.h
124                 include/jeffpc/uuid.h
125                 include/jeffpc/val.h
126                 ${CMAKE_CURRENT_BINARY_DIR}/include/jeffpc/config.h
127         DESTINATION include/jeffpc
128         PERMISSIONS OWNER_WRITE OWNER_READ GROUP_READ WORLD_READ)
131 # Test related executables
134 build_test_bin(sexpr_parser)
135 build_test_bin_and_run(array)
136 build_test_bin_and_run(atomic-single-thread)
137 build_test_bin_and_run(bswap)
138 build_test_bin_and_run(hexdump)
139 build_test_bin_and_run(padding)
140 build_test_bin_and_run(sexpr_eval)
142 add_subdirectory(tests)