diff options
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r-- | CMakeLists.txt | 244 |
1 files changed, 111 insertions, 133 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index a9b083e..845c847 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,187 +1,165 @@ -PROJECT(XTrkCAD) -enable_testing() -cmake_minimum_required(VERSION 2.8) -set(CMAKE_MACOSX_RPATH 0) +# Main CMake file for XTrackCAD -# where to look first for cmake modules, before ${CMAKE_ROOT}/Modules/ is checked +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") -# Setup high-level build options ... -if(UNIX) - include(FindPkgConfig) - set(XTRKCAD_USE_GTK_DEFAULT ON) - if(APPLE) - SET(XTRKCAD_USE_GETTEXT_DEFAULT OFF) - SET(XTRKCAD_USE_APPLEHELP_DEFAULT ON) - PKG_CHECK_MODULES(GTK_WEBKIT "webkit-1.0" QUIET) - if(GTK_WEBKIT_FOUND) - set(XTRKCAD_USE_BROWSER_DEFAULT OFF) - else() - set(XTRKCAD_USE_BROWSER_DEFAULT ON) - endif() - else() - set(XTRKCAD_USE_BROWSER_DEFAULT ON) - set(XTRKCAD_PACKAGE_GA_RELEASE_DEFAULT OFF) - endif(APPLE) -endif(UNIX) +# Include CMake defaults +include(CMakeDefaults) + +include(CheckIncludeFiles) + +include(ProgramVersion.cmake) +include(PlatformSettings.cmake) + +enable_testing() -# Set Win64 flag -IF(WIN32) - if (CMAKE_SIZEOF_VOID_P EQUAL 8) - SET(WIN64 ON CACHE BOOL "Win x64") - IF (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) - SET(CMAKE_INSTALL_PREFIX "C:/Program Files/XTrkCAD" CACHE PATH "WIN64 Install" FORCE) - ENDIF(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) - else (CMAKE_SIZEOF_VOID_P EQUAL 8) - SET(WIN64 OFF CACHE BOOL "Win x86") - endif (CMAKE_SIZEOF_VOID_P EQUAL 8) -ENDIF(WIN32) +# Find all dependencies +# +# Additional libraries find_package(Libzip) find_package(Zlib) -find_package(MiniXML) -if(MINIXML_FOUND) +# Optionally enable SVG export +find_package(MiniXML) +if(MiniXML_FOUND) set(XTRKCAD_CREATE_SVG 1) message( STATUS "MiniXML found: SVG export is enabled") -else(MINIXML_FOUND) +else() message( STATUS "MiniXML not found: no SVG export") -endif(MINIXML_FOUND) +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) -IF(WIN32) - SET(XTRKCAD_USE_GTK_DEFAULT OFF) - SET(XTRKCAD_USE_GETTEXT_DEFAULT ON) +# For handling and creation of bitmaps the FreeImage library is required +find_package(FreeImage REQUIRED) - SET(CMAKE_C_FLAGS_DEBUG "/D_DEBUG /MT /Zi /Ob0 /Od /RTC1" CACHE STRING "Flags used by the compiler during debug builds" FORCE) - SET(CMAKE_C_FLAGS_MINSIZEREL "/MT /O1 /Ob1 /D NDEBUG" CACHE STRING "Flags used by the compiler during release minumum size builds" FORCE) - SET(CMAKE_C_FLAGS_RELEASE "/MT /O2 /Ob2 /D NDEBUG" CACHE STRING "Flags used by the compiler during release builds" FORCE) - SET(CMAKE_C_FLAGS_RELWITHDEBINFO "/MT /Zi /O2 /Ob1 /D NDEBUG" CACHE STRING "Flags used by the compiler during release with debug info builds" FORCE) +# check for GTK+ 2.0 +if(UNIX) + pkg_check_modules(GTK REQUIRED "gtk+-2.0") + set(XTRKCAD_USE_GTK_DEFAULT ON) +endif(UNIX) - ADD_DEFINITIONS(-DWINDOWS) - ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS) -ENDIF(WIN32) +if(WIN32 AND NOT XTRKCAD_USE_GTK) + # use the Windows HTMLHelp tool + find_package(HTMLHelp REQUIRED) +endif(WIN32 AND NOT XTRKCAD_USE_GTK) -if(COMMAND cmake_policy) - cmake_policy(SET CMP0003 NEW) - if( POLICY CMP0026 ) - cmake_policy(SET CMP0026 NEW) - endif( POLICY CMP0026 ) -endif(COMMAND cmake_policy) +# +# Configure options +# -SET(XTRKCAD_USE_DOXYGEN_DEFAULT OFF) +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) -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" ${XTRKCAD_USE_DOXYGEN_DEFAULT}) if(UNIX AND NOT APPLE) option(XTRKCAD_USE_BROWSER "Show help in default browser" ${XTRKCAD_USE_BROWSER_DEFAULT}) - option(XTRKCAD_PACKAGE_GA_RELEASE "Package for a Beta (OFF/Default) or GA (ON) release" ${XTRKCAD_PACKAGE_GA_RELEASE_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() -IF(UNIX) - PKG_CHECK_MODULES(GTK REQUIRED "gtk+-2.0") -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) -IF(APPLE) - OPTION(XTRKCAD_USE_PACKAGEMAKER "Generate an OSX PackageMaker package for distribution." OFF) -ENDIF(APPLE) +# 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() -# 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 dependencies ... -IF(WIN32 AND NOT XTRKCAD_USE_GTK) - FIND_PACKAGE(HTMLHelp REQUIRED) -ENDIF(WIN32 AND NOT XTRKCAD_USE_GTK) - -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(NOT CMAKE_INSTALL_PREFIX STREQUAL "/usr") -ENDIF(XTRKCAD_USE_PACKAGEMAKER) +#packaging related stuff -# 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) +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() -# Find document conversion tool -find_package(Pandoc) - -# Test for headers and libraries for portability ... +# +# configure installation directories +if(WIN32) + set( CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX} ${XTRKCAD_VERSION}" ) +endif() -INCLUDE (CheckIncludeFiles) -CHECK_INCLUDE_FILES (malloc.h HAVE_MALLOC_H) -if(HAVE_MALLOC_H) - add_definitions(-DHAVE_MALLOC_H) -endif(HAVE_MALLOC_H) - -# Setup some global options for installation ... -SET(XTRKCAD_MAJOR_VERSION "5") -SET(XTRKCAD_MINOR_VERSION "2") -SET(XTRKCAD_RELEASE_VERSION "2") -SET(XTRKCAD_VERSION_MODIFIER "GA") -SET(XTRKCAD_VERSION "${XTRKCAD_MAJOR_VERSION}.${XTRKCAD_MINOR_VERSION}.${XTRKCAD_RELEASE_VERSION}${XTRKCAD_VERSION_MODIFIER}") - -IF(WIN32) - SET( CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX} ${XTRKCAD_VERSION}" ) -ENDIF(WIN32) -SET(XTRKCAD_BIN_INSTALL_DIR "bin") -SET(XTRKCAD_LOCALE_INSTALL_DIR "share/locale") -SET(XTRKCAD_PACKAGE "xtrkcad") -SET(XTRKCAD_SHARE_INSTALL_DIR "share/xtrkcad") +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) +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) - SET(GENHELP_OPTS "-bhi") +if(XTRKCAD_USE_GETTEXT) # # Find the GnuWin32 installation directory, the gettext include should be located in subdir include # - IF(WIN32) + 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 ) + 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(INTL_PATH) + include_directories(${INTL_PATH}) + endif() endif() - ENDIF(WIN32) - iF(APPLE) + endif() + if(APPLE) find_path ( INTL_PATH libintl.h ) if(INTL_PATH) message( STATUS "Use installed gettext module" ) - INCLUDE_DIRECTORIES(${INTL_PATH}) - endif(INTL_PATH) - ENDIF(APPLE) -ELSE(XTRKCAD_USE_GETTEXT) - SET(GENHELP_OPTS "-bh") -ENDIF(XTRKCAD_USE_GETTEXT) + include_directories(${INTL_PATH}) + endif() + endif() +endif() # Setup the rest of the build ... -ADD_SUBDIRECTORY(app) -ADD_SUBDIRECTORY(distribution) -ADD_SUBDIRECTORY(docs) +add_subdirectory(app) +add_subdirectory(distribution) +add_subdirectory(docs) |