Skip to content

Commit

Permalink
Merge pull request #307 from LKedward/fix-object-collision
Browse files Browse the repository at this point in the history
Fix: program object file collision
  • Loading branch information
LKedward authored Dec 18, 2020
2 parents c66f052 + a1383a8 commit 483f23b
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 27 deletions.
3 changes: 3 additions & 0 deletions ci/run_tests.bat
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ del /q /f build
%fpm_path% build
if errorlevel 1 exit 1

.\build\gfortran_debug\example\demo-prog
if errorlevel 1 exit 1

.\build\gfortran_debug\app\demo-prog
if errorlevel 1 exit 1

Expand Down
1 change: 1 addition & 0 deletions ci/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ cd ../hello_complex_2

cd ../with_examples
"${f_fpm_path}" build
./build/gfortran_debug/example/demo-prog
./build/gfortran_debug/app/demo-prog

cd ../auto_discovery_off
Expand Down
3 changes: 3 additions & 0 deletions example_packages/with_examples/app/demo-prog.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
program demo
write(*, '(a)') "This is a simple program"
end program demo
2 changes: 1 addition & 1 deletion fpm/fpm.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name = "fpm"
version = "0.1.2"
version = "0.1.3"
license = "MIT"
author = "fpm maintainers"
maintainer = ""
Expand Down
2 changes: 1 addition & 1 deletion fpm/src/fpm_command_line.f90
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ subroutine get_command_line_settings(cmd_settings)
case default ; os_type = "OS Type: UNKNOWN"
end select
version_text = [character(len=80) :: &
& 'Version: 0.1.2, alpha', &
& 'Version: 0.1.3, alpha', &
& 'Program: fpm(1)', &
& 'Description: A Fortran package manager and build system', &
& 'Home Page: https://github.com/fortran-lang/fpm', &
Expand Down
42 changes: 17 additions & 25 deletions fpm/src/fpm_targets.f90
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ subroutine targets_from_sources(model,sources)
type(srcfile_t), intent(in) :: sources(:)

integer :: i
character(:), allocatable :: xsuffix
character(:), allocatable :: xsuffix, exe_dir
type(build_target_t), pointer :: dep
logical :: with_lib

Expand Down Expand Up @@ -99,18 +99,24 @@ subroutine targets_from_sources(model,sources)
source = sources(i) &
)

if (any(sources(i)%unit_scope == [FPM_SCOPE_APP, FPM_SCOPE_EXAMPLE])) then
call add_target(model%targets,type = FPM_TARGET_EXECUTABLE,&
link_libraries = sources(i)%link_libraries, &
output_file = join_path(model%output_directory,'app', &
sources(i)%exe_name//xsuffix))
if (sources(i)%unit_scope == FPM_SCOPE_APP) then

exe_dir = 'app'

else if (sources(i)%unit_scope == FPM_SCOPE_EXAMPLE) then

exe_dir = 'example'

else
call add_target(model%targets,type = FPM_TARGET_EXECUTABLE,&

exe_dir = 'test'

end if

call add_target(model%targets,type = FPM_TARGET_EXECUTABLE,&
link_libraries = sources(i)%link_libraries, &
output_file = join_path(model%output_directory,'test', &
output_file = join_path(model%output_directory,exe_dir, &
sources(i)%exe_name//xsuffix))

end if

! Executable depends on object
call add_dependency(model%targets(size(model%targets))%ptr, model%targets(size(model%targets)-1)%ptr)
Expand Down Expand Up @@ -139,28 +145,14 @@ function get_object_name(source) result(object_file)

object_file = canon_path(source%file_name)

! Ignore first directory level
object_file = object_file(index(object_file,filesep)+1:)

! Convert any remaining directory separators to underscores
i = index(object_file,filesep)
do while(i > 0)
object_file(i:i) = '_'
i = index(object_file,filesep)
end do

select case(source%unit_scope)

case (FPM_SCOPE_APP, FPM_SCOPE_EXAMPLE)
object_file = join_path(model%output_directory,'app',object_file)//'.o'

case (FPM_SCOPE_TEST)
object_file = join_path(model%output_directory,'test',object_file)//'.o'

case default
object_file = join_path(model%output_directory,model%package_name,object_file)//'.o'

end select
object_file = join_path(model%output_directory,model%package_name,object_file)//'.o'

end function get_object_name

Expand Down

0 comments on commit 483f23b

Please sign in to comment.