forked from katef/kgt
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
68 lines (58 loc) · 2.05 KB
/
CMakeLists.txt
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
# This is a community contribution. The official way is to use pmake.
#
# This isn't meant to be a good CMakeList, but it tries to maximize its odds of
# taying relevant without someone to maintain it.
cmake_minimum_required(VERSION 3.0)
project(kgt LANGUAGES C)
# The final executable:
add_executable(kgt_exe ./src/main.c)
set_target_properties(kgt_exe PROPERTIES OUTPUT_NAME "kgt")
target_link_libraries(kgt_exe PRIVATE kgt)
# The common library:
file(GLOB kgt_common_files
${CMAKE_CURRENT_SOURCE_DIR}/src/*.c
${CMAKE_CURRENT_SOURCE_DIR}/src/*.h
)
list(REMOVE_ITEM kgt_common_files
${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
)
add_library(common STATIC ${kgt_common_files})
add_library(kgt::common ALIAS common)
list(APPEND libraries common)
set_target_properties(common PROPERTIES LINKER_LANGUAGE C)
# The modules libraries:
file(GLOB subdirs ${CMAKE_CURRENT_SOURCE_DIR}/src/*)
foreach(subdir ${subdirs})
if(IS_DIRECTORY ${subdir})
get_filename_component(library ${subdir} NAME)
file(GLOB files ${subdir}/*.h ${subdir}/*.c)
add_library(${library} STATIC ${files})
add_library(kgt::${library} ALIAS ${library})
target_link_libraries(${library} PRIVATE m)
target_link_libraries(${library} PUBLIC common)
set_target_properties(${library} PROPERTIES LINKER_LANGUAGE C)
string(REPLACE "-" "_" FORM ${library})
target_compile_definitions(${library} PRIVATE "LX_HEADER=\"lexer.h\"")
target_compile_definitions(${library} PRIVATE "FORM=${FORM}")
list(APPEND libraries ${library})
endif()
endforeach()
# Some depencencies in between the modules above:
target_link_libraries(rrll PUBLIC rrd)
target_link_libraries(rrtext PUBLIC rrd)
# The main library:
add_library(kgt STATIC
${CMAKE_CURRENT_SOURCE_DIR}/src/ast.h
${CMAKE_CURRENT_SOURCE_DIR}/dummy.c
)
add_library(kgt::kgt ALIAS kgt)
set_target_properties(kgt PROPERTIES LINKER_LANGUAGE C)
target_include_directories(kgt PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src/)
target_link_libraries(kgt PUBLIC ${libraries})
export(
TARGETS
kgt
${libraries}
NAMESPACE kgt::
FILE kgt.cmake
)