-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
77 lines (63 loc) · 2.85 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
69
70
71
72
73
74
75
76
77
cmake_minimum_required(VERSION 3.22)
project(Blacksmith VERSION 1.0 DESCRIPTION "A command line solver for the blacksmithing puzzle from the game Puzzle Pirates"
HOMEPAGE_URL "https://github.com/Xaunther/Blacksmith" LANGUAGES CXX)
# C++ 20 required
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Names of relevant directories
set(BLACKSMITH_DIR ${CMAKE_SOURCE_DIR})
set(BLACKSMITH_BINARY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/bin)
set(BLACKSMITH_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
set(BLACKSMITH_LIBS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/lib)
# Compiler-specific flags
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wpedantic -Werror -Os")
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(CMAKE_CXX_FLAGS "-W4 -WX -EHsc -Os")
endif()
set(CMAKE_CXX_FLAGS_RELEASE "-Os")
# Function to add a new object module
function(add_blacksmith_object_module MODULE_NAME SOURCES)
add_Library(${MODULE_NAME}Objects OBJECT ${SOURCES} ${ARGN})
set_target_properties(${MODULE_NAME}Objects PROPERTIES
POSITION_INDEPENDENT_CODE true
ARCHIVE_OUTPUT_DIRECTORY ${BLACKSMITH_LIBS_DIR}
LIBRARY_OUTPUT_DIRECTORY ${BLACKSMITH_LIBS_DIR}
RUNTIME_OUTPUT_DIRECTORY ${BLACKSMITH_LIBS_DIR})
MESSAGE(STATUS "Added object module ${MODULE_NAME}")
endfunction()
# Function to add a new module
function(add_blacksmith_module MODULE_NAME MODULE_TYPE SOURCES)
if(MODULE_TYPE STREQUAL SHARED)
set(MODULE_SUFFIX "Shared")
elseif(MODULE_TYPE STREQUAL STATIC)
set(MODULE_SUFFIX "Static")
else()
MESSAGE(FATAL_ERROR "Module type ${MODULE_TYPE} not recognized. Only 'STATIC' and 'SHARED' are allowed.")
endif()
add_Library(${MODULE_NAME}${MODULE_SUFFIX} ${MODULE_TYPE} ${SOURCES} ${ARGN})
set_target_properties(${MODULE_NAME}${MODULE_SUFFIX} PROPERTIES
POSITION_INDEPENDENT_CODE true
ARCHIVE_OUTPUT_DIRECTORY ${BLACKSMITH_LIBS_DIR}
LIBRARY_OUTPUT_DIRECTORY ${BLACKSMITH_LIBS_DIR}
RUNTIME_OUTPUT_DIRECTORY ${BLACKSMITH_LIBS_DIR})
target_link_libraries(${MODULE_NAME}${MODULE_SUFFIX})
MESSAGE(STATUS "Added ${MODULE_TYPE} module ${MODULE_NAME}")
endfunction()
# List of source files
include(FileList.cmake)
# Include directories
include_directories(${BLACKSMITH_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/src)
# Link directories
link_directories(${BLACKSMITH_LIBS_DIR})
# Build Blacksmith solver
add_blacksmith_object_module(${PROJECT_NAME}Core "${BLACKSMITH_CORE_SOURCE}")
set(BLACKSMITH_CORE_OBJECTS $<TARGET_OBJECTS:${PROJECT_NAME}CoreObjects>)
set(BLACKSMITH_OBJECTS ${BLACKSMITH_CORE_OBJECTS})
# Final build step. All objects must have been appended to BLACKSMITH_OBJECTS.
add_blacksmith_module(${PROJECT_NAME}Core STATIC ${BLACKSMITH_OBJECTS})
if(LIB_BLACKSMITH_SHARED)
add_blacksmith_module(${PROJECT_NAME}Core SHARED ${BLACKSMITH_OBJECTS})
endif()
# Compile solver binary
add_executable(Blacksmith ${CMAKE_SOURCE_DIR}/src/main.cpp ${BLACKSMITH_OBJECTS})