-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCrossPlatform.cmake
More file actions
53 lines (47 loc) · 1.69 KB
/
Copy pathCrossPlatform.cmake
File metadata and controls
53 lines (47 loc) · 1.69 KB
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
# CrossPlatform.cmake
# ============================================================================
# Platform detection and helper functions for Windows and Linux
#
# Usage in your CMakeLists.txt:
# include(${CMAKE_SOURCE_DIR}/../CrossPlatform.cmake)
#
# Variables set by this file:
# CP_PLATFORM - "Windows" or "Linux"
# CP_WINDOWS - TRUE if Windows
# CP_LINUX - TRUE if Linux
# ============================================================================
cmake_minimum_required(VERSION 3.10)
# ----------------------------------------------------------------------------
# Platform Detection
# ----------------------------------------------------------------------------
if(WIN32)
set(CP_PLATFORM "Windows")
set(CP_WINDOWS TRUE)
set(EXE_EXT ".exe")
elseif(UNIX)
set(CP_PLATFORM "Linux")
set(CP_LINUX TRUE)
set(EXE_EXT "")
else()
message(FATAL_ERROR "Unsupported platform!")
endif()
message(STATUS "Platform: ${CP_PLATFORM}")
# ----------------------------------------------------------------------------
# Helper Functions
# ----------------------------------------------------------------------------
# Remove a directory (use for clean targets)
# Usage: cp_remove_directory("/path/to/dir")
function(cp_remove_directory dir_to_remove)
if(EXISTS "${dir_to_remove}")
file(REMOVE_RECURSE "${dir_to_remove}")
message(STATUS "Removed: ${dir_to_remove}")
endif()
endfunction()
# Create a directory if it doesn't exist
# Usage: cp_make_directory("/path/to/dir")
function(cp_make_directory dir_to_make)
if(NOT EXISTS "${dir_to_make}")
file(MAKE_DIRECTORY "${dir_to_make}")
message(STATUS "Created: ${dir_to_make}")
endif()
endfunction()