2017-12-21 12:48:17 -08:00
CMAKE_MINIMUM_REQUIRED ( VERSION 3.2 )
2018-01-13 22:58:29 +08:00
IF ( POLICY CMP0066 )
CMAKE_POLICY ( SET CMP0066 OLD )
ENDIF ( )
IF ( POLICY CMP0067 )
CMAKE_POLICY ( SET CMP0067 OLD )
ENDIF ( )
2018-02-10 19:46:34 +01:00
PROJECT ( fish )
2017-08-31 13:24:20 -07:00
# We are C++11.
SET ( CMAKE_CXX_STANDARD 11 )
2018-06-18 00:21:23 -05:00
SET ( CMAKE_CXX_FLAGS_DEBUG "-O0 -g" )
SET ( CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g" )
SET ( CMAKE_CXX_FLAGS_RELEASE "-O2" )
SET ( DEFAULT_BUILD_TYPE "RelWithDebInfo" )
IF ( NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES )
MESSAGE ( STATUS "Setting build type to default '${DEFAULT_BUILD_TYPE}'" )
SET ( CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}" )
ENDIF ( )
2017-08-31 13:24:20 -07:00
2018-11-02 12:26:27 +01:00
# Force colored warnings in Ninja's output, if the compiler has -fdiagnostics-color support.
# Rationale in https://github.com/ninja-build/ninja/issues/814
if ( CMAKE_GENERATOR STREQUAL "Ninja" AND
( ( C M A K E _ C X X _ C O M P I L E R _ I D S T R E Q U A L " G N U " A N D N O T C M A K E _ C X X _ C O M P I L E R _ V E R S I O N V E R S I O N _ L E S S 4 . 9 ) O R
2018-12-11 03:53:12 -08:00
( C M A K E _ C X X _ C O M P I L E R _ I D S T R E Q U A L " C l a n g " A N D N O T C M A K E _ C X X _ C O M P I L E R _ V E R S I O N V E R S I O N _ L E S S 3 . 5 ) O R
( C M A K E _ C X X _ C O M P I L E R _ I D S T R E Q U A L " A p p l e C l a n g " A N D N O T C M A K E _ C X X _ C O M P I L E R _ V E R S I O N V E R S I O N _ L E S S 6 . 0 ) ) )
2018-11-02 12:26:27 +01:00
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fdiagnostics-color=always" )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=always" )
endif ( )
2017-12-17 14:45:29 -08:00
# Disable exception handling.
ADD_COMPILE_OPTIONS ( -fno-exceptions )
2017-10-04 21:40:58 -07:00
# Hide the CMake Rules directories in Xcode projects.
SOURCE_GROUP ( "CMake Rules" REGULAR_EXPRESSION "^$" )
# Put source and header files at top level under targets.
SOURCE_GROUP ( "Source Files" REGULAR_EXPRESSION "^$" )
SOURCE_GROUP ( "Header Files" REGULAR_EXPRESSION "^$" )
SOURCE_GROUP ( "Builtins" REGULAR_EXPRESSION "builtin_.*" )
# Support folders.
SET_PROPERTY ( GLOBAL PROPERTY USE_FOLDERS ON )
2017-11-11 23:08:37 +08:00
list ( APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake" )
2018-01-23 17:35:38 +08:00
IF ( CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR )
SET ( FISH_IN_TREE_BUILD TRUE )
ELSE ( )
SET ( FISH_IN_TREE_BUILD FALSE )
ENDIF ( )
2017-08-31 13:24:20 -07:00
# All objects that the system needs to build fish, except fish.cpp
SET ( FISH_SRCS
s r c / a u t o l o a d . c p p s r c / b u i l t i n . c p p s r c / b u i l t i n _ b g . c p p s r c / b u i l t i n _ b i n d . c p p
s r c / b u i l t i n _ b l o c k . c p p s r c / b u i l t i n _ b u i l t i n . c p p s r c / b u i l t i n _ c d . c p p
s r c / b u i l t i n _ c o m m a n d . c p p s r c / b u i l t i n _ c o m m a n d l i n e . c p p
s r c / b u i l t i n _ c o m p l e t e . c p p s r c / b u i l t i n _ c o n t a i n s . c p p s r c / b u i l t i n _ d i s o w n . c p p
s r c / b u i l t i n _ e c h o . c p p s r c / b u i l t i n _ e m i t . c p p s r c / b u i l t i n _ e x i t . c p p
s r c / b u i l t i n _ f g . c p p s r c / b u i l t i n _ f u n c t i o n . c p p s r c / b u i l t i n _ f u n c t i o n s . c p p
s r c / b u i l t i n _ a r g p a r s e . c p p s r c / b u i l t i n _ h i s t o r y . c p p s r c / b u i l t i n _ j o b s . c p p
s r c / b u i l t i n _ m a t h . c p p s r c / b u i l t i n _ p r i n t f . c p p s r c / b u i l t i n _ p w d . c p p
s r c / b u i l t i n _ r a n d o m . c p p s r c / b u i l t i n _ r e a d . c p p s r c / b u i l t i n _ r e a l p a t h . c p p
s r c / b u i l t i n _ r e t u r n . c p p s r c / b u i l t i n _ s e t . c p p s r c / b u i l t i n _ s e t _ c o l o r . c p p
s r c / b u i l t i n _ s o u r c e . c p p s r c / b u i l t i n _ s t a t u s . c p p s r c / b u i l t i n _ s t r i n g . c p p
2017-11-16 10:46:44 -08:00
s r c / b u i l t i n _ t e s t . c p p s r c / b u i l t i n _ u l i m i t . c p p s r c / b u i l t i n _ w a i t . c p p
s r c / c o l o r . c p p s r c / c o m m o n . c p p s r c / c o m p l e t e . c p p s r c / e n v . c p p
s r c / e n v _ u n i v e r s a l _ c o m m o n . c p p s r c / e v e n t . c p p s r c / e x e c . c p p s r c / e x p a n d . c p p
s r c / f a l l b a c k . c p p s r c / f i s h _ v e r s i o n . c p p s r c / f u n c t i o n . c p p s r c / h i g h l i g h t . c p p
s r c / h i s t o r y . c p p s r c / i n p u t . c p p s r c / i n p u t _ c o m m o n . c p p s r c / i n t e r n . c p p s r c / i o . c p p
s r c / i o t h r e a d . c p p s r c / k i l l . c p p s r c / o u t p u t . c p p s r c / p a g e r . c p p
s r c / p a r s e _ e x e c u t i o n . c p p s r c / p a r s e _ p r o d u c t i o n s . c p p s r c / p a r s e _ t r e e . c p p
s r c / p a r s e _ u t i l . c p p s r c / p a r s e r . c p p s r c / p a r s e r _ k e y w o r d s . c p p s r c / p a t h . c p p
s r c / p o s t f o r k . c p p s r c / p r o c . c p p s r c / r e a d e r . c p p s r c / s a n i t y . c p p s r c / s c r e e n . c p p
2018-11-02 13:35:06 +01:00
s r c / s i g n a l . c p p s r c / t i n y e x p r . c p p s r c / t n o d e . c p p s r c / t o k e n i z e r . c p p s r c / u t f 8 . c p p s r c / u t i l . c p p
2017-11-16 10:46:44 -08:00
s r c / w c s t r i n g u t i l . c p p s r c / w g e t o p t . c p p s r c / w i l d c a r d . c p p s r c / w u t i l . c p p
2019-01-28 13:26:22 -08:00
s r c / f u t u r e _ f e a t u r e _ f l a g s . c p p s r c / r e d i r e c t i o n . c p p
2017-08-31 13:24:20 -07:00
)
2017-10-04 21:40:58 -07:00
# Header files are just globbed.
FILE ( GLOB FISH_HEADERS src/*.h )
2017-08-31 13:24:20 -07:00
# Set up config.h
2017-11-07 08:31:42 +08:00
INCLUDE ( cmake/ConfigureChecks.cmake )
2017-11-16 21:33:35 +08:00
INCLUDE ( cmake/gettext.cmake )
2017-08-31 13:24:20 -07:00
CONFIGURE_FILE ( ${ CMAKE_CURRENT_SOURCE_DIR } /config_cmake.h.in
$ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / c o n f i g . h )
INCLUDE_DIRECTORIES ( ${ CMAKE_CURRENT_BINARY_DIR } )
# Set up standard directories.
INCLUDE ( GNUInstallDirs )
2018-01-07 22:25:29 -08:00
ADD_DEFINITIONS ( -D_UNICODE=1
2017-08-31 13:24:20 -07:00
- D L O C A L E D I R = " $ { C M A K E _ I N S T A L L _ F U L L _ L O C A L E D I R } "
- D P R E F I X = L " $ { C M A K E _ I N S T A L L _ P R E F I X } "
- D D A T A D I R = L " $ { C M A K E _ I N S T A L L _ F U L L _ D A T A D I R } "
- D S Y S C O N F D I R = L " $ { C M A K E _ I N S T A L L _ F U L L _ S Y S C O N F D I R } "
- D B I N D I R = L " $ { C M A K E _ I N S T A L L _ F U L L _ B I N D I R } "
- D D O C D I R = L " $ { C M A K E _ I N S T A L L _ F U L L _ D O C D I R } " )
2018-01-08 01:39:45 -08:00
# Set up the machinery around FISH-BUILD-VERSION-FILE
# This defines the FBVF variable.
INCLUDE ( Version )
2018-10-13 21:36:59 -05:00
# Let fish pick up when we're running out of the build directory without installing
2019-01-30 14:24:59 -06:00
GET_FILENAME_COMPONENT ( REAL_CMAKE_BINARY_DIR "${CMAKE_BINARY_DIR}" REALPATH )
GET_FILENAME_COMPONENT ( REAL_CMAKE_SOURCE_DIR "${CMAKE_SOURCE_DIR}" REALPATH )
ADD_DEFINITIONS ( -DCMAKE_BINARY_DIR= "${REAL_CMAKE_BINARY_DIR}" )
ADD_DEFINITIONS ( -DCMAKE_SOURCE_DIR= "${REAL_CMAKE_SOURCE_DIR}" )
2018-10-13 21:36:59 -05:00
2018-01-08 01:39:45 -08:00
# Teach fish_version.o to rebuild when FBVF changes.
# The standard C++ include detection machinery misses this.
SET_SOURCE_FILES_PROPERTIES ( src/fish_version.cpp
P R O P E R T I E S O B J E C T _ D E P E N D S
$ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / $ { F B V F } )
2018-03-25 10:19:57 +02:00
OPTION ( INTERNAL_WCWIDTH "use fallback wcwidth" ON )
IF ( INTERNAL_WCWIDTH )
add_definitions ( -DHAVE_BROKEN_WCWIDTH=1 )
ELSE ( )
add_definitions ( -DHAVE_BROKEN_WCWIDTH=0 )
ENDIF ( )
2017-10-04 20:31:35 -07:00
# Set up PCRE2
2017-11-07 08:31:42 +08:00
INCLUDE ( cmake/PCRE2.cmake )
2017-08-31 13:24:20 -07:00
2017-09-11 22:58:49 -07:00
# Set up the docs.
2017-11-07 08:31:42 +08:00
INCLUDE ( cmake/Docs.cmake )
2017-09-11 22:58:49 -07:00
2017-08-31 13:24:20 -07:00
# Define a function to link dependencies.
FUNCTION ( FISH_LINK_DEPS target )
2018-10-22 21:14:35 +02:00
TARGET_LINK_LIBRARIES ( ${ target } fishlib )
2017-08-31 13:24:20 -07:00
ENDFUNCTION ( FISH_LINK_DEPS )
2017-10-04 21:33:43 -07:00
# Define libfish.a.
ADD_LIBRARY ( fishlib STATIC ${ FISH_SRCS } )
2017-10-04 21:40:58 -07:00
TARGET_SOURCES ( fishlib PRIVATE ${ FISH_HEADERS } )
2017-10-04 21:33:43 -07:00
TARGET_LINK_LIBRARIES ( fishlib
2017-10-14 13:07:05 -07:00
$ { C U R S E S _ L I B R A R Y } $ { C U R S E S _ E X T R A _ L I B R A R Y } T h r e a d s : : T h r e a d s $ { C M A K E _ D L _ L I B S }
2018-02-10 19:46:34 +01:00
$ { P C R E 2 _ L I B } $ { I n t l _ L I B R A R I E S } )
2017-10-04 21:33:43 -07:00
2017-08-31 13:24:20 -07:00
# Define fish.
2017-10-04 21:33:43 -07:00
ADD_EXECUTABLE ( fish src/fish.cpp )
2017-09-01 00:31:51 -07:00
FISH_LINK_DEPS ( fish )
2017-08-31 13:24:20 -07:00
2017-09-08 15:19:07 -07:00
# Define fish_indent.
ADD_EXECUTABLE ( fish_indent
2017-10-04 21:33:43 -07:00
s r c / f i s h _ i n d e n t . c p p s r c / p r i n t _ h e l p . c p p )
2017-09-08 15:19:07 -07:00
FISH_LINK_DEPS ( fish_indent )
# Define fish_key_reader.
ADD_EXECUTABLE ( fish_key_reader
2017-10-04 21:33:43 -07:00
s r c / f i s h _ k e y _ r e a d e r . c p p s r c / p r i n t _ h e l p . c p p )
2017-09-08 15:19:07 -07:00
FISH_LINK_DEPS ( fish_key_reader )
2017-09-01 00:31:51 -07:00
# Set up tests.
2017-11-07 08:31:42 +08:00
INCLUDE ( cmake/Tests.cmake )
2017-10-04 20:45:48 -07:00
# Set up install.
2017-11-07 08:31:42 +08:00
INCLUDE ( cmake/Install.cmake )
2017-11-13 22:21:54 +08:00
INCLUDE ( FeatureSummary )
FEATURE_SUMMARY ( WHAT ALL )