2021-06-28 23:56:02 +08:00
cmake_minimum_required ( VERSION 3.5 )
2018-01-13 22:58:29 +08:00
2020-03-14 16:11:35 -07:00
if ( POLICY CMP0066 )
cmake_policy ( SET CMP0066 OLD )
endif ( )
if ( POLICY CMP0067 )
cmake_policy ( SET CMP0067 NEW )
endif ( )
2018-01-13 22:58:29 +08:00
2020-03-14 16:11:35 -07:00
include ( cmake/Mac.cmake )
2020-02-12 22:19:50 -08:00
2020-03-14 16:11:35 -07:00
project ( fish )
2020-04-01 19:33:31 +03:00
set ( CMAKE_EXPORT_COMPILE_COMMANDS ON )
2017-08-31 13:24:20 -07:00
# We are C++11.
2020-03-14 16:11:35 -07:00
set ( CMAKE_CXX_STANDARD 11 )
set ( DEFAULT_BUILD_TYPE "RelWithDebInfo" )
2018-06-18 00:21:23 -05:00
2021-09-18 22:09:31 -07:00
# Generate Xcode schemas (but not for tests).
set ( CMAKE_XCODE_GENERATE_SCHEME 1 )
2020-03-14 16:11:35 -07:00
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
2021-04-25 09:38:04 +02:00
# Error out when linking statically, it doesn't work.
if ( CMAKE_EXE_LINKER_FLAGS MATCHES ".*-static.*" )
message ( FATAL_ERROR "Fish does not support static linking" )
endif ( )
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 ) ) )
2021-10-01 09:08:08 -07:00
add_compile_options ( -fdiagnostics-color=always )
2018-11-02 12:26:27 +01:00
endif ( )
2021-01-29 18:16:00 +01:00
2019-05-29 20:47:18 +02:00
# Enable a whole bunch of warnings, but turn off:
# - comment because we use a bunch of those, and they're not really all that harmful.
# - address, because that occurs for our mkostemp check (weak-linking requires us to compare `&mkostemp == nullptr`).
2021-10-01 09:08:08 -07:00
add_compile_options ( -Wall -Wextra -Wno-comment -Wno-address )
2021-10-01 05:09:04 -07:00
if ( ( CMAKE_CXX_COMPILER_ID STREQUAL "Clang" ) OR ( CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" ) )
2021-10-01 09:08:08 -07:00
add_compile_options ( -Wunused-template -Wunused-local-typedef -Wunused-macros )
2021-10-01 05:09:04 -07:00
endif ( )
2018-11-02 12:26:27 +01:00
2017-12-17 14:45:29 -08:00
# Disable exception handling.
2020-03-14 16:11:35 -07:00
add_compile_options ( -fno-exceptions )
2017-12-17 14:45:29 -08:00
2021-10-01 04:36:14 -07:00
# Undefine NDEBUG to keep assert() in release builds.
add_definitions ( -UNDEBUG )
2022-09-20 15:52:31 -07:00
# Enable large files on GNU.
add_definitions ( -D_LARGEFILE_SOURCE
- D _ L A R G E F I L E 6 4 _ S O U R C E
- D _ F I L E _ O F F S E T _ B I T S = 6 4
- D _ A T F I L E _ S O U R C E )
2017-10-04 21:40:58 -07:00
# Hide the CMake Rules directories in Xcode projects.
2020-03-14 16:11:35 -07:00
source_group ( "CMake Rules" REGULAR_EXPRESSION "^$" )
2017-10-04 21:40:58 -07:00
# Put source and header files at top level under targets.
2021-11-09 17:07:15 -08:00
source_group ( "Source Files" REGULAR_EXPRESSION ".*\\.cpp" )
source_group ( "Header Files" REGULAR_EXPRESSION ".*\\.h" )
source_group ( "Builtins" "builtins/" )
2017-10-04 21:40:58 -07:00
# Support folders.
2020-03-14 16:11:35 -07:00
set_property ( GLOBAL PROPERTY USE_FOLDERS ON )
2017-10-04 21:40:58 -07:00
2019-01-31 15:56:27 -08:00
# Work around issue where archive-built libs go in the wrong place.
2020-03-14 16:11:35 -07:00
set ( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${ PROJECT_BINARY_DIR } )
2019-01-31 15:56:27 -08:00
2017-11-11 23:08:37 +08:00
list ( APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake" )
2020-03-14 16:11:35 -07: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 ( )
2018-01-23 17:35:38 +08:00
2019-02-18 15:22:30 +01:00
# NetBSD does weird things with finding libraries,
# making the tests fail by failing to find pcre.
#
# Keep the rpath used to build.
2020-03-14 16:11:35 -07:00
if ( CMAKE_SYSTEM_NAME STREQUAL NetBSD )
set ( CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE )
endif ( )
2019-02-18 15:22:30 +01:00
2021-11-19 19:12:29 -08:00
# List of sources for builtin functions.
set ( FISH_BUILTIN_SRCS
2022-04-01 12:05:27 -07:00
s r c / b u i l t i n . c p p s r c / b u i l t i n s / a b b r . c p p s r c / b u i l t i n s / a r g p a r s e . c p p
2021-11-09 17:07:15 -08:00
s r c / b u i l t i n s / b g . c p p s r c / b u i l t i n s / b i n d . c p p s r c / b u i l t i n s / b l o c k . c p p
s r c / b u i l t i n s / b u i l t i n . c p p s r c / b u i l t i n s / c d . c p p s r c / b u i l t i n s / c o m m a n d . c p p
s r c / b u i l t i n s / c o m m a n d l i n e . c p p s r c / b u i l t i n s / c o m p l e t e . c p p s r c / b u i l t i n s / c o n t a i n s . c p p
s r c / b u i l t i n s / d i s o w n . c p p s r c / b u i l t i n s / e c h o . c p p s r c / b u i l t i n s / e m i t . c p p
s r c / b u i l t i n s / e v a l . c p p s r c / b u i l t i n s / e x i t . c p p s r c / b u i l t i n s / f g . c p p
s r c / b u i l t i n s / f u n c t i o n . c p p s r c / b u i l t i n s / f u n c t i o n s . c p p s r c / b u i l t i n s / h i s t o r y . c p p
2021-11-17 20:22:21 +01:00
s r c / b u i l t i n s / j o b s . c p p s r c / b u i l t i n s / m a t h . c p p s r c / b u i l t i n s / p r i n t f . c p p s r c / b u i l t i n s / p a t h . c p p
2021-11-09 17:07:15 -08:00
s r c / b u i l t i n s / p w d . c p p s r c / b u i l t i n s / r a n d o m . c p p s r c / b u i l t i n s / r e a d . c p p
s r c / b u i l t i n s / r e a l p a t h . c p p s r c / b u i l t i n s / r e t u r n . c p p s r c / b u i l t i n s / s e t . c p p
s r c / b u i l t i n s / s e t _ c o l o r . c p p s r c / b u i l t i n s / s o u r c e . c p p s r c / b u i l t i n s / s t a t u s . c p p
s r c / b u i l t i n s / s t r i n g . c p p s r c / b u i l t i n s / t e s t . c p p s r c / b u i l t i n s / t y p e . c p p s r c / b u i l t i n s / u l i m i t . c p p
2021-11-19 19:12:29 -08:00
s r c / b u i l t i n s / w a i t . c p p )
# List of other sources.
set ( FISH_SRCS
2022-04-01 12:05:27 -07:00
s r c / a s t . c p p s r c / a b b r s . c p p s r c / a u t o l o a d . 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 _ d i s p a t c h . 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 d _ m o n i t o r . c p p s r c / f i s h _ v e r s i o n . c p p
2020-07-19 16:07:01 -07:00
s r c / f l o g . c p p s r c / f u n c t i o n . c p p 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 / 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 / h i s t o r y _ f i l e . 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
2022-08-13 12:26:34 -07:00
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 / j o b _ g r o u p . c p p s r c / k i l l . c p p
2020-07-19 16:07:01 -07:00
s r c / n u l l _ t e r m i n a t e d _ a r r a y . c p p s r c / o p e r a t i o n _ c o n t e x t . 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 _ 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
2022-07-09 11:08:27 -07:00
s r c / p r o c . c p p s r c / r e . c p p s r c / r e a d e r . c p p s r c / r e d i r e c t i o n . c p p s r c / s c r e e n . c p p
2020-07-19 16:07:01 -07:00
s r c / s i g n a l . c p p s r c / t e r m s i z e . c p p s r c / t i m e r . c p p s r c / t i n y e x p r . c p p
s r c / t o k e n i z e r . c p p s r c / t o p i c _ m o n i t o r . c p p s r c / t r a c e . c p p s r c / u t f 8 . c p p s r c / u t i l . c p p
2021-05-11 12:01:08 -07:00
s r c / w a i t _ h a n d l e . c p p 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 s r c / f d s . c p p
2017-08-31 13:24:20 -07:00
)
2017-10-04 21:40:58 -07:00
# Header files are just globbed.
2020-03-14 16:11:35 -07:00
file ( GLOB FISH_HEADERS src/*.h )
2017-10-04 21:40:58 -07:00
2017-08-31 13:24:20 -07:00
# Set up config.h
2020-03-14 16:11:35 -07:00
include ( cmake/ConfigureChecks.cmake )
include ( cmake/gettext.cmake )
configure_file ( ${ CMAKE_CURRENT_SOURCE_DIR } /config_cmake.h.in
2017-08-31 13:24:20 -07:00
$ { 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 )
2020-03-14 16:11:35 -07:00
include_directories ( ${ CMAKE_CURRENT_BINARY_DIR } )
2017-08-31 13:24:20 -07:00
# Set up standard directories.
2020-03-14 16:11:35 -07:00
include ( GNUInstallDirs )
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.
2020-03-14 16:11:35 -07:00
include ( Version )
2018-01-08 01:39:45 -08:00
2018-10-13 21:36:59 -05:00
# Let fish pick up when we're running out of the build directory without installing
2020-03-14 16:11:35 -07: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.
2020-03-14 16:11:35 -07:00
set_source_files_properties ( src/fish_version.cpp
2018-01-08 01:39:45 -08:00
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 } )
2019-02-20 13:41:02 -08:00
# Enable thread-safe errno on Solaris (#5611)
2020-03-14 16:11:35 -07:00
add_definitions ( -D_REENTRANT )
2018-03-25 10:19:57 +02:00
2017-10-04 20:31:35 -07:00
# Set up PCRE2
2020-03-14 16:11:35 -07:00
include ( cmake/PCRE2.cmake )
2017-08-31 13:24:20 -07:00
# Define a function to link dependencies.
2020-03-14 16:11:35 -07:00
function ( FISH_LINK_DEPS_AND_SIGN target )
target_link_libraries ( ${ target } fishlib )
codesign_on_mac ( ${ target } )
endfunction ( FISH_LINK_DEPS_AND_SIGN )
2017-08-31 13:24:20 -07:00
2017-10-04 21:33:43 -07:00
# Define libfish.a.
2021-11-19 19:12:29 -08:00
add_library ( fishlib STATIC ${ FISH_SRCS } ${ FISH_BUILTIN_SRCS } )
2020-03-14 16:11:35 -07:00
target_sources ( fishlib PRIVATE ${ FISH_HEADERS } )
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 }
2019-12-20 23:00:06 +08:00
$ { P C R E 2 _ L I B } $ { I n t l _ L I B R A R I E S } $ { A T O M I C _ L I B R A R Y } )
2020-07-21 20:56:12 -07:00
target_include_directories ( fishlib PRIVATE
$ { C U R S E S _ I N C L U D E _ D I R S } )
2017-10-04 21:33:43 -07:00
2017-08-31 13:24:20 -07:00
# Define fish.
2020-03-14 16:11:35 -07:00
add_executable ( fish src/fish.cpp )
fish_link_deps_and_sign ( fish )
2017-08-31 13:24:20 -07:00
2017-09-08 15:19:07 -07:00
# Define fish_indent.
2020-03-14 16:11:35 -07:00
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 )
2020-03-14 16:11:35 -07:00
fish_link_deps_and_sign ( fish_indent )
2017-09-08 15:19:07 -07:00
# Define fish_key_reader.
2020-03-14 16:11:35 -07:00
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 )
2020-03-14 16:11:35 -07:00
fish_link_deps_and_sign ( fish_key_reader )
2017-09-08 15:19:07 -07:00
2019-03-14 13:50:35 -07:00
# Set up the docs.
2020-03-14 16:11:35 -07:00
include ( cmake/Docs.cmake )
2019-03-14 13:50:35 -07:00
2019-04-06 22:22:11 -07:00
# A helper for running tests.
2020-03-14 16:11:35 -07:00
add_executable ( fish_test_helper src/fish_test_helper.cpp )
2019-04-06 22:22:11 -07:00
2017-09-01 00:31:51 -07:00
# Set up tests.
2020-03-14 16:11:35 -07:00
include ( cmake/Tests.cmake )
2017-10-04 20:45:48 -07:00
2019-04-10 14:30:31 -07:00
# Benchmarking support.
2020-03-14 16:11:35 -07:00
include ( cmake/Benchmark.cmake )
2019-04-10 14:30:31 -07:00
2017-10-04 20:45:48 -07:00
# Set up install.
2020-03-14 16:11:35 -07:00
include ( cmake/Install.cmake )
2017-11-13 22:21:54 +08:00
2019-01-25 18:43:52 -08:00
# Mac app.
2020-03-14 16:11:35 -07:00
include ( cmake/MacApp.cmake )
2019-01-25 18:43:52 -08:00
2020-11-23 11:45:37 -08:00
# ThreadSanitizer likes to muck with signal handlers, which interferes
# with fish_test_helper printing the ignored signal mask.
# Ensure fish_test_helper does not use TSan.
# Note the environment var is CXXFLAGS, but the CMake var is CMAKE_CXX_FLAGS.
if ( CMAKE_CXX_FLAGS MATCHES ".*-fsanitize=thread.*" )
target_compile_options ( fish_test_helper PRIVATE "-fno-sanitize=all" )
target_link_libraries ( fish_test_helper "-fno-sanitize=all" )
endif ( )
2019-02-19 21:12:04 +08:00
# Lint targets
# This could be implemented as target properties, but the script has the useful feature of only
# checking the currently-staged commands
# The generator expressions below rebuild the command line for the fishlib targets
# CMake does not support the "iquote" flag - https://gitlab.kitware.com/cmake/cmake/issues/15491
2020-03-14 16:11:35 -07:00
set ( LINT_ARGS "-D$<JOIN:$<TARGET_PROPERTY:fishlib,COMPILE_DEFINITIONS>, -D>" "-I$<JOIN:$<TARGET_PROPERTY:fishlib,INCLUDE_DIRECTORIES>, -I>" )
add_custom_target ( lint
2020-04-01 19:33:31 +03:00
C O M M A N D b u i l d _ t o o l s / l i n t . f i s h - p $ { C M A K E _ B I N A R Y _ D I R } - - $ { L I N T _ A R G S }
2019-02-19 21:12:04 +08:00
W O R K I N G _ D I R E C T O R Y " $ { C M A K E _ S O U R C E _ D I R } "
)
2020-03-14 16:11:35 -07:00
add_custom_target ( lint-all
2020-04-01 19:33:31 +03:00
C O M M A N D b u i l d _ t o o l s / l i n t . f i s h - - a l l - p $ { C M A K E _ B I N A R Y _ D I R } - - $ { L I N T _ A R G S }
2019-02-19 21:12:04 +08:00
W O R K I N G _ D I R E C T O R Y " $ { C M A K E _ S O U R C E _ D I R } "
)
2020-03-14 16:11:35 -07:00
include ( FeatureSummary )
feature_summary ( WHAT ALL )