2015-03-29 00:33:46 +00:00
|
|
|
# cmake configuration
|
|
|
|
|
2015-12-25 15:10:01 +00:00
|
|
|
cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR)
|
|
|
|
cmake_policy(VERSION 3.1.0)
|
2015-03-29 00:33:46 +00:00
|
|
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
|
|
|
|
"${CMAKE_SOURCE_DIR}/cmake/")
|
2015-12-25 15:10:01 +00:00
|
|
|
set(CMAKE_CXX_STANDARD 11)
|
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED YES)
|
2015-03-29 00:33:46 +00:00
|
|
|
|
|
|
|
# for /MT on MSVC
|
|
|
|
set(CMAKE_USER_MAKE_RULES_OVERRIDE
|
|
|
|
"${CMAKE_SOURCE_DIR}/cmake/c_flag_overrides.cmake")
|
|
|
|
set(CMAKE_USER_MAKE_RULES_OVERRIDE_CXX
|
|
|
|
"${CMAKE_SOURCE_DIR}/cmake/cxx_flag_overrides.cmake")
|
|
|
|
|
|
|
|
# project
|
|
|
|
|
2016-06-28 09:49:37 +00:00
|
|
|
# NOTE TO PACKAGERS: The embedded git commit hash is critical for rapid bug triage when the builds
|
|
|
|
# can come from a variety of sources. If you are mirroring the sources or otherwise build when
|
|
|
|
# the .git directory is not present, please comment the following line:
|
2016-04-23 22:53:21 +00:00
|
|
|
include(GetGitCommitHash)
|
2016-06-28 09:49:37 +00:00
|
|
|
# and instead uncomment the following, adding the complete git hash of the checkout you are using:
|
|
|
|
# set(GIT_COMMIT_HASH 0000000000000000000000000000000000000000)
|
2016-04-23 22:53:21 +00:00
|
|
|
|
2015-03-29 00:33:46 +00:00
|
|
|
project(solvespace)
|
2016-05-20 14:50:00 +00:00
|
|
|
set(solvespace_VERSION_MAJOR 3)
|
|
|
|
set(solvespace_VERSION_MINOR 0)
|
2016-04-23 22:53:21 +00:00
|
|
|
string(SUBSTRING "${GIT_COMMIT_HASH}" 0 8 solvespace_GIT_HASH)
|
2015-03-29 00:33:46 +00:00
|
|
|
|
2015-12-25 15:10:01 +00:00
|
|
|
if(NOT WIN32 AND NOT APPLE)
|
2015-03-24 23:38:06 +00:00
|
|
|
set(GUI gtk2 CACHE STRING "GUI toolkit to use (one of: gtk2 gtk3)")
|
2015-03-18 17:02:11 +00:00
|
|
|
endif()
|
|
|
|
|
2015-03-29 00:33:46 +00:00
|
|
|
# compiler
|
|
|
|
|
|
|
|
if(WIN32)
|
|
|
|
add_definitions(
|
2016-02-11 16:40:57 +00:00
|
|
|
-D_CRT_SECURE_NO_DEPRECATE
|
|
|
|
-D_CRT_SECURE_NO_WARNINGS
|
|
|
|
-D_SCL_SECURE_NO_WARNINGS
|
2015-03-29 00:33:46 +00:00
|
|
|
-D_WIN32_WINNT=0x500
|
|
|
|
-D_WIN32_IE=_WIN32_WINNT
|
2016-02-11 16:40:57 +00:00
|
|
|
-DISOLATION_AWARE_ENABLED
|
|
|
|
-DWIN32
|
|
|
|
-DWIN32_LEAN_AND_MEAN
|
2015-12-27 07:51:28 +00:00
|
|
|
-DUNICODE
|
2016-05-18 09:35:32 +00:00
|
|
|
-D_UNICODE
|
2016-01-26 06:18:56 +00:00
|
|
|
-DNOMINMAX
|
2016-05-18 09:35:32 +00:00
|
|
|
-D_USE_MATH_DEFINES)
|
2015-03-29 00:33:46 +00:00
|
|
|
endif()
|
|
|
|
|
2016-05-17 12:38:35 +00:00
|
|
|
if(MSVC)
|
|
|
|
# Many versions of MSVC do not have the (C99) inline keyword, instead
|
|
|
|
# they have their own __inline; this breaks `static inline` functions.
|
|
|
|
# We do not want to care and so we fix this with a definition.
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Dinline=__inline")
|
2016-05-18 19:38:17 +00:00
|
|
|
# Same for the (C99) __func__ special variable; we use it only in C++ code.
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D__func__=__FUNCTION__")
|
Enable exhaustive switch coverage warnings as an error, and use them.
Specifically, this enables -Wswitch=error on GCC/Clang and its MSVC
equivalent; the exact way it is handled varies slightly, but what
they all have in common is that in a switch statement over an
enumeration, any enumerand that is not explicitly (via case:) or
implicitly (via default:) handled in the switch triggers an error.
Moreover, we also change the switch statements in three ways:
* Switch statements that ought to be extended every time a new
enumerand is added (e.g. Entity::DrawOrGetDistance(), are changed
to explicitly list every single enumerand, and not have a
default: branch.
Note that the assertions are kept because it is legal for
a enumeration to have a value unlike any of its defined
enumerands, and we can e.g. read garbage from a file, or
an uninitialized variable. This requires some rearranging if
a default: branch is undesired.
* Switch statements that ought to only ever see a few select
enumerands, are changed to always assert in the default: branch.
* Switch statements that do something meaningful for a few
enumerands, and ignore everything else, are changed to do nothing
in a default: branch, under the assumption that changing them
every time an enumerand is added or removed would just result
in noise and catch no bugs.
This commit also removes the {Request,Entity,Constraint}::UNKNOWN and
Entity::DATUM_POINT enumerands, as those were just fancy names for
zeroes. They mess up switch exhaustiveness checks and most of the time
were not the best way to implement what they did anyway.
2016-05-25 06:55:50 +00:00
|
|
|
|
|
|
|
# We rely on these /we flags. They correspond to the GNU-style flags below as
|
|
|
|
# follows: /w4062=-Wswitch
|
|
|
|
set(WARNING_FLAGS "${WARNING_FLAGS} /we4062")
|
2016-05-17 12:38:35 +00:00
|
|
|
endif()
|
|
|
|
|
2016-05-18 16:44:03 +00:00
|
|
|
if(CMAKE_CXX_COMPILER_ID STREQUAL GNU)
|
|
|
|
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0)
|
|
|
|
# GCC 4.8/4.9 ship with broken but present <regex>. meh.
|
|
|
|
message(FATAL_ERROR "GCC 5.0+ is required")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2016-02-14 00:36:54 +00:00
|
|
|
if(CMAKE_CXX_COMPILER_ID STREQUAL GNU OR CMAKE_CXX_COMPILER_ID STREQUAL Clang)
|
2016-05-07 23:34:21 +00:00
|
|
|
set(WARNING_FLAGS "-Wall -Wextra -Wno-unused-parameter")
|
2016-05-18 09:40:50 +00:00
|
|
|
if(CMAKE_CXX_COMPILER_ID STREQUAL Clang)
|
|
|
|
set(WARNING_FLAGS "${WARNING_FLAGS} -Wfloat-conversion")
|
|
|
|
endif()
|
Enable exhaustive switch coverage warnings as an error, and use them.
Specifically, this enables -Wswitch=error on GCC/Clang and its MSVC
equivalent; the exact way it is handled varies slightly, but what
they all have in common is that in a switch statement over an
enumeration, any enumerand that is not explicitly (via case:) or
implicitly (via default:) handled in the switch triggers an error.
Moreover, we also change the switch statements in three ways:
* Switch statements that ought to be extended every time a new
enumerand is added (e.g. Entity::DrawOrGetDistance(), are changed
to explicitly list every single enumerand, and not have a
default: branch.
Note that the assertions are kept because it is legal for
a enumeration to have a value unlike any of its defined
enumerands, and we can e.g. read garbage from a file, or
an uninitialized variable. This requires some rearranging if
a default: branch is undesired.
* Switch statements that ought to only ever see a few select
enumerands, are changed to always assert in the default: branch.
* Switch statements that do something meaningful for a few
enumerands, and ignore everything else, are changed to do nothing
in a default: branch, under the assumption that changing them
every time an enumerand is added or removed would just result
in noise and catch no bugs.
This commit also removes the {Request,Entity,Constraint}::UNKNOWN and
Entity::DATUM_POINT enumerands, as those were just fancy names for
zeroes. They mess up switch exhaustiveness checks and most of the time
were not the best way to implement what they did anyway.
2016-05-25 06:55:50 +00:00
|
|
|
# We rely on these -Werror flags.
|
|
|
|
set(WARNING_FLAGS "${WARNING_FLAGS} -Werror=switch")
|
2016-06-02 02:18:29 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if(WIN32)
|
|
|
|
set(CMAKE_RC_FLAGS "${CMAKE_RC_FLAGS} -l0")
|
2016-02-14 00:36:54 +00:00
|
|
|
endif()
|
|
|
|
|
2015-07-05 05:45:39 +00:00
|
|
|
if(MINGW)
|
2016-02-15 19:58:03 +00:00
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -static-libgcc")
|
2015-07-05 05:45:39 +00:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++")
|
|
|
|
endif()
|
|
|
|
|
2015-12-25 15:10:01 +00:00
|
|
|
if(APPLE)
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed ${CMAKE_EXE_LINKER_FLAGS}")
|
|
|
|
endif()
|
|
|
|
|
2015-12-25 16:06:59 +00:00
|
|
|
if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed ${CMAKE_EXE_LINKER_FLAGS}")
|
|
|
|
endif()
|
|
|
|
|
2016-04-23 23:48:34 +00:00
|
|
|
if(SANITIZE)
|
|
|
|
if(NOT (CMAKE_C_COMPILER_ID STREQUAL Clang AND CMAKE_CXX_COMPILER_ID STREQUAL Clang))
|
|
|
|
message(ERROR "Sanitizers are only available in Clang/Clang++")
|
|
|
|
endif()
|
|
|
|
set(SANITIZE_FLAGS "-O1 -fno-omit-frame-pointer -fno-optimize-sibling-calls")
|
|
|
|
set(SANITIZE_FLAGS "${SANITIZE_FLAGS} -fsanitize=address,undefined,integer")
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SANITIZE_FLAGS}")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SANITIZE_FLAGS}")
|
|
|
|
endif()
|
|
|
|
|
Enable exhaustive switch coverage warnings as an error, and use them.
Specifically, this enables -Wswitch=error on GCC/Clang and its MSVC
equivalent; the exact way it is handled varies slightly, but what
they all have in common is that in a switch statement over an
enumeration, any enumerand that is not explicitly (via case:) or
implicitly (via default:) handled in the switch triggers an error.
Moreover, we also change the switch statements in three ways:
* Switch statements that ought to be extended every time a new
enumerand is added (e.g. Entity::DrawOrGetDistance(), are changed
to explicitly list every single enumerand, and not have a
default: branch.
Note that the assertions are kept because it is legal for
a enumeration to have a value unlike any of its defined
enumerands, and we can e.g. read garbage from a file, or
an uninitialized variable. This requires some rearranging if
a default: branch is undesired.
* Switch statements that ought to only ever see a few select
enumerands, are changed to always assert in the default: branch.
* Switch statements that do something meaningful for a few
enumerands, and ignore everything else, are changed to do nothing
in a default: branch, under the assumption that changing them
every time an enumerand is added or removed would just result
in noise and catch no bugs.
This commit also removes the {Request,Entity,Constraint}::UNKNOWN and
Entity::DATUM_POINT enumerands, as those were just fancy names for
zeroes. They mess up switch exhaustiveness checks and most of the time
were not the best way to implement what they did anyway.
2016-05-25 06:55:50 +00:00
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS}")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS}")
|
|
|
|
|
2015-03-29 00:33:46 +00:00
|
|
|
# dependencies
|
|
|
|
|
|
|
|
find_package(OpenGL REQUIRED)
|
|
|
|
|
2015-11-03 19:05:20 +00:00
|
|
|
message(STATUS "Using in-tree libdxfrw")
|
|
|
|
add_subdirectory(extlib/libdxfrw)
|
|
|
|
|
2015-03-29 00:33:46 +00:00
|
|
|
if(WIN32)
|
2016-07-24 13:55:33 +00:00
|
|
|
include(FindVendoredPackage)
|
|
|
|
|
|
|
|
find_vendored_package(Freetype freetype
|
|
|
|
WITH_ZLIB OFF
|
|
|
|
WITH_BZip2 OFF
|
|
|
|
WITH_PNG OFF
|
|
|
|
WITH_HarfBuzz OFF
|
|
|
|
FREETYPE_LIBRARY freetype
|
|
|
|
FREETYPE_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extlib/freetype/include)
|
|
|
|
|
|
|
|
find_vendored_package(ZLIB zlib
|
|
|
|
ZLIB_LIBRARY zlibstatic
|
|
|
|
ZLIB_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/extlib/zlib)
|
|
|
|
list(APPEND ZLIB_INCLUDE_DIR ${CMAKE_BINARY_DIR}/extlib/zlib)
|
|
|
|
|
|
|
|
find_vendored_package(PNG libpng
|
|
|
|
SKIP_INSTALL_ALL ON
|
|
|
|
PNG_LIBRARY png16_static
|
|
|
|
PNG_PNG_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/extlib/libpng)
|
|
|
|
list(APPEND PNG_PNG_INCLUDE_DIR ${CMAKE_BINARY_DIR}/extlib/libpng)
|
2015-03-29 00:33:46 +00:00
|
|
|
|
2015-07-05 05:45:39 +00:00
|
|
|
if(NOT MINGW)
|
|
|
|
message(STATUS "Using prebuilt SpaceWare")
|
|
|
|
set(SPACEWARE_FOUND TRUE)
|
|
|
|
set(SPACEWARE_INCLUDE_DIR
|
|
|
|
"${CMAKE_SOURCE_DIR}/extlib/si")
|
|
|
|
set(SPACEWARE_LIBRARIES
|
|
|
|
"${CMAKE_SOURCE_DIR}/extlib/si/siapp.lib")
|
|
|
|
endif()
|
2015-03-24 06:45:53 +00:00
|
|
|
elseif(APPLE)
|
2016-06-19 19:46:51 +00:00
|
|
|
set(CMAKE_FIND_FRAMEWORK LAST)
|
2016-06-13 04:15:13 +00:00
|
|
|
|
2016-07-24 13:55:33 +00:00
|
|
|
find_package(ZLIB REQUIRED)
|
2015-03-24 06:45:53 +00:00
|
|
|
find_package(PNG REQUIRED)
|
2016-02-09 15:57:30 +00:00
|
|
|
find_package(Freetype REQUIRED)
|
2016-07-24 13:55:33 +00:00
|
|
|
|
2015-03-24 06:45:53 +00:00
|
|
|
find_library(APPKIT_LIBRARY AppKit REQUIRED)
|
|
|
|
else() # Linux and compatible systems
|
2016-07-19 15:40:52 +00:00
|
|
|
find_package(Backtrace)
|
2015-03-29 00:33:46 +00:00
|
|
|
find_package(SpaceWare)
|
|
|
|
|
2016-07-24 13:55:33 +00:00
|
|
|
find_package(ZLIB REQUIRED)
|
|
|
|
find_package(PNG REQUIRED)
|
|
|
|
find_package(Freetype REQUIRED)
|
|
|
|
|
|
|
|
# Use freedesktop's pkg-config to locate everything else.
|
2015-03-24 23:38:06 +00:00
|
|
|
find_package(PkgConfig REQUIRED)
|
|
|
|
pkg_check_modules(FONTCONFIG REQUIRED fontconfig)
|
|
|
|
pkg_check_modules(JSONC REQUIRED json-c)
|
2016-02-09 15:57:30 +00:00
|
|
|
pkg_check_modules(FREETYPE REQUIRED freetype2)
|
2016-07-24 13:55:33 +00:00
|
|
|
pkg_check_modules(CAIRO REQUIRED cairo)
|
2015-03-24 23:38:06 +00:00
|
|
|
|
|
|
|
set(HAVE_GTK TRUE)
|
|
|
|
if(GUI STREQUAL "gtk3")
|
|
|
|
set(HAVE_GTK3 TRUE)
|
|
|
|
pkg_check_modules(GTKMM REQUIRED gtkmm-3.0 pangomm-1.4 x11)
|
|
|
|
elseif(GUI STREQUAL "gtk2")
|
|
|
|
set(HAVE_GTK2 TRUE)
|
|
|
|
pkg_check_modules(GTKMM REQUIRED gtkmm-2.4 pangomm-1.4 x11)
|
2015-03-18 17:02:11 +00:00
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "GUI unrecognized: ${GUI}")
|
|
|
|
endif()
|
2015-03-29 00:33:46 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# components
|
|
|
|
|
Implement a resource system.
Currently, icons, fonts, etc are converted to C structures at compile
time and are hardcoded to the binary. This presents several problems:
* Cross-compilation is complicated. Right now, it is necessary
to be able to run executables for the target platform; this
happens to work with wine-binfmt installed, but is rather ugly.
* Icons can only have one resolution. On OS X, modern software is
expected to take advantage of high-DPI ("Retina") screens and
use so-called @2x assets when ran in high-DPI mode.
* Localization is complicated. Win32 and OS X provide built-in
support for loading the resource appropriate for the user's
locale.
* Embedding strings can only be done as raw strings, using C++'s
R"(...)" literals. This precludes embedding sizable strings,
e.g. JavaScript libraries as used in Three.js export, and makes
git history less useful. Not embedding the libraries means we
have to rely on external CDNs, which requires an Internet
connection and adds a glaring point of failure.
* Linux distribution guidelines are violated. All architecture-
independent data, especially large data such as fonts, is
expected to be in /usr/share, not in the binary.
* Customization is impossible without recompilation. Minor
modifications like adding a few missing vector font characters
or adjusting localization require a complete development
environment, which is unreasonable to expect from users of
a mechanical CAD.
As such, this commit adds a resource system that bundles (and
sometimes builds) resources with the executable. Where they go is
platform-dependent:
* on Win32: into resources of the executable, which allows us to
keep distributing one file;
* on OS X: into the app bundle;
* on other *nix: into /usr/share/solvespace/ or ../res/ (relative
to the executable path), the latter allowing us to run freshly
built executables without installation.
It also subsides the platform-specific resources that are in src/.
The resource system is not yet used for anything; this will be added
in later commits.
2016-04-21 15:54:18 +00:00
|
|
|
add_subdirectory(res)
|
2015-03-29 00:33:46 +00:00
|
|
|
add_subdirectory(src)
|
|
|
|
add_subdirectory(exposed)
|