2015-03-29 00:33:46 +00:00
|
|
|
# cmake configuration
|
2021-02-08 00:07:21 +00:00
|
|
|
cmake_minimum_required(VERSION 3.9...3.19)
|
2015-03-29 00:33:46 +00:00
|
|
|
|
2016-11-03 07:24:12 +00:00
|
|
|
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
|
|
|
|
message(FATAL_ERROR
|
|
|
|
"In-tree builds are not supported; please perform an out-of-tree build:\n"
|
|
|
|
" rm -rf CMakeCache.txt CMakeFiles/\n"
|
|
|
|
" mkdir build && cd build && cmake ..")
|
|
|
|
endif()
|
|
|
|
|
2021-12-22 17:53:03 +00:00
|
|
|
list(APPEND CMAKE_MODULE_PATH
|
2015-03-29 00:33:46 +00:00
|
|
|
"${CMAKE_SOURCE_DIR}/cmake/")
|
2021-02-08 00:07:21 +00:00
|
|
|
|
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")
|
|
|
|
|
2021-02-08 00:07:21 +00:00
|
|
|
if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
|
2020-10-17 15:05:10 +00:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
|
|
|
|
endif()
|
|
|
|
|
2021-08-15 10:22:56 +00:00
|
|
|
if (APPLE)
|
|
|
|
# Docs say this must be set before the first project() call
|
|
|
|
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.12" CACHE STRING "macOS minimum supported version")
|
|
|
|
endif()
|
|
|
|
|
2015-03-29 00:33:46 +00:00
|
|
|
# project
|
|
|
|
|
2019-05-01 08:32:30 +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:
|
2024-03-07 02:58:48 +00:00
|
|
|
include(GetGitCommitHash)
|
2019-05-01 08:32:30 +00:00
|
|
|
# and instead uncomment the following, adding the complete git hash of the checkout you are using:
|
|
|
|
# set(GIT_COMMIT_HASH 0000000000000000000000000000000000000000)
|
|
|
|
|
|
|
|
string(SUBSTRING "${GIT_COMMIT_HASH}" 0 8 solvespace_GIT_HASH)
|
2024-03-07 02:58:48 +00:00
|
|
|
project(solvespace
|
2022-05-12 17:51:21 +00:00
|
|
|
VERSION 3.1
|
2021-12-22 18:53:28 +00:00
|
|
|
LANGUAGES C CXX ASM)
|
2015-03-29 00:33:46 +00:00
|
|
|
|
2017-01-02 22:02:37 +00:00
|
|
|
set(ENABLE_GUI ON CACHE BOOL
|
2018-07-18 11:49:06 +00:00
|
|
|
"Whether the graphical interface is enabled")
|
2024-03-07 02:58:48 +00:00
|
|
|
set(USE_QT_GUI OFF CACHE BOOL
|
|
|
|
"Whether the Qt library used to build graphical interface")
|
|
|
|
set(ENABLE_CLI ON CACHE BOOL
|
|
|
|
"Whether the command line interface is enabled")
|
|
|
|
set(ENABLE_TESTS ON CACHE BOOL
|
|
|
|
"Whether the test suite will be built and run")
|
|
|
|
set(ENABLE_COVERAGE OFF CACHE BOOL
|
|
|
|
"Whether code coverage information will be collected")
|
|
|
|
set(ENABLE_SANITIZERS OFF CACHE BOOL
|
|
|
|
"Whether to enable Clang's AddressSanitizer and UndefinedBehaviorSanitizer")
|
|
|
|
set(ENABLE_OPENMP OFF CACHE BOOL
|
|
|
|
"Whether geometric operations will be parallelized using OpenMP")
|
|
|
|
set(ENABLE_LTO OFF CACHE BOOL
|
|
|
|
"Whether interprocedural (global) optimizations are enabled")
|
2018-01-02 20:35:27 +00:00
|
|
|
option(FORCE_VENDORED_Eigen3
|
|
|
|
"Whether we should use our bundled Eigen even in the presence of a system copy"
|
|
|
|
OFF)
|
2016-07-25 19:37:48 +00:00
|
|
|
|
2024-03-07 02:58:48 +00:00
|
|
|
set(OPENGL 3 CACHE STRING "OpenGL version to use (one of: 1 3)")
|
2016-11-16 02:22:10 +00:00
|
|
|
|
Use the same code for loading resources in all executables.
All of our executables need resources; e.g. the vector font is
a resource and it is necessary for generation. Before this commit,
the GUI executable loaded the resources in a nice way, and everything
else did it in a very ad-hoc, fragile way.
After this commit, all executables are placed in <build>/bin and
follow the same algorithm:
* On Windows, resources are compiled and linked into every
executable.
* On Linux, resources are copied into <build>/res (which is
tried first) and <prefix>/share/solvespace (which is tried
second).
* On macOS, resources are copied into <build>/res (which is
tried first) and <build>/bin/solvespace.app/Contents/Resources
(which is tried second).
In practice this means that we can add as many executables as we want
without duplicating lots of code. In addition, on macOS, we can
place supplementary executables into the bundle, and they can use
resources from the bundle transparently.
2016-11-28 04:16:18 +00:00
|
|
|
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
|
|
|
|
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
|
2019-11-23 13:20:45 +00:00
|
|
|
if("${CMAKE_GENERATOR}" STREQUAL "Xcode")
|
|
|
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY $<1:${CMAKE_BINARY_DIR}/bin>)
|
|
|
|
endif()
|
Use the same code for loading resources in all executables.
All of our executables need resources; e.g. the vector font is
a resource and it is necessary for generation. Before this commit,
the GUI executable loaded the resources in a nice way, and everything
else did it in a very ad-hoc, fragile way.
After this commit, all executables are placed in <build>/bin and
follow the same algorithm:
* On Windows, resources are compiled and linked into every
executable.
* On Linux, resources are copied into <build>/res (which is
tried first) and <prefix>/share/solvespace (which is tried
second).
* On macOS, resources are copied into <build>/res (which is
tried first) and <build>/bin/solvespace.app/Contents/Resources
(which is tried second).
In practice this means that we can add as many executables as we want
without duplicating lots of code. In addition, on macOS, we can
place supplementary executables into the bundle, and they can use
resources from the bundle transparently.
2016-11-28 04:16:18 +00:00
|
|
|
|
2016-07-31 22:51:50 +00:00
|
|
|
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
2016-05-18 16:44:03 +00:00
|
|
|
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-07-24 20:21:53 +00:00
|
|
|
# common compiler flags
|
2019-11-24 18:55:46 +00:00
|
|
|
include(CheckCXXCompilerFlag)
|
|
|
|
|
2021-02-08 00:07:53 +00:00
|
|
|
if (NOT APPLE)
|
|
|
|
set(FILE_PREFIX_MAP "-ffile-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}=.")
|
|
|
|
check_cxx_compiler_flag("${FILE_PREFIX_MAP}" HAS_FILE_PREFIX_MAP)
|
|
|
|
if(HAS_FILE_PREFIX_MAP)
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FILE_PREFIX_MAP}")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FILE_PREFIX_MAP}")
|
|
|
|
endif()
|
2019-11-23 16:33:47 +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++")
|
2022-06-26 11:58:36 +00:00
|
|
|
# Link 32 bit SolveSpace with --large-address-aware which allows it to access
|
|
|
|
# up to 3GB on a properly configured 32 bit Windows and up to 4GB on 64 bit.
|
|
|
|
# See https://msdn.microsoft.com/en-us/library/aa366778
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "-Wl,--large-address-aware")
|
2020-03-24 12:04:06 +00:00
|
|
|
endif()
|
2016-11-16 02:22:10 +00:00
|
|
|
|
2020-03-24 12:04:06 +00:00
|
|
|
# Ensure that all platforms use 64-bit IEEE floating point operations for consistency;
|
|
|
|
# this is most important for the testsuite, which compares savefiles directly
|
|
|
|
# and depends on consistent rounding of intermediate results.
|
|
|
|
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "i686" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "X86")
|
|
|
|
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
|
|
|
set(FLOAT_FLAGS "-mfpmath=sse -msse2")
|
|
|
|
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
|
|
|
set(FLOAT_FLAGS "-msse2")
|
2016-11-16 02:22:10 +00:00
|
|
|
endif()
|
2020-03-24 12:04:06 +00:00
|
|
|
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLOAT_FLAGS}")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLOAT_FLAGS}")
|
2015-07-05 05:45:39 +00:00
|
|
|
endif()
|
|
|
|
|
2024-03-07 02:58:48 +00:00
|
|
|
if(ENABLE_LTO)
|
|
|
|
include(CheckIPOSupported)
|
|
|
|
check_ipo_supported()
|
|
|
|
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(ENABLE_OPENMP)
|
|
|
|
find_package( OpenMP REQUIRED )
|
|
|
|
if(OPENMP_FOUND)
|
|
|
|
add_library(slvs_openmp INTERFACE)
|
|
|
|
target_compile_options(slvs_openmp INTERFACE ${OpenMP_CXX_FLAGS})
|
|
|
|
target_link_libraries(slvs_openmp INTERFACE
|
|
|
|
${OpenMP_CXX_LIBRARIES})
|
|
|
|
target_include_directories(slvs_openmp INTERFACE SYSTEM
|
|
|
|
${OpenMP_CXX_INCLUDE_DIRS})
|
|
|
|
message(STATUS "found OpenMP, compiling with flags: " ${OpenMP_CXX_FLAGS} )
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2016-07-24 20:21:53 +00:00
|
|
|
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
|
2015-12-25 16:06:59 +00:00
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed ${CMAKE_EXE_LINKER_FLAGS}")
|
|
|
|
endif()
|
|
|
|
|
2024-03-07 02:58:48 +00:00
|
|
|
if(ENABLE_SANITIZERS)
|
|
|
|
if(NOT SANITIZERS)
|
|
|
|
set(SANITIZERS "address;undefined")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if("thread" IN_LIST SANITIZERS)
|
|
|
|
list(REMOVE_ITEM SANITIZERS "thread")
|
|
|
|
list(APPEND SANITIZE_OPTIONS thread)
|
|
|
|
endif()
|
|
|
|
if("address" IN_LIST SANITIZERS)
|
|
|
|
list(REMOVE_ITEM SANITIZERS "address")
|
|
|
|
list(APPEND SANITIZE_OPTIONS address)
|
|
|
|
endif()
|
|
|
|
if("undefined" IN_LIST SANITIZERS)
|
|
|
|
list(REMOVE_ITEM SANITIZERS "undefined")
|
|
|
|
list(APPEND SANITIZE_OPTIONS alignment bounds)
|
|
|
|
list(APPEND SANITIZE_OPTIONS shift signed-integer-overflow integer-divide-by-zero)
|
|
|
|
list(APPEND SANITIZE_OPTIONS null bool enum)
|
|
|
|
list(APPEND SANITIZE_OPTIONS return)
|
|
|
|
endif()
|
|
|
|
if(SANITIZERS)
|
|
|
|
message(FATAL_ERROR "Unknown sanitizer(s) ${SANITIZERS}")
|
|
|
|
else()
|
|
|
|
message(STATUS "Using sanitizer options ${SANITIZE_OPTIONS}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
string(REPLACE ";" "," SANITIZE_OPTIONS "${SANITIZE_OPTIONS}")
|
|
|
|
|
|
|
|
if (NOT APPLE)
|
|
|
|
set(SANITIZE_FLAGS "-O1 -fsanitize=${SANITIZE_OPTIONS} -fno-sanitize-recover=address,undefined")
|
|
|
|
else()
|
|
|
|
set(SANITIZE_FLAGS "-O1 -fsanitize=${SANITIZE_OPTIONS}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
|
|
|
set(SANITIZE_FLAGS "${SANITIZE_FLAGS} -fno-omit-frame-pointer -fno-optimize-sibling-calls")
|
|
|
|
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
|
|
|
set(SANITIZE_FLAGS "${SANITIZE_FLAGS} -fuse-ld=gold")
|
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "Sanitizers are only available when using GCC or Clang")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SANITIZE_FLAGS}")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SANITIZE_FLAGS}")
|
|
|
|
endif()
|
|
|
|
|
2018-07-12 11:10:25 +00:00
|
|
|
# common dependencies
|
|
|
|
|
|
|
|
if(APPLE)
|
|
|
|
set(CMAKE_FIND_FRAMEWORK LAST)
|
|
|
|
endif()
|
2015-03-29 00:33:46 +00:00
|
|
|
|
2022-08-05 02:13:03 +00:00
|
|
|
if(EMSCRIPTEN)
|
|
|
|
set(M_LIBRARY "" CACHE STRING "libm (not necessary)" FORCE)
|
|
|
|
endif()
|
|
|
|
|
2015-11-03 19:05:20 +00:00
|
|
|
message(STATUS "Using in-tree libdxfrw")
|
|
|
|
add_subdirectory(extlib/libdxfrw)
|
|
|
|
|
2020-07-09 13:25:36 +00:00
|
|
|
message(STATUS "Using in-tree mimalloc")
|
|
|
|
set(MI_OVERRIDE OFF CACHE BOOL "")
|
|
|
|
set(MI_BUILD_SHARED OFF CACHE BOOL "")
|
|
|
|
set(MI_BUILD_OBJECT OFF CACHE BOOL "")
|
|
|
|
set(MI_BUILD_TESTS OFF CACHE BOOL "")
|
2020-07-12 20:57:02 +00:00
|
|
|
add_subdirectory(extlib/mimalloc EXCLUDE_FROM_ALL)
|
2020-07-09 13:25:36 +00:00
|
|
|
set(MIMALLOC_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/extlib/mimalloc/include)
|
|
|
|
|
2018-01-02 20:35:27 +00:00
|
|
|
if(NOT FORCE_VENDORED_Eigen3)
|
|
|
|
find_package(Eigen3 CONFIG)
|
|
|
|
endif()
|
2022-05-13 21:00:59 +00:00
|
|
|
if(FORCE_VENDORED_Eigen3 OR NOT EIGEN3_INCLUDE_DIRS)
|
2018-01-02 20:35:27 +00:00
|
|
|
message(STATUS "Using in-tree Eigen")
|
|
|
|
set(EIGEN3_FOUND YES)
|
|
|
|
set(EIGEN3_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extlib/eigen)
|
|
|
|
else()
|
|
|
|
message(STATUS "Using system Eigen: ${EIGEN3_INCLUDE_DIRS}")
|
|
|
|
endif()
|
2022-05-13 21:00:59 +00:00
|
|
|
if(NOT EXISTS "${EIGEN3_INCLUDE_DIRS}")
|
|
|
|
message(FATAL_ERROR "Eigen 3 not found on system or in-tree")
|
|
|
|
endif()
|
2018-01-02 20:35:27 +00:00
|
|
|
|
2024-03-07 02:58:48 +00:00
|
|
|
|
|
|
|
if(WIN32 OR APPLE OR EMSCRIPTEN)
|
|
|
|
# On Win32 and macOS we use vendored packages, since there is little to no benefit
|
|
|
|
# to trying to find system versions. In particular, trying to link to libraries from
|
|
|
|
# Homebrew or macOS system libraries into the .app file is highly likely to result
|
|
|
|
# in incompatibilities after upgrades.
|
|
|
|
|
|
|
|
include(FindVendoredPackage)
|
|
|
|
include(AddVendoredSubdirectory)
|
|
|
|
|
|
|
|
set(FORCE_VENDORED_ZLIB ON)
|
|
|
|
set(FORCE_VENDORED_PNG ON)
|
|
|
|
set(FORCE_VENDORED_Freetype ON)
|
|
|
|
|
|
|
|
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 png_static
|
|
|
|
PNG_ARM_NEON "off"
|
|
|
|
PNG_SHARED OFF
|
|
|
|
PNG_STATIC ON
|
|
|
|
PNG_EXECUTABLES OFF
|
|
|
|
PNG_TESTS OFF
|
|
|
|
PNG_FRAMEWORK OFF
|
|
|
|
PNG_PNG_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/extlib/libpng)
|
|
|
|
list(APPEND PNG_PNG_INCLUDE_DIR ${CMAKE_BINARY_DIR}/extlib/libpng)
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
message(STATUS "Using in-tree pixman")
|
|
|
|
set(PIXMAN_FOUND YES)
|
|
|
|
set(PIXMAN_LIBRARY pixman)
|
|
|
|
set(PIXMAN_BUILD_TESTS OFF CACHE BOOL "")
|
|
|
|
set(PIXMAN_BUILD_DEMOS OFF CACHE BOOL "")
|
|
|
|
|
|
|
|
set(PIXMAN_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extlib/pixman/pixman)
|
|
|
|
list(APPEND PIXMAN_INCLUDE_DIRS ${CMAKE_BINARY_DIR}/extlib/pixman/pixman)
|
|
|
|
add_vendored_subdirectory(extlib/pixman)
|
|
|
|
|
|
|
|
message(STATUS "Using in-tree cairo")
|
|
|
|
add_vendored_subdirectory(extlib/cairo)
|
|
|
|
set(CAIRO_FOUND YES)
|
|
|
|
set(CAIRO_LIBRARIES cairo)
|
|
|
|
set(CAIRO_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extlib/cairo/src)
|
|
|
|
list(APPEND CAIRO_INCLUDE_DIRS ${CMAKE_BINARY_DIR}/extlib/cairo/src)
|
2018-07-12 11:10:25 +00:00
|
|
|
else()
|
2024-03-07 02:58:48 +00:00
|
|
|
# On Linux and BSDs we're a good citizen and link to system libraries.
|
|
|
|
find_package(Backtrace)
|
|
|
|
find_package(PkgConfig REQUIRED)
|
|
|
|
find_package(ZLIB REQUIRED)
|
|
|
|
find_package(PNG REQUIRED)
|
|
|
|
find_package(Freetype REQUIRED)
|
|
|
|
if (NOT USE_QT_GUI OR ENABLE_CLI OR ENABLE_TESTS)
|
|
|
|
find_package(Cairo REQUIRED)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# GUI dependencies
|
|
|
|
|
|
|
|
if(ENABLE_GUI)
|
|
|
|
if(WIN32)
|
|
|
|
if(OPENGL STREQUAL "3")
|
|
|
|
message(STATUS "Using in-tree ANGLE")
|
|
|
|
set(ANGLE_STATIC ON CACHE INTERNAL "")
|
|
|
|
set(ANGLE_ENABLE_D3D9 ON CACHE INTERNAL "")
|
|
|
|
set(ANGLE_ENABLE_D3D11 ON CACHE INTERNAL "")
|
|
|
|
set(ANGLE_ENABLE_OPENGL ON CACHE INTERNAL "")
|
|
|
|
set(ANGLE_ENABLE_ESSL ON CACHE INTERNAL "")
|
|
|
|
set(ANGLE_ENABLE_GLSL ON CACHE INTERNAL "")
|
|
|
|
set(ANGLE_ENABLE_HLSL ON CACHE INTERNAL "")
|
|
|
|
add_vendored_subdirectory(extlib/angle)
|
|
|
|
set(OPENGL_LIBRARIES EGL GLESv2)
|
|
|
|
set(OPENGL_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/extlib/angle/include)
|
|
|
|
else()
|
|
|
|
find_package(OpenGL REQUIRED)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(MSVC AND ${CMAKE_SIZEOF_VOID_P} EQUAL 4)
|
|
|
|
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()
|
|
|
|
elseif(APPLE)
|
|
|
|
find_package(OpenGL REQUIRED)
|
|
|
|
find_library(APPKIT_LIBRARY AppKit REQUIRED)
|
|
|
|
elseif(EMSCRIPTEN)
|
|
|
|
# Everything is built in
|
|
|
|
else()
|
|
|
|
find_package(OpenGL REQUIRED)
|
|
|
|
find_package(SpaceWare)
|
|
|
|
pkg_check_modules(FONTCONFIG REQUIRED fontconfig)
|
|
|
|
if (NOT USE_QT_GUI)
|
|
|
|
pkg_check_modules(JSONC REQUIRED json-c)
|
|
|
|
pkg_check_modules(GTKMM REQUIRED gtkmm-3.0>=3.18 pangomm-1.4 x11)
|
|
|
|
endif()
|
|
|
|
endif()
|
2015-03-29 00:33:46 +00:00
|
|
|
endif()
|
2024-03-07 02:58:48 +00:00
|
|
|
|
2018-07-12 11:10:25 +00:00
|
|
|
# code coverage
|
|
|
|
|
2024-03-07 02:58:48 +00:00
|
|
|
if(ENABLE_COVERAGE)
|
|
|
|
if(CMAKE_CXX_COMPILER_ID STREQUAL GNU)
|
|
|
|
find_program(GCOV gcov)
|
|
|
|
elseif(CMAKE_CXX_COMPILER_ID MATCHES Clang)
|
|
|
|
find_program(LLVM_COV llvm-cov)
|
|
|
|
|
|
|
|
if(LLVM_COV)
|
|
|
|
set(GCOV ${CMAKE_CURRENT_BINARY_DIR}/llvm-gcov.sh)
|
|
|
|
file(WRITE ${GCOV} "#!/bin/sh -e\n${LLVM_COV} gcov $*")
|
|
|
|
execute_process(COMMAND chmod +x ${GCOV})
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
find_program(LCOV lcov)
|
|
|
|
find_program(GENHTML genhtml)
|
|
|
|
if(NOT GCOV OR NOT LCOV OR NOT GENHTML)
|
|
|
|
message(FATAL_ERROR "gcov/llvm-cov and lcov are required for producing coverage reports")
|
|
|
|
endif()
|
|
|
|
endif()
|
2016-07-25 22:09:58 +00:00
|
|
|
|
2018-07-12 11:10:25 +00:00
|
|
|
# translations
|
|
|
|
|
2017-01-04 15:39:27 +00:00
|
|
|
find_program(XGETTEXT xgettext)
|
|
|
|
find_program(MSGINIT msginit)
|
|
|
|
find_program(MSGMERGE msgmerge)
|
|
|
|
if(XGETTEXT AND MSGINIT AND MSGMERGE)
|
|
|
|
set(HAVE_GETTEXT TRUE)
|
|
|
|
else()
|
|
|
|
message(WARNING "Gettext not found, translations will not be updated")
|
|
|
|
set(HAVE_GETTEXT FALSE)
|
|
|
|
endif()
|
|
|
|
|
2016-07-24 20:21:53 +00:00
|
|
|
# solvespace-only compiler flags
|
|
|
|
|
|
|
|
if(WIN32)
|
|
|
|
add_definitions(
|
|
|
|
-D_CRT_SECURE_NO_DEPRECATE
|
|
|
|
-D_CRT_SECURE_NO_WARNINGS
|
|
|
|
-D_SCL_SECURE_NO_WARNINGS
|
2019-05-23 08:01:26 +00:00
|
|
|
-DWINVER=0x0501
|
|
|
|
-D_WIN32_WINNT=0x0501
|
2016-07-24 20:21:53 +00:00
|
|
|
-D_WIN32_IE=_WIN32_WINNT
|
|
|
|
-DISOLATION_AWARE_ENABLED
|
|
|
|
-DWIN32
|
|
|
|
-DWIN32_LEAN_AND_MEAN
|
|
|
|
-DUNICODE
|
|
|
|
-D_UNICODE
|
|
|
|
-DNOMINMAX
|
|
|
|
-D_USE_MATH_DEFINES)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
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")
|
|
|
|
# Same for the (C99) __func__ special variable; we use it only in C++ code.
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D__func__=__FUNCTION__")
|
|
|
|
|
2022-07-08 21:11:24 +00:00
|
|
|
# Multi-processor Compilation
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
|
|
|
|
|
2016-07-24 20:21:53 +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")
|
2022-06-26 11:58:36 +00:00
|
|
|
|
|
|
|
# Link 32 bit SolveSpace with /LARGEADDRESSAWARE which allows it to access
|
|
|
|
# up to 3GB on a properly configured 32 bit Windows and up to 4GB on 64 bit.
|
|
|
|
# See https://msdn.microsoft.com/en-us/library/aa366778
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LARGEADDRESSAWARE")
|
|
|
|
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /LARGEADDRESSAWARE")
|
2016-07-24 20:21:53 +00:00
|
|
|
endif()
|
|
|
|
|
2016-07-25 22:09:58 +00:00
|
|
|
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
2019-05-23 08:01:26 +00:00
|
|
|
set(WARNING_FLAGS "-Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers")
|
2016-07-25 22:09:58 +00:00
|
|
|
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
2016-07-24 20:21:53 +00:00
|
|
|
set(WARNING_FLAGS "${WARNING_FLAGS} -Wfloat-conversion")
|
|
|
|
endif()
|
|
|
|
# We rely on these -Werror flags.
|
|
|
|
set(WARNING_FLAGS "${WARNING_FLAGS} -Werror=switch")
|
|
|
|
endif()
|
|
|
|
|
2016-07-25 19:37:48 +00:00
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS}")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS}")
|
|
|
|
|
2016-07-24 20:21:53 +00:00
|
|
|
if(WIN32)
|
|
|
|
set(CMAKE_RC_FLAGS "${CMAKE_RC_FLAGS} -l0")
|
|
|
|
endif()
|
|
|
|
|
2016-07-25 22:09:58 +00:00
|
|
|
if(ENABLE_COVERAGE)
|
|
|
|
if(NOT (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR
|
|
|
|
CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
|
|
|
|
message(FATAL_ERROR "Code coverage is only available on GCC and Clang")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
|
|
|
|
message(FATAL_ERROR "Code coverage produces reliable results only on Debug builds")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# With -fexceptions, every call becomes a branch. While technically accurate,
|
|
|
|
# this is not useful for us.
|
|
|
|
set(COVERAGE_FLAGS -fno-exceptions --coverage)
|
|
|
|
set(COVERAGE_LIBRARY --coverage)
|
|
|
|
endif()
|
|
|
|
|
2018-07-12 11:10:25 +00:00
|
|
|
# application components
|
2015-03-29 00:33:46 +00:00
|
|
|
|
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)
|
2024-03-07 02:58:48 +00:00
|
|
|
if(ENABLE_TESTS)
|
|
|
|
add_subdirectory(test)
|
|
|
|
endif()
|
2016-11-18 13:55:24 +00:00
|
|
|
if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
|
|
|
|
add_subdirectory(bench)
|
|
|
|
else()
|
|
|
|
message(STATUS "Benchmarking disabled in debug builds.")
|
|
|
|
endif()
|