-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
61 lines (47 loc) · 1.31 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
cmake_minimum_required(VERSION 3.18.1)
project(test_project LANGUAGES C CXX)
# Subproject approach
#add_subdirectory(tool)
# External project approach
include(ExternalProject)
# CMAKE_DISABLE_SOURCE_CHANGES breaks ExternalProject with source dir inside source folder.
# https://gitlab.kitware.com/cmake/cmake/-/issues/18811
set(SOURCE_CHANGES_VALUE ${CMAKE_DISABLE_SOURCE_CHANGES})
set(CMAKE_DISABLE_SOURCE_CHANGES OFF)
ExternalProject_Add(test_tool
PREFIX "${CMAKE_CURRENT_BINARY_DIR}/test_tool"
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_CURRENT_BINARY_DIR}
-DCMAKE_BUILD_TYPE=Release
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/tool"
BUILD_IN_SOURCE 0
)
# Restore previous value
set(CMAKE_DISABLE_SOURCE_CHANGES ${CMAKE_DISABLE_SOURCE_CHANGES})
# Run custom command
set(TOOL_INPUT ${CMAKE_CURRENT_SOURCE_DIR}/source/test.txt)
set(TOOL_OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/output.h)
add_custom_command(
COMMAND
bin/test_tool
${TOOL_INPUT}
${TOOL_OUTPUT}
${CMAKE_SYSTEM_NAME}
OUTPUT ${TOOL_OUTPUT}
DEPENDS test_tool ${TOOL_INPUT}
COMMENT "Running tool"
)
# Build target
add_executable(
${PROJECT_NAME}
source/main.cpp
${TOOL_OUTPUT}
)
if (ANDROID)
target_link_libraries(
${PROJECT_NAME}
PRIVATE
android
log
)
endif()