diff options
author | Brad Richardson <brichardson@structint.com> | 2020-03-31 15:12:50 -0500 |
---|---|---|
committer | Brad Richardson <brichardson@structint.com> | 2020-03-31 15:12:50 -0500 |
commit | 43b28f9559cb4cb3affb1bee7063bf27399c7b31 (patch) | |
tree | 132ac41c7e4a3189cea4c629c48855114d9cd17a | |
parent | cff70a2c97d26e64c65c391ec2121df90196b6cd (diff) | |
download | fpm-43b28f9559cb4cb3affb1bee7063bf27399c7b31.tar.gz fpm-43b28f9559cb4cb3affb1bee7063bf27399c7b31.zip |
Add default for library settings
-rw-r--r-- | app/Main.hs | 13 | ||||
-rw-r--r-- | example_project/fpm.toml | 3 |
2 files changed, 12 insertions, 4 deletions
diff --git a/app/Main.hs b/app/Main.hs index 974c7a6..8d07c40 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -25,6 +25,7 @@ import Options.Applicative ( Parser , progDesc , subparser ) +import System.Directory ( doesDirectoryExist ) import Toml ( TomlCodec , (.=) ) @@ -147,9 +148,19 @@ libraryCodec = Library <$> Toml.text "source-dir" .= librarySourceDir toml2AppSettings :: TomlSettings -> IO AppSettings toml2AppSettings tomlSettings = do + librarySettings <- getLibrarySettings $ tomlSettingsLibrary tomlSettings return AppSettings { appSettingsCompiler = tomlSettingsCompiler tomlSettings , appSettingsProjectName = tomlSettingsProjectName tomlSettings , appSettingsDebugOptions = tomlSettingsDebugOptions tomlSettings - , appSettingsLibrary = tomlSettingsLibrary tomlSettings + , appSettingsLibrary = librarySettings } + +getLibrarySettings :: Maybe Library -> IO (Maybe Library) +getLibrarySettings maybeSettings = case maybeSettings of + Just settings -> return maybeSettings + Nothing -> do + defaultExists <- doesDirectoryExist "src" + if defaultExists + then return (Just (Library { librarySourceDir = "src" })) + else return Nothing diff --git a/example_project/fpm.toml b/example_project/fpm.toml index a8bded7..fae3512 100644 --- a/example_project/fpm.toml +++ b/example_project/fpm.toml @@ -9,9 +9,6 @@ compiler = "gfortran" debug-options = ["-g", "-Wall", "-Wextra", "-Werror", "-pedantic"] release-options = ["-O3"] -[library] - source-dir = "src" - [executables.example_project] main = "main.f90" source-dir = "app" |