summaryrefslogtreecommitdiff
path: root/CMakeLists.txt
blob: 845c8478edd42dbb3da84ec9005b0c9490c8e2c8 (plain)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# Main CMake file for XTrackCAD

cmake_minimum_required(VERSION 3.20.0)
project(XTrkCAD)

cmake_policy(SET CMP0076 NEW)
cmake_policy(SET CMP0079 NEW)

# where to look first for cmake modules, before ${CMAKE_ROOT}/Modules/ is checked
# additional CMake modules can be found here
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/CMake")

# Include CMake defaults
include(CMakeDefaults)

include(CheckIncludeFiles)

include(ProgramVersion.cmake)
include(PlatformSettings.cmake)

enable_testing()

# Find all dependencies
# 
# Additional libraries

find_package(Libzip)
find_package(Zlib)

# Optionally enable SVG export
find_package(MiniXML)
if(MiniXML_FOUND)
    set(XTRKCAD_CREATE_SVG 1)
	message( STATUS "MiniXML found: SVG export is enabled")
else()
	message( STATUS "MiniXML not found: no SVG export")
endif()

# Find unit testing framework
find_package(CMocka)
if(CMOCKA_FOUND)
	include_directories(${CMOCKA_INCLUDE_DIR})
 	set(LIBS ${LIBS} ${CMOCKA_LIBRARIES})
 	option(XTRKCAD_TESTING "Build unittests" ON)
endif()

# Tools
# Find document conversion tool
find_package(Pandoc)

# For handling and creation of bitmaps the FreeImage library is required
find_package(FreeImage REQUIRED)

# check for GTK+ 2.0
if(UNIX)
    pkg_check_modules(GTK REQUIRED "gtk+-2.0")
	set(XTRKCAD_USE_GTK_DEFAULT ON)
endif(UNIX)

if(WIN32 AND NOT XTRKCAD_USE_GTK)
	# use the Windows HTMLHelp tool
	find_package(HTMLHelp REQUIRED)
endif(WIN32 AND NOT XTRKCAD_USE_GTK)

# 
# Configure options
#

option(XTRKCAD_USE_GTK "Use GTK for the graphical user interface back-end" ${XTRKCAD_USE_GTK_DEFAULT})
option(XTRKCAD_USE_GETTEXT "Use gettext for internationalization" ${XTRKCAD_USE_GETTEXT_DEFAULT})
option(XTRKCAD_USE_DOXYGEN "Generate internals documentation using doxygen" OFF)

if(UNIX AND NOT APPLE)
    option(XTRKCAD_USE_BROWSER "Show help in default browser" ${XTRKCAD_USE_BROWSER_DEFAULT})
endif()

if(APPLE)
	option(XTRKCAD_USE_APPLEHELP "Show help in Apple Help" ${XTRKCAD_USE_APPLEHELP_DEFAULT})
	option(XTRKCAD_USE_BROWSER "Show help in default browser" ${XTRKCAD_USE_BROWSER_DEFAULT})
	option(XTRKCAD_USE_PACKAGEMAKER "Generate an OSX PackageMaker package for distribution." OFF)
endif()

# Hide the advanced stuff ...
mark_as_advanced(CMAKE_BACKWARDS_COMPATIBILITY)
mark_as_advanced(CMAKE_EXECUTABLE_FORMAT)
mark_as_advanced(CMAKE_OSX_ARCHITECTURES)
mark_as_advanced(CMAKE_OSX_SYSROOT)
mark_as_advanced(CMAKE_USE_CHRPATH)
mark_as_advanced(EXECUTABLE_OUTPUT_PATH)
mark_as_advanced(LIBRARY_OUTPUT_PATH)

# Test for headers and libraries for portability ...
# check_include_files (malloc.h HAVE_MALLOC_H)
# if(HAVE_MALLOC_H)
#   add_definitions(-DHAVE_MALLOC_H)
# endif()

#packaging related stuff

if(XTRKCAD_USE_PACKAGEMAKER)
	if(NOT CMAKE_INSTALL_PREFIX STREQUAL "/usr")
		message(SEND_ERROR "XTRKCAD_USE_PACKAGEMAKER requires CMAKE_INSTALL_PREFIX set to /usr.")
	endif()
endif()

#
# configure installation directories
if(WIN32)
	set( CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX} ${XTRKCAD_VERSION}" )
endif()

set(XTRKCAD_BIN_INSTALL_DIR "bin")
set(XTRKCAD_LOCALE_INSTALL_DIR "share/locale")
set(XTRKCAD_PACKAGE "xtrkcad")
set(XTRKCAD_BETA "")
if(UNIX AND NOT APPLE)
	if(XTRKCAD_VERSION_MODIFIER MATCHES "^Beta")
		set(XTRKCAD_BETA "-beta")
	endif()
endif()
set(XTRKCAD_SHARE_INSTALL_DIR "share/xtrkcad${XTRKCAD_BETA}")

# Enable use of a configuration file ...
add_definitions(-DXTRKCAD_CMAKE_BUILD)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/xtrkcad-config.h.in ${CMAKE_CURRENT_BINARY_DIR}/xtrkcad-config.h)

# find the config.h include file
include_directories(
	${CMAKE_CURRENT_BINARY_DIR}
)

#
# I18N related dependencies

if(XTRKCAD_USE_GETTEXT)
	#
	# Find the GnuWin32 installation directory, the gettext include should be located in subdir include
	#
	if(WIN32)
		if(MSVC)
			# use supplied gettext library for Visual Studio
			message( STATUS "Use simple_gettext module included with XTrackCAD" )
			add_definitions(-DUSE_SIMPLE_GETTEXT )
		else()
			# for mingw & co. find libintl.h and use it
			find_path ( INTL_PATH libintl.h )
			if(INTL_PATH)
				message( STATUS "Use installed gettext module" )
				include_directories(${INTL_PATH})
			endif()
		endif()
	endif()
	if(APPLE)
		find_path ( INTL_PATH libintl.h )
		if(INTL_PATH)
			message( STATUS "Use installed gettext module" )
			include_directories(${INTL_PATH})
		endif()
	endif()
endif()

# Setup the rest of the build ...
add_subdirectory(app)
add_subdirectory(distribution)
add_subdirectory(docs)